-
-
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.
[DataGrid] Extract
getRowId
API method as a selector (#16574)
- Loading branch information
1 parent
c505f40
commit 91d461d
Showing
31 changed files
with
133 additions
and
41 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { GridStateCommunity } from '../../models/gridStateCommunity'; | ||
import type { GridRowId, GridRowModel } from '../../models/gridRows'; | ||
import { GRID_ID_AUTOGENERATED } from '../features/rows/gridRowsUtils'; | ||
|
||
/** | ||
* Get the row id for a given row | ||
* @param state - The grid state | ||
* @param {GridRowModel} row - The row to get the id for | ||
* @returns {GridRowId} The row id | ||
*/ | ||
export const gridRowIdSelector = <State extends GridStateCommunity>( | ||
state: State, | ||
row: GridRowModel, | ||
): GridRowId => { | ||
if (GRID_ID_AUTOGENERATED in row) { | ||
return row[GRID_ID_AUTOGENERATED]; | ||
} | ||
return state.props.getRowId ? state.props.getRowId(row) : row.id; | ||
}; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export type { GridPipeProcessingLookup } from './pipeProcessing'; | ||
export { gridRowIdSelector } from './gridPropsSelectors'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react'; | ||
import type { RefObject } from '@mui/x-internals/types'; | ||
import type { DataGridProps } from '../../models/props/DataGridProps'; | ||
import type { GridPrivateApiCommon } from '../../models/api/gridApiCommon'; | ||
import type { GridStateInitializer } from '../utils/useGridInitializeState'; | ||
|
||
type Props = Pick<DataGridProps, 'getRowId'>; | ||
|
||
export const propsStateInitializer: GridStateInitializer<Props> = (state, props) => { | ||
return { | ||
...state, | ||
props: { | ||
getRowId: props.getRowId, | ||
}, | ||
}; | ||
}; | ||
|
||
export const useGridProps = <PrivateApi extends GridPrivateApiCommon>( | ||
apiRef: RefObject<PrivateApi>, | ||
props: Props, | ||
) => { | ||
React.useEffect(() => { | ||
apiRef.current.setState((state) => ({ | ||
...state, | ||
props: { | ||
getRowId: props.getRowId, | ||
}, | ||
})); | ||
}, [apiRef, props.getRowId]); | ||
}; |
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
Oops, something went wrong.