wip:milestone 0 fixes
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped

This commit is contained in:
2026-03-15 12:35:42 +02:00
parent 6708cf28a7
commit cffdf8af86
61266 changed files with 4511646 additions and 1938 deletions

View File

@@ -0,0 +1,250 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var _excluded = ["sort", "searchPredicate", "autoFocusSearchField", "disableHideAllButton", "disableShowAllButton", "getTogglableColumns"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import IconButton from '@mui/material/IconButton';
import { switchClasses } from '@mui/material/Switch';
import FormControlLabel from '@mui/material/FormControlLabel';
import { styled } from '@mui/material/styles';
import { gridColumnDefinitionsSelector, gridColumnVisibilityModelSelector } from '../../hooks/features/columns/gridColumnsSelector';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { GridPanelContent } from './GridPanelContent';
import { GridPanelFooter } from './GridPanelFooter';
import { GridPanelHeader } from './GridPanelHeader';
import { GridPanelWrapper } from './GridPanelWrapper';
import { GRID_EXPERIMENTAL_ENABLED } from '../../constants/envConstants';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['columnsPanel'],
columnsPanelRow: ['columnsPanelRow']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridColumnsPanelRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'ColumnsPanel',
overridesResolver: function overridesResolver(props, styles) {
return styles.columnsPanel;
}
})({
padding: '8px 0px 8px 8px'
});
var GridColumnsPanelRowRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'ColumnsPanelRow',
overridesResolver: function overridesResolver(props, styles) {
return styles.columnsPanelRow;
}
})(function (_ref) {
var theme = _ref.theme;
return _defineProperty({
display: 'flex',
justifyContent: 'space-between',
padding: '1px 8px 1px 7px'
}, "& .".concat(switchClasses.root), {
marginRight: theme.spacing(0.5)
});
});
var GridIconButtonRoot = styled(IconButton)({
justifyContent: 'flex-end'
});
var collator = new Intl.Collator();
var defaultSearchPredicate = function defaultSearchPredicate(column, searchValue) {
return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
};
function GridColumnsPanel(props) {
var _rootProps$slotProps, _rootProps$slotProps3, _rootProps$slotProps4;
var apiRef = useGridApiContext();
var searchInputRef = React.useRef(null);
var columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
var columnVisibilityModel = useGridSelector(apiRef, gridColumnVisibilityModelSelector);
var rootProps = useGridRootProps();
var _React$useState = React.useState(''),
_React$useState2 = _slicedToArray(_React$useState, 2),
searchValue = _React$useState2[0],
setSearchValue = _React$useState2[1];
var classes = useUtilityClasses(rootProps);
var sort = props.sort,
_props$searchPredicat = props.searchPredicate,
searchPredicate = _props$searchPredicat === void 0 ? defaultSearchPredicate : _props$searchPredicat,
_props$autoFocusSearc = props.autoFocusSearchField,
autoFocusSearchField = _props$autoFocusSearc === void 0 ? true : _props$autoFocusSearc,
_props$disableHideAll = props.disableHideAllButton,
disableHideAllButton = _props$disableHideAll === void 0 ? false : _props$disableHideAll,
_props$disableShowAll = props.disableShowAllButton,
disableShowAllButton = _props$disableShowAll === void 0 ? false : _props$disableShowAll,
getTogglableColumns = props.getTogglableColumns,
other = _objectWithoutProperties(props, _excluded);
var sortedColumns = React.useMemo(function () {
switch (sort) {
case 'asc':
return _toConsumableArray(columns).sort(function (a, b) {
return collator.compare(a.headerName || a.field, b.headerName || b.field);
});
case 'desc':
return _toConsumableArray(columns).sort(function (a, b) {
return -collator.compare(a.headerName || a.field, b.headerName || b.field);
});
default:
return columns;
}
}, [columns, sort]);
var toggleColumn = function toggleColumn(event) {
var _ref3 = event.target,
field = _ref3.name;
apiRef.current.setColumnVisibility(field, columnVisibilityModel[field] === false);
};
var toggleAllColumns = React.useCallback(function (isVisible) {
var currentModel = gridColumnVisibilityModelSelector(apiRef);
var newModel = _extends({}, currentModel);
var togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
columns.forEach(function (col) {
if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
if (isVisible) {
// delete the key from the model instead of setting it to `true`
delete newModel[col.field];
} else {
newModel[col.field] = false;
}
}
});
return apiRef.current.setColumnVisibilityModel(newModel);
}, [apiRef, columns, getTogglableColumns]);
var handleSearchValueChange = React.useCallback(function (event) {
setSearchValue(event.target.value);
}, []);
var currentColumns = React.useMemo(function () {
var togglableColumns = getTogglableColumns ? getTogglableColumns(sortedColumns) : null;
var togglableSortedColumns = togglableColumns ? sortedColumns.filter(function (_ref4) {
var field = _ref4.field;
return togglableColumns.includes(field);
}) : sortedColumns;
if (!searchValue) {
return togglableSortedColumns;
}
return togglableSortedColumns.filter(function (column) {
return searchPredicate(column, searchValue.toLowerCase());
});
}, [sortedColumns, searchValue, searchPredicate, getTogglableColumns]);
var firstSwitchRef = React.useRef(null);
React.useEffect(function () {
if (autoFocusSearchField) {
searchInputRef.current.focus();
} else if (firstSwitchRef.current && typeof firstSwitchRef.current.focus === 'function') {
firstSwitchRef.current.focus();
}
}, [autoFocusSearchField]);
var firstHideableColumnFound = false;
var isFirstHideableColumn = function isFirstHideableColumn(column) {
if (firstHideableColumnFound === false && column.hideable !== false) {
firstHideableColumnFound = true;
return true;
}
return false;
};
return /*#__PURE__*/_jsxs(GridPanelWrapper, _extends({}, other, {
children: [/*#__PURE__*/_jsx(GridPanelHeader, {
children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
label: apiRef.current.getLocaleText('columnsPanelTextFieldLabel'),
placeholder: apiRef.current.getLocaleText('columnsPanelTextFieldPlaceholder'),
inputRef: searchInputRef,
value: searchValue,
onChange: handleSearchValueChange,
variant: "standard",
fullWidth: true
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField))
}), /*#__PURE__*/_jsx(GridPanelContent, {
children: /*#__PURE__*/_jsx(GridColumnsPanelRoot, {
className: classes.root,
ownerState: rootProps,
children: currentColumns.map(function (column) {
var _rootProps$slotProps2;
return /*#__PURE__*/_jsxs(GridColumnsPanelRowRoot, {
className: classes.columnsPanelRow,
ownerState: rootProps,
children: [/*#__PURE__*/_jsx(FormControlLabel, {
control: /*#__PURE__*/_jsx(rootProps.slots.baseSwitch, _extends({
disabled: column.hideable === false,
checked: columnVisibilityModel[column.field] !== false,
onClick: toggleColumn,
name: column.field,
size: "small",
inputRef: isFirstHideableColumn(column) ? firstSwitchRef : undefined
}, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSwitch)),
label: column.headerName || column.field
}), !rootProps.disableColumnReorder && GRID_EXPERIMENTAL_ENABLED && /*#__PURE__*/_jsx(GridIconButtonRoot, {
draggable: true,
"aria-label": apiRef.current.getLocaleText('columnsPanelDragIconLabel'),
title: apiRef.current.getLocaleText('columnsPanelDragIconLabel'),
size: "small",
disabled: true,
children: /*#__PURE__*/_jsx(rootProps.slots.columnReorderIcon, {})
})]
}, column.field);
})
})
}), disableShowAllButton && disableHideAllButton ? null : /*#__PURE__*/_jsxs(GridPanelFooter, {
children: [!disableHideAllButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
onClick: function onClick() {
return toggleAllColumns(false);
}
}, (_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseButton, {
disabled: disableHideAllButton,
children: apiRef.current.getLocaleText('columnsPanelHideAllButton')
})) : /*#__PURE__*/_jsx("span", {}), !disableShowAllButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
onClick: function onClick() {
return toggleAllColumns(true);
}
}, (_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseButton, {
disabled: disableShowAllButton,
children: apiRef.current.getLocaleText('columnsPanelShowAllButton')
})) : null]
})]
}));
}
process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* If `true`, the column search field will be focused automatically.
* If `false`, the first column switch input will be focused automatically.
* This helps to avoid input keyboard panel to popup automatically on touch devices.
* @default true
*/
autoFocusSearchField: PropTypes.bool,
/**
* If `true`, the `Hide all` button will not be displayed.
* @default false
*/
disableHideAllButton: PropTypes.bool,
/**
* If `true`, the `Show all` button will be disabled
* @default false
*/
disableShowAllButton: PropTypes.bool,
/**
* Returns the list of togglable columns.
* If used, only those columns will be displayed in the panel
* which are passed as the return value of the function.
* @param {GridColDef[]} columns The `ColDef` list of all columns.
* @returns {GridColDef['field'][]} The list of togglable columns' field names.
*/
getTogglableColumns: PropTypes.func,
searchPredicate: PropTypes.func,
slotProps: PropTypes.object,
sort: PropTypes.oneOf(['asc', 'desc'])
} : void 0;
export { GridColumnsPanel };

