-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Added a guard for reorder cells #11159
[DataGrid] Added a guard for reorder cells #11159
Conversation
@@ -277,8 +277,11 @@ const GridRow = React.forwardRef<HTMLDivElement, GridRowProps>(function GridRow( | |||
'width' | 'colSpan' | 'showRightBorder' | 'indexRelativeToAllColumns' | |||
>, | |||
) => { | |||
const isReorderCell = column.field === '__reorder__'; |
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 whole condition is way to complex and hard to read.
IMHO it should be a full method or at list a variable assignment.
It was already too complex before your addition though 😬
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.
thats true (😛) ... I'll check if I can extract that into a helper
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.
OK, I did look around a bit.
mui-x/packages/grid/x-data-grid/src/components/GridRow.tsx
Lines 280 to 285 in 891cea1
const disableDragEvents = | |
(disableColumnReorder && column.disableReorder) || | |
(!rowReordering && | |
!!sortModel.length && | |
treeDepth > 1 && | |
Object.keys(editRowsState).length > 0); |
Is basically duplicated in the drag handlers. That seems a bit weird.
My proposal would be to allow the drag events to being published, but handle the event execution like before.
For reference the row reorder handles it here:
mui-x/packages/grid/x-data-grid-pro/src/hooks/features/rowReorder/useGridRowReorder.tsx
Lines 75 to 77 in 891cea1
const isRowReorderDisabled = React.useMemo((): boolean => { | |
return !props.rowReordering || !!sortModel.length || treeDepth !== 1; | |
}, [props.rowReordering, sortModel, treeDepth]); |
And the column reorder here:
mui-x/packages/grid/x-data-grid-pro/src/hooks/features/columnReorder/useGridColumnReorder.tsx
Lines 88 to 90 in 891cea1
if (props.disableColumnReorder || params.colDef.disableReorder) { | |
return; | |
} |
I would still keep the disableDragEvents
variable for this case:
const disableDragEvents = Object.keys(editRowsState).length > 0;
@flaviendelangle WDYT?
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 can make sense
I'll let @cherniavskii validate because my knowledge of the codebase is rusted.
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.
Adding some context on why we disable drag handlers: #4841
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.
Since disabling the dragEvents is beneficial (thanks for pointing that out @cherniavskii) I just renamed and restructured it a tiny bit to make it more readable at least.
Deploy preview: https://deploy-preview-11159--material-ui-x.netlify.app/ |
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.
Seems like some of the changes above broke a few tests
@cherniavskii fixed (finally 😅 ) |
const isEditingRows = Object.keys(editRowsState).length > 0; | ||
|
||
const canReorderColumn = !(disableColumnReorder || column.disableReorder); | ||
const canReorderRow = rowReordering || !sortModel.length || treeDepth <= 1 || isEditingRows; |
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 this expression correct? I would expect it to be:
const canReorderRow = rowReordering && !sortModel.length && treeDepth <= 1 && !isEditingRows;
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.
nice catch ... it was working like this as well ... but the cases where it shouldn't be working did work as well, so that would have been bad! Thanks for catching that!
Prevents
disableColumnReorder
prop from disabling dragevents on the reorder cell.Fixes #11126