-
-
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] Add props to control cell mode #4210
Conversation
These are the results for the performance tests:
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
147b297
to
0107caf
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
9e6016a
to
1e331dd
Compare
```tsx | ||
// Changes the mode of field=name from row with id=1 to "edit" | ||
<DataGrid | ||
cellModesModel={{ 1: { name: { mode: GridCellModes.Edit } } }} |
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.
It doesn't look good because of PrismJS/prism#1548
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.
Agree, I found the same Prisma issue.
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.
What use case are we trying to cover with this control mode ?
I understand the technical part but I struggle to understand why people might need it.
@flaviendelangle In the legacy API, there's the |
Is it supposed to support multiple cells being edited at the same time? Screen.Recording.2022-04-07.at.18.06.17.mov |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
Is the feature designed to have multiple cells in edit mode?
If yes, perhaps we should have an example for that too.
Each cell and row has two modes: `edit` and `view`. | ||
You can control the active mode using the props `cellModesModel` and `rowModesModel` (only works if `editMode="row"`). | ||
|
||
The `cellModesModel` prop accepts an object where the key corresponds to the row ID containing the cell whose mode will be changed. |
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'm wondering if we could exchange this whole paragraph, and simplify the description of the expected object by displaying the expected interface or a sample code.
The `cellModesModel` prop accepts an object where the key corresponds to the row ID containing the cell whose mode will be changed. | |
The `cellModesModel` prop accepts an object as the following: | |
```tsx | |
{ | |
rowId: { fieldName: { mode: GridCellModes.Edit | GridCellModes.View }}; | |
} | |
``` | |
You can find a practical example below. |
We can let the following example complement and confirm the usage of the feature's API.
What do you think?
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.
The problem is that this interface suggested is not TS and the code will not be properly formatted. The correct interface would be
export type GridCellModesModelProps =
| ({ mode: GridCellModes.View } & Omit<GridStopCellEditModeParams, 'id' | 'field'>)
| ({ mode: GridCellModes.Edit } & Omit<GridStartCellEditModeParams, 'id' | 'field'>);
export type GridCellModesModel = Record<GridRowId, Record<string, GridCellModesModelProps>>;
export type GridRowModesModelProps =
| ({ mode: GridRowModes.View } & Omit<GridStopRowEditModeParams, 'id' | 'field'>)
| ({ mode: GridRowModes.Edit } & Omit<GridStartRowEditModeParams, 'id' | 'field'>);
export type GridRowModesModel = Record<GridRowId, GridRowModesModelProps>;
but it doesn't make any sense.
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.
Yeah. that interface is not really helpful in explaining it :).
Can we use jsx on this case to display the "template" object?
I think the paragraph describing the object is a bit convoluted. I tried simplifying it, but I don't think it's enough because the object itself is hard to explain while keeping the description accurate.
The `cellModesModel` prop accepts an object where the key corresponds to the row ID containing the cell whose mode will be changed. | |
The `cellModesModel` prop accepts an object containing the `mode` (and additional options) for a given column field, in a given row, as in the following example. | |
The options accepted are the same available in apiRef.current.startCellEditMode and apiRef.current.stopCellEditMode. |
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 applied the suggestion. We can only use JSX on JavaScript code. I think the example with the comments explain well the shape of the object.
@joserodolfofreitas It's not the main purpose, since |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
It looks good to go 👌 (dx and doc-wise)
I've added links to referenced sections explaining the accepted options.
You can control the active mode using the props `cellModesModel` and `rowModesModel` (only works if `editMode="row"`). | ||
|
||
The `cellModesModel` prop accepts an object containing the `mode` (and additional options) for a given column field, in a given row, as in the following example. | ||
The options accepted are the same available in `apiRef.current.startCellEditMode` and `apiRef.current.stopCellEditMode`. |
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.
The options accepted are the same available in `apiRef.current.startCellEditMode` and `apiRef.current.stopCellEditMode`. | |
The options accepted are the same available in `[apiRef.current.startCellEditMode](#start-editing)` and `[apiRef.current.stopCellEditMode](#stop-editing)`. |
``` | ||
|
||
For row editing, the `rowModesModel` props work in a similar manner. | ||
The options accepted are the same available in `apiRef.current.startRowEditMode` and `apiRef.current.stopRowEditMode`. |
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.
The options accepted are the same available in `apiRef.current.startRowEditMode` and `apiRef.current.stopRowEditMode`. | |
The options accepted are the same available in `[apiRef.current.startRowEditMode](#start-editing)` and `[apiRef.current.stopRowEditMode](#stop-editing)`. |
Preview: https://deploy-preview-4210--material-ui-x.netlify.app/x/react-data-grid/editing/#controlled-mode
This PR adds props to start or stop the edit mode of a cell/row. The following props were added:
cellModesModel
rowModesModel
onCellModesModelChange
onRowModesModelChange
Different from other controllable states, here we don't react simply when the prop value changes. It has to change but also the
mode
needs to be different from the previous mode. These props work by storing the params that we should pass tostartXXXEditMode
andstopXXXEditMode
when the mode is changed. For the implementation, I created a parallel state variable only to track the params. Now we havestate.editRows
, which tracks the props for the edit cells, and the state variable storing the params. I didn't merge both states because I don't want to recreate the model when, for exampe, only the value changes. To react to changes in the model, I moved everything fromstartXXXEditMode
andstopXXXEditMode
to helper methodsupdateStateToStartXXXEditMode
andupdateStateToStopXXXEditMode
. The role of the public API methods now is to only update the model.