View File

@@ -0,0 +1,141 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children", "className", "classes"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/material/styles';
import { unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
import ClickAwayListener from '@mui/material/ClickAwayListener';
import Paper from '@mui/material/Paper';
import Popper from '@mui/material/Popper';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { isEscapeKey } from '../../utils/keyboardUtils';
import { gridClasses } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
export var gridPanelClasses = generateUtilityClasses('MuiDataGrid', ['panel', 'paper']);
var GridPanelRoot = styled(Popper, {
name: 'MuiDataGrid',
slot: 'Panel',
overridesResolver: function overridesResolver(props, styles) {
return styles.panel;
}
})(function (_ref) {
var theme = _ref.theme;
return {
zIndex: theme.zIndex.modal
};
});
var GridPaperRoot = styled(Paper, {
name: 'MuiDataGrid',
slot: 'Paper',
overridesResolver: function overridesResolver(props, styles) {
return styles.paper;
}
})(function (_ref2) {
var theme = _ref2.theme;
return {
backgroundColor: (theme.vars || theme).palette.background.paper,
minWidth: 300,
maxHeight: 450,
display: 'flex'
};
});
var GridPanel = /*#__PURE__*/React.forwardRef(function (props, ref) {
var children = props.children,
className = props.className,
classesProp = props.classes,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var classes = gridPanelClasses;
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
isPlaced = _React$useState2[0],
setIsPlaced = _React$useState2[1];
var handleClickAway = React.useCallback(function () {
apiRef.current.hidePreferences();
}, [apiRef]);
var handleKeyDown = React.useCallback(function (event) {
if (isEscapeKey(event.key)) {
apiRef.current.hidePreferences();
}
}, [apiRef]);
var modifiers = React.useMemo(function () {
return [{
name: 'flip',
enabled: true,
options: {
rootBoundary: 'document'
}
}, {
name: 'isPlaced',
enabled: true,
phase: 'main',
fn: function fn() {
setIsPlaced(true);
},
effect: function effect() {
return function () {
setIsPlaced(false);
};
}
}];
}, []);
var _React$useState3 = React.useState(null),
_React$useState4 = _slicedToArray(_React$useState3, 2),
anchorEl = _React$useState4[0],
setAnchorEl = _React$useState4[1];
React.useEffect(function () {
var _apiRef$current$rootE;
var columnHeadersElement = (_apiRef$current$rootE = apiRef.current.rootElementRef) == null || (_apiRef$current$rootE = _apiRef$current$rootE.current) == null ? void 0 : _apiRef$current$rootE.querySelector(".".concat(gridClasses.columnHeaders));
if (columnHeadersElement) {
setAnchorEl(columnHeadersElement);
}
}, [apiRef]);
if (!anchorEl) {
return null;
}
return /*#__PURE__*/_jsx(GridPanelRoot, _extends({
ref: ref,
placement: "bottom-start",
className: clsx(className, classes.panel),
ownerState: rootProps,
anchorEl: anchorEl,
modifiers: modifiers
}, other, {
children: /*#__PURE__*/_jsx(ClickAwayListener, {
mouseEvent: "onMouseUp",
onClickAway: handleClickAway,
children: /*#__PURE__*/_jsx(GridPaperRoot, {
className: classes.paper,
ownerState: rootProps,
elevation: 8,
onKeyDown: handleKeyDown,
children: isPlaced && children
})
})
}));
});
process.env.NODE_ENV !== "production" ? GridPanel.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* Popper render function or node.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* If `true`, the component is shown.
*/
open: PropTypes.bool.isRequired,
ownerState: PropTypes.object
} : void 0;
export { GridPanel };

View File

@@ -0,0 +1,49 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["className"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/system';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['panelContent']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridPanelContentRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'PanelContent',
overridesResolver: function overridesResolver(props, styles) {
return styles.panelContent;
}
})({
display: 'flex',
flexDirection: 'column',
overflow: 'auto',
flex: '1 1',
maxHeight: 400
});
function GridPanelContent(props) {
var className = props.className,
other = _objectWithoutProperties(props, _excluded);
var rootProps = useGridRootProps();
var classes = useUtilityClasses(rootProps);
return /*#__PURE__*/_jsx(GridPanelContentRoot, _extends({
className: clsx(className, classes.root),
ownerState: rootProps
}, other));
}
process.env.NODE_ENV !== "production" ? GridPanelContent.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export { GridPanelContent };

View File

@@ -0,0 +1,50 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["className"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/system';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['panelFooter']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridPanelFooterRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'PanelFooter',
overridesResolver: function overridesResolver(props, styles) {
return styles.panelFooter;
}
})(function (_ref) {
var theme = _ref.theme;
return {
padding: theme.spacing(0.5),
display: 'flex',
justifyContent: 'space-between'
};
});
function GridPanelFooter(props) {
var className = props.className,
other = _objectWithoutProperties(props, _excluded);
var rootProps = useGridRootProps();
var classes = useUtilityClasses(rootProps);
return /*#__PURE__*/_jsx(GridPanelFooterRoot, _extends({
className: clsx(className, classes.root),
ownerState: rootProps
}, other));
}
process.env.NODE_ENV !== "production" ? GridPanelFooter.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export { GridPanelFooter };

View File

@@ -0,0 +1,48 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["className"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/system';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['panelHeader']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridPanelHeaderRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'PanelHeader',
overridesResolver: function overridesResolver(props, styles) {
return styles.panelHeader;
}
})(function (_ref) {
var theme = _ref.theme;
return {
padding: theme.spacing(1)
};
});
function GridPanelHeader(props) {
var className = props.className,
other = _objectWithoutProperties(props, _excluded);
var rootProps = useGridRootProps();
var classes = useUtilityClasses(rootProps);
return /*#__PURE__*/_jsx(GridPanelHeaderRoot, _extends({
className: clsx(className, classes.root),
ownerState: rootProps
}, other));
}
process.env.NODE_ENV !== "production" ? GridPanelHeader.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export { GridPanelHeader };

View File

@@ -0,0 +1,64 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["className", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import FocusTrap from '@mui/material/Unstable_TrapFocus';
import { styled } from '@mui/material/styles';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['panelWrapper']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridPanelWrapperRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'PanelWrapper',
overridesResolver: function overridesResolver(props, styles) {
return styles.panelWrapper;
}
})({
display: 'flex',
flexDirection: 'column',
flex: 1,
'&:focus': {
outline: 0
}
});
var isEnabled = function isEnabled() {
return true;
};
var GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper(props, ref) {
var className = props.className,
_props$slotProps = props.slotProps,
slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
other = _objectWithoutProperties(props, _excluded);
var rootProps = useGridRootProps();
var classes = useUtilityClasses(rootProps);
return /*#__PURE__*/_jsx(FocusTrap, _extends({
open: true,
disableEnforceFocus: true,
isEnabled: isEnabled
}, slotProps.TrapFocus, {
children: /*#__PURE__*/_jsx(GridPanelWrapperRoot, _extends({
ref: ref,
tabIndex: -1,
className: clsx(className, classes.root),
ownerState: rootProps
}, other))
}));
});
process.env.NODE_ENV !== "production" ? GridPanelWrapper.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
slotProps: PropTypes.object
} : void 0;
export { GridPanelWrapper };

View File

