-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move column hydratation in a dedicated hook
- Loading branch information
1 parent
0a11d17
commit 22782a0
Showing
6 changed files
with
48 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/grid/x-data-grid/src/hooks/features/columns/useGridColumnGroupingPreProcessors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as React from 'react'; | ||
import { GridPipeProcessor, useGridRegisterPipeProcessor } from '../../core/pipeProcessing'; | ||
import { DataGridProcessedProps } from '../../../models/props/DataGridProps'; | ||
import { GridApiCommunity } from '../../../models/api/gridApiCommunity'; | ||
import { isDeepEqual } from '../../../utils/utils'; | ||
import { unwrapGroupingColumnModel, hasGroupPath } from './useGridColumnGrouping'; | ||
|
||
export const useGridColumnGroupingPreProcessors = ( | ||
apiRef: React.MutableRefObject<GridApiCommunity>, | ||
props: DataGridProcessedProps, | ||
) => { | ||
const addHeaderGroups = React.useCallback<GridPipeProcessor<'hydrateColumns'>>( | ||
(columnsState) => { | ||
if (!props.columnGroupingModel) { | ||
return columnsState; | ||
} | ||
const unwrappedGroupingModel = unwrapGroupingColumnModel(props.columnGroupingModel); | ||
if (Object.keys(unwrappedGroupingModel).length === 0) { | ||
return columnsState; | ||
} | ||
|
||
columnsState.all.forEach((field) => { | ||
const newGroupPath = unwrappedGroupingModel[field] ?? []; | ||
|
||
const lookupElement = columnsState.lookup[field]; | ||
if (hasGroupPath(lookupElement) && isDeepEqual(newGroupPath, lookupElement?.groupPath)) { | ||
// Avoid modifying the pointer to allow shadow comparison in https://github.com/mui/mui-x/blob/f90afbf10a1264ee8b453d7549dd7cdd6110a4ed/packages/grid/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts#L446:L453 | ||
return; | ||
} | ||
columnsState.lookup[field] = { | ||
...columnsState.lookup[field], | ||
groupPath: unwrappedGroupingModel[field] ?? [], | ||
}; | ||
}); | ||
return columnsState; | ||
}, | ||
[props.columnGroupingModel], | ||
); | ||
|
||
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addHeaderGroups); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters