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

[DataGrid] Fix undefined slot values #10934

Merged
merged 2 commits into from
Nov 8, 2023
Merged

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Nov 7, 2023

Closes #10933

Allow passing undefined as a slot value.

@romgrk romgrk added the component: data grid This is the name of the generic UI component, not the React module! label Nov 7, 2023
@romgrk romgrk enabled auto-merge (squash) November 7, 2023 18:40
@romgrk romgrk changed the base branch from next to master November 7, 2023 18:41
@mui-bot
Copy link

mui-bot commented Nov 7, 2023

Deploy preview: https://deploy-preview-10934--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 1ad08e4

@romgrk romgrk disabled auto-merge November 7, 2023 18:43
Comment on lines +21 to +30
const result = { ...defaultSlots };
Object.keys(overrides).forEach((key) => {
const k = key as keyof typeof overrides;

if (overrides[k] !== undefined) {
result[k] = overrides[k] as any;
}
});

return result;
Copy link

@scamden scamden Nov 7, 2023

Choose a reason for hiding this comment

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

thanks for the fix! little bit less boilerplatey suggestion if you want:

Suggested change
const result = { ...defaultSlots };
Object.keys(overrides).forEach((key) => {
const k = key as keyof typeof overrides;
if (overrides[k] !== undefined) {
result[k] = overrides[k] as any;
}
});
return result;
return {
...defaultSlots,
...Object.fromEntries(Object.entries(overrides).filter([k] => k !== undefined))
}

Copy link
Contributor Author

@romgrk romgrk Nov 7, 2023

Choose a reason for hiding this comment

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

Doesn't seem equivalent. overrides needs to be used. And the result needs to be set to the default slot unless an override is provided.

Copy link

Choose a reason for hiding this comment

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

updated to be correct :)

Copy link

Choose a reason for hiding this comment

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

Object.fromEntries(Object.entries(overrides).filter(fn) is basically just a pickBy pattern, so if you all have lodash or a similar util you could reduce this code even a little bit further

@cherniavskii cherniavskii added the bug 🐛 Something doesn't work label Nov 7, 2023
@romgrk romgrk merged commit 35f9dd9 into mui:master Nov 8, 2023
6 checks passed
@romgrk romgrk deleted the fix-undefined-slot branch November 8, 2023 00:12
@romgrk romgrk restored the fix-undefined-slot branch November 8, 2023 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoRowsOverlay slot throws when passed undefined but types allow it
4 participants