@@ -0,0 +1,26 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { gridColumnDefinitionsSelector } from '../../hooks/features/columns/gridColumnsSelector';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { gridPreferencePanelStateSelector } from '../../hooks/features/preferencesPanel/gridPreferencePanelSelector';
import { GridPreferencePanelsValue } from '../../hooks/features/preferencesPanel/gridPreferencePanelsValue';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
export var GridPreferencesPanel = /*#__PURE__*/React.forwardRef(function GridPreferencesPanel(props, ref) {
var _preferencePanelState, _rootProps$slotProps, _rootProps$slotProps2;
var apiRef = useGridApiContext();
var columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
var rootProps = useGridRootProps();
var preferencePanelState = useGridSelector(apiRef, gridPreferencePanelStateSelector);
var panelContent = apiRef.current.unstable_applyPipeProcessors('preferencePanel', null, (_preferencePanelState = preferencePanelState.openedPanelValue) != null ? _preferencePanelState : GridPreferencePanelsValue.filters);
return /*#__PURE__*/_jsx(rootProps.slots.panel, _extends({
ref: ref,
as: rootProps.slots.basePopper,
open: columns.length > 0 && preferencePanelState.open,
id: preferencePanelState.panelId,
"aria-labelledby": preferencePanelState.labelId
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.panel, props, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.basePopper, {
children: panelContent
}));
});

View File

@@ -0,0 +1,479 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "logicOperators", "columnsSort", "filterColumns", "deleteIconProps", "logicOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
_excluded2 = ["InputComponentProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses, unstable_useId as useId, unstable_capitalize as capitalize } from '@mui/utils';
import { styled } from '@mui/material/styles';
import clsx from 'clsx';
import { gridFilterableColumnDefinitionsSelector } from '../../../hooks/features/columns/gridColumnsSelector';
import { gridFilterModelSelector } from '../../../hooks/features/filter/gridFilterSelector';
import { useGridSelector } from '../../../hooks/utils/useGridSelector';
import { GridLogicOperator } from '../../../models/gridFilterItem';
import { useGridApiContext } from '../../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { getDataGridUtilityClass } from '../../../constants/gridClasses';
import { jsx as _jsx } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
import { jsxs as _jsxs } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['filterForm'],
deleteIcon: ['filterFormDeleteIcon'],
logicOperatorInput: ['filterFormLogicOperatorInput'],
columnInput: ['filterFormColumnInput'],
operatorInput: ['filterFormOperatorInput'],
valueInput: ['filterFormValueInput']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridFilterFormRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterForm',
overridesResolver: function overridesResolver(props, styles) {
return styles.filterForm;
}
})(function (_ref) {
var theme = _ref.theme;
return {
display: 'flex',
padding: theme.spacing(1)
};
});
var FilterFormDeleteIcon = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterFormDeleteIcon',
overridesResolver: function overridesResolver(_, styles) {
return styles.filterFormDeleteIcon;
}
})(function (_ref2) {
var theme = _ref2.theme;
return {
flexShrink: 0,
justifyContent: 'flex-end',
marginRight: theme.spacing(0.5),
marginBottom: theme.spacing(0.2)
};
});
var FilterFormLogicOperatorInput = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterFormLogicOperatorInput',
overridesResolver: function overridesResolver(_, styles) {
return styles.filterFormLogicOperatorInput;
}
})({
minWidth: 55,
marginRight: 5,
justifyContent: 'end'
});
var FilterFormColumnInput = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterFormColumnInput',
overridesResolver: function overridesResolver(_, styles) {
return styles.filterFormColumnInput;
}
})({
width: 150
});
var FilterFormOperatorInput = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterFormOperatorInput',
overridesResolver: function overridesResolver(_, styles) {
return styles.filterFormOperatorInput;
}
})({
width: 120
});
var FilterFormValueInput = styled('div', {
name: 'MuiDataGrid',
slot: 'FilterFormValueInput',
overridesResolver: function overridesResolver(_, styles) {
return styles.filterFormValueInput;
}
})({
width: 190
});
var getLogicOperatorLocaleKey = function getLogicOperatorLocaleKey(logicOperator) {
switch (logicOperator) {
case GridLogicOperator.And:
return 'filterPanelOperatorAnd';
case GridLogicOperator.Or:
return 'filterPanelOperatorOr';
default:
throw new Error('MUI: Invalid `logicOperator` property in the `GridFilterPanel`.');
}
};
var getColumnLabel = function getColumnLabel(col) {
return col.headerName || col.field;
};
var collator = new Intl.Collator();
var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props, ref) {
var _rootProps$slotProps, _rootProps$slotProps2, _baseSelectProps$nati, _rootProps$slotProps3, _rootProps$slotProps4, _rootProps$slotProps5, _rootProps$slotProps6, _rootProps$slotProps7, _rootProps$slotProps8, _currentColumn$filter2;
var item = props.item,
hasMultipleFilters = props.hasMultipleFilters,
deleteFilter = props.deleteFilter,
applyFilterChanges = props.applyFilterChanges,
multiFilterOperator = props.multiFilterOperator,
showMultiFilterOperators = props.showMultiFilterOperators,
disableMultiFilterOperator = props.disableMultiFilterOperator,
applyMultiFilterOperatorChanges = props.applyMultiFilterOperatorChanges,
focusElementRef = props.focusElementRef,
_props$logicOperators = props.logicOperators,
logicOperators = _props$logicOperators === void 0 ? [GridLogicOperator.And, GridLogicOperator.Or] : _props$logicOperators,
columnsSort = props.columnsSort,
filterColumns = props.filterColumns,
_props$deleteIconProp = props.deleteIconProps,
deleteIconProps = _props$deleteIconProp === void 0 ? {} : _props$deleteIconProp,
_props$logicOperatorI = props.logicOperatorInputProps,
logicOperatorInputProps = _props$logicOperatorI === void 0 ? {} : _props$logicOperatorI,
_props$operatorInputP = props.operatorInputProps,
operatorInputProps = _props$operatorInputP === void 0 ? {} : _props$operatorInputP,
_props$columnInputPro = props.columnInputProps,
columnInputProps = _props$columnInputPro === void 0 ? {} : _props$columnInputPro,
_props$valueInputProp = props.valueInputProps,
valueInputProps = _props$valueInputProp === void 0 ? {} : _props$valueInputProp,
children = props.children,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var filterableColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
var filterModel = useGridSelector(apiRef, gridFilterModelSelector);
var columnSelectId = useId();
var columnSelectLabelId = useId();
var operatorSelectId = useId();
var operatorSelectLabelId = useId();
var rootProps = useGridRootProps();
var classes = useUtilityClasses(rootProps);
var valueRef = React.useRef(null);
var filterSelectorRef = React.useRef(null);
var hasLogicOperatorColumn = hasMultipleFilters && logicOperators.length > 0;
var baseFormControlProps = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseFormControl) || {};
var baseSelectProps = ((_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSelect) || {};
var isBaseSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
var baseInputLabelProps = ((_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseInputLabel) || {};
var baseSelectOptionProps = ((_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseSelectOption) || {};
var InputComponentProps = valueInputProps.InputComponentProps,
valueInputPropsOther = _objectWithoutProperties(valueInputProps, _excluded2);
var filteredColumns = React.useMemo(function () {
if (filterColumns === undefined || typeof filterColumns !== 'function') {
return filterableColumns;
}
var filteredFields = filterColumns({
field: item.field,
columns: filterableColumns,
currentFilters: (filterModel == null ? void 0 : filterModel.items) || []
});
return filterableColumns.filter(function (column) {
return filteredFields.includes(column.field);
});
}, [filterColumns, filterModel == null ? void 0 : filterModel.items, filterableColumns, item.field]);
var sortedFilteredColumns = React.useMemo(function () {
switch (columnsSort) {
case 'asc':
return filteredColumns.sort(function (a, b) {
return collator.compare(getColumnLabel(a), getColumnLabel(b));
});
case 'desc':
return filteredColumns.sort(function (a, b) {
return -collator.compare(getColumnLabel(a), getColumnLabel(b));
});
default:
return filteredColumns;
}
}, [filteredColumns, columnsSort]);
var currentColumn = item.field ? apiRef.current.getColumn(item.field) : null;
var currentOperator = React.useMemo(function () {
var _currentColumn$filter;
if (!item.operator || !currentColumn) {
return null;
}
return (_currentColumn$filter = currentColumn.filterOperators) == null ? void 0 : _currentColumn$filter.find(function (operator) {
return operator.value === item.operator;
});
}, [item, currentColumn]);
var changeColumn = React.useCallback(function (event) {
var field = event.target.value;
var column = apiRef.current.getColumn(field);
if (column.field === currentColumn.field) {
// column did not change
return;
}
// try to keep the same operator when column change
var newOperator = column.filterOperators.find(function (operator) {
return operator.value === item.operator;
}) || column.filterOperators[0];
// Erase filter value if the input component or filtered column type is modified
var eraseItemValue = !newOperator.InputComponent || newOperator.InputComponent !== (currentOperator == null ? void 0 : currentOperator.InputComponent) || column.type !== currentColumn.type;
applyFilterChanges(_extends({}, item, {
field: field,
operator: newOperator.value,
value: eraseItemValue ? undefined : item.value
}));
}, [apiRef, applyFilterChanges, item, currentColumn, currentOperator]);
var changeOperator = React.useCallback(function (event) {
var operator = event.target.value;
var newOperator = currentColumn == null ? void 0 : currentColumn.filterOperators.find(function (op) {
return op.value === operator;
});
var eraseItemValue = !(newOperator != null && newOperator.InputComponent) || (newOperator == null ? void 0 : newOperator.InputComponent) !== (currentOperator == null ? void 0 : currentOperator.InputComponent);
applyFilterChanges(_extends({}, item, {
operator: operator,
value: eraseItemValue ? undefined : item.value
}));
}, [applyFilterChanges, item, currentColumn, currentOperator]);
var changeLogicOperator = React.useCallback(function (event) {
var logicOperator = event.target.value === GridLogicOperator.And.toString() ? GridLogicOperator.And : GridLogicOperator.Or;
applyMultiFilterOperatorChanges(logicOperator);
}, [applyMultiFilterOperatorChanges]);
var handleDeleteFilter = function handleDeleteFilter() {
if (rootProps.disableMultipleColumnsFiltering) {
if (item.value === undefined) {
deleteFilter(item);
} else {
// TODO v6: simplify the behavior by always remove the filter form
applyFilterChanges(_extends({}, item, {
value: undefined
}));
}
} else {
deleteFilter(item);
}
};
React.useImperativeHandle(focusElementRef, function () {
return {
focus: function focus() {
if (currentOperator != null && currentOperator.InputComponent) {
var _valueRef$current;
valueRef == null || (_valueRef$current = valueRef.current) == null || _valueRef$current.focus();
} else {
filterSelectorRef.current.focus();
}
}
};
}, [currentOperator]);
return /*#__PURE__*/_jsxs(GridFilterFormRoot, _extends({
ref: ref,
className: classes.root,
"data-id": item.id,
ownerState: rootProps
}, other, {
children: [/*#__PURE__*/_jsx(FilterFormDeleteIcon, _extends({
variant: "standard",
as: rootProps.slots.baseFormControl
}, baseFormControlProps, deleteIconProps, {
className: clsx(classes.deleteIcon, baseFormControlProps.className, deleteIconProps.className),
ownerState: rootProps,
children: /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
"aria-label": apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
title: apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
onClick: handleDeleteFilter,
size: "small"
}, (_rootProps$slotProps5 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps5.baseIconButton, {
children: /*#__PURE__*/_jsx(rootProps.slots.filterPanelDeleteIcon, {
fontSize: "small"
})
}))
})), /*#__PURE__*/_jsx(FilterFormLogicOperatorInput, _extends({
variant: "standard",
as: rootProps.slots.baseFormControl
}, baseFormControlProps, logicOperatorInputProps, {
sx: _extends({
display: hasLogicOperatorColumn ? 'flex' : 'none',
visibility: showMultiFilterOperators ? 'visible' : 'hidden'
}, baseFormControlProps.sx || {}, logicOperatorInputProps.sx || {}),
className: clsx(classes.logicOperatorInput, baseFormControlProps.className, logicOperatorInputProps.className),
ownerState: rootProps,
children: /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
inputProps: {
'aria-label': apiRef.current.getLocaleText('filterPanelLogicOperator')
},
value: multiFilterOperator,
onChange: changeLogicOperator,
disabled: !!disableMultiFilterOperator || logicOperators.length === 1,
native: isBaseSelectNative
}, (_rootProps$slotProps6 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps6.baseSelect, {
children: logicOperators.map(function (logicOperator) {
return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isBaseSelectNative,
key: logicOperator.toString(),
value: logicOperator.toString()
}), apiRef.current.getLocaleText(getLogicOperatorLocaleKey(logicOperator)));
})
}))
})), /*#__PURE__*/_jsxs(FilterFormColumnInput, _extends({
variant: "standard",
as: rootProps.slots.baseFormControl
}, baseFormControlProps, columnInputProps, {
className: clsx(classes.columnInput, baseFormControlProps.className, columnInputProps.className),
ownerState: rootProps,
children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, baseInputLabelProps, {
htmlFor: columnSelectId,
id: columnSelectLabelId,
children: apiRef.current.getLocaleText('filterPanelColumns')
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
labelId: columnSelectLabelId,
id: columnSelectId,
label: apiRef.current.getLocaleText('filterPanelColumns'),
value: item.field || '',
onChange: changeColumn,
native: isBaseSelectNative
}, (_rootProps$slotProps7 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps7.baseSelect, {
children: sortedFilteredColumns.map(function (col) {
return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isBaseSelectNative,
key: col.field,
value: col.field
}), getColumnLabel(col));
})
}))]
})), /*#__PURE__*/_jsxs(FilterFormOperatorInput, _extends({
variant: "standard",
as: rootProps.slots.baseFormControl
}, baseFormControlProps, operatorInputProps, {
className: clsx(classes.operatorInput, baseFormControlProps.className, operatorInputProps.className),
ownerState: rootProps,
children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, baseInputLabelProps, {
htmlFor: operatorSelectId,
id: operatorSelectLabelId,
children: apiRef.current.getLocaleText('filterPanelOperator')
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
labelId: operatorSelectLabelId,
label: apiRef.current.getLocaleText('filterPanelOperator'),
id: operatorSelectId,
value: item.operator,
onChange: changeOperator,
native: isBaseSelectNative,
inputRef: filterSelectorRef
}, (_rootProps$slotProps8 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps8.baseSelect, {
children: currentColumn == null || (_currentColumn$filter2 = currentColumn.filterOperators) == null ? void 0 : _currentColumn$filter2.map(function (operator) {
return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isBaseSelectNative,
key: operator.value,
value: operator.value
}), operator.label || apiRef.current.getLocaleText("filterOperator".concat(capitalize(operator.value))));
})
}))]
})), /*#__PURE__*/_jsx(FilterFormValueInput, _extends({
variant: "standard",
as: rootProps.slots.baseFormControl
}, baseFormControlProps, valueInputPropsOther, {
className: clsx(classes.valueInput, baseFormControlProps.className, valueInputPropsOther.className),
ownerState: rootProps,
children: currentOperator != null && currentOperator.InputComponent ? /*#__PURE__*/_jsx(currentOperator.InputComponent, _extends({
apiRef: apiRef,
item: item,
applyValue: applyFilterChanges,
focusElementRef: valueRef
}, currentOperator.InputComponentProps, InputComponentProps)) : null
}))]
}));
});
process.env.NODE_ENV !== "production" ? GridFilterForm.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* Callback called when the operator, column field or value is changed.
* @param {GridFilterItem} item The updated [[GridFilterItem]].
*/
applyFilterChanges: PropTypes.func.isRequired,
/**
* Callback called when the logic operator is changed.
* @param {GridLogicOperator} operator The new logic operator.
*/
applyMultiFilterOperatorChanges: PropTypes.func.isRequired,
/**
* @ignore - do not document.
*/
children: PropTypes.node,
/**
* Props passed to the column input component.
* @default {}
*/
columnInputProps: PropTypes.any,
/**
* Changes how the options in the columns selector should be ordered.
* If not specified, the order is derived from the `columns` prop.
*/
columnsSort: PropTypes.oneOf(['asc', 'desc']),
/**
* Callback called when the delete button is clicked.
* @param {GridFilterItem} item The deleted [[GridFilterItem]].
*/
deleteFilter: PropTypes.func.isRequired,
/**
* Props passed to the delete icon.
* @default {}
*/
deleteIconProps: PropTypes.any,
/**
* If `true`, disables the logic operator field but still renders it.
*/
disableMultiFilterOperator: PropTypes.bool,
/**
* Allows to filter the columns displayed in the filter form.
* @param {FilterColumnsArgs} args The columns of the grid and name of field.
* @returns {GridColDef['field'][]} The filtered fields array.
*/
filterColumns: PropTypes.func,
/**
* A ref allowing to set imperative focus.
* It can be passed to the el
*/
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
/**
* If `true`, the logic operator field is rendered.
* The field will be invisible if `showMultiFilterOperators` is also `true`.
*/
hasMultipleFilters: PropTypes.bool.isRequired,
/**
* The [[GridFilterItem]] representing this form.
*/
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired,
/**
* Props passed to the logic operator input component.
* @default {}
*/
logicOperatorInputProps: PropTypes.any,
/**
* Sets the available logic operators.
* @default [GridLogicOperator.And, GridLogicOperator.Or]
*/
logicOperators: PropTypes.arrayOf(PropTypes.oneOf(['and', 'or']).isRequired),
/**
* The current logic operator applied.
*/
multiFilterOperator: PropTypes.oneOf(['and', 'or']),
/**
* Props passed to the operator input component.
* @default {}
*/
operatorInputProps: PropTypes.any,
/**
* If `true`, the logic operator field is visible.
*/
showMultiFilterOperators: PropTypes.bool,
/**
* Props passed to the value input component.
* @default {}
*/
valueInputProps: PropTypes.any
} : void 0;
/**
* Demos:
* - [Filtering - overview](https://mui.com/x/react-data-grid/filtering/)
*
* API:
* - [GridFilterForm API](https://mui.com/x/api/data-grid/grid-filter-form/)
*/
export { GridFilterForm };

