@mui/x-data-grid 9.8.0 → 9.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +119 -0
- package/DataGrid/DataGrid.js +7 -0
- package/DataGrid/DataGrid.mjs +7 -0
- package/components/GridColumnSortButton.d.mts +1 -1
- package/components/GridColumnSortButton.d.ts +1 -1
- package/components/GridColumnUnsortedIcon.d.mts +2 -1
- package/components/GridColumnUnsortedIcon.d.ts +2 -1
- package/components/GridHeader.d.mts +2 -1
- package/components/GridHeader.d.ts +2 -1
- package/components/GridHeaders.d.mts +1 -1
- package/components/GridHeaders.d.ts +1 -1
- package/components/GridPagination.d.mts +2 -1
- package/components/GridPagination.d.ts +2 -1
- package/components/GridRowDragAndDropOverlay.d.mts +1 -1
- package/components/GridRowDragAndDropOverlay.d.ts +1 -1
- package/components/GridScrollArea.d.mts +2 -1
- package/components/GridScrollArea.d.ts +2 -1
- package/components/GridScrollShadows.d.mts +2 -1
- package/components/GridScrollShadows.d.ts +2 -1
- package/components/GridScrollbarFillerCell.d.mts +1 -1
- package/components/GridScrollbarFillerCell.d.ts +1 -1
- package/components/base/GridFooterPlaceholder.d.mts +1 -1
- package/components/base/GridFooterPlaceholder.d.ts +1 -1
- package/components/base/GridFooterPlaceholder.js +1 -1
- package/components/base/GridFooterPlaceholder.mjs +1 -1
- package/components/base/GridOverlays.d.mts +1 -1
- package/components/base/GridOverlays.d.ts +1 -1
- package/components/cell/GridActionsCell.d.mts +2 -2
- package/components/cell/GridActionsCell.d.ts +2 -2
- package/components/cell/GridActionsCellItem.js +1 -58
- package/components/cell/GridActionsCellItem.mjs +1 -58
- package/components/cell/GridBooleanCell.d.mts +1 -1
- package/components/cell/GridBooleanCell.d.ts +1 -1
- package/components/cell/GridEditBooleanCell.d.mts +2 -2
- package/components/cell/GridEditBooleanCell.d.ts +2 -2
- package/components/cell/GridEditDateCell.d.mts +2 -2
- package/components/cell/GridEditDateCell.d.ts +2 -2
- package/components/cell/GridEditInputCell.d.mts +1 -1
- package/components/cell/GridEditInputCell.d.ts +1 -1
- package/components/cell/GridEditLongTextCell.d.mts +2 -2
- package/components/cell/GridEditLongTextCell.d.ts +2 -2
- package/components/cell/GridEditSingleSelectCell.d.mts +3 -2
- package/components/cell/GridEditSingleSelectCell.d.ts +3 -2
- package/components/cell/GridFooterCell.d.mts +1 -1
- package/components/cell/GridFooterCell.d.ts +1 -1
- package/components/cell/GridLongTextCell.d.mts +2 -2
- package/components/cell/GridLongTextCell.d.ts +2 -2
- package/components/cell/GridSkeletonCell.d.mts +1 -1
- package/components/cell/GridSkeletonCell.d.ts +1 -1
- package/components/columnHeaders/ColumnHeaderMenuIcon.d.mts +1 -1
- package/components/columnHeaders/ColumnHeaderMenuIcon.d.ts +1 -1
- package/components/columnHeaders/GridColumnGroupHeader.d.mts +1 -1
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +1 -1
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.mts +1 -1
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.ts +1 -1
- package/components/columnHeaders/GridColumnHeaderItem.d.mts +1 -1
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +1 -1
- package/components/columnHeaders/GridColumnHeaderSeparator.d.mts +1 -1
- package/components/columnHeaders/GridColumnHeaderSeparator.d.ts +1 -1
- package/components/columnHeaders/GridColumnHeaderSortIcon.d.mts +1 -1
- package/components/columnHeaders/GridColumnHeaderSortIcon.d.ts +1 -1
- package/components/columnHeaders/GridColumnHeaderTitle.d.mts +1 -1
- package/components/columnHeaders/GridColumnHeaderTitle.d.ts +1 -1
- package/components/columnsManagement/GridColumnsManagement.d.mts +2 -1
- package/components/columnsManagement/GridColumnsManagement.d.ts +2 -1
- package/components/menu/GridMenu.d.mts +1 -1
- package/components/menu/GridMenu.d.ts +1 -1
- package/components/menu/columnMenu/GridColumnHeaderMenu.d.mts +1 -1
- package/components/menu/columnMenu/GridColumnHeaderMenu.d.ts +1 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuColumnsItem.d.mts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuColumnsItem.d.ts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuFilterItem.d.mts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuFilterItem.d.ts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuHideItem.d.mts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuHideItem.d.ts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuManageItem.d.mts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuManageItem.d.ts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.d.mts +2 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.d.ts +2 -1
- package/components/panel/GridColumnsPanel.d.mts +1 -1
- package/components/panel/GridColumnsPanel.d.ts +1 -1
- package/components/panel/GridPanelContent.d.mts +1 -1
- package/components/panel/GridPanelContent.d.ts +1 -1
- package/components/panel/GridPanelContext.d.mts +1 -1
- package/components/panel/GridPanelContext.d.ts +1 -1
- package/components/panel/GridPanelFooter.d.mts +1 -1
- package/components/panel/GridPanelFooter.d.ts +1 -1
- package/components/panel/GridPanelHeader.d.mts +1 -1
- package/components/panel/GridPanelHeader.d.ts +1 -1
- package/components/panel/GridPreferencesPanel.d.mts +1 -1
- package/components/panel/GridPreferencesPanel.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterForm.d.mts +1 -98
- package/components/panel/filterPanel/GridFilterForm.d.ts +1 -98
- package/components/panel/filterPanel/GridFilterForm.js +9 -355
- package/components/panel/filterPanel/GridFilterForm.mjs +8 -354
- package/components/panel/filterPanel/GridFilterFormBase.d.mts +119 -0
- package/components/panel/filterPanel/GridFilterFormBase.d.ts +119 -0
- package/components/panel/filterPanel/GridFilterFormBase.js +497 -0
- package/components/panel/filterPanel/GridFilterFormBase.mjs +491 -0
- package/components/panel/filterPanel/GridFilterInputBoolean.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.mjs +6 -1
- package/components/panel/filterPanel/GridFilterInputDate.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +21 -9
- package/components/panel/filterPanel/GridFilterInputDate.mjs +21 -9
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.mjs +6 -1
- package/components/panel/filterPanel/GridFilterInputMultipleValue.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleValue.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +6 -1
- package/components/panel/filterPanel/GridFilterInputMultipleValue.mjs +6 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +6 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.mjs +6 -1
- package/components/panel/filterPanel/GridFilterInputValue.d.mts +2 -1
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +19 -8
- package/components/panel/filterPanel/GridFilterInputValue.mjs +19 -8
- package/components/panel/filterPanel/GridFilterPanel.d.mts +3 -40
- package/components/panel/filterPanel/GridFilterPanel.d.ts +3 -40
- package/components/panel/filterPanel/GridFilterPanel.js +19 -174
- package/components/panel/filterPanel/GridFilterPanel.mjs +14 -173
- package/components/panel/filterPanel/GridFilterPanelBase.d.mts +79 -0
- package/components/panel/filterPanel/GridFilterPanelBase.d.ts +79 -0
- package/components/panel/filterPanel/GridFilterPanelBase.js +304 -0
- package/components/panel/filterPanel/GridFilterPanelBase.mjs +297 -0
- package/components/panel/filterPanel/index.d.mts +3 -1
- package/components/panel/filterPanel/index.d.ts +3 -1
- package/components/panel/filterPanel/index.js +9 -1
- package/components/panel/filterPanel/index.mjs +3 -0
- package/components/quickFilter/QuickFilter.d.mts +1 -1
- package/components/quickFilter/QuickFilter.d.ts +1 -1
- package/components/toolbar/GridToolbarExport.d.mts +2 -2
- package/components/toolbar/GridToolbarExport.d.ts +2 -2
- package/components/toolbar/GridToolbarQuickFilter.d.mts +1 -1
- package/components/toolbar/GridToolbarQuickFilter.d.ts +1 -1
- package/components/toolbarV8/GridToolbar.d.mts +3 -3
- package/components/toolbarV8/GridToolbar.d.ts +3 -3
- package/components/virtualization/GridBottomContainer.d.mts +1 -1
- package/components/virtualization/GridBottomContainer.d.ts +1 -1
- package/components/virtualization/GridTopContainer.d.mts +1 -1
- package/components/virtualization/GridTopContainer.d.ts +1 -1
- package/components/virtualization/GridVirtualScroller.d.mts +1 -1
- package/components/virtualization/GridVirtualScroller.d.ts +1 -1
- package/components/virtualization/GridVirtualScrollerFiller.d.mts +2 -1
- package/components/virtualization/GridVirtualScrollerFiller.d.ts +2 -1
- package/constants/dataGridPropsDefaultValues.js +1 -0
- package/constants/dataGridPropsDefaultValues.mjs +1 -0
- package/context/GridContextProvider.d.mts +1 -1
- package/context/GridContextProvider.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.mts +2 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +2 -2
- package/hooks/features/dataSource/useGridDataSourceBase.d.mts +1 -1
- package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
- package/hooks/features/dataSource/useGridDataSourceBase.js +39 -10
- package/hooks/features/dataSource/useGridDataSourceBase.mjs +39 -10
- package/hooks/features/filter/gridFilterUtils.d.mts +12 -0
- package/hooks/features/filter/gridFilterUtils.d.ts +12 -0
- package/hooks/features/filter/gridFilterUtils.js +56 -1
- package/hooks/features/filter/gridFilterUtils.mjs +52 -0
- package/hooks/features/filter/useGridFilter.js +4 -35
- package/hooks/features/filter/useGridFilter.mjs +5 -36
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/demo/TailwindDemoContainer.d.mts +1 -1
- package/internals/demo/TailwindDemoContainer.d.ts +1 -1
- package/models/gridFilterInputComponent.d.mts +5 -0
- package/models/gridFilterInputComponent.d.ts +5 -0
- package/models/gridSlotsComponentsProps.d.mts +1 -1
- package/models/gridSlotsComponentsProps.d.ts +1 -1
- package/models/props/DataGridProps.d.mts +7 -0
- package/models/props/DataGridProps.d.ts +7 -0
- package/package.json +4 -4
- package/utils/css/context.d.mts +3 -3
- package/utils/css/context.d.ts +3 -3
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.GridFilterFormBase = void 0;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
|
+
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
+
var React = _react;
|
|
15
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
17
|
+
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
18
|
+
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
19
|
+
var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
|
|
20
|
+
var _styles = require("@mui/material/styles");
|
|
21
|
+
var _forwardRef = require("@mui/x-internals/forwardRef");
|
|
22
|
+
var _cssVariables = require("../../../constants/cssVariables");
|
|
23
|
+
var _gridColumnsSelector = require("../../../hooks/features/columns/gridColumnsSelector");
|
|
24
|
+
var _useGridSelector = require("../../../hooks/utils/useGridSelector");
|
|
25
|
+
var _gridFilterItem = require("../../../models/gridFilterItem");
|
|
26
|
+
var _useGridApiContext = require("../../../hooks/utils/useGridApiContext");
|
|
27
|
+
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
28
|
+
var _gridClasses = require("../../../constants/gridClasses");
|
|
29
|
+
var _filterPanelUtils = require("./filterPanelUtils");
|
|
30
|
+
var _pivoting = require("../../../hooks/features/pivoting");
|
|
31
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
32
|
+
const _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "logicOperators", "columnsSort", "filterColumns", "deleteIconProps", "logicOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "disableDebounce", "readOnly", "filterModel", "children"],
|
|
33
|
+
_excluded2 = ["InputComponentProps"];
|
|
34
|
+
const useUtilityClasses = ownerState => {
|
|
35
|
+
const {
|
|
36
|
+
classes
|
|
37
|
+
} = ownerState;
|
|
38
|
+
const slots = {
|
|
39
|
+
root: ['filterForm'],
|
|
40
|
+
deleteIcon: ['filterFormDeleteIcon'],
|
|
41
|
+
logicOperatorInput: ['filterFormLogicOperatorInput'],
|
|
42
|
+
columnInput: ['filterFormColumnInput'],
|
|
43
|
+
operatorInput: ['filterFormOperatorInput'],
|
|
44
|
+
valueInput: ['filterFormValueInput']
|
|
45
|
+
};
|
|
46
|
+
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
|
|
47
|
+
};
|
|
48
|
+
const GridFilterFormRoot = (0, _styles.styled)('div', {
|
|
49
|
+
name: 'MuiDataGrid',
|
|
50
|
+
slot: 'FilterForm'
|
|
51
|
+
})({
|
|
52
|
+
display: 'flex',
|
|
53
|
+
gap: _cssVariables.vars.spacing(1.5)
|
|
54
|
+
});
|
|
55
|
+
const FilterFormDeleteIcon = (0, _styles.styled)('div', {
|
|
56
|
+
name: 'MuiDataGrid',
|
|
57
|
+
slot: 'FilterFormDeleteIcon'
|
|
58
|
+
})({
|
|
59
|
+
flexShrink: 0,
|
|
60
|
+
display: 'flex',
|
|
61
|
+
justifyContent: 'center',
|
|
62
|
+
alignItems: 'center'
|
|
63
|
+
});
|
|
64
|
+
const FilterFormLogicOperatorInput = (0, _styles.styled)('div', {
|
|
65
|
+
name: 'MuiDataGrid',
|
|
66
|
+
slot: 'FilterFormLogicOperatorInput'
|
|
67
|
+
})({
|
|
68
|
+
minWidth: 75,
|
|
69
|
+
justifyContent: 'end'
|
|
70
|
+
});
|
|
71
|
+
const FilterFormColumnInput = (0, _styles.styled)('div', {
|
|
72
|
+
name: 'MuiDataGrid',
|
|
73
|
+
slot: 'FilterFormColumnInput'
|
|
74
|
+
})({
|
|
75
|
+
width: 150
|
|
76
|
+
});
|
|
77
|
+
const FilterFormOperatorInput = (0, _styles.styled)('div', {
|
|
78
|
+
name: 'MuiDataGrid',
|
|
79
|
+
slot: 'FilterFormOperatorInput'
|
|
80
|
+
})({
|
|
81
|
+
width: 150
|
|
82
|
+
});
|
|
83
|
+
const FilterFormValueInput = (0, _styles.styled)('div', {
|
|
84
|
+
name: 'MuiDataGrid',
|
|
85
|
+
slot: 'FilterFormValueInput'
|
|
86
|
+
})({
|
|
87
|
+
width: 190
|
|
88
|
+
});
|
|
89
|
+
const getLogicOperatorLocaleKey = logicOperator => {
|
|
90
|
+
switch (logicOperator) {
|
|
91
|
+
case _gridFilterItem.GridLogicOperator.And:
|
|
92
|
+
return 'filterPanelOperatorAnd';
|
|
93
|
+
case _gridFilterItem.GridLogicOperator.Or:
|
|
94
|
+
return 'filterPanelOperatorOr';
|
|
95
|
+
default:
|
|
96
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Invalid `logicOperator` property in the `GridFilterPanel`.' : (0, _formatErrorMessage2.default)(71));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const getColumnLabel = col => col.headerName || col.field;
|
|
100
|
+
const collator = new Intl.Collator();
|
|
101
|
+
const GridFilterFormBase = exports.GridFilterFormBase = (0, _forwardRef.forwardRef)(function GridFilterFormBase(props, ref) {
|
|
102
|
+
const {
|
|
103
|
+
item,
|
|
104
|
+
hasMultipleFilters,
|
|
105
|
+
deleteFilter,
|
|
106
|
+
applyFilterChanges,
|
|
107
|
+
showMultiFilterOperators,
|
|
108
|
+
disableMultiFilterOperator,
|
|
109
|
+
applyMultiFilterOperatorChanges,
|
|
110
|
+
focusElementRef,
|
|
111
|
+
logicOperators = [_gridFilterItem.GridLogicOperator.And, _gridFilterItem.GridLogicOperator.Or],
|
|
112
|
+
columnsSort,
|
|
113
|
+
filterColumns,
|
|
114
|
+
deleteIconProps = {},
|
|
115
|
+
logicOperatorInputProps = {},
|
|
116
|
+
operatorInputProps = {},
|
|
117
|
+
columnInputProps = {},
|
|
118
|
+
valueInputProps = {},
|
|
119
|
+
disableDebounce = false,
|
|
120
|
+
readOnly,
|
|
121
|
+
filterModel
|
|
122
|
+
} = props,
|
|
123
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
124
|
+
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
125
|
+
const columnLookup = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridColumnLookupSelector);
|
|
126
|
+
const filterableColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridFilterableColumnDefinitionsSelector);
|
|
127
|
+
const columnSelectId = (0, _useId.default)();
|
|
128
|
+
const columnSelectLabelId = (0, _useId.default)();
|
|
129
|
+
const operatorSelectId = (0, _useId.default)();
|
|
130
|
+
const operatorSelectLabelId = (0, _useId.default)();
|
|
131
|
+
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
132
|
+
const classes = useUtilityClasses(rootProps);
|
|
133
|
+
const valueRef = React.useRef(null);
|
|
134
|
+
const filterSelectorRef = React.useRef(null);
|
|
135
|
+
const multiFilterOperator = filterModel.logicOperator ?? _gridFilterItem.GridLogicOperator.And;
|
|
136
|
+
const hasLogicOperatorColumn = hasMultipleFilters && logicOperators.length > 0;
|
|
137
|
+
const baseSelectProps = rootProps.slotProps?.baseSelect || {};
|
|
138
|
+
const isBaseSelectNative = baseSelectProps.native ?? false;
|
|
139
|
+
const baseSelectOptionProps = rootProps.slotProps?.baseSelectOption || {};
|
|
140
|
+
const {
|
|
141
|
+
InputComponentProps
|
|
142
|
+
} = valueInputProps,
|
|
143
|
+
valueInputPropsOther = (0, _objectWithoutPropertiesLoose2.default)(valueInputProps, _excluded2);
|
|
144
|
+
const pivotActive = (0, _useGridSelector.useGridSelector)(apiRef, _pivoting.gridPivotActiveSelector);
|
|
145
|
+
const initialColumns = (0, _useGridSelector.useGridSelector)(apiRef, _pivoting.gridPivotInitialColumnsSelector);
|
|
146
|
+
const {
|
|
147
|
+
filteredColumns,
|
|
148
|
+
selectedField
|
|
149
|
+
} = React.useMemo(() => {
|
|
150
|
+
let itemField = item.field;
|
|
151
|
+
|
|
152
|
+
// Yields a valid value if the current filter belongs to a column that is not filterable
|
|
153
|
+
const selectedNonFilterableColumn = columnLookup[item.field].filterable === false ? columnLookup[item.field] : null;
|
|
154
|
+
if (selectedNonFilterableColumn) {
|
|
155
|
+
return {
|
|
156
|
+
filteredColumns: [selectedNonFilterableColumn],
|
|
157
|
+
selectedField: itemField
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (pivotActive) {
|
|
161
|
+
return {
|
|
162
|
+
filteredColumns: filterableColumns.filter(column => initialColumns.get(column.field) !== undefined),
|
|
163
|
+
selectedField: itemField
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (filterColumns === undefined || typeof filterColumns !== 'function') {
|
|
167
|
+
return {
|
|
168
|
+
filteredColumns: filterableColumns,
|
|
169
|
+
selectedField: itemField
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const filteredFields = filterColumns({
|
|
173
|
+
field: item.field,
|
|
174
|
+
columns: filterableColumns,
|
|
175
|
+
currentFilters: filterModel?.items || []
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
filteredColumns: filterableColumns.filter(column => {
|
|
179
|
+
const isFieldIncluded = filteredFields.includes(column.field);
|
|
180
|
+
if (column.field === item.field && !isFieldIncluded) {
|
|
181
|
+
itemField = undefined;
|
|
182
|
+
}
|
|
183
|
+
return isFieldIncluded;
|
|
184
|
+
}),
|
|
185
|
+
selectedField: itemField
|
|
186
|
+
};
|
|
187
|
+
}, [item.field, columnLookup, pivotActive, filterColumns, filterableColumns, filterModel?.items, initialColumns]);
|
|
188
|
+
const sortedFilteredColumns = React.useMemo(() => {
|
|
189
|
+
switch (columnsSort) {
|
|
190
|
+
case 'asc':
|
|
191
|
+
return filteredColumns.sort((a, b) => collator.compare(getColumnLabel(a), getColumnLabel(b)));
|
|
192
|
+
case 'desc':
|
|
193
|
+
return filteredColumns.sort((a, b) => -collator.compare(getColumnLabel(a), getColumnLabel(b)));
|
|
194
|
+
default:
|
|
195
|
+
return filteredColumns;
|
|
196
|
+
}
|
|
197
|
+
}, [filteredColumns, columnsSort]);
|
|
198
|
+
const currentColumn = item.field ? apiRef.current.getColumn(item.field) : null;
|
|
199
|
+
const currentOperator = React.useMemo(() => {
|
|
200
|
+
if (!item.operator || !currentColumn) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return currentColumn.filterOperators?.find(operator => operator.value === item.operator);
|
|
204
|
+
}, [item, currentColumn]);
|
|
205
|
+
const changeColumn = React.useCallback(event => {
|
|
206
|
+
const field = event.target.value;
|
|
207
|
+
const column = apiRef.current.getColumn(field);
|
|
208
|
+
if (column.field === currentColumn.field) {
|
|
209
|
+
// column did not change
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// try to keep the same operator when column change
|
|
214
|
+
const newOperator = column.filterOperators.find(operator => operator.value === item.operator) || column.filterOperators[0];
|
|
215
|
+
|
|
216
|
+
// Erase filter value if the input component or filtered column type is modified
|
|
217
|
+
const eraseFilterValue = !newOperator.InputComponent || newOperator.InputComponent !== currentOperator?.InputComponent || column.type !== currentColumn.type;
|
|
218
|
+
let filterValue = eraseFilterValue ? undefined : item.value;
|
|
219
|
+
|
|
220
|
+
// Check filter value against the new valueOptions
|
|
221
|
+
if (column.type === 'singleSelect' && filterValue !== undefined) {
|
|
222
|
+
const colDef = column;
|
|
223
|
+
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef);
|
|
224
|
+
if (Array.isArray(filterValue)) {
|
|
225
|
+
filterValue = filterValue.filter(val => {
|
|
226
|
+
return (
|
|
227
|
+
// Only keep values that are in the new value options
|
|
228
|
+
(0, _filterPanelUtils.getValueFromValueOptions)(val, valueOptions, colDef?.getOptionValue) !== undefined
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
} else if ((0, _filterPanelUtils.getValueFromValueOptions)(item.value, valueOptions, colDef?.getOptionValue) === undefined) {
|
|
232
|
+
// Reset the filter value if it is not in the new value options
|
|
233
|
+
filterValue = undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
applyFilterChanges((0, _extends2.default)({}, item, {
|
|
237
|
+
field,
|
|
238
|
+
operator: newOperator.value,
|
|
239
|
+
value: filterValue
|
|
240
|
+
}));
|
|
241
|
+
}, [apiRef, applyFilterChanges, item, currentColumn, currentOperator]);
|
|
242
|
+
const changeOperator = React.useCallback(event => {
|
|
243
|
+
const operator = event.target.value;
|
|
244
|
+
const newOperator = currentColumn?.filterOperators.find(op => op.value === operator);
|
|
245
|
+
const eraseItemValue = !newOperator?.InputComponent || newOperator?.InputComponent !== currentOperator?.InputComponent;
|
|
246
|
+
applyFilterChanges((0, _extends2.default)({}, item, {
|
|
247
|
+
operator,
|
|
248
|
+
value: eraseItemValue ? undefined : item.value
|
|
249
|
+
}));
|
|
250
|
+
}, [applyFilterChanges, item, currentColumn, currentOperator]);
|
|
251
|
+
const changeLogicOperator = React.useCallback(event => {
|
|
252
|
+
const logicOperator = event.target.value === _gridFilterItem.GridLogicOperator.And.toString() ? _gridFilterItem.GridLogicOperator.And : _gridFilterItem.GridLogicOperator.Or;
|
|
253
|
+
applyMultiFilterOperatorChanges(logicOperator);
|
|
254
|
+
}, [applyMultiFilterOperatorChanges]);
|
|
255
|
+
const handleDeleteFilter = () => {
|
|
256
|
+
deleteFilter(item);
|
|
257
|
+
};
|
|
258
|
+
React.useImperativeHandle(focusElementRef, () => ({
|
|
259
|
+
focus: () => {
|
|
260
|
+
if (currentOperator?.InputComponent) {
|
|
261
|
+
valueRef?.current?.focus();
|
|
262
|
+
} else {
|
|
263
|
+
filterSelectorRef.current.focus();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}), [currentOperator]);
|
|
267
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(GridFilterFormRoot, (0, _extends2.default)({
|
|
268
|
+
className: classes.root,
|
|
269
|
+
"data-id": item.id,
|
|
270
|
+
ownerState: rootProps
|
|
271
|
+
}, other, {
|
|
272
|
+
ref: ref,
|
|
273
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(FilterFormDeleteIcon, (0, _extends2.default)({}, deleteIconProps, {
|
|
274
|
+
className: (0, _clsx.default)(classes.deleteIcon, deleteIconProps.className),
|
|
275
|
+
ownerState: rootProps,
|
|
276
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, (0, _extends2.default)({
|
|
277
|
+
"aria-label": apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
|
|
278
|
+
title: apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
|
|
279
|
+
onClick: handleDeleteFilter,
|
|
280
|
+
size: "small",
|
|
281
|
+
disabled: readOnly
|
|
282
|
+
}, rootProps.slotProps?.baseIconButton, {
|
|
283
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.filterPanelDeleteIcon, {
|
|
284
|
+
fontSize: "small"
|
|
285
|
+
})
|
|
286
|
+
}))
|
|
287
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(FilterFormLogicOperatorInput, (0, _extends2.default)({
|
|
288
|
+
as: rootProps.slots.baseSelect,
|
|
289
|
+
sx: [hasLogicOperatorColumn ? {
|
|
290
|
+
display: 'flex'
|
|
291
|
+
} : {
|
|
292
|
+
display: 'none'
|
|
293
|
+
}, showMultiFilterOperators ? {
|
|
294
|
+
visibility: 'visible'
|
|
295
|
+
} : {
|
|
296
|
+
visibility: 'hidden'
|
|
297
|
+
}, logicOperatorInputProps.sx],
|
|
298
|
+
className: (0, _clsx.default)(classes.logicOperatorInput, logicOperatorInputProps.className),
|
|
299
|
+
ownerState: rootProps
|
|
300
|
+
}, logicOperatorInputProps, {
|
|
301
|
+
size: "small",
|
|
302
|
+
slotProps: {
|
|
303
|
+
htmlInput: {
|
|
304
|
+
'aria-label': apiRef.current.getLocaleText('filterPanelLogicOperator')
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
value: multiFilterOperator ?? '',
|
|
308
|
+
onChange: changeLogicOperator,
|
|
309
|
+
disabled: !!disableMultiFilterOperator || logicOperators.length === 1,
|
|
310
|
+
native: isBaseSelectNative
|
|
311
|
+
}, rootProps.slotProps?.baseSelect, {
|
|
312
|
+
children: logicOperators.map(logicOperator => /*#__PURE__*/(0, _react.createElement)(rootProps.slots.baseSelectOption, (0, _extends2.default)({}, baseSelectOptionProps, {
|
|
313
|
+
native: isBaseSelectNative,
|
|
314
|
+
key: logicOperator.toString(),
|
|
315
|
+
value: logicOperator.toString()
|
|
316
|
+
}), apiRef.current.getLocaleText(getLogicOperatorLocaleKey(logicOperator))))
|
|
317
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(FilterFormColumnInput, (0, _extends2.default)({
|
|
318
|
+
as: rootProps.slots.baseSelect
|
|
319
|
+
}, columnInputProps, {
|
|
320
|
+
className: (0, _clsx.default)(classes.columnInput, columnInputProps.className),
|
|
321
|
+
ownerState: rootProps,
|
|
322
|
+
size: "small",
|
|
323
|
+
labelId: columnSelectLabelId,
|
|
324
|
+
id: columnSelectId,
|
|
325
|
+
label: apiRef.current.getLocaleText('filterPanelColumn'),
|
|
326
|
+
value: selectedField ?? '',
|
|
327
|
+
onChange: changeColumn,
|
|
328
|
+
native: isBaseSelectNative,
|
|
329
|
+
disabled: readOnly
|
|
330
|
+
}, rootProps.slotProps?.baseSelect, {
|
|
331
|
+
children: sortedFilteredColumns.map(col => /*#__PURE__*/(0, _react.createElement)(rootProps.slots.baseSelectOption, (0, _extends2.default)({}, baseSelectOptionProps, {
|
|
332
|
+
native: isBaseSelectNative,
|
|
333
|
+
key: col.field,
|
|
334
|
+
value: col.field
|
|
335
|
+
}), getColumnLabel(col)))
|
|
336
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(FilterFormOperatorInput, (0, _extends2.default)({
|
|
337
|
+
as: rootProps.slots.baseSelect,
|
|
338
|
+
size: "small"
|
|
339
|
+
}, operatorInputProps, {
|
|
340
|
+
className: (0, _clsx.default)(classes.operatorInput, operatorInputProps.className),
|
|
341
|
+
ownerState: rootProps,
|
|
342
|
+
labelId: operatorSelectLabelId,
|
|
343
|
+
label: apiRef.current.getLocaleText('filterPanelOperator'),
|
|
344
|
+
id: operatorSelectId,
|
|
345
|
+
value: item.operator,
|
|
346
|
+
onChange: changeOperator,
|
|
347
|
+
native: isBaseSelectNative,
|
|
348
|
+
inputRef: filterSelectorRef,
|
|
349
|
+
disabled: readOnly
|
|
350
|
+
}, rootProps.slotProps?.baseSelect, {
|
|
351
|
+
children: currentColumn?.filterOperators?.map(operator => /*#__PURE__*/(0, _react.createElement)(rootProps.slots.baseSelectOption, (0, _extends2.default)({}, baseSelectOptionProps, {
|
|
352
|
+
native: isBaseSelectNative,
|
|
353
|
+
key: operator.value,
|
|
354
|
+
value: operator.value
|
|
355
|
+
}), operator.label || apiRef.current.getLocaleText(`filterOperator${(0, _capitalize.default)(operator.value)}`)))
|
|
356
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(FilterFormValueInput, (0, _extends2.default)({}, valueInputPropsOther, {
|
|
357
|
+
className: (0, _clsx.default)(classes.valueInput, valueInputPropsOther.className),
|
|
358
|
+
ownerState: rootProps,
|
|
359
|
+
children: currentOperator?.InputComponent ? /*#__PURE__*/(0, _jsxRuntime.jsx)(currentOperator.InputComponent, (0, _extends2.default)({
|
|
360
|
+
apiRef: apiRef,
|
|
361
|
+
item: item,
|
|
362
|
+
applyValue: applyFilterChanges,
|
|
363
|
+
focusElementRef: valueRef,
|
|
364
|
+
disabled: readOnly,
|
|
365
|
+
disableDebounce: disableDebounce,
|
|
366
|
+
slotProps: {
|
|
367
|
+
root: {
|
|
368
|
+
size: 'small'
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}, currentOperator.InputComponentProps, InputComponentProps), item.field) : null
|
|
372
|
+
}))]
|
|
373
|
+
}));
|
|
374
|
+
});
|
|
375
|
+
if (process.env.NODE_ENV !== "production") GridFilterFormBase.displayName = "GridFilterFormBase";
|
|
376
|
+
process.env.NODE_ENV !== "production" ? GridFilterFormBase.propTypes /* remove-proptypes */ = {
|
|
377
|
+
// ----------------------------- Warning --------------------------------
|
|
378
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
379
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
380
|
+
// ----------------------------------------------------------------------
|
|
381
|
+
/**
|
|
382
|
+
* Callback called when the operator, column field or value is changed.
|
|
383
|
+
* @param {GridFilterItem} item The updated [[GridFilterItem]].
|
|
384
|
+
*/
|
|
385
|
+
applyFilterChanges: _propTypes.default.func.isRequired,
|
|
386
|
+
/**
|
|
387
|
+
* Callback called when the logic operator is changed.
|
|
388
|
+
* @param {GridLogicOperator} operator The new logic operator.
|
|
389
|
+
*/
|
|
390
|
+
applyMultiFilterOperatorChanges: _propTypes.default.func.isRequired,
|
|
391
|
+
/**
|
|
392
|
+
* @ignore - do not document.
|
|
393
|
+
*/
|
|
394
|
+
children: _propTypes.default.node,
|
|
395
|
+
/**
|
|
396
|
+
* Props passed to the column input component.
|
|
397
|
+
* @default {}
|
|
398
|
+
*/
|
|
399
|
+
columnInputProps: _propTypes.default.any,
|
|
400
|
+
/**
|
|
401
|
+
* Changes how the options in the columns selector should be ordered.
|
|
402
|
+
* If not specified, the order is derived from the `columns` prop.
|
|
403
|
+
*/
|
|
404
|
+
columnsSort: _propTypes.default.oneOf(['asc', 'desc']),
|
|
405
|
+
/**
|
|
406
|
+
* Callback called when the delete button is clicked.
|
|
407
|
+
* @param {GridFilterItem} item The deleted [[GridFilterItem]].
|
|
408
|
+
*/
|
|
409
|
+
deleteFilter: _propTypes.default.func.isRequired,
|
|
410
|
+
/**
|
|
411
|
+
* Props passed to the delete icon.
|
|
412
|
+
* @default {}
|
|
413
|
+
*/
|
|
414
|
+
deleteIconProps: _propTypes.default.any,
|
|
415
|
+
/**
|
|
416
|
+
* If `true`, disables the logic operator field but still renders it.
|
|
417
|
+
*/
|
|
418
|
+
disableMultiFilterOperator: _propTypes.default.bool,
|
|
419
|
+
/**
|
|
420
|
+
* Allows to filter the columns displayed in the filter form.
|
|
421
|
+
* @param {FilterColumnsArgs} args The columns of the grid and name of field.
|
|
422
|
+
* @returns {GridColDef['field'][]} The filtered fields array.
|
|
423
|
+
*/
|
|
424
|
+
filterColumns: _propTypes.default.func,
|
|
425
|
+
/**
|
|
426
|
+
* The filter model that populates the form.
|
|
427
|
+
* Its `logicOperator` drives the logic operator field and its `items` are used to compute the
|
|
428
|
+
* columns available in the column selector (e.g. via the `filterColumns` callback).
|
|
429
|
+
*/
|
|
430
|
+
filterModel: _propTypes.default.shape({
|
|
431
|
+
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
432
|
+
field: _propTypes.default.string.isRequired,
|
|
433
|
+
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
434
|
+
operator: _propTypes.default.string.isRequired,
|
|
435
|
+
value: _propTypes.default.any
|
|
436
|
+
})).isRequired,
|
|
437
|
+
logicOperator: _propTypes.default.oneOf(['and', 'or']),
|
|
438
|
+
quickFilterExcludeHiddenColumns: _propTypes.default.bool,
|
|
439
|
+
quickFilterLogicOperator: _propTypes.default.oneOf(['and', 'or']),
|
|
440
|
+
quickFilterValues: _propTypes.default.array
|
|
441
|
+
}).isRequired,
|
|
442
|
+
/**
|
|
443
|
+
* A ref allowing to set imperative focus.
|
|
444
|
+
* It can be passed to the el
|
|
445
|
+
*/
|
|
446
|
+
focusElementRef: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.func, _propTypes.default.object]),
|
|
447
|
+
/**
|
|
448
|
+
* If `true`, the logic operator field is rendered.
|
|
449
|
+
* The field will be invisible if `showMultiFilterOperators` is also `true`.
|
|
450
|
+
*/
|
|
451
|
+
hasMultipleFilters: _propTypes.default.bool.isRequired,
|
|
452
|
+
/**
|
|
453
|
+
* The [[GridFilterItem]] representing this form.
|
|
454
|
+
*/
|
|
455
|
+
item: _propTypes.default.shape({
|
|
456
|
+
field: _propTypes.default.string.isRequired,
|
|
457
|
+
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
458
|
+
operator: _propTypes.default.string.isRequired,
|
|
459
|
+
value: _propTypes.default.any
|
|
460
|
+
}).isRequired,
|
|
461
|
+
/**
|
|
462
|
+
* Props passed to the logic operator input component.
|
|
463
|
+
* @default {}
|
|
464
|
+
*/
|
|
465
|
+
logicOperatorInputProps: _propTypes.default.any,
|
|
466
|
+
/**
|
|
467
|
+
* Sets the available logic operators.
|
|
468
|
+
* @default [GridLogicOperator.And, GridLogicOperator.Or]
|
|
469
|
+
*/
|
|
470
|
+
logicOperators: _propTypes.default.arrayOf(_propTypes.default.oneOf(['and', 'or']).isRequired),
|
|
471
|
+
/**
|
|
472
|
+
* Props passed to the operator input component.
|
|
473
|
+
* @default {}
|
|
474
|
+
*/
|
|
475
|
+
operatorInputProps: _propTypes.default.any,
|
|
476
|
+
/**
|
|
477
|
+
* `true` if the filter is disabled/read only.
|
|
478
|
+
* i.e. `colDef.fiterable = false` but passed in `filterModel`
|
|
479
|
+
* @default false
|
|
480
|
+
*/
|
|
481
|
+
readOnly: _propTypes.default.bool,
|
|
482
|
+
/**
|
|
483
|
+
* If `true`, the logic operator field is visible.
|
|
484
|
+
*/
|
|
485
|
+
showMultiFilterOperators: _propTypes.default.bool,
|
|
486
|
+
/**
|
|
487
|
+
* Props passed to the value input component.
|
|
488
|
+
* @default {}
|
|
489
|
+
*/
|
|
490
|
+
valueInputProps: _propTypes.default.any
|
|
491
|
+
} : void 0;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* The lower-level filter form rendered by `GridFilterForm` and `GridFilterPanelBase`.
|
|
495
|
+
* It is controlled through the `filterModel` prop instead of reading the grid filter state.
|
|
496
|
+
* This is an internal component that is not part of the public API.
|
|
497
|
+
*/
|