Skip to content
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] Allows keyboard navigation in group header #5947

Merged
merged 28 commits into from
Oct 18, 2022

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Aug 29, 2022

Preview: https://deploy-preview-5947--material-ui-x.netlify.app/x/react-data-grid/column-groups/

The structure column group structure was shared between columns definitions and the columnGroups state.

In this PR I move the column.groupPath which contains the list of the group parent into a method unstable_getColumnGroupPath(field) ANd the all group header structure is saved in the state. The idea being to simplify query such as "What is the group on the left of the focused one" and later on for groups drag and drop: "What are the children of their dragged group and the children of the drop group"

@alexfauquette alexfauquette added the feature: Column groups Related to the data grid Column groups feature label Aug 29, 2022
@mui-bot
Copy link

mui-bot commented Aug 29, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 500.6 788.2 721.8 661.56 120.799
Sort 100k rows ms 550.5 1,172.4 550.5 888.56 216.606
Select 100k rows ms 156.5 272.9 229.7 228.64 42.071
Deselect 100k rows ms 146.1 221.8 181.7 182.3 28.532

Generated by 🚫 dangerJS against 72f6024

@alexfauquette alexfauquette self-assigned this Aug 29, 2022
@github-actions
Copy link

github-actions bot commented Sep 1, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 1, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 7, 2022
@alexfauquette alexfauquette changed the base branch from master to next September 9, 2022 12:15
@alexfauquette alexfauquette marked this pull request as ready for review September 9, 2022 12:15
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 12, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 15, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 26, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Member

@DanailH DanailH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! The only thing I would consider adding is a check if a column header doesn't have content (it's empty) not to be able to navigate in it. Idk how difficult lit would be tho.

});
}, [apiRef, props.columnGroupingModel]);

useGridApiEventHandler(apiRef, 'columnOrderChange', handleColumnReorderChange);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be handled in the useGridColumnReorder hook?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because the useGridColumnReorder trigger the event, then other hooks listen to it, like the useGridcolumnSpanning, or useGridcolumnPinning which already listen tot this event to recompute their state

Did you had a specific idea in mind like performance impact for putting the logic in the useGridColumnReorder?

@@ -103,15 +48,6 @@ const createGroupLookup = (columnGroupingModel: GridColumnNode[]): GridColumnGro

return { ...groupLookup };
};
export const columnGroupsStateInitializer: GridStateInitializer<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be lost but does this mean that the groups are no longer persisted in the state? Shouldn't we initialize an empty columnGrouping state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear for me when an initializer is necessary. I thaught it was used to initialise the state before pipe processors are called.

Since column grouping is not used by any processors, I removed the initialization. But if it's needed for other purpose, I can bring initializer back

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main purpose of the state initializers was to allow the state to be initialized synchronously before any feature hook. Later, we had to also initialize them before any pre-processor. You can delete the state initializer and have the feature working normally. The React.useEffect in this hook will take care of initializing the state, but it will happen asynchronously now. This will only be a problem if another hook depends on the state of the column grouping.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since the state is reused by columnReorder and columnHeader I put back the initializer

@alexfauquette
Copy link
Member Author

@DanailH It was my first it do not navigate to empty cell but then comes the question about where does the focus go. And their is no obvious answer to that, so I looked at other libraries, and they just let navigate in empty column group. For example AG grid column group

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I didn't thing any bug related to keyboard navigation, although I noticed a small problem when the user hides a column in https://deploy-preview-5947--material-ui-x.netlify.app/x/react-data-grid/column-groups/.

msedge_dJb50P4sDK.mp4

I can't reproduce it in https://docs-next--material-ui-x.netlify.app/x/react-data-grid/column-groups/ so it propabily was added in this PR.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 5, 2022
@alexfauquette
Copy link
Member Author

@m4theushw the bug is fixed by this commit I was rendering all the column groups between the first and last columns to render. Now I remove groups that have all their columns hidden

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 10, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 11, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 15, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 17, 2022
@alexfauquette alexfauquette merged commit 955179e into mui:next Oct 18, 2022
@alexfauquette alexfauquette deleted the keyboard-column-group branch October 18, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: Column groups Related to the data grid Column groups feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants