From f5dcc9d5119ba738cd2f72eb8cc1d331ceccb94a Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Mon, 18 Mar 2024 16:04:06 +0500 Subject: [PATCH 1/6] [DataGrid] Make rows an optional prop --- docs/pages/x/api/data-grid/data-grid-premium.json | 5 +---- docs/pages/x/api/data-grid/data-grid-pro.json | 5 +---- docs/pages/x/api/data-grid/data-grid.json | 5 +---- .../src/DataGridPremium/DataGridPremium.tsx | 3 ++- .../x-data-grid-pro/src/DataGridPro/DataGridPro.tsx | 3 ++- packages/x-data-grid/src/DataGrid/DataGrid.tsx | 3 ++- packages/x-data-grid/src/DataGrid/useDataGridProps.ts | 1 + .../x-data-grid/src/models/props/DataGridProps.ts | 11 ++++++----- 8 files changed, 16 insertions(+), 20 deletions(-) diff --git a/docs/pages/x/api/data-grid/data-grid-premium.json b/docs/pages/x/api/data-grid/data-grid-premium.json index 559aa75b2e3f..8f51c4920df7 100644 --- a/docs/pages/x/api/data-grid/data-grid-premium.json +++ b/docs/pages/x/api/data-grid/data-grid-premium.json @@ -4,10 +4,6 @@ "type": { "name": "arrayOf", "description": "Array<object>" }, "required": true }, - "rows": { - "type": { "name": "arrayOf", "description": "Array<object>" }, - "required": true - }, "aggregationFunctions": { "type": { "name": "object" }, "default": "GRID_AGGREGATION_FUNCTIONS" @@ -557,6 +553,7 @@ "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, "rowReordering": { "type": { "name": "bool" }, "default": "false" }, + "rows": { "type": { "name": "array" }, "default": "[]" }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/docs/pages/x/api/data-grid/data-grid-pro.json b/docs/pages/x/api/data-grid/data-grid-pro.json index 198c5f68c6da..d377c3adf998 100644 --- a/docs/pages/x/api/data-grid/data-grid-pro.json +++ b/docs/pages/x/api/data-grid/data-grid-pro.json @@ -4,10 +4,6 @@ "type": { "name": "arrayOf", "description": "Array<object>" }, "required": true }, - "rows": { - "type": { "name": "arrayOf", "description": "Array<object>" }, - "required": true - }, "apiRef": { "type": { "name": "shape", "description": "{ current: object }" } }, "aria-label": { "type": { "name": "string" } }, "aria-labelledby": { "type": { "name": "string" } }, @@ -495,6 +491,7 @@ "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, "rowReordering": { "type": { "name": "bool" }, "default": "false" }, + "rows": { "type": { "name": "array" }, "default": "[]" }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/docs/pages/x/api/data-grid/data-grid.json b/docs/pages/x/api/data-grid/data-grid.json index 468423143dd7..4b56fa6c33a2 100644 --- a/docs/pages/x/api/data-grid/data-grid.json +++ b/docs/pages/x/api/data-grid/data-grid.json @@ -4,10 +4,6 @@ "type": { "name": "arrayOf", "description": "Array<object>" }, "required": true }, - "rows": { - "type": { "name": "arrayOf", "description": "Array<object>" }, - "required": true - }, "apiRef": { "type": { "name": "shape", "description": "{ current: object }" } }, "aria-label": { "type": { "name": "string" } }, "aria-labelledby": { "type": { "name": "string" } }, @@ -411,6 +407,7 @@ "rowHeight": { "type": { "name": "number" }, "default": "52" }, "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, + "rows": { "type": { "name": "array" }, "default": "[]" }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx index a411583a776c..b61c1a370021 100644 --- a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx +++ b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx @@ -926,8 +926,9 @@ DataGridPremiumRaw.propTypes = { rowReordering: PropTypes.bool, /** * Set of rows of type [[GridRowsProp]]. + * @default [] */ - rows: PropTypes.arrayOf(PropTypes.object).isRequired, + rows: PropTypes.array, /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx b/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx index 55bae2609179..0e483790cb6a 100644 --- a/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx +++ b/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx @@ -818,8 +818,9 @@ DataGridProRaw.propTypes = { rowReordering: PropTypes.bool, /** * Set of rows of type [[GridRowsProp]]. + * @default [] */ - rows: PropTypes.arrayOf(PropTypes.object).isRequired, + rows: PropTypes.array, /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid/src/DataGrid/DataGrid.tsx b/packages/x-data-grid/src/DataGrid/DataGrid.tsx index 475dc646e981..451530908598 100644 --- a/packages/x-data-grid/src/DataGrid/DataGrid.tsx +++ b/packages/x-data-grid/src/DataGrid/DataGrid.tsx @@ -680,8 +680,9 @@ DataGridRaw.propTypes = { rowPositionsDebounceMs: PropTypes.number, /** * Set of rows of type [[GridRowsProp]]. + * @default [] */ - rows: PropTypes.arrayOf(PropTypes.object).isRequired, + rows: PropTypes.array, /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid/src/DataGrid/useDataGridProps.ts b/packages/x-data-grid/src/DataGrid/useDataGridProps.ts index b0f91d49cf29..7ad7b8c7b205 100644 --- a/packages/x-data-grid/src/DataGrid/useDataGridProps.ts +++ b/packages/x-data-grid/src/DataGrid/useDataGridProps.ts @@ -33,6 +33,7 @@ export const DATA_GRID_PROPS_DEFAULT_VALUES: DataGridPropsWithDefaultValues = { checkboxSelectionVisibleOnly: false, columnBuffer: 3, rowBuffer: 3, + rows: [], columnThreshold: 3, rowThreshold: 3, rowSelection: true, diff --git a/packages/x-data-grid/src/models/props/DataGridProps.ts b/packages/x-data-grid/src/models/props/DataGridProps.ts index 90c2b031ccbe..8c84b732d412 100644 --- a/packages/x-data-grid/src/models/props/DataGridProps.ts +++ b/packages/x-data-grid/src/models/props/DataGridProps.ts @@ -105,7 +105,7 @@ export interface DataGridPropsWithComplexDefaultValueBeforeProcessing { * The controlled model do not have a default value at the prop processing level, so they must be defined in `DataGridOtherProps` * TODO: add multiSortKey */ -export interface DataGridPropsWithDefaultValues { +export interface DataGridPropsWithDefaultValues { /** * If `true`, the Data Grid height is dynamic and follow the number of rows in the Data Grid. * @default false @@ -290,6 +290,11 @@ export interface DataGridPropsWithDefaultValues { * @default "client" */ paginationMode: GridFeatureMode; + /** + * Set of rows of type [[GridRowsProp]]. + * @default [] + */ + rows?: GridRowsProp; /** * Sets the height in pixel of a row in the Data Grid. * @default 52 @@ -728,10 +733,6 @@ export interface DataGridPropsWithoutDefaultValue; /** * The initial state of the DataGrid. * The data in it will be set in the state on initialization but will not be controlled. From b2d068d39140952f362de70573e428638c353d91 Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Mon, 18 Mar 2024 16:21:30 +0500 Subject: [PATCH 2/6] A few type issues fixed --- packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx | 2 +- packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts | 4 ++-- packages/x-data-grid/src/hooks/features/rows/useGridRows.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx index ece96b663e62..3652411e30dc 100644 --- a/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx +++ b/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx @@ -27,7 +27,7 @@ import { useBasicDemoData, getBasicGridData } from '@mui/x-data-grid-generator'; const isJSDOM = /jsdom/.test(window.navigator.userAgent); describe(' - Rows', () => { - let baselineProps: DataGridProProps; + let baselineProps: DataGridProProps & { rows: GridRowModel[] }; const { clock, render } = createRenderer({ clock: 'fake' }); diff --git a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts index a2704b611c8e..e5d2dacfa520 100644 --- a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts +++ b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts @@ -93,8 +93,8 @@ export const createRowsInternalCache = ({ const dataRowIdToModelLookup: GridRowIdToModelLookup = {}; const dataRowIdToIdLookup: GridRowIdToIdLookup = {}; - for (let i = 0; i < rows.length; i += 1) { - const model = rows[i]; + for (let i = 0; i < rows!.length; i += 1) { + const model = rows![i]; const id = getRowIdFromRowModel(model, getRowId); dataRowIdToModelLookup[id] = model; dataRowIdToIdLookup[id] = id; diff --git a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts index f9001be7054b..f9eebf588628 100644 --- a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts +++ b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts @@ -629,7 +629,7 @@ export const useGridRows = ( return; } - logger.debug(`Updating all rows, new length ${props.rows.length}`); + logger.debug(`Updating all rows, new length ${props.rows!.length}`); throttledRowsChange({ cache: createRowsInternalCache({ rows: props.rows, From 050278b34912f15640dbeff4cf968a64fcf8ab25 Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Mon, 18 Mar 2024 19:36:54 +0500 Subject: [PATCH 3/6] spec test updates --- packages/x-data-grid/src/tests/DataGrid.spec.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/x-data-grid/src/tests/DataGrid.spec.tsx b/packages/x-data-grid/src/tests/DataGrid.spec.tsx index c82da0c7f74e..24dafbcce571 100644 --- a/packages/x-data-grid/src/tests/DataGrid.spec.tsx +++ b/packages/x-data-grid/src/tests/DataGrid.spec.tsx @@ -59,9 +59,7 @@ function RowEditingProps() { function RowPropTest() { return (
- {/* @ts-expect-error */} rows={[{ firstName: 2 }]} columns={[]} />; - {/* @ts-expect-error */} rows={[{}]} columns={[]} />; rows={[{ firstName: 'John' }]} columns={[]} />; ; @@ -114,16 +112,12 @@ function ColumnPropTest() { columns={[ { field: 'firstName', - // @ts-expect-error valueGetter: (value, row) => row.lastName, - // @ts-expect-error valueParser: (value, row) => row!.lastName, valueSetter: (value, row) => { - // @ts-expect-error const lastName = row.lastName; return {} as any; }, - // @ts-expect-error renderCell: (params) => params.row.lastName, }, ]} From 969b50753d58dba02bf89a3f54dd48c8fa25cef2 Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Tue, 19 Mar 2024 19:24:17 +0500 Subject: [PATCH 4/6] Remove expect-error statements --- packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx | 1 - packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx b/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx index 8f76012552ef..87f2af79ef7a 100644 --- a/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx +++ b/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx @@ -31,7 +31,6 @@ function ColumnPropTest() { columns={[ { field: 'firstName', - // @ts-expect-error groupingValueGetter: (value, row) => row.lastName, }, ]} diff --git a/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx b/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx index 381641537a0e..9676b1653a6d 100644 --- a/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx +++ b/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx @@ -35,7 +35,6 @@ function ColumnPropTest() { columns={[ { field: 'firstName', - // @ts-expect-error valueGetter: (value, row) => row.lastName, }, ]} From f7e14e4e2f33552616cf331f99f3ca339eb8024e Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Tue, 19 Mar 2024 21:48:05 +0500 Subject: [PATCH 5/6] Revert unnecessary changes --- packages/x-data-grid/src/models/props/DataGridProps.ts | 4 ++-- packages/x-data-grid/src/tests/DataGrid.spec.tsx | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/x-data-grid/src/models/props/DataGridProps.ts b/packages/x-data-grid/src/models/props/DataGridProps.ts index 8c84b732d412..233876009dcf 100644 --- a/packages/x-data-grid/src/models/props/DataGridProps.ts +++ b/packages/x-data-grid/src/models/props/DataGridProps.ts @@ -45,7 +45,7 @@ export interface GridExperimentalFeatures { * The props users can give to the `DataGrid` component. */ export type DataGridProps = Omit< - Partial & + Partial> & DataGridPropsWithComplexDefaultValueBeforeProcessing & DataGridPropsWithoutDefaultValue, DataGridForcedPropsKey @@ -294,7 +294,7 @@ export interface DataGridPropsWithDefaultValues; + rows: GridRowsProp; /** * Sets the height in pixel of a row in the Data Grid. * @default 52 diff --git a/packages/x-data-grid/src/tests/DataGrid.spec.tsx b/packages/x-data-grid/src/tests/DataGrid.spec.tsx index 24dafbcce571..c82da0c7f74e 100644 --- a/packages/x-data-grid/src/tests/DataGrid.spec.tsx +++ b/packages/x-data-grid/src/tests/DataGrid.spec.tsx @@ -59,7 +59,9 @@ function RowEditingProps() { function RowPropTest() { return (
+ {/* @ts-expect-error */} rows={[{ firstName: 2 }]} columns={[]} />; + {/* @ts-expect-error */} rows={[{}]} columns={[]} />; rows={[{ firstName: 'John' }]} columns={[]} />; ; @@ -112,12 +114,16 @@ function ColumnPropTest() { columns={[ { field: 'firstName', + // @ts-expect-error valueGetter: (value, row) => row.lastName, + // @ts-expect-error valueParser: (value, row) => row!.lastName, valueSetter: (value, row) => { + // @ts-expect-error const lastName = row.lastName; return {} as any; }, + // @ts-expect-error renderCell: (params) => params.row.lastName, }, ]} From 93c00495246e9647128173629789635891d804ea Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Tue, 19 Mar 2024 22:39:51 +0500 Subject: [PATCH 6/6] Updates --- docs/pages/x/api/data-grid/data-grid-premium.json | 5 ++++- docs/pages/x/api/data-grid/data-grid-pro.json | 5 ++++- docs/pages/x/api/data-grid/data-grid.json | 5 ++++- .../src/DataGridPremium/DataGridPremium.tsx | 2 +- .../x-data-grid-premium/src/models/dataGridPremiumProps.ts | 5 +++-- .../x-data-grid-premium/src/tests/DataGridPremium.spec.tsx | 1 + packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx | 2 +- packages/x-data-grid-pro/src/models/dataGridProProps.ts | 7 ++++--- packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx | 1 + .../x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx | 3 ++- packages/x-data-grid/src/DataGrid/DataGrid.tsx | 2 +- .../x-data-grid/src/hooks/features/rows/gridRowsUtils.ts | 4 ++-- .../x-data-grid/src/hooks/features/rows/useGridRows.ts | 2 +- 13 files changed, 29 insertions(+), 15 deletions(-) diff --git a/docs/pages/x/api/data-grid/data-grid-premium.json b/docs/pages/x/api/data-grid/data-grid-premium.json index 8f51c4920df7..cecb2e305f5d 100644 --- a/docs/pages/x/api/data-grid/data-grid-premium.json +++ b/docs/pages/x/api/data-grid/data-grid-premium.json @@ -553,7 +553,10 @@ "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, "rowReordering": { "type": { "name": "bool" }, "default": "false" }, - "rows": { "type": { "name": "array" }, "default": "[]" }, + "rows": { + "type": { "name": "arrayOf", "description": "Array<object>" }, + "default": "[]" + }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/docs/pages/x/api/data-grid/data-grid-pro.json b/docs/pages/x/api/data-grid/data-grid-pro.json index d377c3adf998..6d68af9fc832 100644 --- a/docs/pages/x/api/data-grid/data-grid-pro.json +++ b/docs/pages/x/api/data-grid/data-grid-pro.json @@ -491,7 +491,10 @@ "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, "rowReordering": { "type": { "name": "bool" }, "default": "false" }, - "rows": { "type": { "name": "array" }, "default": "[]" }, + "rows": { + "type": { "name": "arrayOf", "description": "Array<object>" }, + "default": "[]" + }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/docs/pages/x/api/data-grid/data-grid.json b/docs/pages/x/api/data-grid/data-grid.json index 4b56fa6c33a2..395e0c667778 100644 --- a/docs/pages/x/api/data-grid/data-grid.json +++ b/docs/pages/x/api/data-grid/data-grid.json @@ -407,7 +407,10 @@ "rowHeight": { "type": { "name": "number" }, "default": "52" }, "rowModesModel": { "type": { "name": "object" } }, "rowPositionsDebounceMs": { "type": { "name": "number" }, "default": "166" }, - "rows": { "type": { "name": "array" }, "default": "[]" }, + "rows": { + "type": { "name": "arrayOf", "description": "Array<object>" }, + "default": "[]" + }, "rowSelection": { "type": { "name": "bool" }, "default": "true" }, "rowSelectionModel": { "type": { diff --git a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx index b61c1a370021..efebedb9ad4d 100644 --- a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx +++ b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx @@ -928,7 +928,7 @@ DataGridPremiumRaw.propTypes = { * Set of rows of type [[GridRowsProp]]. * @default [] */ - rows: PropTypes.array, + rows: PropTypes.arrayOf(PropTypes.object), /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid-premium/src/models/dataGridPremiumProps.ts b/packages/x-data-grid-premium/src/models/dataGridPremiumProps.ts index ee3b030e670e..ebba8956e323 100644 --- a/packages/x-data-grid-premium/src/models/dataGridPremiumProps.ts +++ b/packages/x-data-grid-premium/src/models/dataGridPremiumProps.ts @@ -38,7 +38,7 @@ export interface DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing */ export interface DataGridPremiumProps extends Omit< - Partial & + Partial> & DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing & DataGridPremiumPropsWithoutDefaultValue, DataGridPremiumForcedPropsKey @@ -64,7 +64,8 @@ export type DataGridPremiumForcedPropsKey = 'signature'; * None of the entry of this interface should be optional, they all have default values and `DataGridProps` already applies a `Partial` for the public interface. * The controlled model do not have a default value at the prop processing level, so they must be defined in `DataGridOtherProps`. */ -export interface DataGridPremiumPropsWithDefaultValue extends DataGridProPropsWithDefaultValue { +export interface DataGridPremiumPropsWithDefaultValue + extends DataGridProPropsWithDefaultValue { /** * If `true`, the cell selection mode is enabled. * @default false diff --git a/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx b/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx index 87f2af79ef7a..8f76012552ef 100644 --- a/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx +++ b/packages/x-data-grid-premium/src/tests/DataGridPremium.spec.tsx @@ -31,6 +31,7 @@ function ColumnPropTest() { columns={[ { field: 'firstName', + // @ts-expect-error groupingValueGetter: (value, row) => row.lastName, }, ]} diff --git a/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx b/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx index 0e483790cb6a..33d4c05d99b1 100644 --- a/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx +++ b/packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx @@ -820,7 +820,7 @@ DataGridProRaw.propTypes = { * Set of rows of type [[GridRowsProp]]. * @default [] */ - rows: PropTypes.array, + rows: PropTypes.arrayOf(PropTypes.object), /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid-pro/src/models/dataGridProProps.ts b/packages/x-data-grid-pro/src/models/dataGridProProps.ts index de56c3be465e..e7425e47b4ac 100644 --- a/packages/x-data-grid-pro/src/models/dataGridProProps.ts +++ b/packages/x-data-grid-pro/src/models/dataGridProProps.ts @@ -41,7 +41,7 @@ interface DataGridProPropsWithComplexDefaultValueBeforeProcessing */ export interface DataGridProProps extends Omit< - Partial & + Partial> & DataGridProPropsWithComplexDefaultValueBeforeProcessing & DataGridProPropsWithoutDefaultValue, DataGridProForcedPropsKey @@ -56,7 +56,7 @@ interface DataGridProPropsWithComplexDefaultValueAfterProcessing * The props of the `DataGridPro` component after the pre-processing phase. */ export interface DataGridProProcessedProps - extends DataGridProPropsWithDefaultValue, + extends DataGridProPropsWithDefaultValue, DataGridProPropsWithComplexDefaultValueAfterProcessing, Omit, 'componentsProps'> {} @@ -67,7 +67,8 @@ export type DataGridProForcedPropsKey = 'signature'; * None of the entry of this interface should be optional, they all have default values and `DataGridProps` already applies a `Partial` for the public interface * The controlled model do not have a default value at the prop processing level, so they must be defined in `DataGridOtherProps` */ -export interface DataGridProPropsWithDefaultValue extends DataGridPropsWithDefaultValues { +export interface DataGridProPropsWithDefaultValue + extends DataGridPropsWithDefaultValues { /** * Set the area in `px` at the bottom of the grid viewport where onRowsScrollEnd is called. * @default 80 diff --git a/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx b/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx index 9676b1653a6d..381641537a0e 100644 --- a/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx +++ b/packages/x-data-grid-pro/src/tests/DataGridPro.spec.tsx @@ -35,6 +35,7 @@ function ColumnPropTest() { columns={[ { field: 'firstName', + // @ts-expect-error valueGetter: (value, row) => row.lastName, }, ]} diff --git a/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx index 3652411e30dc..0de05978e3e4 100644 --- a/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx +++ b/packages/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx @@ -21,13 +21,14 @@ import { GridApi, gridFocusCellSelector, gridClasses, + GridValidRowModel, } from '@mui/x-data-grid-pro'; import { useBasicDemoData, getBasicGridData } from '@mui/x-data-grid-generator'; const isJSDOM = /jsdom/.test(window.navigator.userAgent); describe(' - Rows', () => { - let baselineProps: DataGridProProps & { rows: GridRowModel[] }; + let baselineProps: DataGridProProps & { rows: GridValidRowModel }; const { clock, render } = createRenderer({ clock: 'fake' }); diff --git a/packages/x-data-grid/src/DataGrid/DataGrid.tsx b/packages/x-data-grid/src/DataGrid/DataGrid.tsx index 451530908598..b3c1f3a3e940 100644 --- a/packages/x-data-grid/src/DataGrid/DataGrid.tsx +++ b/packages/x-data-grid/src/DataGrid/DataGrid.tsx @@ -682,7 +682,7 @@ DataGridRaw.propTypes = { * Set of rows of type [[GridRowsProp]]. * @default [] */ - rows: PropTypes.array, + rows: PropTypes.arrayOf(PropTypes.object), /** * If `false`, the row selection mode is disabled. * @default true diff --git a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts index e5d2dacfa520..a2704b611c8e 100644 --- a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts +++ b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts @@ -93,8 +93,8 @@ export const createRowsInternalCache = ({ const dataRowIdToModelLookup: GridRowIdToModelLookup = {}; const dataRowIdToIdLookup: GridRowIdToIdLookup = {}; - for (let i = 0; i < rows!.length; i += 1) { - const model = rows![i]; + for (let i = 0; i < rows.length; i += 1) { + const model = rows[i]; const id = getRowIdFromRowModel(model, getRowId); dataRowIdToModelLookup[id] = model; dataRowIdToIdLookup[id] = id; diff --git a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts index f9eebf588628..f9001be7054b 100644 --- a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts +++ b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts @@ -629,7 +629,7 @@ export const useGridRows = ( return; } - logger.debug(`Updating all rows, new length ${props.rows!.length}`); + logger.debug(`Updating all rows, new length ${props.rows.length}`); throttledRowsChange({ cache: createRowsInternalCache({ rows: props.rows,