View File

@@ -0,0 +1,118 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var _excluded = ["item", "applyValue", "apiRef", "focusElementRef", "isFilterActive", "clearButton", "tabIndex", "label", "variant", "InputLabelProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { refType, unstable_useId as useId } from '@mui/utils';
import { styled } from '@mui/material/styles';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var BooleanOperatorContainer = styled('div')(_defineProperty({
display: 'flex',
alignItems: 'center',
width: '100%'
}, "& button", {
margin: 'auto 0px 5px 5px'
}));
function GridFilterInputBoolean(props) {
var _rootProps$slotProps, _baseSelectProps$nati, _rootProps$slotProps2, _rootProps$slotProps3;
var item = props.item,
applyValue = props.applyValue,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
isFilterActive = props.isFilterActive,
clearButton = props.clearButton,
tabIndex = props.tabIndex,
labelProp = props.label,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
InputLabelProps = props.InputLabelProps,
others = _objectWithoutProperties(props, _excluded);
var _React$useState = React.useState(item.value || ''),
_React$useState2 = _slicedToArray(_React$useState, 2),
filterValueState = _React$useState2[0],
setFilterValueState = _React$useState2[1];
var rootProps = useGridRootProps();
var labelId = useId();
var selectId = useId();
var baseSelectProps = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseSelect) || {};
var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
var baseSelectOptionProps = ((_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSelectOption) || {};
var onFilterChange = React.useCallback(function (event) {
var value = event.target.value;
setFilterValueState(value);
applyValue(_extends({}, item, {
value: value
}));
}, [applyValue, item]);
React.useEffect(function () {
setFilterValueState(item.value || '');
}, [item.value]);
var label = labelProp != null ? labelProp : apiRef.current.getLocaleText('filterPanelInputLabel');
return /*#__PURE__*/_jsxs(BooleanOperatorContainer, {
children: [/*#__PURE__*/_jsxs(rootProps.slots.baseFormControl, {
fullWidth: true,
children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, (_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseInputLabel, {
id: labelId,
shrink: true,
variant: variant,
children: label
})), /*#__PURE__*/_jsxs(rootProps.slots.baseSelect, _extends({
labelId: labelId,
id: selectId,
label: label,
value: filterValueState,
onChange: onFilterChange,
variant: variant,
notched: variant === 'outlined' ? true : undefined,
native: isSelectNative,
displayEmpty: true,
inputProps: {
ref: focusElementRef,
tabIndex: tabIndex
}
}, others, baseSelectProps, {
children: [/*#__PURE__*/_jsx(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isSelectNative,
value: "",
children: apiRef.current.getLocaleText('filterValueAny')
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isSelectNative,
value: "true",
children: apiRef.current.getLocaleText('filterValueTrue')
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
native: isSelectNative,
value: "false",
children: apiRef.current.getLocaleText('filterValueFalse')
}))]
}))]
}), clearButton]
});
}
process.env.NODE_ENV !== "production" ? GridFilterInputBoolean.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
clearButton: PropTypes.node,
focusElementRef: refType,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (e.g. `isEmpty`)
*/
isFilterActive: PropTypes.bool,
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired
} : void 0;
export { GridFilterInputBoolean };

