Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] Fix column definition undefined value #14456

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/x-data-grid-pro/src/tests/filtering.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,26 @@ describe('<DataGridPro /> - Filter', () => {
expect(getColumnHeaderCell(0, 1).textContent).to.equal('Custom Input');
});

it('should not cause unexpected behavior when props are explictly set to undefined', () => {
expect(() => {
render(
<TestCase
columns={[
{
field: 'actions',
headerName: 'Actions',
type: 'actions',
width: 80,
filterOperators: undefined,
getActions: () => [<React.Fragment>action</React.Fragment>],
},
]}
headerFilters
/>,
);
}).not.toErrorDev();
});

// See https://github.com/mui/mui-x/issues/13217
it('should not throw when custom filter operator is used with an initilaized value', () => {
expect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import resolveProps from '@mui/utils/resolveProps';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to be noted that this helper handles a few properties differently, so to be careful with it.

Copy link
Contributor Author

@sai6855 sai6855 Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is custom code if slots or components or slotsProps or componentsProps are passed.

https://github.com/mui/material-ui/blob/e13f1c9e37aa986624dddc44c19325d5bd97f455/packages/mui-utils/src/resolveProps/resolveProps.ts#L26

https://github.com/mui/material-ui/blob/e13f1c9e37aa986624dddc44c19325d5bd97f455/packages/mui-utils/src/resolveProps/resolveProps.ts#L21

Looks like CI has passed without any failed tests. So i'm expecting using resolveProps would be OK.

import {
GridColumnLookup,
GridColumnsState,
Expand Down Expand Up @@ -379,11 +380,7 @@ export const createColumnsState = ({
}
});

columnsState.lookup[field] = {
...existingState,
...newColumn,
hasBeenResized,
};
columnsState.lookup[field] = resolveProps(existingState, { ...newColumn, hasBeenResized });
});

if (keepOnlyColumnsToUpsert && !isInsideStateInitializer) {
Expand Down