-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 calling onCellEditStop on error #12747
Changes from 1 commit
928a846
1f6d3ae
2652319
9c183ab
dbc474e
a887256
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -234,6 +234,42 @@ export const useGridCellEditing = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[apiRef], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const runIfNoPreProcessError = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Args extends any[]>(callback?: (...args: Args) => void) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async (...args: Args) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { field, id, value, debounceMs, unstable_skipValueParser: skipValueParser } = args[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const column = apiRef.current.getColumn(field); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const row = apiRef.current.getRow(id)!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let parsedValue = value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (column.valueParser && !skipValueParser) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
parsedValue = column.valueParser(value, row, column, apiRef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const editingState = gridEditRowsStateSelector(apiRef.current.state); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let newProps: GridEditCellProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...editingState[id][field], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value: parsedValue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (column.preProcessEditCellProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const hasChanged = value !== editingState[id][field].value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
newProps = { ...newProps, isProcessingProps: true }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire logic was copied from mui-x/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts Lines 449 to 478 in aed8aeb
Thought of storing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't aware of that PR. Now I've updated code to use similar approach as in #11383. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
newProps = await Promise.resolve( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
column.preProcessEditCellProps({ id, row, props: newProps, hasChanged }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!newProps.error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback(...args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiEventHandler(apiRef, 'cellDoubleClick', runIfEditModeIsCell(handleCellDoubleClick)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiEventHandler(apiRef, 'cellFocusOut', runIfEditModeIsCell(handleCellFocusOut)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiEventHandler(apiRef, 'cellKeyDown', runIfEditModeIsCell(handleCellKeyDown)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -242,7 +278,7 @@ export const useGridCellEditing = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiEventHandler(apiRef, 'cellEditStop', runIfEditModeIsCell(handleCellEditStop)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiOptionHandler(apiRef, 'cellEditStart', props.onCellEditStart); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiOptionHandler(apiRef, 'cellEditStop', props.onCellEditStop); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useGridApiOptionHandler(apiRef, 'cellEditStop', runIfNoPreProcessError(props.onCellEditStop)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const getCellMode = React.useCallback<GridCellEditingApi['getCellMode']>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(id, field) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
Nitpick: better type safety