@carbon/ibm-products 2.0.0-rc.17 → 2.0.0-rc.19
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +140 -21
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +3 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +413 -0
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +1 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +140 -21
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +3 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +139 -21
- package/css/index.css.map +1 -1
- package/css/index.min.css +2 -2
- package/css/index.min.css.map +1 -1
- package/es/components/Datagrid/Datagrid/Datagrid.js +4 -4
- package/es/components/Datagrid/Datagrid/DatagridContent.js +46 -16
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +3 -21
- package/es/components/Datagrid/Datagrid/DraggableElement.js +7 -3
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +7 -2
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
- package/es/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +120 -60
- package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +514 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +10 -2
- package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +9 -1
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/index.js +9 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +4 -1
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +38 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js +25 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/index.js +3 -1
- package/es/components/Datagrid/Datagrid/addons/Filtering/motion/variants.js +55 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/utils.js +53 -19
- package/es/components/Datagrid/Datagrid.stories/index.js +0 -1
- package/es/components/Datagrid/useFiltering.js +11 -4
- package/es/components/Datagrid/utils/DatagridActions.js +41 -13
- package/es/components/OptionsTile/OptionsTile.js +3 -3
- package/es/components/Tearsheet/Tearsheet.js +5 -0
- package/es/components/Tearsheet/TearsheetNarrow.js +5 -0
- package/es/components/Tearsheet/TearsheetShell.js +1 -1
- package/es/global/js/package-settings.js +2 -2
- package/lib/components/Datagrid/Datagrid/Datagrid.js +4 -4
- package/lib/components/Datagrid/Datagrid/DatagridContent.js +48 -15
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +2 -23
- package/lib/components/Datagrid/Datagrid/DraggableElement.js +6 -2
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +7 -2
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
- package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +113 -51
- package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +538 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +9 -1
- package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +15 -3
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/index.js +31 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +5 -1
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +50 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js +35 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/index.js +23 -1
- package/lib/components/Datagrid/Datagrid/addons/Filtering/motion/variants.js +67 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/utils.js +53 -18
- package/lib/components/Datagrid/Datagrid.stories/index.js +0 -8
- package/lib/components/Datagrid/useFiltering.js +11 -3
- package/lib/components/Datagrid/utils/DatagridActions.js +41 -11
- package/lib/components/OptionsTile/OptionsTile.js +2 -2
- package/lib/components/Tearsheet/Tearsheet.js +5 -0
- package/lib/components/Tearsheet/TearsheetNarrow.js +5 -0
- package/lib/components/Tearsheet/TearsheetShell.js +1 -1
- package/lib/global/js/package-settings.js +2 -2
- package/package.json +2 -2
- package/scss/components/Datagrid/styles/_datagrid.scss +16 -17
- package/scss/components/Datagrid/styles/_draggableElement.scss +5 -1
- package/scss/components/Datagrid/styles/_index.scss +1 -0
- package/scss/components/Datagrid/styles/addons/_FilterPanel.scss +129 -0
- package/scss/components/Datagrid/styles/addons/_RowSizeDropdown.scss +3 -3
- package/scss/components/FilterSummary/_filter-summary.scss +1 -0
- package/scss/components/MultiAddSelect/_multi-add-select.scss +1 -1
- package/scss/components/SingleAddSelect/_single-add-select.scss +1 -1
- package/scss/components/_index-released-only-with-carbon.scss +2 -0
- package/scss/components/_index-released-only.scss +2 -0
- package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +0 -6
- package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +0 -13
@@ -7,16 +7,13 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
7
7
|
* This source code is licensed under the Apache-2.0 license found in the
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
|
-
import React, { useEffect, useState
|
10
|
+
import React, { useEffect, useState } from 'react';
|
11
11
|
import { Add, OverflowMenuVertical } from '@carbon/react/icons';
|
12
12
|
import { TableToolbar, TableBatchActions, TableBatchAction } from '@carbon/react';
|
13
13
|
import { useResizeDetector } from 'react-resize-detector';
|
14
14
|
import { ButtonMenu, ButtonMenuItem } from '../../ButtonMenu';
|
15
15
|
import { pkg, carbon } from '../../../settings';
|
16
16
|
import cx from 'classnames';
|
17
|
-
import { FilterSummary } from '../../FilterSummary';
|
18
|
-
import { FilterContext } from './addons/Filtering/FilterProvider';
|
19
|
-
import { CLEAR_FILTERS } from './addons/Filtering/constants';
|
20
17
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
21
18
|
|
22
19
|
var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridState, width, ref) {
|
@@ -144,29 +141,14 @@ var DatagridToolbar = function DatagridToolbar(datagridState) {
|
|
144
141
|
var DatagridActions = datagridState.DatagridActions,
|
145
142
|
DatagridBatchActions = datagridState.DatagridBatchActions,
|
146
143
|
batchActions = datagridState.batchActions,
|
147
|
-
state = datagridState.state,
|
148
144
|
rowSize = datagridState.rowSize;
|
149
|
-
|
150
|
-
var _useContext = useContext(FilterContext),
|
151
|
-
filterTags = _useContext.filterTags,
|
152
|
-
EventEmitter = _useContext.EventEmitter;
|
153
|
-
|
154
|
-
var renderFilterSummary = function renderFilterSummary() {
|
155
|
-
return state.filters.length > 0 && /*#__PURE__*/React.createElement(FilterSummary, {
|
156
|
-
filters: filterTags,
|
157
|
-
clearFilters: function clearFilters() {
|
158
|
-
return EventEmitter.dispatch(CLEAR_FILTERS);
|
159
|
-
}
|
160
|
-
});
|
161
|
-
};
|
162
|
-
|
163
145
|
var getRowHeight = rowSize ? rowSize : 'lg';
|
164
146
|
return batchActions && DatagridActions ? /*#__PURE__*/React.createElement("div", {
|
165
147
|
ref: ref,
|
166
148
|
className: cx("".concat(blockClass, "__table-toolbar"), "".concat(blockClass, "__table-toolbar--").concat(getRowHeight))
|
167
|
-
}, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref))
|
149
|
+
}, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref))) : DatagridActions ? /*#__PURE__*/React.createElement("div", {
|
168
150
|
className: "".concat(blockClass, "__table-toolbar")
|
169
|
-
}, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState))
|
151
|
+
}, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState))) : null;
|
170
152
|
};
|
171
153
|
|
172
154
|
export default DatagridToolbar;
|
@@ -11,7 +11,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
11
11
|
*/
|
12
12
|
import * as React from 'react';
|
13
13
|
import PropTypes from 'prop-types';
|
14
|
-
import { Draggable } from '@carbon/react/icons';
|
14
|
+
import { Draggable, Locked } from '@carbon/react/icons';
|
15
15
|
import { useDrag, useDrop } from 'react-dnd';
|
16
16
|
import cx from 'classnames';
|
17
17
|
import { pkg } from '../../../settings';
|
@@ -34,6 +34,7 @@ var DraggableElement = function DraggableElement(_ref) {
|
|
34
34
|
onGrab = _ref.onGrab,
|
35
35
|
onArrowKeyDown = _ref.onArrowKeyDown,
|
36
36
|
isFocused = _ref.isFocused,
|
37
|
+
isSticky = _ref.isSticky,
|
37
38
|
moveElement = _ref.moveElement,
|
38
39
|
selected = _ref.selected,
|
39
40
|
_ref$positionLabel = _ref.positionLabel,
|
@@ -120,11 +121,13 @@ var DraggableElement = function DraggableElement(_ref) {
|
|
120
121
|
className: cx({
|
121
122
|
disabled: disabled
|
122
123
|
}, "".concat(blockClass, "__draggable-handleStyle"))
|
123
|
-
}, /*#__PURE__*/React.createElement(
|
124
|
+
}, isSticky ? /*#__PURE__*/React.createElement(Locked, {
|
125
|
+
size: 16
|
126
|
+
}) : /*#__PURE__*/React.createElement(Draggable, {
|
124
127
|
size: 16
|
125
128
|
})), children);
|
126
129
|
return /*#__PURE__*/React.createElement("li", {
|
127
|
-
className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-grabbed"), isGrabbed), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder"), !selected), _cx)),
|
130
|
+
className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-grabbed"), isGrabbed), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--sticky"), isSticky), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder"), !selected), _cx)),
|
128
131
|
ref: ref,
|
129
132
|
"aria-selected": isFocused,
|
130
133
|
role: "option",
|
@@ -173,6 +176,7 @@ DraggableElement.propTypes = {
|
|
173
176
|
id: PropTypes.string.isRequired,
|
174
177
|
index: PropTypes.number.isRequired,
|
175
178
|
isFocused: PropTypes.bool.isRequired,
|
179
|
+
isSticky: PropTypes.bool,
|
176
180
|
listData: PropTypes.array.isRequired,
|
177
181
|
moveElement: PropTypes.func.isRequired,
|
178
182
|
onArrowKeyDown: PropTypes.func.isRequired,
|
@@ -103,9 +103,11 @@ var Columns = function Columns(_ref) {
|
|
103
103
|
var res = filterString.length ? colDef.Header.props.title.toLowerCase().split(searchString) : null;
|
104
104
|
var firstWord = res !== null ? res[0] === '' ? res[1].charAt(0).toUpperCase() + res[1].substring(1) : res[0].charAt(0).toUpperCase() + res[0].substring(1) : null;
|
105
105
|
var highlightedText = res !== null ? res[0] === '' ? "<strong>".concat(firstWord, "</strong>") + res[2] : firstWord + "<strong>".concat(res[1], "</strong>") + res[2] : colDef.Header.props.title;
|
106
|
+
var isFrozenColumn = !!colDef.sticky;
|
106
107
|
var listContents = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
|
107
108
|
className: cx("".concat(blockClass, "__customize-columns-checkbox-wrapper"), "".concat(blockClass, "__customize-columns-checkbox")),
|
108
109
|
checked: isColumnVisible(colDef),
|
110
|
+
disabled: isFrozenColumn,
|
109
111
|
onChange: function onChange(_, _ref2) {
|
110
112
|
var checked = _ref2.checked;
|
111
113
|
return onSelectColumn(colDef, checked);
|
@@ -126,18 +128,21 @@ var Columns = function Columns(_ref) {
|
|
126
128
|
setListData: setColumnsObject,
|
127
129
|
id: "dnd-datagrid-columns-".concat(colDef.id),
|
128
130
|
type: "column-customization",
|
129
|
-
disabled: filterString.length > 0,
|
131
|
+
disabled: filterString.length > 0 || isFrozenColumn,
|
130
132
|
ariaLabel: colDef.Header.props.title,
|
131
133
|
onGrab: setAriaRegionText,
|
132
134
|
isFocused: focusIndex === i,
|
135
|
+
isSticky: isFrozenColumn,
|
133
136
|
moveElement: moveElement,
|
134
137
|
onArrowKeyDown: function onArrowKeyDown(e, isGrabbed, currentIndex) {
|
135
138
|
if (isGrabbed) {
|
139
|
+
var _columns$nextIndex;
|
140
|
+
|
136
141
|
var nextIndex = getNextIndex(columns, currentIndex, e.key);
|
137
142
|
e.preventDefault();
|
138
143
|
e.stopPropagation();
|
139
144
|
|
140
|
-
if (nextIndex >= 0) {
|
145
|
+
if (nextIndex >= 0 && !((_columns$nextIndex = columns[nextIndex]) !== null && _columns$nextIndex !== void 0 && _columns$nextIndex.sticky)) {
|
141
146
|
setFocusIndex(nextIndex);
|
142
147
|
moveElement(currentIndex, nextIndex);
|
143
148
|
e.target.scrollIntoView({
|
package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js
CHANGED
@@ -63,7 +63,7 @@ var CustomizeColumnsTearsheet = function CustomizeColumnsTearsheet(_ref) {
|
|
63
63
|
|
64
64
|
var _useState7 = useState(columnDefinitions // hide the columns without Header, e.g the sticky actions, spacer
|
65
65
|
.filter(function (colDef) {
|
66
|
-
return !!colDef.Header.props;
|
66
|
+
return !!colDef.Header.props && !colDef.isAction;
|
67
67
|
}) // only sort the hidden column to the end when modal reopen
|
68
68
|
.sort(function (defA, defB) {
|
69
69
|
var isVisibleA = isColumnVisible(defA);
|
@@ -9,26 +9,22 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
9
9
|
|
10
10
|
// @flow
|
11
11
|
|
12
|
-
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
12
|
+
/**
|
13
|
+
* Copyright IBM Corp. 2022, 2023
|
14
|
+
*
|
15
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
18
17
|
*/
|
19
18
|
import { Filter } from '@carbon/react/icons';
|
20
|
-
import { Button, Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup } from '@carbon/react';
|
19
|
+
import { Button, Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup, usePrefix } from '@carbon/react';
|
21
20
|
import cx from 'classnames';
|
22
21
|
import PropTypes from 'prop-types';
|
23
22
|
import React, { useCallback, useRef, useState } from 'react';
|
24
|
-
import { useEffect } from 'react';
|
25
|
-
import { useContext } from 'react';
|
26
23
|
import { useClickOutside } from '../../../../../global/js/hooks';
|
27
24
|
import { pkg } from '../../../../../settings';
|
28
25
|
import { ActionSet } from '../../../../ActionSet';
|
29
|
-
import { BATCH, CHECKBOX, CLEAR_FILTERS, DATE, DROPDOWN, INSTANT, NUMBER, RADIO } from './constants';
|
30
|
-
import {
|
31
|
-
import useInitialStateFromFilters from './hooks/useInitialStateFromFilters';
|
26
|
+
import { BATCH, CHECKBOX, CLEAR_FILTERS, DATE, DROPDOWN, FLYOUT, INSTANT, NUMBER, RADIO } from './constants';
|
27
|
+
import { useInitialStateFromFilters, useSubscribeToEventEmitter, useShouldDisableButtons } from './hooks';
|
32
28
|
import { getInitialStateFromFilters } from './utils';
|
33
29
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
34
30
|
var componentClass = "".concat(blockClass, "-filter-flyout");
|
@@ -56,20 +52,17 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
56
52
|
onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel,
|
57
53
|
_ref$secondaryActionL = _ref.secondaryActionLabel,
|
58
54
|
secondaryActionLabel = _ref$secondaryActionL === void 0 ? 'Cancel' : _ref$secondaryActionL,
|
59
|
-
setAllFilters = _ref.setAllFilters
|
55
|
+
setAllFilters = _ref.setAllFilters,
|
56
|
+
_ref$data = _ref.data,
|
57
|
+
data = _ref$data === void 0 ? [] : _ref$data;
|
60
58
|
|
61
|
-
/** Context state and methods */
|
62
|
-
var _useContext = useContext(FilterContext),
|
63
|
-
EventEmitter = _useContext.EventEmitter;
|
64
59
|
/** State */
|
65
|
-
|
66
|
-
|
67
60
|
var _useState = useState(false),
|
68
61
|
_useState2 = _slicedToArray(_useState, 2),
|
69
62
|
open = _useState2[0],
|
70
63
|
setOpen = _useState2[1];
|
71
64
|
|
72
|
-
var _useInitialStateFromF = useInitialStateFromFilters(filters),
|
65
|
+
var _useInitialStateFromF = useInitialStateFromFilters(filters, FLYOUT),
|
73
66
|
_useInitialStateFromF2 = _slicedToArray(_useInitialStateFromF, 2),
|
74
67
|
filtersState = _useInitialStateFromF2[0],
|
75
68
|
setFiltersState = _useInitialStateFromF2[1];
|
@@ -85,9 +78,21 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
85
78
|
|
86
79
|
var prevFiltersRef = useRef(JSON.stringify(filtersState));
|
87
80
|
var prevFiltersObjectArrayRef = useRef(JSON.stringify(filtersObjectArray));
|
81
|
+
/** State from hooks */
|
82
|
+
|
83
|
+
var _useShouldDisableButt = useShouldDisableButtons({
|
84
|
+
initialValue: true,
|
85
|
+
filtersState: filtersState,
|
86
|
+
prevFiltersRef: prevFiltersRef
|
87
|
+
}),
|
88
|
+
_useShouldDisableButt2 = _slicedToArray(_useShouldDisableButt, 2),
|
89
|
+
shouldDisableButtons = _useShouldDisableButt2[0],
|
90
|
+
setShouldDisableButtons = _useShouldDisableButt2[1];
|
88
91
|
/** Memos */
|
89
92
|
|
93
|
+
|
90
94
|
var showActionSet = updateMethod === BATCH;
|
95
|
+
var carbonPrefix = usePrefix();
|
91
96
|
/** Methods */
|
92
97
|
|
93
98
|
var openFlyout = function openFlyout() {
|
@@ -102,8 +107,11 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
102
107
|
|
103
108
|
var apply = function apply() {
|
104
109
|
setAllFilters(filtersObjectArray);
|
105
|
-
closeFlyout();
|
106
|
-
|
110
|
+
closeFlyout(); // From the user
|
111
|
+
|
112
|
+
onApply(); // When the user clicks apply, the action set buttons should be disabled again
|
113
|
+
|
114
|
+
setShouldDisableButtons(true); // updates the ref so next time the flyout opens we have records of the previous filters
|
107
115
|
|
108
116
|
prevFiltersRef.current = JSON.stringify(filtersState);
|
109
117
|
prevFiltersObjectArrayRef.current = JSON.stringify(filtersObjectArray);
|
@@ -121,7 +129,7 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
121
129
|
|
122
130
|
var reset = function reset() {
|
123
131
|
// Get the initial values for the filters
|
124
|
-
var initialFiltersState = getInitialStateFromFilters(filters);
|
132
|
+
var initialFiltersState = getInitialStateFromFilters(filters, FLYOUT);
|
125
133
|
var initialFiltersObjectArray = []; // Set the state to the initial values
|
126
134
|
|
127
135
|
setFiltersState(initialFiltersState);
|
@@ -166,6 +174,37 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
166
174
|
});
|
167
175
|
}
|
168
176
|
|
177
|
+
if (type === CHECKBOX) {
|
178
|
+
/**
|
179
|
+
When all checkboxes of a group are all unselected the value still exists in the filtersObjectArray
|
180
|
+
This checks if all the checkboxes are selected = false and removes it from the array
|
181
|
+
*/
|
182
|
+
var index = filtersObjectArrayCopy.findIndex(function (filter) {
|
183
|
+
return filter.id === column;
|
184
|
+
}); // If all the selected state is false remove from array
|
185
|
+
|
186
|
+
var shouldRemoveFromArray = filtersObjectArrayCopy[index].value.every(function (val) {
|
187
|
+
return val.selected === false;
|
188
|
+
});
|
189
|
+
|
190
|
+
if (shouldRemoveFromArray) {
|
191
|
+
filtersObjectArrayCopy.splice(index, 1);
|
192
|
+
}
|
193
|
+
} else if (type === DROPDOWN || type === RADIO) {
|
194
|
+
if (value === 'Any') {
|
195
|
+
/**
|
196
|
+
Checks to see if the selected value is 'Any', that means the user wants
|
197
|
+
to reset specific filter
|
198
|
+
*/
|
199
|
+
var _index = filtersObjectArrayCopy.findIndex(function (filter) {
|
200
|
+
return filter.id === column;
|
201
|
+
}); // Remove it from the filters array
|
202
|
+
|
203
|
+
|
204
|
+
filtersObjectArrayCopy.splice(_index, 1);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
169
208
|
setFiltersObjectArray(filtersObjectArrayCopy); // Automatically apply the filters if the updateMethod is instant
|
170
209
|
|
171
210
|
if (updateMethod === INSTANT) {
|
@@ -176,33 +215,31 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
176
215
|
|
177
216
|
useClickOutside(filterFlyoutRef, function (target) {
|
178
217
|
var hasClickedOnDatePicker = target.closest('.flatpickr-calendar');
|
218
|
+
var hasClickedOnDropdown = target.className === "".concat(carbonPrefix, "--list-box__menu-item__option");
|
179
219
|
|
180
|
-
if (!open || hasClickedOnDatePicker) {
|
220
|
+
if (!open || hasClickedOnDatePicker || hasClickedOnDropdown) {
|
181
221
|
return;
|
182
222
|
}
|
183
223
|
|
184
224
|
cancel();
|
185
225
|
});
|
186
|
-
|
187
|
-
// This event is emitted from the DatagridToolbar component when clearFilters is clicked in FilterSummary
|
188
|
-
EventEmitter.subscribe(CLEAR_FILTERS, reset);
|
189
|
-
});
|
226
|
+
useSubscribeToEventEmitter(CLEAR_FILTERS, reset);
|
190
227
|
/** Render the individual filter component */
|
191
228
|
|
192
|
-
var renderFilter =
|
229
|
+
var renderFilter = function renderFilter(_ref3) {
|
193
230
|
var type = _ref3.type,
|
194
231
|
column = _ref3.column,
|
195
232
|
components = _ref3.props;
|
196
|
-
var key = "".concat(type, "-").concat(column, "-").concat(Math.random());
|
197
233
|
|
198
234
|
if (type === DATE) {
|
199
|
-
return /*#__PURE__*/React.createElement(DatePicker, _extends({
|
200
|
-
key: key
|
201
|
-
}, components.DatePicker, {
|
235
|
+
return /*#__PURE__*/React.createElement(DatePicker, _extends({}, components.DatePicker, {
|
202
236
|
onChange: function onChange(value) {
|
203
237
|
var _components$DatePicke, _components$DatePicke2;
|
204
238
|
|
205
|
-
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column,
|
239
|
+
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
|
240
|
+
value: value,
|
241
|
+
type: type
|
242
|
+
})));
|
206
243
|
applyFilters({
|
207
244
|
column: column,
|
208
245
|
value: value,
|
@@ -210,7 +247,7 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
210
247
|
});
|
211
248
|
(_components$DatePicke = (_components$DatePicke2 = components.DatePicker).onChange) === null || _components$DatePicke === void 0 ? void 0 : _components$DatePicke.call(_components$DatePicke2, value);
|
212
249
|
},
|
213
|
-
value: filtersState[column],
|
250
|
+
value: filtersState[column].value,
|
214
251
|
datePickerType: "range"
|
215
252
|
}), /*#__PURE__*/React.createElement(DatePickerInput, _extends({
|
216
253
|
placeholder: "mm/dd/yyyy",
|
@@ -221,7 +258,6 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
221
258
|
}, components.DatePickerInput.end)));
|
222
259
|
} else if (type === NUMBER) {
|
223
260
|
return /*#__PURE__*/React.createElement(NumberInput, _extends({
|
224
|
-
key: key,
|
225
261
|
step: 1,
|
226
262
|
allowEmpty: true,
|
227
263
|
hideSteppers: true
|
@@ -229,7 +265,10 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
229
265
|
onChange: function onChange(event) {
|
230
266
|
var _components$NumberInp, _components$NumberInp2;
|
231
267
|
|
232
|
-
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column,
|
268
|
+
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
|
269
|
+
value: event.target.value,
|
270
|
+
type: type
|
271
|
+
})));
|
233
272
|
applyFilters({
|
234
273
|
column: column,
|
235
274
|
value: event.target.value,
|
@@ -237,44 +276,48 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
237
276
|
});
|
238
277
|
(_components$NumberInp = (_components$NumberInp2 = components.NumberInput).onChange) === null || _components$NumberInp === void 0 ? void 0 : _components$NumberInp.call(_components$NumberInp2, event);
|
239
278
|
},
|
240
|
-
value: filtersState[column]
|
279
|
+
value: filtersState[column].value
|
241
280
|
}));
|
242
281
|
} else if (type === CHECKBOX) {
|
243
|
-
return /*#__PURE__*/React.createElement(FormGroup,
|
244
|
-
key: key
|
245
|
-
}, components.FormGroup), filtersState[column].map(function (option) {
|
282
|
+
return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, filtersState[column].value.map(function (option) {
|
246
283
|
return /*#__PURE__*/React.createElement(Checkbox, _extends({
|
247
284
|
key: option.labelText
|
248
285
|
}, option, {
|
249
286
|
onChange: function onChange(_, _ref4) {
|
250
287
|
var _option$onChange;
|
251
288
|
|
252
|
-
var
|
253
|
-
var checkboxCopy = filtersState[column];
|
289
|
+
var isSelected = _ref4.checked;
|
290
|
+
var checkboxCopy = filtersState[column].value;
|
254
291
|
var foundCheckbox = checkboxCopy.find(function (checkbox) {
|
255
292
|
return checkbox.value === option.value;
|
256
293
|
});
|
257
|
-
foundCheckbox.selected =
|
258
|
-
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column,
|
294
|
+
foundCheckbox.selected = isSelected;
|
295
|
+
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
|
296
|
+
value: checkboxCopy,
|
297
|
+
type: type
|
298
|
+
})));
|
259
299
|
applyFilters({
|
260
300
|
column: column,
|
261
|
-
value: _toConsumableArray(filtersState[column]),
|
301
|
+
value: _toConsumableArray(filtersState[column].value),
|
262
302
|
type: type
|
263
303
|
});
|
264
|
-
(_option$onChange = option.onChange) === null || _option$onChange === void 0 ? void 0 : _option$onChange.call(option,
|
304
|
+
(_option$onChange = option.onChange) === null || _option$onChange === void 0 ? void 0 : _option$onChange.call(option, isSelected);
|
265
305
|
},
|
266
306
|
checked: option.selected
|
267
307
|
}));
|
268
308
|
}));
|
269
309
|
} else if (type === RADIO) {
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
valueSelected: filtersState[column],
|
310
|
+
var _filtersState$column, _filtersState$column2;
|
311
|
+
|
312
|
+
return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, /*#__PURE__*/React.createElement(RadioButtonGroup, _extends({}, components.RadioButtonGroup, {
|
313
|
+
valueSelected: ((_filtersState$column = filtersState[column]) === null || _filtersState$column === void 0 ? void 0 : _filtersState$column.value) === '' ? 'Any' : (_filtersState$column2 = filtersState[column]) === null || _filtersState$column2 === void 0 ? void 0 : _filtersState$column2.value,
|
274
314
|
onChange: function onChange(selected) {
|
275
315
|
var _components$RadioButt, _components$RadioButt2;
|
276
316
|
|
277
|
-
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column,
|
317
|
+
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
|
318
|
+
value: selected,
|
319
|
+
type: type
|
320
|
+
})));
|
278
321
|
applyFilters({
|
279
322
|
column: column,
|
280
323
|
value: selected,
|
@@ -282,6 +325,10 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
282
325
|
});
|
283
326
|
(_components$RadioButt = (_components$RadioButt2 = components.RadioButtonGroup).onChange) === null || _components$RadioButt === void 0 ? void 0 : _components$RadioButt.call(_components$RadioButt2, selected);
|
284
327
|
}
|
328
|
+
}), /*#__PURE__*/React.createElement(RadioButton, {
|
329
|
+
id: "any",
|
330
|
+
labelText: "Any",
|
331
|
+
value: "Any"
|
285
332
|
}), components.RadioButton.map(function (radio) {
|
286
333
|
var _ref5, _radio$id;
|
287
334
|
|
@@ -290,15 +337,19 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
290
337
|
}, radio));
|
291
338
|
})));
|
292
339
|
} else if (type === DROPDOWN) {
|
293
|
-
|
294
|
-
|
295
|
-
}, components.Dropdown, {
|
296
|
-
selectedItem: filtersState[column],
|
340
|
+
var _filtersState$column3, _filtersState$column4;
|
341
|
+
|
342
|
+
return /*#__PURE__*/React.createElement(Dropdown, _extends({}, components.Dropdown, {
|
343
|
+
selectedItem: ((_filtersState$column3 = filtersState[column]) === null || _filtersState$column3 === void 0 ? void 0 : _filtersState$column3.value) === '' ? 'Any' : (_filtersState$column4 = filtersState[column]) === null || _filtersState$column4 === void 0 ? void 0 : _filtersState$column4.value,
|
344
|
+
items: ['Any'].concat(_toConsumableArray(components.Dropdown.items)),
|
297
345
|
onChange: function onChange(_ref6) {
|
298
346
|
var _components$Dropdown$, _components$Dropdown;
|
299
347
|
|
300
348
|
var selectedItem = _ref6.selectedItem;
|
301
|
-
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column,
|
349
|
+
setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
|
350
|
+
value: selectedItem,
|
351
|
+
type: type
|
352
|
+
})));
|
302
353
|
applyFilters({
|
303
354
|
column: column,
|
304
355
|
value: selectedItem,
|
@@ -308,9 +359,10 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
308
359
|
}
|
309
360
|
}));
|
310
361
|
}
|
311
|
-
}
|
362
|
+
};
|
312
363
|
/** Renders all filters */
|
313
364
|
|
365
|
+
|
314
366
|
var renderFilters = function renderFilters() {
|
315
367
|
return filters.map(renderFilter);
|
316
368
|
};
|
@@ -322,13 +374,15 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
322
374
|
kind: 'primary',
|
323
375
|
label: primaryActionLabel,
|
324
376
|
onClick: apply,
|
325
|
-
isExpressive: false
|
377
|
+
isExpressive: false,
|
378
|
+
disabled: shouldDisableButtons
|
326
379
|
}, {
|
327
380
|
key: 3,
|
328
381
|
kind: 'secondary',
|
329
382
|
label: secondaryActionLabel,
|
330
383
|
onClick: cancel,
|
331
|
-
isExpressive: false
|
384
|
+
isExpressive: false,
|
385
|
+
disabled: shouldDisableButtons
|
332
386
|
}],
|
333
387
|
size: "md",
|
334
388
|
buttonSize: "md"
|
@@ -348,7 +402,8 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
348
402
|
},
|
349
403
|
iconDescription: flyoutIconDescription,
|
350
404
|
onClick: open ? closeFlyout : openFlyout,
|
351
|
-
className: cx("".concat(componentClass, "__trigger"), _defineProperty({}, "".concat(componentClass, "__trigger--open"), open))
|
405
|
+
className: cx("".concat(componentClass, "__trigger"), _defineProperty({}, "".concat(componentClass, "__trigger--open"), open)),
|
406
|
+
disabled: data.length === 0
|
352
407
|
}), /*#__PURE__*/React.createElement("div", {
|
353
408
|
ref: filterFlyoutRef,
|
354
409
|
className: cx(componentClass, (_cx2 = {}, _defineProperty(_cx2, "".concat(componentClass, "--open"), open), _defineProperty(_cx2, "".concat(componentClass, "--batch"), showActionSet), _defineProperty(_cx2, "".concat(componentClass, "--instant"), !showActionSet), _cx2))
|
@@ -362,6 +417,11 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
362
417
|
};
|
363
418
|
|
364
419
|
FilterFlyout.propTypes = {
|
420
|
+
/**
|
421
|
+
* All data rows in the table
|
422
|
+
*/
|
423
|
+
data: PropTypes.array.isRequired,
|
424
|
+
|
365
425
|
/**
|
366
426
|
* Array of filters to render
|
367
427
|
*/
|