View File

@@ -0,0 +1,102 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "InputProps", "isFilterActive", "clearButton", "tabIndex", "disabled"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useId as useId } from '@mui/utils';
import { useTimeout } from '../../../hooks/utils/useTimeout';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
function GridFilterInputDate(props) {
var _item$value, _rootProps$slotProps;
var item = props.item,
applyValue = props.applyValue,
type = props.type,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
InputProps = props.InputProps,
isFilterActive = props.isFilterActive,
clearButton = props.clearButton,
tabIndex = props.tabIndex,
disabled = props.disabled,
other = _objectWithoutProperties(props, _excluded);
var filterTimeout = useTimeout();
var _React$useState = React.useState((_item$value = item.value) != null ? _item$value : ''),
_React$useState2 = _slicedToArray(_React$useState, 2),
filterValueState = _React$useState2[0],
setFilterValueState = _React$useState2[1];
var _React$useState3 = React.useState(false),
_React$useState4 = _slicedToArray(_React$useState3, 2),
applying = _React$useState4[0],
setIsApplying = _React$useState4[1];
var id = useId();
var rootProps = useGridRootProps();
var onFilterChange = React.useCallback(function (event) {
var value = event.target.value;
setFilterValueState(String(value));
setIsApplying(true);
filterTimeout.start(rootProps.filterDebounceMs, function () {
applyValue(_extends({}, item, {
value: value
}));
setIsApplying(false);
});
}, [applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
React.useEffect(function () {
var _item$value2;
var itemValue = (_item$value2 = item.value) != null ? _item$value2 : '';
setFilterValueState(String(itemValue));
}, [item.value]);
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
fullWidth: true,
id: id,
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'),
value: filterValueState,
onChange: onFilterChange,
variant: "standard",
type: type || 'text',
InputLabelProps: {
shrink: true
},
inputRef: focusElementRef,
InputProps: _extends({}, applying || clearButton ? {
endAdornment: applying ? /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {
fontSize: "small",
color: "action"
}) : clearButton
} : {}, {
disabled: disabled
}, InputProps, {
inputProps: _extends({
max: type === 'datetime-local' ? '9999-12-31T23:59' : '9999-12-31',
tabIndex: tabIndex
}, InputProps == null ? void 0 : InputProps.inputProps)
})
}, other, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField));
}
process.env.NODE_ENV !== "production" ? GridFilterInputDate.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
clearButton: PropTypes.node,
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (e.g. `isEmpty`)
*/
isFilterActive: PropTypes.bool,
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired
} : void 0;
export { GridFilterInputDate };

View File

