@mui/x-data-grid 5.12.0 → 5.12.1
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 +59 -0
- package/components/containers/GridRootStyles.js +3 -0
- package/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/components/toolbar/GridToolbarQuickFilter.d.ts +7 -0
- package/components/toolbar/GridToolbarQuickFilter.js +57 -4
- package/constants/defaultGridSlotsComponents.js +2 -1
- package/hooks/core/useGridStateInitialization.js +19 -6
- package/hooks/features/columnMenu/useGridColumnMenu.js +22 -0
- package/hooks/features/columns/useGridColumns.js +1 -1
- package/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/hooks/features/filter/gridFilterSelector.d.ts +5 -0
- package/hooks/features/filter/gridFilterSelector.js +6 -0
- package/hooks/features/filter/gridFilterUtils.d.ts +1 -1
- package/hooks/features/filter/gridFilterUtils.js +2 -4
- package/hooks/features/filter/useGridFilter.js +24 -7
- package/hooks/features/pagination/useGridPage.js +1 -1
- package/hooks/features/pagination/useGridPageSize.js +1 -1
- package/hooks/features/selection/useGridSelection.js +1 -1
- package/hooks/features/sorting/useGridSorting.js +1 -1
- package/index.js +1 -1
- package/legacy/components/containers/GridRootStyles.js +6 -4
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +2 -4
- package/legacy/components/toolbar/GridToolbarQuickFilter.js +67 -6
- package/legacy/constants/defaultGridSlotsComponents.js +2 -1
- package/legacy/hooks/core/useGridStateInitialization.js +18 -6
- package/legacy/hooks/features/columnMenu/useGridColumnMenu.js +22 -0
- package/legacy/hooks/features/columns/useGridColumns.js +1 -1
- package/legacy/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/legacy/hooks/features/filter/gridFilterSelector.js +8 -0
- package/legacy/hooks/features/filter/gridFilterUtils.js +3 -5
- package/legacy/hooks/features/filter/useGridFilter.js +28 -7
- package/legacy/hooks/features/pagination/useGridPage.js +1 -1
- package/legacy/hooks/features/pagination/useGridPageSize.js +1 -1
- package/legacy/hooks/features/selection/useGridSelection.js +1 -1
- package/legacy/hooks/features/sorting/useGridSorting.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/locales/jaJP.js +28 -24
- package/legacy/locales/ruRU.js +6 -6
- package/locales/jaJP.js +24 -24
- package/locales/ruRU.js +6 -6
- package/models/api/gridCallbackDetails.d.ts +6 -1
- package/models/api/gridFilterApi.d.ts +8 -1
- package/models/api/gridStateApi.d.ts +14 -3
- package/models/events/gridEventLookup.d.ts +3 -0
- package/models/gridIconSlotsComponent.d.ts +5 -0
- package/models/props/DataGridProps.d.ts +1 -1
- package/modern/components/containers/GridRootStyles.js +3 -0
- package/modern/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/modern/components/toolbar/GridToolbarQuickFilter.js +57 -4
- package/modern/constants/defaultGridSlotsComponents.js +2 -1
- package/modern/hooks/core/useGridStateInitialization.js +19 -6
- package/modern/hooks/features/columnMenu/useGridColumnMenu.js +22 -0
- package/modern/hooks/features/columns/useGridColumns.js +1 -1
- package/modern/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/modern/hooks/features/filter/gridFilterSelector.js +6 -0
- package/modern/hooks/features/filter/gridFilterUtils.js +2 -4
- package/modern/hooks/features/filter/useGridFilter.js +24 -7
- package/modern/hooks/features/pagination/useGridPage.js +1 -1
- package/modern/hooks/features/pagination/useGridPageSize.js +1 -1
- package/modern/hooks/features/selection/useGridSelection.js +1 -1
- package/modern/hooks/features/sorting/useGridSorting.js +1 -1
- package/modern/index.js +1 -1
- package/modern/locales/jaJP.js +24 -24
- package/modern/locales/ruRU.js +6 -6
- package/node/components/containers/GridRootStyles.js +3 -0
- package/node/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/node/components/toolbar/GridToolbarQuickFilter.js +61 -4
- package/node/constants/defaultGridSlotsComponents.js +2 -1
- package/node/hooks/core/useGridStateInitialization.js +19 -6
- package/node/hooks/features/columnMenu/useGridColumnMenu.js +23 -0
- package/node/hooks/features/columns/useGridColumns.js +1 -1
- package/node/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/node/hooks/features/filter/gridFilterSelector.js +9 -2
- package/node/hooks/features/filter/gridFilterUtils.js +2 -4
- package/node/hooks/features/filter/useGridFilter.js +24 -7
- package/node/hooks/features/pagination/useGridPage.js +1 -1
- package/node/hooks/features/pagination/useGridPageSize.js +1 -1
- package/node/hooks/features/selection/useGridSelection.js +1 -1
- package/node/hooks/features/sorting/useGridSorting.js +1 -1
- package/node/index.js +1 -1
- package/node/locales/jaJP.js +24 -24
- package/node/locales/ruRU.js +6 -6
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,63 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## v5.12.1
|
|
7
|
+
|
|
8
|
+
_Jun 9, 2022_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 10 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🎁 Add `reason` to `onFilterModelChange` (#4938) @m4theushw
|
|
13
|
+
- 🔎 Control quick filter input value via model prop (#5013) @alexfauquette
|
|
14
|
+
- 📚 Documentation improvements
|
|
15
|
+
- 🐞 Bugfixes
|
|
16
|
+
|
|
17
|
+
### `@mui/x-data-grid@v5.12.1` / `@mui/x-data-grid-pro@v5.12.1` / `@mui/x-data-grid-premium@v5.12.1`
|
|
18
|
+
|
|
19
|
+
#### Changes
|
|
20
|
+
|
|
21
|
+
- [DataGrid] Add `reason` to `onFilterModelChange` (#4938) @m4theushw
|
|
22
|
+
- [DataGrid] Restore focus after dismissing the column menu (#5027) @m4theushw
|
|
23
|
+
- [DataGrid] Update quick filter input when model is modified (#5013) @alexfauquette
|
|
24
|
+
- [DataGrid] Fix implicit dependency on react-dom (#5121) @oliviertassinari
|
|
25
|
+
- [DataGrid] Support `getRowId` in row reordering (#5093) @flaviendelangle
|
|
26
|
+
- [DataGridPro] Fix column resizing in RTL mode (#4989) @cherniavskii
|
|
27
|
+
- [DataGridPro] Fix column resizing on touchscreen (#5056) @cherniavskii
|
|
28
|
+
- [l10n] Update Japanese (ja-JP) locale (#5122) @hikotq
|
|
29
|
+
- [l10n] Update Russian (ru-RU) locale (#5069) @Artboomy
|
|
30
|
+
|
|
31
|
+
### `@mui/x-date-pickers@5.0.0-alpha.6` / `@mui/x-date-pickers-pro@5.0.0-alpha.6`
|
|
32
|
+
|
|
33
|
+
#### Changes
|
|
34
|
+
|
|
35
|
+
- [pickers] Fix usage of `maxDate` / `minDate` / `disableFuture` and `disablePast` (#5081) @flaviendelangle
|
|
36
|
+
- [pickers] Infer mask from `inputFormat` (#5060) @alexfauquette
|
|
37
|
+
- [pickers] Manage input value without using the focus (#4486) @alexfauquette
|
|
38
|
+
- [pickers] Use new localization for doc examples (#5097) @flaviendelangle
|
|
39
|
+
- [pickers] Fix `shouldDisableDate` in range pickers (#5123) @flaviendelangle
|
|
40
|
+
- [l10n] Add Brazilian Portuguese (pt-BR) locale (#5100) @jardelnovaes
|
|
41
|
+
- [l10n] Use `localText` for remaining texts (#4986) @alexfauquette
|
|
42
|
+
|
|
43
|
+
### Docs
|
|
44
|
+
|
|
45
|
+
- [docs] Implement the focus management on data grid demo links (#5070) @alexfauquette
|
|
46
|
+
- [docs] Fix `301` link to render cell (#5106) @oliviertassinari
|
|
47
|
+
- [docs] Fix broken anchor link @oliviertassinari
|
|
48
|
+
- [docs] Improve movie dataset (#5142) @flaviendelangle
|
|
49
|
+
- [docs] Move all localization documentation in a unique page (#5072) @alexfauquette
|
|
50
|
+
- [docs] Section for overwriting core components i18n keys (#4998) @DanailH
|
|
51
|
+
- [docs] Small grammar and format fixes for Dynamic Row Height section (#5098) @samuelsycamore
|
|
52
|
+
|
|
53
|
+
### Core
|
|
54
|
+
|
|
55
|
+
- [core] Allows to run tests with different date adapters (#5055) @alexfauquette
|
|
56
|
+
- [core] Prettify the l10n issue (#4928) @alexfauquette
|
|
57
|
+
- [core] Set correct `apiRef` type in row reorder pre processors #5125 @DanailH
|
|
58
|
+
- [core] Stop using `GridEvents` in technical doc (#5157) @flaviendelangle
|
|
59
|
+
- [core] Upgrade monorepo (#5101) @oliviertassinari
|
|
60
|
+
- [test] Fix dynamic row height test failing on Chrome (#5147) @m4theushw
|
|
61
|
+
- [test] Remove delay on server demo for regression tests (#5131) @alexfauquette
|
|
62
|
+
|
|
6
63
|
## v5.12.0
|
|
7
64
|
|
|
8
65
|
_May 31, 2022_
|
|
@@ -21,6 +78,8 @@ We'd like to offer a big thanks to the 15 contributors who made this release pos
|
|
|
21
78
|
|
|
22
79
|
### `@mui/x-data-grid@v5.12.0` / `@mui/x-data-grid-pro@v5.12.0` / `@mui/x-data-grid-premium@v5.12.0`
|
|
23
80
|
|
|
81
|
+
#### Changes
|
|
82
|
+
|
|
24
83
|
- [DataGrid] Support dynamic row height (#4859) @m4theushw
|
|
25
84
|
- [DataGrid] Add `onMenuOpen` and `onMenuClose` props (#4825) @DanailH
|
|
26
85
|
- [DataGrid] Add generics to `GridActionsColDef` to match `GridColDef` (#4982) @subvertallchris
|
|
@@ -221,6 +221,9 @@ export const GridRootStyles = styled('div', {
|
|
|
221
221
|
},
|
|
222
222
|
[`&.${gridClasses['columnSeparator--resizing']}`]: {
|
|
223
223
|
color: theme.palette.text.primary
|
|
224
|
+
},
|
|
225
|
+
'& svg': {
|
|
226
|
+
pointerEvents: 'none'
|
|
224
227
|
}
|
|
225
228
|
},
|
|
226
229
|
[`& .${gridClasses.iconSeparator}`]: {
|
|
@@ -72,9 +72,7 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
apiRef.current.
|
|
76
|
-
items: [...items, defaultItem]
|
|
77
|
-
}));
|
|
75
|
+
apiRef.current.upsertFilterItems([...items, defaultItem]);
|
|
78
76
|
};
|
|
79
77
|
|
|
80
78
|
const deleteFilter = React.useCallback(item => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import { GridFilterModel } from '../../models/gridFilterModel';
|
|
3
4
|
export declare type GridToolbarQuickFilterProps = TextFieldProps & {
|
|
4
5
|
/**
|
|
5
6
|
* Function responsible for parsing text input in an array of independent values for quick filtering.
|
|
@@ -7,6 +8,12 @@ export declare type GridToolbarQuickFilterProps = TextFieldProps & {
|
|
|
7
8
|
* @returns {any[]} The array of value on which quick filter is applied
|
|
8
9
|
*/
|
|
9
10
|
quickFilterParser?: (input: string) => any[];
|
|
11
|
+
/**
|
|
12
|
+
* Function responsible for formatting values of quick filter in a string when the model is modified
|
|
13
|
+
* @param {any[]} values The new values passed to the quick filter model
|
|
14
|
+
* @returns {string} The string to display in the text field
|
|
15
|
+
*/
|
|
16
|
+
quickFilterFormatter?: (values: GridFilterModel['quickFilterValues']) => string;
|
|
10
17
|
/**
|
|
11
18
|
* The debounce time in milliseconds.
|
|
12
19
|
* @default 500
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["quickFilterParser", "debounceMs"];
|
|
3
|
+
const _excluded = ["quickFilterParser", "quickFilterFormatter", "debounceMs"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import TextField from '@mui/material/TextField';
|
|
7
|
+
import IconButton from '@mui/material/IconButton';
|
|
7
8
|
import { styled } from '@mui/material/styles';
|
|
8
9
|
import { debounce } from '@mui/material/utils';
|
|
9
10
|
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
10
11
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
12
|
+
import { useGridSelector } from '../../hooks/utils/useGridSelector';
|
|
13
|
+
import { gridQuickFilterValuesSelector } from '../../hooks/features/filter';
|
|
14
|
+
import { isDeepEqual } from '../../utils/utils';
|
|
11
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
16
|
const GridToolbarQuickFilterRoot = styled(TextField, {
|
|
13
17
|
name: 'MuiDataGrid',
|
|
@@ -18,28 +22,55 @@ const GridToolbarQuickFilterRoot = styled(TextField, {
|
|
|
18
22
|
}) => ({
|
|
19
23
|
width: 'auto',
|
|
20
24
|
paddingBottom: theme.spacing(0.5),
|
|
21
|
-
'&
|
|
22
|
-
|
|
25
|
+
'& input': {
|
|
26
|
+
marginLeft: theme.spacing(0.5)
|
|
23
27
|
},
|
|
24
28
|
'& .MuiInput-underline:before': {
|
|
25
29
|
borderBottom: `1px solid ${theme.palette.divider}`
|
|
30
|
+
},
|
|
31
|
+
[`& input[type=search]::-ms-clear,
|
|
32
|
+
& input[type=search]::-ms-reveal`]: {
|
|
33
|
+
/* clears the 'X' icon from IE */
|
|
34
|
+
display: 'none',
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0
|
|
37
|
+
},
|
|
38
|
+
[`& input[type="search"]::-webkit-search-decoration,
|
|
39
|
+
& input[type="search"]::-webkit-search-cancel-button,
|
|
40
|
+
& input[type="search"]::-webkit-search-results-button,
|
|
41
|
+
& input[type="search"]::-webkit-search-results-decoration`]: {
|
|
42
|
+
/* clears the 'X' icon from Chrome */
|
|
43
|
+
display: 'none'
|
|
26
44
|
}
|
|
27
45
|
}));
|
|
28
46
|
|
|
29
47
|
const defaultSearchValueParser = searchText => searchText.split(' ').filter(word => word !== '');
|
|
30
48
|
|
|
49
|
+
const defaultSearchValueFormatter = values => values.join(' ');
|
|
50
|
+
|
|
31
51
|
function GridToolbarQuickFilter(props) {
|
|
32
52
|
var _rootProps$components;
|
|
33
53
|
|
|
34
54
|
const {
|
|
35
55
|
quickFilterParser = defaultSearchValueParser,
|
|
56
|
+
quickFilterFormatter = defaultSearchValueFormatter,
|
|
36
57
|
debounceMs = 500
|
|
37
58
|
} = props,
|
|
38
59
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
39
60
|
|
|
40
61
|
const apiRef = useGridApiContext();
|
|
41
62
|
const rootProps = useGridRootProps();
|
|
42
|
-
const
|
|
63
|
+
const quickFilterValues = useGridSelector(apiRef, gridQuickFilterValuesSelector);
|
|
64
|
+
const [searchValue, setSearchValue] = React.useState(() => quickFilterFormatter(quickFilterValues != null ? quickFilterValues : []));
|
|
65
|
+
const [prevQuickFilterValues, setPrevQuickFilterValues] = React.useState(quickFilterValues);
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
if (!isDeepEqual(prevQuickFilterValues, quickFilterValues)) {
|
|
68
|
+
// The model of quick filter value has been updated
|
|
69
|
+
setPrevQuickFilterValues(quickFilterValues); // Update the input value if needed to match the new model
|
|
70
|
+
|
|
71
|
+
setSearchValue(prevSearchValue => isDeepEqual(quickFilterParser(prevSearchValue), quickFilterValues) ? prevSearchValue : quickFilterFormatter(quickFilterValues != null ? quickFilterValues : []));
|
|
72
|
+
}
|
|
73
|
+
}, [prevQuickFilterValues, quickFilterValues, quickFilterFormatter, quickFilterParser]);
|
|
43
74
|
const updateSearchValue = React.useCallback(newSearchValue => {
|
|
44
75
|
apiRef.current.setQuickFilterValues(quickFilterParser(newSearchValue));
|
|
45
76
|
}, [apiRef, quickFilterParser]);
|
|
@@ -49,6 +80,10 @@ function GridToolbarQuickFilter(props) {
|
|
|
49
80
|
setSearchValue(newSearchValue);
|
|
50
81
|
debouncedUpdateSearchValue(newSearchValue);
|
|
51
82
|
}, [debouncedUpdateSearchValue]);
|
|
83
|
+
const handleSearchReset = React.useCallback(() => {
|
|
84
|
+
setSearchValue('');
|
|
85
|
+
updateSearchValue('');
|
|
86
|
+
}, [updateSearchValue]);
|
|
52
87
|
return /*#__PURE__*/_jsx(GridToolbarQuickFilterRoot, _extends({
|
|
53
88
|
as: rootProps.components.BaseTextField,
|
|
54
89
|
variant: "standard",
|
|
@@ -60,6 +95,17 @@ function GridToolbarQuickFilter(props) {
|
|
|
60
95
|
InputProps: {
|
|
61
96
|
startAdornment: /*#__PURE__*/_jsx(rootProps.components.QuickFilterIcon, {
|
|
62
97
|
fontSize: "small"
|
|
98
|
+
}),
|
|
99
|
+
endAdornment: /*#__PURE__*/_jsx(IconButton, {
|
|
100
|
+
"aria-label": apiRef.current.getLocaleText('toolbarQuickFilterDeleteIconLabel'),
|
|
101
|
+
size: "small",
|
|
102
|
+
sx: {
|
|
103
|
+
visibility: searchValue ? 'visible' : 'hidden'
|
|
104
|
+
},
|
|
105
|
+
onClick: handleSearchReset,
|
|
106
|
+
children: /*#__PURE__*/_jsx(rootProps.components.QuickFilterClearIcon, {
|
|
107
|
+
fontSize: "small"
|
|
108
|
+
})
|
|
63
109
|
})
|
|
64
110
|
}
|
|
65
111
|
}, other, (_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.baseTextField));
|
|
@@ -77,6 +123,13 @@ process.env.NODE_ENV !== "production" ? GridToolbarQuickFilter.propTypes = {
|
|
|
77
123
|
*/
|
|
78
124
|
debounceMs: PropTypes.number,
|
|
79
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Function responsible for formatting values of quick filter in a string when the model is modified
|
|
128
|
+
* @param {any[]} values The new values passed to the quick filter model
|
|
129
|
+
* @returns {string} The string to display in the text field
|
|
130
|
+
*/
|
|
131
|
+
quickFilterFormatter: PropTypes.func,
|
|
132
|
+
|
|
80
133
|
/**
|
|
81
134
|
* Function responsible for parsing text input in an array of independent values for quick filtering.
|
|
82
135
|
* @param {string} input The value entered by the user
|
|
@@ -35,7 +35,8 @@ const DEFAULT_GRID_ICON_SLOTS_COMPONENTS = {
|
|
|
35
35
|
DetailPanelExpandIcon: GridAddIcon,
|
|
36
36
|
DetailPanelCollapseIcon: GridRemoveIcon,
|
|
37
37
|
RowReorderIcon: GridDragIcon,
|
|
38
|
-
QuickFilterIcon: GridSearchIcon
|
|
38
|
+
QuickFilterIcon: GridSearchIcon,
|
|
39
|
+
QuickFilterClearIcon: GridCloseIcon
|
|
39
40
|
};
|
|
40
41
|
/**
|
|
41
42
|
* TODO: Differentiate community and pro value and interface
|
|
@@ -8,7 +8,7 @@ import { isFunction } from '../../utils/utils';
|
|
|
8
8
|
export const useGridStateInitialization = (apiRef, props) => {
|
|
9
9
|
const controlStateMapRef = React.useRef({});
|
|
10
10
|
const [, rawForceUpdate] = React.useState();
|
|
11
|
-
const
|
|
11
|
+
const registerControlState = React.useCallback(controlStateItem => {
|
|
12
12
|
const {
|
|
13
13
|
stateId
|
|
14
14
|
} = controlStateItem,
|
|
@@ -18,7 +18,7 @@ export const useGridStateInitialization = (apiRef, props) => {
|
|
|
18
18
|
stateId
|
|
19
19
|
});
|
|
20
20
|
}, []);
|
|
21
|
-
const setState = React.useCallback(state => {
|
|
21
|
+
const setState = React.useCallback((state, reason) => {
|
|
22
22
|
let newState;
|
|
23
23
|
|
|
24
24
|
if (isFunction(state)) {
|
|
@@ -79,23 +79,36 @@ export const useGridStateInitialization = (apiRef, props) => {
|
|
|
79
79
|
|
|
80
80
|
if (controlState.propOnChange && hasPropChanged) {
|
|
81
81
|
const details = props.signature === GridSignature.DataGridPro ? {
|
|
82
|
-
api: apiRef.current
|
|
83
|
-
|
|
82
|
+
api: apiRef.current,
|
|
83
|
+
reason
|
|
84
|
+
} : {
|
|
85
|
+
reason
|
|
86
|
+
};
|
|
84
87
|
controlState.propOnChange(model, details);
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
if (!ignoreSetState) {
|
|
88
|
-
apiRef.current.publishEvent(controlState.changeEvent, model
|
|
91
|
+
apiRef.current.publishEvent(controlState.changeEvent, model, {
|
|
92
|
+
reason
|
|
93
|
+
});
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
return !ignoreSetState;
|
|
93
98
|
}, [apiRef, props.signature]);
|
|
99
|
+
const updateControlState = React.useCallback((key, state, reason) => {
|
|
100
|
+
return apiRef.current.setState(previousState => {
|
|
101
|
+
return _extends({}, previousState, {
|
|
102
|
+
[key]: state(previousState[key])
|
|
103
|
+
});
|
|
104
|
+
}, reason);
|
|
105
|
+
}, [apiRef]);
|
|
94
106
|
const forceUpdate = React.useCallback(() => rawForceUpdate(() => apiRef.current.state), [apiRef]);
|
|
95
107
|
const stateApi = {
|
|
96
108
|
setState,
|
|
97
109
|
forceUpdate,
|
|
98
|
-
unstable_updateControlState: updateControlState
|
|
110
|
+
unstable_updateControlState: updateControlState,
|
|
111
|
+
unstable_registerControlState: registerControlState
|
|
99
112
|
};
|
|
100
113
|
useGridApiMethod(apiRef, stateApi, 'GridStateApi');
|
|
101
114
|
};
|
|
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGridLogger, useGridApiMethod, useGridApiEventHandler } from '../../utils';
|
|
4
4
|
import { gridColumnMenuSelector } from './columnMenuSelector';
|
|
5
|
+
import { gridClasses } from '../../../constants/gridClasses';
|
|
5
6
|
export const columnMenuStateInitializer = state => _extends({}, state, {
|
|
6
7
|
columnMenu: {
|
|
7
8
|
open: false
|
|
@@ -77,7 +78,28 @@ export const useGridColumnMenu = apiRef => {
|
|
|
77
78
|
* EVENTS
|
|
78
79
|
*/
|
|
79
80
|
|
|
81
|
+
const handleColumnHeaderFocus = React.useCallback((params, event) => {
|
|
82
|
+
// Check if the column menu button received focus
|
|
83
|
+
if (!event.target.classList.contains(gridClasses.menuIconButton)) {
|
|
84
|
+
return;
|
|
85
|
+
} // Check if there's an element which lost focus
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if (!event.relatedTarget) {
|
|
89
|
+
return;
|
|
90
|
+
} // `true` if the focus was on the column menu itself, not on any item
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const columnMenuLostFocus = event.relatedTarget.classList.contains(gridClasses.menuList); // `true` if the focus was on an item from the column menu
|
|
94
|
+
|
|
95
|
+
const columnMenuItemLostFocus = event.relatedTarget.getAttribute('role') === 'menuitem';
|
|
96
|
+
|
|
97
|
+
if (columnMenuLostFocus || columnMenuItemLostFocus) {
|
|
98
|
+
apiRef.current.setColumnHeaderFocus(params.field);
|
|
99
|
+
}
|
|
100
|
+
}, [apiRef]);
|
|
80
101
|
useGridApiEventHandler(apiRef, 'columnResizeStart', hideColumnMenu);
|
|
102
|
+
useGridApiEventHandler(apiRef, 'columnHeaderFocus', handleColumnHeaderFocus);
|
|
81
103
|
useGridApiEventHandler(apiRef, 'virtualScrollerWheel', apiRef.current.hideColumnMenu);
|
|
82
104
|
useGridApiEventHandler(apiRef, 'virtualScrollerTouchMove', apiRef.current.hideColumnMenu);
|
|
83
105
|
};
|
|
@@ -42,7 +42,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
42
42
|
const columnTypes = React.useMemo(() => computeColumnTypes(props.columnTypes), [props.columnTypes]);
|
|
43
43
|
const previousColumnsProp = React.useRef(props.columns);
|
|
44
44
|
const previousColumnTypesProp = React.useRef(columnTypes);
|
|
45
|
-
apiRef.current.
|
|
45
|
+
apiRef.current.unstable_registerControlState({
|
|
46
46
|
stateId: 'visibleColumns',
|
|
47
47
|
propModel: props.columnVisibilityModel,
|
|
48
48
|
propOnChange: props.onColumnVisibilityModelChange,
|
|
@@ -23,7 +23,7 @@ export function useGridEditing(apiRef, props) {
|
|
|
23
23
|
useCellEditing(apiRef, props);
|
|
24
24
|
useGridRowEditing(apiRef, props);
|
|
25
25
|
const debounceMap = React.useRef({});
|
|
26
|
-
apiRef.current.
|
|
26
|
+
apiRef.current.unstable_registerControlState({
|
|
27
27
|
stateId: 'editRows',
|
|
28
28
|
propModel: props.editRowsModel,
|
|
29
29
|
propOnChange: props.onEditRowsModelChange,
|
|
@@ -9,6 +9,11 @@ export declare const gridFilterStateSelector: (state: GridStateCommunity) => imp
|
|
|
9
9
|
* @category Filtering
|
|
10
10
|
*/
|
|
11
11
|
export declare const gridFilterModelSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridFilterModel>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the current quick filter values.
|
|
14
|
+
* @category Filtering
|
|
15
|
+
*/
|
|
16
|
+
export declare const gridQuickFilterValuesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, any[] | undefined>;
|
|
12
17
|
/**
|
|
13
18
|
* @category Filtering
|
|
14
19
|
* @ignore - do not document.
|
|
@@ -13,6 +13,12 @@ export const gridFilterStateSelector = state => state.filter;
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
export const gridFilterModelSelector = createSelector(gridFilterStateSelector, filterState => filterState.filterModel);
|
|
16
|
+
/**
|
|
17
|
+
* Get the current quick filter values.
|
|
18
|
+
* @category Filtering
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const gridQuickFilterValuesSelector = createSelector(gridFilterModelSelector, filterModel => filterModel.quickFilterValues);
|
|
16
22
|
/**
|
|
17
23
|
* @category Filtering
|
|
18
24
|
* @ignore - do not document.
|
|
@@ -12,7 +12,7 @@ import { GridAggregatedFilterItemApplier } from './gridFilterState';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const cleanFilterItem: (item: GridFilterItem, apiRef: React.MutableRefObject<GridApiCommunity>) => GridFilterItem;
|
|
14
14
|
export declare const sanitizeFilterModel: (model: GridFilterModel, disableMultipleColumnsFiltering: boolean, apiRef: React.MutableRefObject<GridApiCommunity>) => GridFilterModel;
|
|
15
|
-
export declare const mergeStateWithFilterModel: (filterModel: GridFilterModel, disableMultipleColumnsFiltering: boolean, apiRef: React.MutableRefObject<GridApiCommunity>) => (
|
|
15
|
+
export declare const mergeStateWithFilterModel: (filterModel: GridFilterModel, disableMultipleColumnsFiltering: boolean, apiRef: React.MutableRefObject<GridApiCommunity>) => (filteringState: GridStateCommunity['filter']) => GridStateCommunity['filter'];
|
|
16
16
|
/**
|
|
17
17
|
* Generates a method to easily check if a row is matching the current filter model.
|
|
18
18
|
* @param {GridFilterModel} filterModel The model with which we want to filter the rows.
|
|
@@ -64,10 +64,8 @@ export const sanitizeFilterModel = (model, disableMultipleColumnsFiltering, apiR
|
|
|
64
64
|
|
|
65
65
|
return model;
|
|
66
66
|
};
|
|
67
|
-
export const mergeStateWithFilterModel = (filterModel, disableMultipleColumnsFiltering, apiRef) =>
|
|
68
|
-
|
|
69
|
-
filterModel: sanitizeFilterModel(filterModel, disableMultipleColumnsFiltering, apiRef)
|
|
70
|
-
})
|
|
67
|
+
export const mergeStateWithFilterModel = (filterModel, disableMultipleColumnsFiltering, apiRef) => filteringState => _extends({}, filteringState, {
|
|
68
|
+
filterModel: sanitizeFilterModel(filterModel, disableMultipleColumnsFiltering, apiRef)
|
|
71
69
|
});
|
|
72
70
|
/**
|
|
73
71
|
* Generates a method to easily check if a row is matching the current filter model.
|
|
@@ -37,7 +37,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
37
37
|
var _props$componentsProp2;
|
|
38
38
|
|
|
39
39
|
const logger = useGridLogger(apiRef, 'useGridFilter');
|
|
40
|
-
apiRef.current.
|
|
40
|
+
apiRef.current.unstable_registerControlState({
|
|
41
41
|
stateId: 'filter',
|
|
42
42
|
propModel: props.filterModel,
|
|
43
43
|
propOnChange: props.onFilterModelChange,
|
|
@@ -78,7 +78,23 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
78
78
|
|
|
79
79
|
apiRef.current.setFilterModel(_extends({}, filterModel, {
|
|
80
80
|
items
|
|
81
|
-
}));
|
|
81
|
+
}), 'upsertFilterItem');
|
|
82
|
+
}, [apiRef]);
|
|
83
|
+
const upsertFilterItems = React.useCallback(items => {
|
|
84
|
+
const filterModel = gridFilterModelSelector(apiRef);
|
|
85
|
+
const existingItems = [...filterModel.items];
|
|
86
|
+
items.forEach(item => {
|
|
87
|
+
const itemIndex = items.findIndex(filterItem => filterItem.id === item.id);
|
|
88
|
+
|
|
89
|
+
if (itemIndex === -1) {
|
|
90
|
+
existingItems.push(item);
|
|
91
|
+
} else {
|
|
92
|
+
existingItems[itemIndex] = item;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
apiRef.current.setFilterModel(_extends({}, filterModel, {
|
|
96
|
+
items
|
|
97
|
+
}), 'upsertFilterItems');
|
|
82
98
|
}, [apiRef]);
|
|
83
99
|
const deleteFilterItem = React.useCallback(itemToDelete => {
|
|
84
100
|
const filterModel = gridFilterModelSelector(apiRef);
|
|
@@ -90,7 +106,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
90
106
|
|
|
91
107
|
apiRef.current.setFilterModel(_extends({}, filterModel, {
|
|
92
108
|
items
|
|
93
|
-
}));
|
|
109
|
+
}), 'deleteFilterItem');
|
|
94
110
|
}, [apiRef]);
|
|
95
111
|
const showFilterPanel = React.useCallback(targetColumnField => {
|
|
96
112
|
logger.debug('Displaying filter panel');
|
|
@@ -133,7 +149,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
133
149
|
|
|
134
150
|
apiRef.current.setFilterModel(_extends({}, filterModel, {
|
|
135
151
|
linkOperator
|
|
136
|
-
}));
|
|
152
|
+
}), 'changeLogicOperator');
|
|
137
153
|
}, [apiRef]);
|
|
138
154
|
const setQuickFilterValues = React.useCallback(values => {
|
|
139
155
|
const filterModel = gridFilterModelSelector(apiRef);
|
|
@@ -146,12 +162,12 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
146
162
|
quickFilterValues: [...values]
|
|
147
163
|
}));
|
|
148
164
|
}, [apiRef]);
|
|
149
|
-
const setFilterModel = React.useCallback(model => {
|
|
165
|
+
const setFilterModel = React.useCallback((model, reason) => {
|
|
150
166
|
const currentModel = gridFilterModelSelector(apiRef);
|
|
151
167
|
|
|
152
168
|
if (currentModel !== model) {
|
|
153
169
|
logger.debug('Setting filter model');
|
|
154
|
-
apiRef.current.
|
|
170
|
+
apiRef.current.unstable_updateControlState('filter', mergeStateWithFilterModel(model, props.disableMultipleColumnsFiltering, apiRef), reason);
|
|
155
171
|
apiRef.current.unstable_applyFilters();
|
|
156
172
|
}
|
|
157
173
|
}, [apiRef, logger, props.disableMultipleColumnsFiltering]);
|
|
@@ -164,6 +180,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
164
180
|
unstable_applyFilters: applyFilters,
|
|
165
181
|
deleteFilterItem,
|
|
166
182
|
upsertFilterItem,
|
|
183
|
+
upsertFilterItems,
|
|
167
184
|
setFilterModel,
|
|
168
185
|
showFilterPanel,
|
|
169
186
|
hideFilterPanel,
|
|
@@ -197,7 +214,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
197
214
|
return params;
|
|
198
215
|
}
|
|
199
216
|
|
|
200
|
-
apiRef.current.
|
|
217
|
+
apiRef.current.unstable_updateControlState('filter', mergeStateWithFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef), 'restoreState');
|
|
201
218
|
return _extends({}, params, {
|
|
202
219
|
callbacks: [...params.callbacks, apiRef.current.unstable_applyFilters]
|
|
203
220
|
});
|
|
@@ -39,7 +39,7 @@ export const useGridPage = (apiRef, props) => {
|
|
|
39
39
|
|
|
40
40
|
const logger = useGridLogger(apiRef, 'useGridPage');
|
|
41
41
|
const visibleTopLevelRowCount = useGridSelector(apiRef, gridVisibleTopLevelRowCountSelector);
|
|
42
|
-
apiRef.current.
|
|
42
|
+
apiRef.current.unstable_registerControlState({
|
|
43
43
|
stateId: 'page',
|
|
44
44
|
propModel: props.page,
|
|
45
45
|
propOnChange: props.onPageChange,
|
|
@@ -21,7 +21,7 @@ export const useGridPageSize = (apiRef, props) => {
|
|
|
21
21
|
|
|
22
22
|
const logger = useGridLogger(apiRef, 'useGridPageSize');
|
|
23
23
|
const rowHeight = useGridSelector(apiRef, gridDensityRowHeightSelector);
|
|
24
|
-
apiRef.current.
|
|
24
|
+
apiRef.current.unstable_registerControlState({
|
|
25
25
|
stateId: 'pageSize',
|
|
26
26
|
propModel: props.pageSize,
|
|
27
27
|
propOnChange: props.onPageSizeChange,
|
|
@@ -50,7 +50,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
50
50
|
return getSelectionModelPropValue(props.selectionModel, gridSelectionStateSelector(apiRef.current.state));
|
|
51
51
|
}, [apiRef, props.selectionModel]);
|
|
52
52
|
const lastRowToggled = React.useRef(null);
|
|
53
|
-
apiRef.current.
|
|
53
|
+
apiRef.current.unstable_registerControlState({
|
|
54
54
|
stateId: 'selection',
|
|
55
55
|
propModel: propSelectionModel,
|
|
56
56
|
propOnChange: props.onSelectionModelChange,
|
|
@@ -30,7 +30,7 @@ export const sortingStateInitializer = (state, props) => {
|
|
|
30
30
|
|
|
31
31
|
export const useGridSorting = (apiRef, props) => {
|
|
32
32
|
const logger = useGridLogger(apiRef, 'useGridSorting');
|
|
33
|
-
apiRef.current.
|
|
33
|
+
apiRef.current.unstable_registerControlState({
|
|
34
34
|
stateId: 'sortModel',
|
|
35
35
|
propModel: props.sortModel,
|
|
36
36
|
propOnChange: props.onSortModelChange,
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export var GridRootStyles = styled('div', {
|
|
|
10
10
|
_defineProperty({}, "& .".concat(gridClasses['cell--withRenderer']), styles['cell--withRenderer']), _defineProperty({}, "& .".concat(gridClasses.cell), styles.cell), _defineProperty({}, "& .".concat(gridClasses.cellContent), styles.cellContent), _defineProperty({}, "& .".concat(gridClasses.cellCheckbox), styles.cellCheckbox), _defineProperty({}, "& .".concat(gridClasses.checkboxInput), styles.checkboxInput), _defineProperty({}, "& .".concat(gridClasses['columnHeader--alignCenter']), styles['columnHeader--alignCenter']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--alignLeft']), styles['columnHeader--alignLeft']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--alignRight']), styles['columnHeader--alignRight']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--dragging']), styles['columnHeader--dragging']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--moving']), styles['columnHeader--moving']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--numeric']), styles['columnHeader--numeric']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--sortable']), styles['columnHeader--sortable']), _defineProperty({}, "& .".concat(gridClasses['columnHeader--sorted']), styles['columnHeader--sorted']), _defineProperty({}, "& .".concat(gridClasses.columnHeader), styles.columnHeader), _defineProperty({}, "& .".concat(gridClasses.columnHeaderCheckbox), styles.columnHeaderCheckbox), _defineProperty({}, "& .".concat(gridClasses.columnHeaderDraggableContainer), styles.columnHeaderDraggableContainer), _defineProperty({}, "& .".concat(gridClasses.columnHeaderTitleContainer), styles.columnHeaderTitleContainer), _defineProperty({}, "& .".concat(gridClasses['columnSeparator--resizable']), styles['columnSeparator--resizable']), _defineProperty({}, "& .".concat(gridClasses['columnSeparator--resizing']), styles['columnSeparator--resizing']), _defineProperty({}, "& .".concat(gridClasses.columnSeparator), styles.columnSeparator), _defineProperty({}, "& .".concat(gridClasses.filterIcon), styles.filterIcon), _defineProperty({}, "& .".concat(gridClasses.iconSeparator), styles.iconSeparator), _defineProperty({}, "& .".concat(gridClasses.menuIcon), styles.menuIcon), _defineProperty({}, "& .".concat(gridClasses.menuIconButton), styles.menuIconButton), _defineProperty({}, "& .".concat(gridClasses.menuOpen), styles.menuOpen), _defineProperty({}, "& .".concat(gridClasses.menuList), styles.menuList), _defineProperty({}, "& .".concat(gridClasses['row--editable']), styles['row--editable']), _defineProperty({}, "& .".concat(gridClasses['row--editing']), styles['row--editing']), _defineProperty({}, "& .".concat(gridClasses['row--dragging']), styles['row--dragging']), _defineProperty({}, "& .".concat(gridClasses.row), styles.row), _defineProperty({}, "& .".concat(gridClasses.rowReorderCellPlaceholder), styles.rowReorderCellPlaceholder), _defineProperty({}, "& .".concat(gridClasses.rowReorderCell), styles.rowReorderCell), _defineProperty({}, "& .".concat(gridClasses['rowReorderCell--draggable']), styles['rowReorderCell--draggable']), _defineProperty({}, "& .".concat(gridClasses.sortIcon), styles.sortIcon), _defineProperty({}, "& .".concat(gridClasses.withBorder), styles.withBorder), _defineProperty({}, "& .".concat(gridClasses.treeDataGroupingCell), styles.treeDataGroupingCell), _defineProperty({}, "& .".concat(gridClasses.treeDataGroupingCellToggle), styles.treeDataGroupingCellToggle), _defineProperty({}, "& .".concat(gridClasses.detailPanelToggleCell), styles.detailPanelToggleCell), _defineProperty({}, "& .".concat(gridClasses['detailPanelToggleCell--expanded']), styles['detailPanelToggleCell--expanded']), styles.root];
|
|
11
11
|
}
|
|
12
12
|
})(function (_ref46) {
|
|
13
|
-
var _$concat3, _extends2;
|
|
13
|
+
var _$concat2, _$concat3, _extends2;
|
|
14
14
|
|
|
15
15
|
var theme = _ref46.theme;
|
|
16
16
|
var borderColor = theme.palette.mode === 'light' ? lighten(alpha(theme.palette.divider, 1), 0.88) : darken(alpha(theme.palette.divider, 1), 0.68);
|
|
@@ -100,7 +100,7 @@ export var GridRootStyles = styled('div', {
|
|
|
100
100
|
left: -12
|
|
101
101
|
}), _defineProperty(_extends2, "& .".concat(gridClasses['columnSeparator--sideRight']), {
|
|
102
102
|
right: -12
|
|
103
|
-
}), _defineProperty(_extends2, "& .".concat(gridClasses['columnSeparator--resizable']),
|
|
103
|
+
}), _defineProperty(_extends2, "& .".concat(gridClasses['columnSeparator--resizable']), (_$concat2 = {
|
|
104
104
|
cursor: 'col-resize',
|
|
105
105
|
touchAction: 'none',
|
|
106
106
|
'&:hover': {
|
|
@@ -110,9 +110,11 @@ export var GridRootStyles = styled('div', {
|
|
|
110
110
|
color: borderColor
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
}, "&.".concat(gridClasses['columnSeparator--resizing']), {
|
|
113
|
+
}, _defineProperty(_$concat2, "&.".concat(gridClasses['columnSeparator--resizing']), {
|
|
114
114
|
color: theme.palette.text.primary
|
|
115
|
-
})
|
|
115
|
+
}), _defineProperty(_$concat2, '& svg', {
|
|
116
|
+
pointerEvents: 'none'
|
|
117
|
+
}), _$concat2)), _defineProperty(_extends2, "& .".concat(gridClasses.iconSeparator), {
|
|
116
118
|
color: 'inherit'
|
|
117
119
|
}), _defineProperty(_extends2, "& .".concat(gridClasses.menuIcon), {
|
|
118
120
|
width: 0,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["linkOperators", "columnsSort", "filterFormProps", "children"];
|
|
5
5
|
import * as React from 'react';
|
|
@@ -73,9 +73,7 @@ var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(pro
|
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
apiRef.current.
|
|
77
|
-
items: [].concat(_toConsumableArray(items), [defaultItem])
|
|
78
|
-
}));
|
|
76
|
+
apiRef.current.upsertFilterItems([].concat(_toConsumableArray(items), [defaultItem]));
|
|
79
77
|
};
|
|
80
78
|
|
|
81
79
|
var deleteFilter = React.useCallback(function (item) {
|