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] Filtering performance: V7 API #9254

Merged
merged 46 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fb1ea84
perf: v7 filters
romgrk Jun 7, 2023
9830c58
lint
romgrk Jun 7, 2023
9608d9d
fix: aggregation filtering
romgrk Jun 7, 2023
fad4bb2
lint
romgrk Jun 7, 2023
030f2a5
fix: some tests
romgrk Jun 7, 2023
1b063cb
Merge branch 'master' into perf-filtering-v7-filters
romgrk Jun 9, 2023
64ba858
fix: some tests
romgrk Jun 9, 2023
2c4d970
fix: rows list
romgrk Jun 9, 2023
40e05b4
fix: quickfilter
romgrk Jun 9, 2023
c24143a
lint
romgrk Jun 9, 2023
e8a8aec
lint
romgrk Jun 9, 2023
a7483b4
lint
romgrk Jun 9, 2023
6fd694f
lint
romgrk Jun 9, 2023
d1be29a
fix: restore column fields
romgrk Jun 12, 2023
3e0a6bc
Merge branch 'master' into perf-filtering-v7-filters
romgrk Jun 14, 2023
b04cb1e
refactor
romgrk Jun 14, 2023
f7cb7b6
docs
romgrk Jun 14, 2023
9fdbe9a
lint
romgrk Jun 14, 2023
5706be9
doc: update
romgrk Jun 14, 2023
3a084e6
doc
romgrk Jun 14, 2023
03e6cd8
Update docs/data/data-grid/filtering/customization.md
romgrk Jun 14, 2023
c66cd40
Update docs/data/data-grid/filtering/customization.md
romgrk Jun 14, 2023
adc8027
fix: missed v7 refactor
romgrk Jun 14, 2023
6223641
Merge branch 'perf-filtering-v7-filters' of github.com:romgrk/mui-x i…
romgrk Jun 14, 2023
f7b30d4
refactor: typings
romgrk Jun 14, 2023
f7b19c6
lint
romgrk Jun 14, 2023
6f5fb73
lint
romgrk Jun 14, 2023
c285417
Merge branch 'master' into perf-filtering-v7-filters
romgrk Jun 20, 2023
1372ed9
refactor: compatibility changes
romgrk Jun 20, 2023
08a3223
doc: update
romgrk Jun 20, 2023
d59889f
lint
romgrk Jun 20, 2023
5c26f45
lint
romgrk Jun 20, 2023
343c385
lint
romgrk Jun 20, 2023
c9146f5
lint
romgrk Jun 21, 2023
dca10c7
fix: quickfilter compatibility
romgrk Jun 21, 2023
cde04ba
lint
romgrk Jun 21, 2023
ff9d602
Update packages/grid/x-data-grid/src/models/api/gridParamsApi.ts
romgrk Jun 21, 2023
441ee98
Update packages/grid/x-data-grid/src/models/api/gridParamsApi.ts
romgrk Jun 21, 2023
3eb9812
lint
romgrk Jun 28, 2023
2dda132
refactor
romgrk Jun 28, 2023
725139e
test: add v7 compat
romgrk Jun 28, 2023
2c6f402
Merge branch 'perf-filtering-v7-filters' of github.com:romgrk/mui-x i…
romgrk Jun 28, 2023
0af6482
test: add v7 qf tests
romgrk Jun 28, 2023
3cbac8f
lint
romgrk Jun 28, 2023
52482e5
lint
romgrk Jun 28, 2023
ffa0250
docs: api
romgrk Jun 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: v7 filters
  • Loading branch information