@@ -0,0 +1,163 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant", "getOptionLabel", "getOptionValue"];
import * as React from 'react';
import PropTypes from 'prop-types';
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import { unstable_useId as useId } from '@mui/utils';
import { isSingleSelectColDef } from './filterPanelUtils';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
var filter = createFilterOptions();
function GridFilterInputMultipleSingleSelect(props) {
var _resolvedColumn, _resolvedColumn2;
var item = props.item,
applyValue = props.applyValue,
type = props.type,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
color = props.color,
error = props.error,
helperText = props.helperText,
size = props.size,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
getOptionLabelProp = props.getOptionLabel,
getOptionValueProp = props.getOptionValue,
other = _objectWithoutProperties(props, _excluded);
var TextFieldProps = {
color: color,
error: error,
helperText: helperText,
size: size,
variant: variant
};
var id = useId();
var rootProps = useGridRootProps();
var resolvedColumn = null;
if (item.field) {
var column = apiRef.current.getColumn(item.field);
if (isSingleSelectColDef(column)) {
resolvedColumn = column;
}
}
var getOptionValue = getOptionValueProp || ((_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue);
var getOptionLabel = getOptionLabelProp || ((_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel);
var isOptionEqualToValue = React.useCallback(function (option, value) {
return getOptionValue(option) === getOptionValue(value);
}, [getOptionValue]);
var resolvedValueOptions = React.useMemo(function () {
var _resolvedColumn3;
if (!((_resolvedColumn3 = resolvedColumn) != null && _resolvedColumn3.valueOptions)) {
return [];
}
if (typeof resolvedColumn.valueOptions === 'function') {
return resolvedColumn.valueOptions({
field: resolvedColumn.field
});
}
return resolvedColumn.valueOptions;
}, [resolvedColumn]);
var resolvedFormattedValueOptions = React.useMemo(function () {
return resolvedValueOptions == null ? void 0 : resolvedValueOptions.map(getOptionValue);
}, [resolvedValueOptions, getOptionValue]);
// The value is computed from the item.value and used directly
// If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
var filteredValues = React.useMemo(function () {
if (!Array.isArray(item.value)) {
return [];
}
if (resolvedValueOptions !== undefined) {
var itemValueIndexes = item.value.map(function (element) {
// Gets the index matching between values and valueOptions
return resolvedFormattedValueOptions == null ? void 0 : resolvedFormattedValueOptions.findIndex(function (formattedOption) {
return formattedOption === element;
});
});
return itemValueIndexes.filter(function (index) {
return index >= 0;
}).map(function (index) {
return resolvedValueOptions[index];
});
}
return item.value;
}, [item.value, resolvedValueOptions, resolvedFormattedValueOptions]);
React.useEffect(function () {
if (!Array.isArray(item.value) || filteredValues.length !== item.value.length) {
// Updates the state if the filter value has been cleaned by the component
applyValue(_extends({}, item, {
value: filteredValues.map(getOptionValue)
}));
}
}, [item, filteredValues, applyValue, getOptionValue]);
var handleChange = React.useCallback(function (event, value) {
applyValue(_extends({}, item, {
value: value.map(getOptionValue)
}));
}, [applyValue, item, getOptionValue]);
return /*#__PURE__*/_jsx(Autocomplete, _extends({
multiple: true,
options: resolvedValueOptions,
isOptionEqualToValue: isOptionEqualToValue,
filterOptions: filter,
id: id,
value: filteredValues,
onChange: handleChange,
getOptionLabel: getOptionLabel,
renderTags: function renderTags(value, getTagProps) {
return value.map(function (option, index) {
return /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({
variant: "outlined",
size: "small",
label: getOptionLabel(option)
}, getTagProps({
index: index
})));
});
},
renderInput: function renderInput(params) {
var _rootProps$slotProps;
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({}, params, {
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'),
InputLabelProps: _extends({}, params.InputLabelProps, {
shrink: true
}),
inputRef: focusElementRef,
type: "singleSelect"
}, TextFieldProps, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField));
}
}, other));
}
process.env.NODE_ENV !== "production" ? GridFilterInputMultipleSingleSelect.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Used to determine the label displayed for a given value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The text to be displayed.
*/
getOptionLabel: PropTypes.func,
/**
* Used to determine the value used for a value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The value to be used.
*/
getOptionValue: PropTypes.func,
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired,
type: PropTypes.oneOf(['singleSelect'])
} : void 0;
export { GridFilterInputMultipleSingleSelect };

View File

@@ -0,0 +1,102 @@
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant"];
import * as React from 'react';
import PropTypes from 'prop-types';
import Autocomplete from '@mui/material/Autocomplete';
import { unstable_useId as useId } from '@mui/utils';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
function GridFilterInputMultipleValue(props) {
var item = props.item,
applyValue = props.applyValue,
type = props.type,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
color = props.color,
error = props.error,
helperText = props.helperText,
size = props.size,
variant = props.variant,
other = _objectWithoutProperties(props, _excluded);
var TextFieldProps = {
color: color,
error: error,
helperText: helperText,
size: size,
variant: variant
};
var _React$useState = React.useState(item.value || []),
_React$useState2 = _slicedToArray(_React$useState, 2),
filterValueState = _React$useState2[0],
setFilterValueState = _React$useState2[1];
var id = useId();
var rootProps = useGridRootProps();
React.useEffect(function () {
var _item$value;
var itemValue = (_item$value = item.value) != null ? _item$value : [];
setFilterValueState(itemValue.map(String));
}, [item.value]);
var handleChange = React.useCallback(function (event, value) {
setFilterValueState(value.map(String));
applyValue(_extends({}, item, {
value: _toConsumableArray(value)
}));
}, [applyValue, item]);
return /*#__PURE__*/_jsx(Autocomplete, _extends({
multiple: true,
freeSolo: true,
options: [],
filterOptions: function filterOptions(options, params) {
var inputValue = params.inputValue;
return inputValue == null || inputValue === '' ? [] : [inputValue];
},
id: id,
value: filterValueState,
onChange: handleChange,
renderTags: function renderTags(value, getTagProps) {
return value.map(function (option, index) {
return /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({
variant: "outlined",
size: "small",
label: option
}, getTagProps({
index: index
})));
});
},
renderInput: function renderInput(params) {
var _rootProps$slotProps;
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({}, params, {
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'),
InputLabelProps: _extends({}, params.InputLabelProps, {
shrink: true
}),
inputRef: focusElementRef,
type: type || 'text'
}, TextFieldProps, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField));
}
}, other));
}
process.env.NODE_ENV !== "production" ? GridFilterInputMultipleValue.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired,
type: PropTypes.oneOf(['number', 'text'])
} : void 0;
export { GridFilterInputMultipleValue };

View File

