-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] getCellAggregationResult
: handle null rowNode case
#9915
Conversation
packages/grid/x-data-grid-premium/src/hooks/features/aggregation/wrapColumnWithAggregation.tsx
Show resolved
Hide resolved
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9915--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that
!
often ends up causing bugs down the line. I wonder if there is a set of rules we could enfore for its usage that would protect us more from bugs.
Agreed we should reduce its usage where possible, one justified use is when we set a default value for a function argument but TS infers it to be possibly null
or undefined.
Should we enable this rule? |
Thanks for fixing this! Quick question: how can I find which version this change is released in so I can bump the package.json in our client app? |
We release each week at the end of the week. Unreleased yet. |
Sounds good. Thanks again for the fix! |
I think there is one case where using I don't know how this rule behaves, but I think it would be great to retain this In the case of this PR, how is it possible for |
Since #9037, |
@romgrk I had a quick look at the error to wrap my head around what's going on. The root issue I can find is different. As far as I can see, the error happens when getCellAggregationResult is called with an Why is the id undefined? This seems to solve this issue: diff --git a/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/wrapColumnWithAggregation.tsx b/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/wrapColumnWithAggregation.tsx
index d724dcd49..6f0b91b22 100644
--- a/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/wrapColumnWithAggregation.tsx
+++ b/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/wrapColumnWithAggregation.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import { GridColDef, GridFilterOperator, GridRowId } from '@mui/x-data-grid-pro';
import { GridBaseColDef, tagInternalFilter } from '@mui/x-data-grid-pro/internals';
+import { GRID_ID_AUTOGENERATED } from '@mui/x-data-grid/internals';
import { GridApiPremium } from '../../../models/gridApiPremium';
import {
GridAggregationCellMeta,
@@ -154,7 +155,8 @@ const getWrappedFilterOperators: ColumnPropertyWrapper<'filterOperators'> = ({
return null;
}
return (value, row, column, api) => {
- if (getCellAggregationResult(row.id, column.field) != null) {
+ const id = GRID_ID_AUTOGENERATED in row ? row[GRID_ID_AUTOGENERATED] : row.id;
+ if (getCellAggregationResult(id, column.field) != null) {
return true;
}
return filterFn(value, row, column, api);
@@ -203,10 +205,7 @@ export const wrapColumnWithAggregationValue = ({
field: string,
): GridAggregationLookup[GridRowId][string] | null => {
let cellAggregationPosition: GridAggregationPosition | null = null;
- const rowNode = apiRef.current.getRowNode(id);
- if (!rowNode) {
- return null;
- }
+ const rowNode = apiRef.current.getRowNode(id)!;
if (rowNode.type === 'group') {
cellAggregationPosition = 'inline'; |
Ah, good catch. I think we also need to add |
Closes #9876
Remove a
!
and handle the null case.I find that
!
often ends up causing bugs down the line. I wonder if there is a set of rules we could enfore for its usage that would protect us more from bugs.Before: https://codesandbox.io/s/frosty-burnell-smdsgs?file=/Demo.tsx
After: https://codesandbox.io/s/vibrant-wu-c9gjj7?file=/Demo.tsx