romgrk committed Jun 7, 2023
commit fb1ea8468aa4107c2fd2a5a9748027ccc6d381ab
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ module.exports = {
rules: {
...baseline.rules,
'import/prefer-default-export': 'off',
'@typescript-eslint/no-unused-vars': [
romgrk marked this conversation as resolved.
Show resolved Hide resolved
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
// TODO move rule into the main repo once it has upgraded
'@typescript-eslint/return-await': 'off',
'no-restricted-imports': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const useDataGridPremiumComponent = (
useGridRowPinning(privateApiRef, props);
useGridColumns(privateApiRef, props);
useGridRows(privateApiRef, props);
useGridParamsApi(privateApiRef);
useGridParamsApi(privateApiRef, props);
useGridDetailPanel(privateApiRef, props);
useGridColumnSpanning(privateApiRef);
useGridColumnGrouping(privateApiRef, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
GridRowModel,
GridColDef,
GridKeyValue,
gridRowsLookupSelector,
} from '@mui/x-data-grid-pro';
import {
passFilterLogic,
GridAggregatedFilterItemApplier,
GridAggregatedFilterItemApplierResult,
GridColumnRawLookup,
GridApiCommunity,
} from '@mui/x-data-grid-pro/internals';
Expand Down Expand Up @@ -82,17 +84,18 @@ const shouldApplyFilterItemOnGroup = (columnField: string, node: GridGroupNode)
export const filterRowTreeFromGroupingColumns = (
params: FilterRowTreeFromTreeDataParams,
): Omit<GridFilterState, 'filterModel'> => {
const { rowTree, isRowMatchingFilters, filterModel } = params;
const { apiRef, rowTree, isRowMatchingFilters, filterModel } = params;
const dataRowIdToModelLookup = gridRowsLookupSelector(apiRef);
const filteredRowsLookup: Record<GridRowId, boolean> = {};
const filteredDescendantCountLookup: Record<GridRowId, number> = {};

const filterTreeNode = (
node: GridTreeNode,
areAncestorsExpanded: boolean,
ancestorsResults: ReturnType<GridAggregatedFilterItemApplier>[],
ancestorsResults: GridAggregatedFilterItemApplierResult[],
): number => {
let isPassingFiltering = false;
let filterResults: ReturnType<GridAggregatedFilterItemApplier> = {
const filterResults: GridAggregatedFilterItemApplierResult = {
passingFilterItems: null,
passingQuickFilterValues: null,
};
Expand All @@ -103,7 +106,8 @@ export const filterRowTreeFromGroupingColumns = (
? (columnField: string) => shouldApplyFilterItemOnGroup(columnField, node)
: undefined;

filterResults = isRowMatchingFilters(node.id, shouldApplyItem);
const row = dataRowIdToModelLookup[node.id];
isRowMatchingFilters(row, shouldApplyItem, filterResults);
} else {
isPassingFiltering = true;
}
Expand All @@ -116,7 +120,7 @@ export const filterRowTreeFromGroupingColumns = (
childNode,

areAncestorsExpanded && !!node.childrenExpanded,
[...ancestorsResults, filterResults],
[...ancestorsResults, { ...filterResults }],
romgrk marked this conversation as resolved.
Show resolved Hide resolved
);
filteredDescendantCount += childSubTreeSize;
});
Expand All @@ -127,7 +131,7 @@ export const filterRowTreeFromGroupingColumns = (
// If node has children - it's passing if at least one child passes filters
isPassingFiltering = filteredDescendantCount > 0;
} else {
const allResults = [...ancestorsResults, filterResults];
const allResults = [...ancestorsResults, { ...filterResults }];
isPassingFiltering = passFilterLogic(
allResults.map((result) => result.passingFilterItems),
allResults.map((result) => result.passingQuickFilterValues),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const useDataGridProComponent = (
useGridRowPinning(apiRef, props);
useGridColumns(apiRef, props);
useGridRows(apiRef, props);
useGridParamsApi(apiRef);
useGridParamsApi(apiRef, props);
useGridDetailPanel(apiRef, props);
useGridColumnSpanning(apiRef);
useGridColumnGrouping(apiRef, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
GridTreeNode,
GridFilterState,
GridFilterModel,
gridRowsLookupSelector,
} from '@mui/x-data-grid';
import {
GridAggregatedFilterItemApplier,
GridAggregatedFilterItemApplierResult,
GridApiCommunity,
passFilterLogic,
} from '@mui/x-data-grid/internals';
Expand All @@ -29,10 +31,16 @@ export const TREE_DATA_STRATEGY = 'tree-data';
export const filterRowTreeFromTreeData = (
params: FilterRowTreeFromTreeDataParams,
): Omit<GridFilterState, 'filterModel'> => {
const { rowTree, disableChildrenFiltering, isRowMatchingFilters } = params;
const { apiRef, rowTree, disableChildrenFiltering, isRowMatchingFilters } = params;
const dataRowIdToModelLookup = gridRowsLookupSelector(apiRef);
const filteredRowsLookup: Record<GridRowId, boolean> = {};
const filteredDescendantCountLookup: Record<GridRowId, number> = {};

const filterResults: GridAggregatedFilterItemApplierResult = {
passingFilterItems: null,
passingQuickFilterValues: null,
};

const filterTreeNode = (
node: GridTreeNode,
isParentMatchingFilters: boolean,
Expand All @@ -46,10 +54,11 @@ export const filterRowTreeFromTreeData = (
} else if (!isRowMatchingFilters || node.type === 'footer') {
isMatchingFilters = true;
} else {
const { passingFilterItems, passingQuickFilterValues } = isRowMatchingFilters(node.id);
const row = dataRowIdToModelLookup[node.id];
isRowMatchingFilters(row, undefined, filterResults);
isMatchingFilters = passFilterLogic(
[passingFilterItems],
[passingQuickFilterValues],
[filterResults.passingFilterItems],
[filterResults.passingQuickFilterValues],
params.filterModel,
params.apiRef,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useDataGridComponent = (
useGridRowSelection(privateApiRef, props);
useGridColumns(privateApiRef, props);
useGridRows(privateApiRef, props);
useGridParamsApi(privateApiRef);
useGridParamsApi(privateApiRef, props);
useGridColumnSpanning(privateApiRef);
useGridColumnGrouping(privateApiRef, props);
useGridEditing(privateApiRef, props);
Expand Down
7 changes: 4 additions & 3 deletions packages/grid/x-data-grid/src/colDef/gridBooleanOperators.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { GridFilterInputBoolean } from '../components/panel/filterPanel/GridFilterInputBoolean';
import { GridFilterItem } from '../models/gridFilterItem';
import { GridFilterOperator } from '../models/gridFilterOperator';
import { v7 } from './utils';

export const getGridBooleanOperators = (): GridFilterOperator<any, boolean | null, any>[] => [
{
value: 'is',
getApplyFilterFn: (filterItem: GridFilterItem) => {
getApplyFilterFn: v7((filterItem: GridFilterItem) => {
if (!filterItem.value) {
return null;
}

const valueAsBoolean = filterItem.value === 'true';
return ({ value }): boolean => {
return (value, _, __, ___): boolean => {
romgrk marked this conversation as resolved.
Show resolved Hide resolved
return Boolean(value) === valueAsBoolean;
};
},
}),
InputComponent: GridFilterInputBoolean,
},
];
44 changes: 22 additions & 22 deletions packages/grid/x-data-grid/src/colDef/gridDateOperators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GridFilterInputDate } from '../components/panel/filterPanel/GridFilterInputDate';
import { GridFilterItem } from '../models/gridFilterItem';
import { GridFilterOperator } from '../models/gridFilterOperator';
import { GridCellParams } from '../models/params/gridCellParams';
import { GridFilterOperator, GetApplyFilterFnV7 } from '../models/gridFilterOperator';
import { v7 } from './utils';

const dateRegex = /(\d+)-(\d+)-(\d+)/;
const dateTimeRegex = /(\d+)-(\d+)-(\d+)T(\d+):(\d+)/;
Expand All @@ -11,7 +11,7 @@ function buildApplyFilterFn(
compareFn: (value1: number, value2: number) => boolean,
showTime?: boolean,
keepHours?: boolean,
) {
): ReturnType<GetApplyFilterFnV7> {
if (!filterItem.value) {
return null;
}
Expand All @@ -23,7 +23,7 @@ function buildApplyFilterFn(

const time = new Date(year, month - 1, day, hour || 0, minute || 0).getTime();

return ({ value }: GridCellParams<any, Date, any>): boolean => {
return (value, _, __, ___): boolean => {
if (!value) {
return false;
}
Expand All @@ -47,73 +47,73 @@ function buildApplyFilterFn(
export const getGridDateOperators = (showTime?: boolean): GridFilterOperator<any, Date, any>[] => [
{
value: 'is',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
return buildApplyFilterFn(filterItem, (value1, value2) => value1 === value2, showTime);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'not',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
romgrk marked this conversation as resolved.
Show resolved Hide resolved
return buildApplyFilterFn(filterItem, (value1, value2) => value1 !== value2, showTime);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'after',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
return buildApplyFilterFn(filterItem, (value1, value2) => value1 > value2, showTime);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'onOrAfter',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
return buildApplyFilterFn(filterItem, (value1, value2) => value1 >= value2, showTime);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'before',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
return buildApplyFilterFn(
filterItem,
(value1, value2) => value1 < value2,
showTime,
!showTime,
);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'onOrBefore',
getApplyFilterFn: (filterItem) => {
getApplyFilterFn: v7((filterItem) => {
return buildApplyFilterFn(filterItem, (value1, value2) => value1 <= value2, showTime);
},
}),
InputComponent: GridFilterInputDate,
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
value: 'isEmpty',
getApplyFilterFn: () => {
return ({ value }): boolean => {
getApplyFilterFn: v7(() => {
return (value, _, __, ___): boolean => {
return value == null;
};
},
}),
requiresFilterValue: false,
},
{
value: 'isNotEmpty',
getApplyFilterFn: () => {
return ({ value }): boolean => {
getApplyFilterFn: v7(() => {
return (value, _, __, ___): boolean => {
return value != null;
};
},
}),
requiresFilterValue: false,
},
];
Loading