@@ -0,0 +1,194 @@
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "getOptionLabel", "getOptionValue", "placeholder", "tabIndex", "label", "variant", "isFilterActive", "clearButton", "InputLabelProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useId as useId } from '@mui/utils';
import { styled } from '@mui/material/styles';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var renderSingleSelectOptions = function renderSingleSelectOptions(_ref) {
var _ref$column = _ref.column,
valueOptions = _ref$column.valueOptions,
field = _ref$column.field,
OptionComponent = _ref.OptionComponent,
getOptionLabel = _ref.getOptionLabel,
getOptionValue = _ref.getOptionValue,
isSelectNative = _ref.isSelectNative,
baseSelectOptionProps = _ref.baseSelectOptionProps;
var iterableColumnValues = typeof valueOptions === 'function' ? [''].concat(_toConsumableArray(valueOptions({
field: field
}))) : [''].concat(_toConsumableArray(valueOptions || []));
return iterableColumnValues.map(function (option) {
var value = getOptionValue(option);
var label = getOptionLabel(option);
return /*#__PURE__*/_createElement(OptionComponent, _extends({}, baseSelectOptionProps, {
native: isSelectNative,
key: value,
value: value
}), label);
});
};
var SingleSelectOperatorContainer = styled('div')(_defineProperty({
display: 'flex',
alignItems: 'flex-end',
width: '100%'
}, "& button", {
margin: 'auto 0px 5px 5px'
}));
function GridFilterInputSingleSelect(props) {
var _item$value, _rootProps$slotProps$, _rootProps$slotProps, _resolvedColumn, _resolvedColumn2, _rootProps$slotProps2, _rootProps$slotProps3, _rootProps$slotProps4;
var item = props.item,
applyValue = props.applyValue,
type = props.type,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
getOptionLabelProp = props.getOptionLabel,
getOptionValueProp = props.getOptionValue,
placeholder = props.placeholder,
tabIndex = props.tabIndex,
labelProp = props.label,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
isFilterActive = props.isFilterActive,
clearButton = props.clearButton,
InputLabelProps = props.InputLabelProps,
others = _objectWithoutProperties(props, _excluded);
var _React$useState = React.useState((_item$value = item.value) != null ? _item$value : ''),
_React$useState2 = _slicedToArray(_React$useState, 2),
filterValueState = _React$useState2[0],
setFilterValueState = _React$useState2[1];
var id = useId();
var labelId = useId();
var rootProps = useGridRootProps();
var isSelectNative = (_rootProps$slotProps$ = (_rootProps$slotProps = rootProps.slotProps) == null || (_rootProps$slotProps = _rootProps$slotProps.baseSelect) == null ? void 0 : _rootProps$slotProps.native) != null ? _rootProps$slotProps$ : true;
var resolvedColumn = null;
if (item.field) {
var column = apiRef.current.getColumn(item.field);
if (isSingleSelectColDef(column)) {
resolvedColumn = column;
}
}
var getOptionValue = getOptionValueProp || ((_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue);
var getOptionLabel = getOptionLabelProp || ((_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel);
var currentValueOptions = React.useMemo(function () {
if (!resolvedColumn) {
return undefined;
}
return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
field: resolvedColumn.field
}) : resolvedColumn.valueOptions;
}, [resolvedColumn]);
var onFilterChange = React.useCallback(function (event) {
var value = event.target.value;
// NativeSelect casts the value to a string.
value = getValueFromValueOptions(value, currentValueOptions, getOptionValue);
setFilterValueState(String(value));
applyValue(_extends({}, item, {
value: value
}));
}, [currentValueOptions, getOptionValue, applyValue, item]);
React.useEffect(function () {
var _itemValue;
var itemValue;
if (currentValueOptions !== undefined) {
// sanitize if valueOptions are provided
itemValue = getValueFromValueOptions(item.value, currentValueOptions, getOptionValue);
if (itemValue !== item.value) {
applyValue(_extends({}, item, {
value: itemValue
}));
return;
}
} else {
itemValue = item.value;
}
itemValue = (_itemValue = itemValue) != null ? _itemValue : '';
setFilterValueState(String(itemValue));
}, [item, currentValueOptions, applyValue, getOptionValue]);
if (!isSingleSelectColDef(resolvedColumn)) {
return null;
}
if (!isSingleSelectColDef(resolvedColumn)) {
return null;
}
var label = labelProp != null ? labelProp : apiRef.current.getLocaleText('filterPanelInputLabel');
return /*#__PURE__*/_jsxs(SingleSelectOperatorContainer, {
children: [/*#__PURE__*/_jsxs(rootProps.slots.baseFormControl, {
children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseInputLabel, {
id: labelId,
htmlFor: id,
shrink: true,
variant: variant,
children: label
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
id: id,
label: label,
labelId: labelId,
value: filterValueState,
onChange: onFilterChange,
variant: variant,
type: type || 'text',
inputProps: {
tabIndex: tabIndex,
ref: focusElementRef,
placeholder: placeholder != null ? placeholder : apiRef.current.getLocaleText('filterPanelInputPlaceholder')
},
native: isSelectNative,
notched: variant === 'outlined' ? true : undefined
}, others /* FIXME: typing error */, (_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseSelect, {
children: renderSingleSelectOptions({
column: resolvedColumn,
OptionComponent: rootProps.slots.baseSelectOption,
getOptionLabel: getOptionLabel,
getOptionValue: getOptionValue,
isSelectNative: isSelectNative,
baseSelectOptionProps: (_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseSelectOption
})
}))]
}), clearButton]
});
}
process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
clearButton: PropTypes.node,
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Used to determine the label displayed for a given value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The text to be displayed.
*/
getOptionLabel: PropTypes.func,
/**
* Used to determine the value used for a value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The value to be used.
*/
getOptionValue: PropTypes.func,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (e.g. `isEmpty`)
*/
isFilterActive: PropTypes.bool,
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired
} : void 0;
export { GridFilterInputSingleSelect };

View File

@@ -0,0 +1,106 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "tabIndex", "disabled", "isFilterActive", "clearButton", "InputProps", "variant"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useId as useId } from '@mui/utils';
import { useTimeout } from '../../../hooks/utils/useTimeout';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
function GridFilterInputValue(props) {
var _item$value, _rootProps$slotProps;
var item = props.item,
applyValue = props.applyValue,
type = props.type,
apiRef = props.apiRef,
focusElementRef = props.focusElementRef,
tabIndex = props.tabIndex,
disabled = props.disabled,
isFilterActive = props.isFilterActive,
clearButton = props.clearButton,
InputProps = props.InputProps,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
others = _objectWithoutProperties(props, _excluded);
var filterTimeout = useTimeout();
var _React$useState = React.useState((_item$value = item.value) != null ? _item$value : ''),
_React$useState2 = _slicedToArray(_React$useState, 2),
filterValueState = _React$useState2[0],
setFilterValueState = _React$useState2[1];
var _React$useState3 = React.useState(false),
_React$useState4 = _slicedToArray(_React$useState3, 2),
applying = _React$useState4[0],
setIsApplying = _React$useState4[1];
var id = useId();
var rootProps = useGridRootProps();
var onFilterChange = React.useCallback(function (event) {
var value = event.target.value;
setFilterValueState(String(value));
setIsApplying(true);
filterTimeout.start(rootProps.filterDebounceMs, function () {
var newItem = _extends({}, item, {
value: value,
fromInput: id
});
applyValue(newItem);
setIsApplying(false);
});
}, [id, applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
React.useEffect(function () {
var itemPlusTag = item;
if (itemPlusTag.fromInput !== id || item.value === undefined) {
var _item$value2;
setFilterValueState(String((_item$value2 = item.value) != null ? _item$value2 : ''));
}
}, [id, item]);
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
id: id,
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
placeholder: apiRef.current.getLocaleText('filterPanelInputPlaceholder'),
value: filterValueState,
onChange: onFilterChange,
variant: variant,
type: type || 'text',
InputProps: _extends({}, applying || clearButton ? {
endAdornment: applying ? /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {
fontSize: "small",
color: "action"
}) : clearButton
} : {}, {
disabled: disabled
}, InputProps, {
inputProps: _extends({
tabIndex: tabIndex
}, InputProps == null ? void 0 : InputProps.inputProps)
}),
InputLabelProps: {
shrink: true
},
inputRef: focusElementRef
}, others, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField));
}
process.env.NODE_ENV !== "production" ? GridFilterInputValue.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
apiRef: PropTypes.shape({
current: PropTypes.object.isRequired
}).isRequired,
applyValue: PropTypes.func.isRequired,
clearButton: PropTypes.node,
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (e.g. `isEmpty`)
*/
isFilterActive: PropTypes.bool,
item: PropTypes.shape({
field: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
operator: PropTypes.string.isRequired,
value: PropTypes.any
}).isRequired
} : void 0;
export { GridFilterInputValue };

View File

