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] Unify filtering / sorting / pagination / rows selectors #2942

Merged
merged 21 commits into from
Oct 26, 2021

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Oct 22, 2021

Some of those breaking change were needed for the Tree Data (especially the migration from a Map to a clean array structure for the selectors).
After this PR, the Tree Data should have no breaking change, I removed the rest from the v5 millestone.

The only selectors without the grid prefix are now the selectors of useGridColumns but I want to keep this PR focused on the selectors of the rows lifecycle.

New behavior

  • The selectors are always prefixed by grid
  • The features applied to a selector are indicated in the selector name in their application order (ex: gridSortedRowIds => gridVisibleSortedRowIds => gridPaginatedVisibleSortedRowIds)
  • The selector never creates a map if it is not usefull in our own codebase (we were creating maps and then turning them back into arrays to use them internally), instead we now have 2 types of selectors for the rows gridXXXRowIds and gridXXXRowEntries.
  • Do not create 100% trivial selector like createSelector(someSelector, val => val.length), this increase the public API surface for no real value

I did not change the signature of the API functions, but I don't find relevant to return a map in getVisibleRowModels.

Breaking changes

Selectors

Rows

// Rename
-unorderedGridRowIdsSelector
+gridRowIdsSelector

// Removed
// You can `apiRef.current.getRowModels` for the pro version
// Or `gridRowIdsSelector` and `gridRowsLookupSelector` for the free version
-unorderedGridRowModelsSelector: (state: GridState) => GridRowModel[];

Sorting

// Rename
-sortingGridStateSelector
+gridSortingStateSelector

// Rename
-sortedGridRowIdsSelector
+gridSortedRowIdsSelector

// Rename + behavior change
// You can rebuild the Map yourself
-sortedGridRowsSelector: (state: GridState) => Map<GridRowId, GridRowModel>
+gridSortedRowEntriesSelector: (state: GridState) => GridRowEntry[]

-const map = sortedGridRowsSelector(state);
+const map = new Map(gridSortedRowEntriesSelector(state).map(row => [row.id, row.model]));

Filter

// Rename + behavior change
// Migrating from the old format should be trivial
-visibleSortedGridRowsAsArraySelector: (state: GridState) => [GridRowId, GridRowData][];
+gridVisibleSortedRowEntriesSelector: (state: GridState) => GridRowEntry[]

// Rename + behavior change
// You can use `apiRef.current.getVisibleRowModels` for the pro version
// Or you can rebuild the Map yourself for the free version
-visibleSortedGridRowsSelector: (state: GridState) => Map<GridRowId, GridRowModel>;
+gridVisibleSortedRowEntriesSelector: (state: GridState) => GridRowEntry[]

-const map = visibleSortedGridRowsSelector(state);
+const map = new Map(gridVisibleSortedRowEntriesSelector(state).map(row => [row.id, row.model]));

// Rename
-visibleSortedGridRowIdsSelector
+gridVisibleSortedRowIdsSelector

// Rename
-visibleGridRowCountSelector
+gridVisibleRowCountSelector
+gridVisibleTopLevelRowCountSelector

// Rename
-filterGridColumnLookupSelector
+gridFilterActiveItemsLookupSelector

// Rename
-activeGridFilterItemsSelector
+gridFilterActiveItemsSelector

// Remove
// You can use gridFilterActiveItemsSelector instead
- filterGridItemsCounterSelector

-const filterCount = filterGridItemsCounterSelector(state);
+const filterCount = gridFilterActiveItemsSelector(state).length;

@flaviendelangle flaviendelangle added the component: data grid This is the name of the generic UI component, not the React module! label Oct 22, 2021
@flaviendelangle flaviendelangle added this to the v5 stable version milestone Oct 22, 2021
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 22, 2021
@github-actions
Copy link

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

@flaviendelangle flaviendelangle marked this pull request as ready for review October 22, 2021 11:55
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 22, 2021
@flaviendelangle flaviendelangle merged commit d1d0793 into mui:next Oct 26, 2021
@flaviendelangle flaviendelangle deleted the selector-prepare-tree-data branch October 26, 2021 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants