Skip to content

Commit

Permalink
[core] Replace usage of GridRowData with GridRowModel (#2936)
Browse files Browse the repository at this point in the history
* [core] Replace usage of GridRowData with GridRowModel

* api build
  • Loading branch information
flaviendelangle authored Oct 22, 2021
1 parent dfc581c commit c9ace58
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/data-grid/grid-col-def.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GridColDef } from '@mui/x-data-grid';
| <span class="prop-name optional">disableExport<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | <span class="prop-default">false<br /></span> | If `true`, this column will not be included in exports. |
| <span class="prop-name optional">disableReorder<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | <span class="prop-default">false<br /></span> | If `true`, this column cannot be reordered. |
| <span class="prop-name optional">editable<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | <span class="prop-default">false<br /></span> | If `true`, the cells of the column are editable. |
| <span class="prop-name">field</span> | <span class="prop-type">string</span> | | The column identifier. It's used to map with GridRowData values. |
| <span class="prop-name">field</span> | <span class="prop-type">string</span> | | The column identifier. It's used to map with GridRowModel values. |
| <span class="prop-name optional">filterable<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | <span class="prop-default">true<br /></span> | If `true`, the column is filterable. |
| <span class="prop-name optional">filterOperators<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">GridFilterOperator[]</span> | | Allows setting the filter operators for this column. |
| <span class="prop-name optional">flex<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">number</span> | | If set, it indicates that a column has fluid width. Range [0, ∞). |
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/data-grid/columns/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Grid columns are defined with the `columns` prop.
`columns` expects an array of objects.
The columns should have this type: `GridColDef[]`.

`field` is the only required property since it's the column identifier. It's also used to match with `GridRowData` values.
`field` is the only required property since it's the column identifier. It's also used to match with `GridRowModel` values.

