UNPKG

@mui/x-data-grid

Version:

The Community plan edition of the Data Grid components (MUI X).

64 lines (60 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.gridSortedRowIdsSelector = exports.gridSortedRowEntriesSelector = exports.gridSortModelSelector = exports.gridSortColumnLookupSelector = void 0; var _createSelector = require("../../../utils/createSelector"); var _gridRowsSelector = require("../rows/gridRowsSelector"); var _gridRowsUtils = require("../rows/gridRowsUtils"); /** * @category Sorting * @ignore - do not document. */ const gridSortingStateSelector = state => state.sorting; /** * Get the id of the rows after the sorting process. * @category Sorting */ const gridSortedRowIdsSelector = exports.gridSortedRowIdsSelector = (0, _createSelector.createSelector)(gridSortingStateSelector, sortingState => sortingState.sortedRows); /** * Get the id and the model of the rows after the sorting process. * @category Sorting */ const gridSortedRowEntriesSelector = exports.gridSortedRowEntriesSelector = (0, _createSelector.createSelectorMemoized)(gridSortedRowIdsSelector, _gridRowsSelector.gridRowsLookupSelector, _gridRowsSelector.gridRowTreeSelector, (sortedIds, idRowsLookup, rowTree) => sortedIds.reduce((acc, id) => { const model = idRowsLookup[id]; if (model) { acc.push({ id, model }); } const rowNode = rowTree[id]; if (rowNode && (0, _gridRowsUtils.isAutoGeneratedRow)(rowNode)) { acc.push({ id, model: { [_gridRowsUtils.GRID_ID_AUTOGENERATED]: id } }); } return acc; }, [])); /** * Get the current sorting model. * @category Sorting */ const gridSortModelSelector = exports.gridSortModelSelector = (0, _createSelector.createSelector)(gridSortingStateSelector, sorting => sorting.sortModel); /** * @category Sorting * @ignore - do not document. */ const gridSortColumnLookupSelector = exports.gridSortColumnLookupSelector = (0, _createSelector.createSelectorMemoized)(gridSortModelSelector, sortModel => { const result = sortModel.reduce((res, sortItem, index) => { res[sortItem.field] = { sortDirection: sortItem.sort, sortIndex: sortModel.length > 1 ? index + 1 : undefined }; return res; }, {}); return result; });