Skip to content

Commit

Permalink
[data grid] GridCellParams.formattedValue should be nullable (mui#4376
Browse files Browse the repository at this point in the history
)
  • Loading branch information
flaviendelangle authored and alexfauquette committed Aug 26, 2022
1 parent 15118e1 commit 753275b
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/data/data-grid/editing/AutoStopEditComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SelectEditInputCell.propTypes = {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: PropTypes.any.isRequired,
value: PropTypes.any,
};

function renderSelectEditInputCell(params) {
Expand Down
3 changes: 2 additions & 1 deletion docs/data/data-grid/filtering/CustomMultiValueOperator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DataGrid,
GridFilterItem,
GridFilterModel,
GridFilterOperator,
} from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';
import SyncIcon from '@mui/icons-material/Sync';
Expand Down Expand Up @@ -85,7 +86,7 @@ function InputNumberInterval(props: GridFilterInputValueProps) {
);
}

const quantityOnlyOperators = [
const quantityOnlyOperators: GridFilterOperator[] = [
{
label: 'Between',
value: 'between',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CustomDetailPanelToggle.propTypes = {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: PropTypes.any.isRequired,
value: PropTypes.any,
};

const columns = [
Expand Down
2 changes: 1 addition & 1 deletion docs/data/data-grid/group-pivot/TreeDataLazyLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ GroupingCellWithLazyLoading.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
hideDescendantCount: PropTypes.bool,
/**
* The grid row id.
Expand Down
28 changes: 14 additions & 14 deletions docs/pages/x/api/data-grid/grid-cell-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import { GridCellParams } from '@mui/x-data-grid';

## Properties

| Name | Type | Description |
| :------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :--------------------------------------------------------------- |
| <span class="prop-name">cellMode</span> | <span class="prop-type">GridCellMode</span> | The mode of the cell. |
| <span class="prop-name">colDef</span> | <span class="prop-type">GridStateColDef</span> | The column of the row that the current cell belongs to. |
| <span class="prop-name">field</span> | <span class="prop-type">string</span> | The column field of the cell that triggered the event. |
| <span class="prop-name">formattedValue</span> | <span class="prop-type">F</span> | The cell value formatted with the column valueFormatter. |
| <span class="prop-name">getValue</span> | <span class="prop-type">(id: GridRowId, field: string) =&gt; any</span> | Get the cell value of a row and field. |
| <span class="prop-name">hasFocus</span> | <span class="prop-type">boolean</span> | If true, the cell is the active element. |
| <span class="prop-name">id</span> | <span class="prop-type">GridRowId</span> | The grid row id. |
| <span class="prop-name optional">isEditable<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | If true, the cell is editable. |
| <span class="prop-name">row</span> | <span class="prop-type">GridRowModel&lt;R&gt;</span> | The row model of the row that the current cell belongs to. |
| <span class="prop-name">rowNode</span> | <span class="prop-type">GridRowTreeNodeConfig</span> | The node of the row that the current cell belongs to. |
| <span class="prop-name">tabIndex</span> | <span class="prop-type">0 \| -1</span> | the tabIndex value. |
| <span class="prop-name">value</span> | <span class="prop-type">V \| undefined</span> | The cell value, but if the column has valueGetter, use getValue. |
| Name | Type | Description |
| :----------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :--------------------------------------------------------------- |
| <span class="prop-name">cellMode</span> | <span class="prop-type">GridCellMode</span> | The mode of the cell. |
| <span class="prop-name">colDef</span> | <span class="prop-type">GridStateColDef</span> | The column of the row that the current cell belongs to. |
| <span class="prop-name">field</span> | <span class="prop-type">string</span> | The column field of the cell that triggered the event. |
| <span class="prop-name optional">formattedValue<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">F \| undefined</span> | The cell value formatted with the column valueFormatter. |
| <span class="prop-name">getValue</span> | <span class="prop-type">(id: GridRowId, field: string) =&gt; any</span> | Get the cell value of a row and field. |
| <span class="prop-name">hasFocus</span> | <span class="prop-type">boolean</span> | If true, the cell is the active element. |
| <span class="prop-name">id</span> | <span class="prop-type">GridRowId</span> | The grid row id. |
| <span class="prop-name optional">isEditable<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">boolean</span> | If true, the cell is editable. |
| <span class="prop-name">row</span> | <span class="prop-type">GridRowModel&lt;R&gt;</span> | The row model of the row that the current cell belongs to. |
| <span class="prop-name">rowNode</span> | <span class="prop-type">GridRowTreeNodeConfig</span> | The node of the row that the current cell belongs to. |
| <span class="prop-name">tabIndex</span> | <span class="prop-type">0 \| -1</span> | the tabIndex value. |
| <span class="prop-name optional">value<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">V \| undefined</span> | The cell value, but if the column has valueGetter, use getValue. |
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GridDetailPanelToggleCell.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
/**
* Get the cell value of a row and field.
* @param {GridRowId} id The row id.
Expand Down Expand Up @@ -114,7 +114,7 @@ GridDetailPanelToggleCell.propTypes = {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: PropTypes.any.isRequired,
value: PropTypes.any,
} as any;

export { GridDetailPanelToggleCell };
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ GridTreeDataGroupingCell.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
/**
* Get the cell value of a row and field.
* @param {GridRowId} id The row id.
Expand Down Expand Up @@ -154,7 +154,7 @@ GridTreeDataGroupingCell.propTypes = {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: PropTypes.any.isRequired,
value: PropTypes.any,
} as any;

export { GridTreeDataGroupingCell };
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ GridEditInputCell.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
/**
* Get the cell value of a row and field.
* @param {GridRowId} id The row id.
Expand Down Expand Up @@ -164,6 +164,7 @@ GridEditInputCell.propTypes = {
} as any;

export { GridEditInputCell };

export const renderEditInputCell: GridColDef['renderEditCell'] = (params) => (
<GridEditInputCell {...params} />
);
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ GridEditSingleSelectCell.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
/**
* Get the cell value of a row and field.
* @param {GridRowId} id The row id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ GridCellCheckboxForwardRef.propTypes = {
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any.isRequired,
formattedValue: PropTypes.any,
/**
* Get the cell value of a row and field.
* @param {GridRowId} id The row id.
Expand Down Expand Up @@ -169,7 +169,7 @@ GridCellCheckboxForwardRef.propTypes = {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: PropTypes.any.isRequired,
value: PropTypes.any,
} as any;

export { GridCellCheckboxForwardRef };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export const useGridCellEditing = (
}

let editingState = gridEditRowsStateSelector(apiRef.current.state);
let newProps = { ...editingState[id][field], value: parsedValue };
let newProps: GridEditCellProps = { ...editingState[id][field], value: parsedValue };

if (column.preProcessEditCellProps) {
const hasChanged = value !== editingState[id][field].value;
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/x-data-grid/src/models/gridEditRowModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface GridEditCellProps<V = any> {
value: V | undefined;
value?: V | undefined;
isValidating?: boolean;
isProcessingProps?: boolean;
[prop: string]: any;
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-data-grid/src/models/params/gridCellParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export interface GridCellParams<V = any, R extends GridValidRowModel = any, F =
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: V | undefined;
value?: V | undefined;
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: F;
formattedValue?: F | undefined;
/**
* The row model of the row that the current cell belongs to.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
GridFilterInputValue,
GridFilterInputValueProps,
GridPreferencePanelsValue,
GridFilterItem,
} from '@mui/x-data-grid';
// @ts-ignore Remove once the test utils are typed
import { createRenderer, fireEvent, screen, waitFor } from '@mui/monorepo/test/utils';
Expand Down Expand Up @@ -52,7 +51,7 @@ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
describe('<DataGrid /> - Filter panel', () => {
const { render } = createRenderer();

const baselineProps = {
const baselineProps: DataGridProps = {
autoHeight: isJSDOM,
disableVirtualization: true,
rows: [
Expand Down Expand Up @@ -96,15 +95,15 @@ describe('<DataGrid /> - Filter panel', () => {
},
{
value: 'equals',
getApplyFilterFn: (filterItem: GridFilterItem) => {
getApplyFilterFn: (filterItem) => {
if (!filterItem.value) {
return null;
}
const collator = new Intl.Collator(undefined, {
sensitivity: 'base',
usage: 'search',
});
return ({ value }: { value: any }): boolean => {
return ({ value }): boolean => {
return collator.compare(filterItem.value, (value && value.toString()) || '') === 0;
};
},
Expand Down

0 comments on commit 753275b

Please sign in to comment.