```ts
interface GridColDef {
/**
* The column identifier. It's used to match with [[GridRowData]] values.
* The column identifier. It's used to match with [[GridRowModel]] values.
*/
field: string;
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/data-grid/rows/rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ title: Data Grid - Rows

Grid rows can be defined with the `rows` prop.
`rows` expects an array of objects.
Rows should have this type: `GridRowData[]`.
The columns' "field" property should match a key of the row object (`GridRowData`).
Rows should have this type: `GridRowModel[]`.
The columns' "field" property should match a key of the row object (`GridRowModel`).

{{"demo": "pages/components/data-grid/rows/RowsGrid.js", "bg": "inline"}}

Expand Down
2 changes: 1 addition & 1 deletion packages/grid/_modules_/grid/GridComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ interface GridComponentOtherProps {
*/
error?: any;
/**
* Return the id of a given [[GridRowData]].
* Return the id of a given [[GridRowModel]].
*/
getRowId?: GridRowIdGetter;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/_modules_/grid/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses } from '@mui/material';
import { GridEvents } from '../constants/eventsConstants';
import { GridRowId, GridRowData } from '../models/gridRows';
import { GridRowId, GridRowModel } from '../models/gridRows';
import { GridEditModes, GridRowModes, GridEditRowsModel } from '../models/gridEditRowModel';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { getDataGridUtilityClass, gridClasses } from '../gridClasses';
Expand All @@ -23,7 +23,7 @@ export interface GridRowProps {
index: number;
rowHeight: number;
containerWidth: number;
row: GridRowData;
row: GridRowModel;
firstColumnToRender: number;
lastColumnToRender: number;
visibleColumns: GridStateColDef[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
GridRowId,
GridRowsProp,
GridRowIdGetter,
GridRowData,
} from '../../../models/gridRows';
import { useGridApiMethod } from '../../utils/useGridApiMethod';
import { useGridLogger } from '../../utils/useGridLogger';
Expand All @@ -29,12 +28,12 @@ export interface GridRowsInternalCache {
}

function getGridRowId(
rowData: GridRowData,
rowModel: GridRowModel,
getRowId?: GridRowIdGetter,
detailErrorMessage?: string,
): GridRowId {
const id = getRowId ? getRowId(rowData) : rowData.id;
checkGridRowIdIsValid(id, rowData, detailErrorMessage);
const id = getRowId ? getRowId(rowModel) : rowModel.id;
checkGridRowIdIsValid(id, rowModel, detailErrorMessage);
return id;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/grid/_modules_/grid/models/colDef/gridColDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type GridAlignment = 'left' | 'right' | 'center';
*/
export interface GridColDef {
/**
* The column identifier. It's used to map with [[GridRowData]] values.
* The column identifier. It's used to map with [[GridRowModel]] values.
*/
field: string;
/**
Expand Down
10 changes: 5 additions & 5 deletions packages/grid/_modules_/grid/models/gridRows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type GridRowsProp = Readonly<GridRowData[]>;
export type GridRowsProp = Readonly<GridRowModel[]>;

/**
* @deprecated prefer GridRowModel.
Expand All @@ -12,7 +12,7 @@ export type GridRowModel<T = { [key: string]: any }> = T;

export type GridUpdateAction = 'delete';

export interface GridRowModelUpdate extends GridRowData {
export interface GridRowModelUpdate extends GridRowModel {
_action?: GridUpdateAction;
}

Expand All @@ -38,15 +38,15 @@ export type GridRowsLookup = Record<GridRowId, GridRowModel>;
export type GridRowId = string | number;

/**
* The function to retrieve the id of a [[GridRowData]].
* The function to retrieve the id of a [[GridRowModel]].
*/
export type GridRowIdGetter = (row: GridRowData) => GridRowId;
export type GridRowIdGetter = (row: GridRowModel) => GridRowId;

/**
* An helper function to check if the id provided is valid.
*
* @param {GridRowId} id Id as [[GridRowId]].
* @param {GridRowModel | Partial<GridRowModel>} row Row as [[GridRowData]].
* @param {GridRowModel | Partial<GridRowModel>} row Row as [[GridRowModel]].
* @param {string} detailErrorMessage A custom error message to display for invalid IDs
*/
export function checkGridRowIdIsValid(
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/data-grid/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ DataGridRaw.propTypes = {
*/
getRowClassName: PropTypes.func,
/**
* Return the id of a given [[GridRowData]].
* Return the id of a given [[GridRowModel]].
*/
getRowId: PropTypes.func,
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/x-grid/src/DataGridPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ DataGridProRaw.propTypes = {
*/
getRowClassName: PropTypes.func,
/**
* Return the id of a given [[GridRowData]].
* Return the id of a given [[GridRowModel]].
*/
getRowId: PropTypes.func,
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-grid/src/tests/rows.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getCell, getRow, getColumnValues } from 'test/utils/helperFn';
import {
GridApiRef,
GridComponentProps,
GridRowData,
GridRowModel,
useGridApiRef,
DataGridPro,
DataGridProProps,
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('<DataGridPro /> - Rows', () => {
it('update row data should process getRowId', () => {
const TestCaseGetRowId = () => {
apiRef = useGridApiRef();
const getRowId = React.useCallback((row: GridRowData) => row.idField, []);
const getRowId = React.useCallback((row: GridRowModel) => row.idField, []);
return (
<div style={{ width: 300, height: 300 }}>
<DataGridPro
Expand Down
4 changes: 2 additions & 2 deletions packages/storybook/src/stories/grid-rows.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GridEditRowsModel,
GridLoadIcon,
GridColDef,
GridRowData,
GridRowModel,
useGridApiRef,
DataGridPro,
GridEvents,
Expand Down Expand Up @@ -93,7 +93,7 @@ export function NoId() {
}
export function CommodityNewRowId() {
const { data } = useDemoData({ dataSet: 'Commodity', rowLength: 100 });
const getRowId = React.useCallback((row: GridRowData) => `${row.desk}-${row.commodity}`, []);
const getRowId = React.useCallback((row: GridRowModel) => `${row.desk}-${row.commodity}`, []);
return (
<div className="grid-container">
<DataGridPro
Expand Down

0 comments on commit c9ace58

Please sign in to comment.