@@ -0,0 +1,235 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["logicOperators", "columnsSort", "filterFormProps", "getColumnForNewFilter", "children", "disableAddFilterButton", "disableRemoveAllButton"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { GridLogicOperator } from '../../../models/gridFilterItem';
import { useGridApiContext } from '../../../hooks/utils/useGridApiContext';
import { GridPanelContent } from '../GridPanelContent';
import { GridPanelFooter } from '../GridPanelFooter';
import { GridPanelWrapper } from '../GridPanelWrapper';
import { GridFilterForm } from './GridFilterForm';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { useGridSelector } from '../../../hooks/utils/useGridSelector';
import { gridFilterModelSelector } from '../../../hooks/features/filter/gridFilterSelector';
import { gridFilterableColumnDefinitionsSelector } from '../../../hooks/features/columns/gridColumnsSelector';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var getGridFilter = function getGridFilter(col) {
return {
field: col.field,
operator: col.filterOperators[0].value,
id: Math.round(Math.random() * 1e5)
};
};
var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(props, ref) {
var _rootProps$slotProps, _rootProps$slotProps2;
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var filterModel = useGridSelector(apiRef, gridFilterModelSelector);
var filterableColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
var lastFilterRef = React.useRef(null);
var placeholderFilter = React.useRef(null);
var _props$logicOperators = props.logicOperators,
logicOperators = _props$logicOperators === void 0 ? [GridLogicOperator.And, GridLogicOperator.Or] : _props$logicOperators,
columnsSort = props.columnsSort,
filterFormProps = props.filterFormProps,
getColumnForNewFilter = props.getColumnForNewFilter,
children = props.children,
_props$disableAddFilt = props.disableAddFilterButton,
disableAddFilterButton = _props$disableAddFilt === void 0 ? false : _props$disableAddFilt,
_props$disableRemoveA = props.disableRemoveAllButton,
disableRemoveAllButton = _props$disableRemoveA === void 0 ? false : _props$disableRemoveA,
other = _objectWithoutProperties(props, _excluded);
var applyFilter = apiRef.current.upsertFilterItem;
var applyFilterLogicOperator = React.useCallback(function (operator) {
apiRef.current.setFilterLogicOperator(operator);
}, [apiRef]);
var getDefaultFilter = React.useCallback(function () {
var nextColumnWithOperator;
if (getColumnForNewFilter && typeof getColumnForNewFilter === 'function') {
// To allow override the column for default (first) filter
var nextFieldName = getColumnForNewFilter({
currentFilters: (filterModel == null ? void 0 : filterModel.items) || [],
columns: filterableColumns
});
if (nextFieldName === null) {
return null;
}
nextColumnWithOperator = filterableColumns.find(function (_ref) {
var field = _ref.field;
return field === nextFieldName;
});
} else {
nextColumnWithOperator = filterableColumns.find(function (colDef) {
var _colDef$filterOperato;
return (_colDef$filterOperato = colDef.filterOperators) == null ? void 0 : _colDef$filterOperato.length;
});
}
if (!nextColumnWithOperator) {
return null;
}
return getGridFilter(nextColumnWithOperator);
}, [filterModel == null ? void 0 : filterModel.items, filterableColumns, getColumnForNewFilter]);
var getNewFilter = React.useCallback(function () {
if (getColumnForNewFilter === undefined || typeof getColumnForNewFilter !== 'function') {
return getDefaultFilter();
}
var currentFilters = filterModel.items.length ? filterModel.items : [getDefaultFilter()].filter(Boolean);
// If no items are there in filterModel, we have to pass defaultFilter
var nextColumnFieldName = getColumnForNewFilter({
currentFilters: currentFilters,
columns: filterableColumns
});
if (nextColumnFieldName === null) {
return null;
}
var nextColumnWithOperator = filterableColumns.find(function (_ref2) {
var field = _ref2.field;
return field === nextColumnFieldName;
});
if (!nextColumnWithOperator) {
return null;
}
return getGridFilter(nextColumnWithOperator);
}, [filterModel.items, filterableColumns, getColumnForNewFilter, getDefaultFilter]);
var items = React.useMemo(function () {
if (filterModel.items.length) {
return filterModel.items;
}
if (!placeholderFilter.current) {
placeholderFilter.current = getDefaultFilter();
}
return placeholderFilter.current ? [placeholderFilter.current] : [];
}, [filterModel.items, getDefaultFilter]);
var hasMultipleFilters = items.length > 1;
var addNewFilter = function addNewFilter() {
var newFilter = getNewFilter();
if (!newFilter) {
return;
}
apiRef.current.upsertFilterItems([].concat(_toConsumableArray(items), [newFilter]));
};
var deleteFilter = React.useCallback(function (item) {
var shouldCloseFilterPanel = items.length === 1;
apiRef.current.deleteFilterItem(item);
if (shouldCloseFilterPanel) {
apiRef.current.hideFilterPanel();
}
}, [apiRef, items.length]);
var handleRemoveAll = function handleRemoveAll() {
if (items.length === 1 && items[0].value === undefined) {
apiRef.current.deleteFilterItem(items[0]);
apiRef.current.hideFilterPanel();
}
apiRef.current.setFilterModel(_extends({}, filterModel, {
items: []
}));
};
React.useEffect(function () {
if (logicOperators.length > 0 && filterModel.logicOperator && !logicOperators.includes(filterModel.logicOperator)) {
applyFilterLogicOperator(logicOperators[0]);
}
}, [logicOperators, applyFilterLogicOperator, filterModel.logicOperator]);
React.useEffect(function () {
if (items.length > 0) {
lastFilterRef.current.focus();
}
}, [items.length]);
return /*#__PURE__*/_jsxs(GridPanelWrapper, _extends({
ref: ref
}, other, {
children: [/*#__PURE__*/_jsx(GridPanelContent, {
children: items.map(function (item, index) {
return /*#__PURE__*/_jsx(GridFilterForm, _extends({
item: item,
applyFilterChanges: applyFilter,
deleteFilter: deleteFilter,
hasMultipleFilters: hasMultipleFilters,
showMultiFilterOperators: index > 0,
multiFilterOperator: filterModel.logicOperator,
disableMultiFilterOperator: index !== 1,
applyMultiFilterOperatorChanges: applyFilterLogicOperator,
focusElementRef: index === items.length - 1 ? lastFilterRef : null,
logicOperators: logicOperators,
columnsSort: columnsSort
}, filterFormProps), item.id == null ? index : item.id);
})
}), !rootProps.disableMultipleColumnsFiltering && !(disableAddFilterButton && disableRemoveAllButton) ? /*#__PURE__*/_jsxs(GridPanelFooter, {
children: [!disableAddFilterButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
onClick: addNewFilter,
startIcon: /*#__PURE__*/_jsx(rootProps.slots.filterPanelAddIcon, {})
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseButton, {
children: apiRef.current.getLocaleText('filterPanelAddFilter')
})) : /*#__PURE__*/_jsx("span", {}), !disableRemoveAllButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
onClick: handleRemoveAll,
startIcon: /*#__PURE__*/_jsx(rootProps.slots.filterPanelRemoveAllIcon, {})
}, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseButton, {
children: apiRef.current.getLocaleText('filterPanelRemoveAll')
})) : null]
}) : null]
}));
});
process.env.NODE_ENV !== "production" ? GridFilterPanel.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* @ignore - do not document.
*/
children: PropTypes.node,
/**
* Changes how the options in the columns selector should be ordered.
* If not specified, the order is derived from the `columns` prop.
*/
columnsSort: PropTypes.oneOf(['asc', 'desc']),
/**
* If `true`, the `Add filter` button will not be displayed.
* @default false
*/
disableAddFilterButton: PropTypes.bool,
/**
* If `true`, the `Remove all` button will be disabled
* @default false
*/
disableRemoveAllButton: PropTypes.bool,
/**
* Props passed to each filter form.
*/
filterFormProps: PropTypes.shape({
columnInputProps: PropTypes.any,
columnsSort: PropTypes.oneOf(['asc', 'desc']),
deleteIconProps: PropTypes.any,
filterColumns: PropTypes.func,
logicOperatorInputProps: PropTypes.any,
operatorInputProps: PropTypes.any,
valueInputProps: PropTypes.any
}),
/**
* Function that returns the next filter item to be picked as default filter.
* @param {GetColumnForNewFilterArgs} args Currently configured filters and columns.
* @returns {GridColDef['field']} The field to be used for the next filter or `null` to prevent adding a filter.
*/
getColumnForNewFilter: PropTypes.func,
/**
* Sets the available logic operators.
* @default [GridLogicOperator.And, GridLogicOperator.Or]
*/
logicOperators: PropTypes.arrayOf(PropTypes.oneOf(['and', 'or']).isRequired),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
/**
* Demos:
* - [Filtering - overview](https://mui.com/x/react-data-grid/filtering/)
*
* API:
* - [GridFilterPanel API](https://mui.com/x/api/data-grid/grid-filter-panel/)
*/
export { GridFilterPanel, getGridFilter };

View File

@@ -0,0 +1,18 @@
import _typeof from "@babel/runtime/helpers/esm/typeof";
export function isSingleSelectColDef(colDef) {
return (colDef == null ? void 0 : colDef.type) === 'singleSelect';
}
export function getValueFromValueOptions(value, valueOptions, getOptionValue) {
if (valueOptions === undefined) {
return undefined;
}
var result = valueOptions.find(function (option) {
var optionValue = getOptionValue(option);
return String(optionValue) === String(value);
});
return getOptionValue(result);
}
export var getLabelFromValueOption = function getLabelFromValueOption(valueOption) {
var label = _typeof(valueOption) === 'object' ? valueOption.label : valueOption;
return label != null ? String(label) : '';
};

View File

@@ -0,0 +1,9 @@
export * from './GridFilterForm';
export * from './GridFilterInputValue';
export * from './GridFilterInputDate';
export * from './GridFilterInputSingleSelect';
export * from './GridFilterInputBoolean';
export * from './GridFilterInputValueProps';
export { GridFilterPanel } from './GridFilterPanel';
export * from './GridFilterInputMultipleValue';
export * from './GridFilterInputMultipleSingleSelect';

View File

@@ -0,0 +1,8 @@
export * from './GridColumnsPanel';
export * from './GridPanel';
export * from './GridPanelContent';
export * from './GridPanelFooter';
export * from './GridPanelHeader';
export * from './GridPanelWrapper';
export * from './GridPreferencesPanel';
export * from './filterPanel';