@mui/x-data-grid
Version:
The community edition of the data grid component (MUI X).
131 lines (117 loc) • 5.33 kB
JavaScript
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
import { gridSortedRowEntriesSelector } from '../sorting/gridSortingSelector';
import { gridColumnLookupSelector } from '../columns/gridColumnsSelector';
import { gridRowMaximumTreeDepthSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
/**
* @category Filtering
*/
const gridFilterStateSelector = state => state.filter;
/**
* Get the current filter model.
* @category Filtering
*/
export const gridFilterModelSelector = createSelector(gridFilterStateSelector, filterState => filterState.filterModel);
/**
* Get the current quick filter values.
* @category Filtering
*/
export const gridQuickFilterValuesSelector = createSelector(gridFilterModelSelector, filterModel => filterModel.quickFilterValues);
/**
* @category Visible rows
* @ignore - do not document.
*/
export const gridVisibleRowsLookupSelector = state => state.visibleRowsLookup;
/**
* @category Filtering
* @ignore - do not document.
*/
export const gridFilteredRowsLookupSelector = createSelector(gridFilterStateSelector, filterState => filterState.filteredRowsLookup);
/**
* @category Filtering
* @ignore - do not document.
*/
export const gridFilteredDescendantCountLookupSelector = createSelector(gridFilterStateSelector, filterState => filterState.filteredDescendantCountLookup);
/**
* Get the id and the model of the rows accessible after the filtering process.
* Does not contain the collapsed children.
* @category Filtering
*/
export const gridExpandedSortedRowEntriesSelector = createSelectorMemoized(gridVisibleRowsLookupSelector, gridSortedRowEntriesSelector, (visibleRowsLookup, sortedRows) => sortedRows.filter(row => visibleRowsLookup[row.id] !== false));
/**
* Get the id of the rows accessible after the filtering process.
* Does not contain the collapsed children.
* @category Filtering
*/
export const gridExpandedSortedRowIdsSelector = createSelectorMemoized(gridExpandedSortedRowEntriesSelector, visibleSortedRowEntries => visibleSortedRowEntries.map(row => row.id));
/**
* Get the id and the model of the rows accessible after the filtering process.
* Contains the collapsed children.
* @category Filtering
*/
export const gridFilteredSortedRowEntriesSelector = createSelectorMemoized(gridFilteredRowsLookupSelector, gridSortedRowEntriesSelector, (filteredRowsLookup, sortedRows) => sortedRows.filter(row => filteredRowsLookup[row.id] !== false));
/**
* Get the id of the rows accessible after the filtering process.
* Contains the collapsed children.
* @category Filtering
*/
export const gridFilteredSortedRowIdsSelector = createSelectorMemoized(gridFilteredSortedRowEntriesSelector, filteredSortedRowEntries => filteredSortedRowEntries.map(row => row.id));
/**
* Get the id and the model of the top level rows accessible after the filtering process.
* @category Filtering
*/
export const gridFilteredSortedTopLevelRowEntriesSelector = createSelectorMemoized(gridExpandedSortedRowEntriesSelector, gridRowTreeSelector, gridRowMaximumTreeDepthSelector, (visibleSortedRows, rowTree, rowTreeDepth) => {
if (rowTreeDepth < 2) {
return visibleSortedRows;
}
return visibleSortedRows.filter(row => {
var _rowTree$row$id;
return ((_rowTree$row$id = rowTree[row.id]) == null ? void 0 : _rowTree$row$id.depth) === 0;
});
});
/**
* Get the amount of rows accessible after the filtering process.
* @category Filtering
*/
export const gridExpandedRowCountSelector = createSelector(gridExpandedSortedRowEntriesSelector, visibleSortedRows => visibleSortedRows.length);
/**
* Get the amount of top level rows accessible after the filtering process.
* @category Filtering
*/
export const gridFilteredTopLevelRowCountSelector = createSelector(gridFilteredSortedTopLevelRowEntriesSelector, visibleSortedTopLevelRows => visibleSortedTopLevelRows.length);
/**
* @category Filtering
* @ignore - do not document.
*/
export const gridFilterActiveItemsSelector = createSelectorMemoized(gridFilterModelSelector, gridColumnLookupSelector, (filterModel, columnLookup) => {
var _filterModel$items;
return (_filterModel$items = filterModel.items) == null ? void 0 : _filterModel$items.filter(item => {
var _column$filterOperato, _item$value;
if (!item.field) {
return false;
}
const column = columnLookup[item.field];
if (!(column != null && column.filterOperators) || (column == null || (_column$filterOperato = column.filterOperators) == null ? void 0 : _column$filterOperato.length) === 0) {
return false;
}
const filterOperator = column.filterOperators.find(operator => operator.value === item.operator);
if (!filterOperator) {
return false;
}
return !filterOperator.InputComponent || item.value != null && ((_item$value = item.value) == null ? void 0 : _item$value.toString()) !== '';
});
});
/**
* @category Filtering
* @ignore - do not document.
*/
export const gridFilterActiveItemsLookupSelector = createSelectorMemoized(gridFilterActiveItemsSelector, activeFilters => {
const result = activeFilters.reduce((res, filterItem) => {
if (!res[filterItem.field]) {
res[filterItem.field] = [filterItem];
} else {
res[filterItem.field].push(filterItem);
}
return res;
}, {});
return result;
});