-
Notifications
You must be signed in to change notification settings - Fork 9
POC: Generic way of making Grid rows editable #4934
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
base: main
Are you sure you want to change the base?
Conversation
e9cef4f to
4394bf9
Compare
4394bf9 to
a3f5dbd
Compare
| actionsCell: GridColDef; | ||
| }; | ||
|
|
||
| export const useEditGridRow = (): UseEditGridRowReturn => { |
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.
Do we need this new hook? It seems to me that the only "new" code is opening the detail page in the on click handler. The rest looks like the code we already generate? What's you motivation for this hook?
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.
Do we need this new hook?
Not necessarily but it seems to me like a hook is easier than writing (copy-pasting) all that code into every grid.
It seems to me that the only "new" code is opening the detail page in the on click handler.
True, the rest (except for the aria-label) can be generated by the admin-generator.
What's you motivation for this hook?
- Less code for non-generated grids: All three returned values would have to be done manually
- A consistent Edit-Button: devs can't forget the aria-label or the correct color or render a less accessible
<button />instead of theStackLink(<a />)
| const handleDataGridRowClick: GridEventListener<"rowClick"> = (params, event) => { | ||
| const shouldOpenLinkInNewTab = event.ctrlKey || event.metaKey; | ||
|
|
||
| if (shouldOpenLinkInNewTab) { | ||
| const url = stackSwitchApi.getTargetUrl("edit", params.row.id); | ||
| window.open(url, "_blank"); | ||
| return; | ||
| } | ||
|
|
||
| stackSwitchApi.activatePage("edit", params.row.id); | ||
| }; |
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.
This is something the Admin Generator could generate.
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.
We also need a solution for non-generated grids. I think whenever implementing this manually, devs won't always think of adding the shouldOpenLinkInNewTab logic.
I'm not sure if this is a good idea since it breaks other features like sorting and filtering. |
|
Isn't this issue (two actions with overlapping tap targets) solvable using different z-indices? 🤔 |
No, when multiple nested elements have an |
This shouldn't be an issue if we go with the |
johnnyomair
left a comment
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 data grid's primary action may not always be edit. For instance, in the cron jobs module, the primary action is to start a cron job (now that I think of it, it's probably no good idea to start the cron job on row click 😅). Maybe we should go with a useDataGridPrimaryAction approach instead?
We should discuss this in the next Comet JFX.
I'm not sure if further extending/changing the grid column definition is a good idea. This moves Comet further away from MUI, making it IMO more confusing. |
TLDR
Allow editing rows of a DataGrid by clicking on the row directly, in addition to the edit button.
Add tests to make sure clicking in interactive cells does not trigger the edit-action.
This adds a new hook
useEditGridRowThe hook returns the following:
handleDataGridRowClick: the function to be passed toonRowClickof the DataGrid to allow editing the row by clicking anywhere in the row.EditIconButton: The IconButton that should be rendered in theactionscell, which is used to edit the row. This should be used when other, additional actions should be rendered inside the actions cell.actionsCellthe full actions-cell that includes theEditIconButton, this should be used when the actions-cell should include only the edit button.onRowClickandEditIconButtonintentionally do not share a functionThe IconButton uses
StackLinkto render an actual link (<a href="..." />), which is preferred due to it's default accessibility behavior, e.g. usingcmd+click/ctrl+clickor the system context-menu to open the link in a new tab.DataGrid does not support an actual link for it's row-click, therefore we must use a function here.
This function manually adds support for
cmd+click/ctrl+clickto open the link in a new tab, as this is likely a common use-case. Other accessibility-features of link are not supported when clicking the row.Interactive elements within a cell
If the
onRowClickprop is set, clicking anywhere within a cell will trigger this function.To avoid this, we manually set
type: "actions"on every interactive cell, the same as we already do in the cell that includes "edit" and other icon-buttons.Negatives of using
type: "actions"type: "actions", will therefore trigger the function instead of allowing the interactiontype: "actions"on all custom columns by default, as they will likely often be interactive anyway.onRowClickon generated grids, if they include custom columns (at least until V9)type: "actions"will not be sortable or filterable by defaultsortable: trueandfilterable: truevisibleor filter bydescriptionAlternative to
type: "actions"We could wrap the content of each
renderCellwith an element that doesevent.stopPropagation()when clicked.We could also possibly abstract this away by adding an
interactive: trueflag toGridColDef.interactive: trueon every interactive columnonRowClickwhen clicking within the cell but not on the interactive part, e.g. 1px next to thevisibleselectScreenshots/screencasts
Simple.grid.mov
Grid.with.interactive.cells.mov
Open TODOs
onRowClickis set #4933Questions
useEditGridRowin@comet/admin?type: "actions"vs.InteractiveCellWrappervs.interactive: trueflagFollow-up tasks
useEditGridRowfrom@comet/adminand use it in these storiesuseEditGridRowin Admin-Generator in a way that won't break custom interactive cells (maybe settype: "actions"by default on all custom cells)If we go with
type: "actions":type: "actions"If we go with
InteractiveCellWrapperorinteractive: true:@comet/adminFurther information