@carbon/ibm-products 1.38.0 → 1.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/css/index-full-carbon.css +124 -3
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css.map +1 -1
  6. package/css/index-without-carbon-released-only.min.css.map +1 -1
  7. package/css/index-without-carbon.css +124 -3
  8. package/css/index-without-carbon.css.map +1 -1
  9. package/css/index-without-carbon.min.css +3 -1
  10. package/css/index-without-carbon.min.css.map +1 -1
  11. package/css/index.css +124 -3
  12. package/css/index.css.map +1 -1
  13. package/css/index.min.css +3 -1
  14. package/css/index.min.css.map +1 -1
  15. package/es/components/ActionBar/ActionBarOverflowItems.js +1 -0
  16. package/es/components/ButtonMenu/ButtonMenu.js +1 -1
  17. package/es/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +1 -1
  18. package/es/components/Card/Card.js +1 -1
  19. package/es/components/CreateFullPage/CreateFullPage.js +4 -1
  20. package/es/components/Datagrid/Datagrid/Datagrid.js +7 -3
  21. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +9 -2
  22. package/es/components/Datagrid/Datagrid/DatagridRow.js +35 -2
  23. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +19 -3
  24. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +381 -0
  25. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +35 -46
  26. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +19 -0
  27. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +18 -0
  28. package/es/components/Datagrid/Datagrid/addons/Filtering/index.js +7 -0
  29. package/es/components/Datagrid/Datagrid/addons/Filtering/utils.js +38 -0
  30. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +10 -8
  31. package/es/components/Datagrid/index.js +2 -1
  32. package/es/components/Datagrid/useFiltering.js +83 -0
  33. package/es/components/Datagrid/useNestedRows.js +11 -2
  34. package/es/components/Datagrid/utils/DatagridActions.js +134 -33
  35. package/es/components/Datagrid/utils/getArgTypes.js +4 -0
  36. package/es/components/Datagrid/utils/makeData.js +23 -16
  37. package/es/components/InlineEditV1/InlineEditV1.js +2 -1
  38. package/es/components/PageHeader/PageHeader.js +1 -1
  39. package/es/components/RemoveModal/RemoveModal.js +17 -3
  40. package/es/global/js/package-settings.js +2 -1
  41. package/lib/components/ActionBar/ActionBarOverflowItems.js +1 -0
  42. package/lib/components/ButtonMenu/ButtonMenu.js +1 -1
  43. package/lib/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +1 -1
  44. package/lib/components/Card/Card.js +1 -1
  45. package/lib/components/CreateFullPage/CreateFullPage.js +4 -1
  46. package/lib/components/Datagrid/Datagrid/Datagrid.js +7 -3
  47. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +9 -2
  48. package/lib/components/Datagrid/Datagrid/DatagridRow.js +35 -2
  49. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +18 -3
  50. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +382 -0
  51. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +35 -46
  52. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +33 -0
  53. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +27 -0
  54. package/lib/components/Datagrid/Datagrid/addons/Filtering/index.js +13 -0
  55. package/lib/components/Datagrid/Datagrid/addons/Filtering/utils.js +45 -0
  56. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +12 -10
  57. package/lib/components/Datagrid/index.js +8 -1
  58. package/lib/components/Datagrid/useFiltering.js +83 -0
  59. package/lib/components/Datagrid/useNestedRows.js +11 -2
  60. package/lib/components/Datagrid/utils/DatagridActions.js +135 -31
  61. package/lib/components/Datagrid/utils/getArgTypes.js +4 -0
  62. package/lib/components/Datagrid/utils/makeData.js +24 -17
  63. package/lib/components/InlineEditV1/InlineEditV1.js +2 -1
  64. package/lib/components/PageHeader/PageHeader.js +1 -1
  65. package/lib/components/RemoveModal/RemoveModal.js +17 -3
  66. package/lib/global/js/package-settings.js +2 -1
  67. package/package.json +2 -2
  68. package/scss/components/ActionSet/_action-set.scss +3 -1
  69. package/scss/components/AddSelect/_add-select.scss +3 -1
  70. package/scss/components/Datagrid/_datagrid.scss +0 -1
  71. package/scss/components/Datagrid/_storybook-styles.scss +4 -0
  72. package/scss/components/Datagrid/styles/_datagrid.scss +48 -4
  73. package/scss/components/Datagrid/styles/_index.scss +1 -0
  74. package/scss/components/Datagrid/styles/_useInlineEdit.scss +9 -3
  75. package/scss/components/Datagrid/styles/addons/_FilterFlyout.scss +80 -0
  76. package/scss/components/InlineEditV1/_inline-edit-v1.scss +3 -1
  77. package/scss/components/PageHeader/_page-header.scss +6 -2
@@ -9,7 +9,7 @@ import _extends from "@babel/runtime/helpers/extends";
9
9
  import React from 'react';
10
10
  import { pkg } from '../../../settings';
11
11
  import { DataTable } from 'carbon-components-react';
12
- import { NoDataEmptyState } from '../../EmptyStates/NoDataEmptyState';
12
+ import { NoDataEmptyState, ErrorEmptyState } from '../../EmptyStates';
13
13
  var blockClass = "".concat(pkg.prefix, "--datagrid");
14
14
  var TableBody = DataTable.TableBody,
15
15
  TableRow = DataTable.TableRow,
@@ -20,12 +20,19 @@ var DatagridEmptyBody = function DatagridEmptyBody(datagridState) {
20
20
  emptyStateTitle = datagridState.emptyStateTitle,
21
21
  emptyStateDescription = datagridState.emptyStateDescription,
22
22
  emptyStateSize = datagridState.emptyStateSize,
23
+ _datagridState$emptyS = datagridState.emptyStateType,
24
+ emptyStateType = _datagridState$emptyS === void 0 ? 'noData' : _datagridState$emptyS,
23
25
  illustrationTheme = datagridState.illustrationTheme;
24
26
  return /*#__PURE__*/React.createElement(TableBody, _extends({}, getTableBodyProps(), {
25
27
  className: "".concat(blockClass, "__empty-state-body")
26
28
  }), /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableCell, {
27
29
  colSpan: headers.length
28
- }, /*#__PURE__*/React.createElement(NoDataEmptyState, {
30
+ }, emptyStateType === 'error' && /*#__PURE__*/React.createElement(ErrorEmptyState, {
31
+ illustrationTheme: illustrationTheme,
32
+ size: emptyStateSize,
33
+ title: emptyStateTitle,
34
+ subtitle: emptyStateDescription
35
+ }), emptyStateType === 'noData' && /*#__PURE__*/React.createElement(NoDataEmptyState, {
29
36
  illustrationTheme: illustrationTheme,
30
37
  size: emptyStateSize,
31
38
  title: emptyStateTitle,
@@ -12,30 +12,63 @@ var _excluded = ["children"];
12
12
  // @flow
13
13
  import React, { useContext } from 'react';
14
14
  import { DataTable, SkeletonText } from 'carbon-components-react';
15
- import { selectionColumnId } from '../common-column-ids';
15
+ import { px } from '@carbon/layout';
16
16
  import cx from 'classnames';
17
+ import { selectionColumnId } from '../common-column-ids';
17
18
  import { pkg, carbon } from '../../../settings';
18
19
  import { InlineEditContext } from './addons/InlineEdit/InlineEditContext/InlineEditContext';
19
20
  import { getCellIdAsObject } from './addons/InlineEdit/InlineEditContext/getCellIdAsObject';
20
21
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
22
  var TableRow = DataTable.TableRow,
22
23
  TableCell = DataTable.TableCell;
24
+ var rowHeights = {
25
+ xs: 24,
26
+ sm: 32,
27
+ md: 40,
28
+ lg: 48,
29
+ xl: 64
30
+ };
23
31
 
24
32
  // eslint-disable-next-line react/prop-types
25
33
  var DatagridRow = function DatagridRow(datagridState) {
26
34
  var _cx;
27
- var row = datagridState.row;
35
+ var row = datagridState.row,
36
+ rowSize = datagridState.rowSize,
37
+ withNestedRows = datagridState.withNestedRows;
28
38
  var _useContext = useContext(InlineEditContext),
29
39
  state = _useContext.state;
30
40
  var activeCellId = state.activeCellId;
31
41
  var activeCellObject = activeCellId && getCellIdAsObject(activeCellId);
42
+ var getVisibleNestedRowCount = function getVisibleNestedRowCount(_ref) {
43
+ var isExpanded = _ref.isExpanded,
44
+ subRows = _ref.subRows;
45
+ var size = 0;
46
+ if (isExpanded && subRows) {
47
+ size += subRows.length;
48
+ subRows.forEach(function (child) {
49
+ size += getVisibleNestedRowCount(child);
50
+ });
51
+ }
52
+ return size;
53
+ };
32
54
  return /*#__PURE__*/React.createElement(TableRow, _extends({
33
55
  className: cx("".concat(blockClass, "__carbon-row"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__carbon-row-expanded"), row.isExpanded), _defineProperty(_cx, "".concat(blockClass, "__carbon-row-expandable"), row.canExpand), _defineProperty(_cx, "".concat(carbon.prefix, "--data-table--selected"), row.isSelected), _defineProperty(_cx, "".concat(blockClass, "__carbon-row-hover-active"), activeCellObject && row.index === activeCellObject.row), _cx))
34
56
  }, row.getRowProps(), {
35
57
  key: row.id,
36
58
  onMouseEnter: function onMouseEnter(event) {
59
+ var _hoverRow$style, _hoverRow$style2, _hoverRow$style3;
60
+ if (!withNestedRows) {
61
+ return;
62
+ }
63
+ var subRowCount = getVisibleNestedRowCount(row);
64
+ var totalNestedRowIndicatorHeight = px(subRowCount * rowHeights[rowSize]);
37
65
  var hoverRow = event.target.closest(".".concat(blockClass, "__carbon-row-expanded"));
38
66
  hoverRow === null || hoverRow === void 0 ? void 0 : hoverRow.classList.add("".concat(blockClass, "__carbon-row-expanded-hover-active"));
67
+ var rowExpanderButton = hoverRow === null || hoverRow === void 0 ? void 0 : hoverRow.querySelector(".".concat(blockClass, "__row-expander"));
68
+ var rowSizeValue = rowSize || 'lg';
69
+ hoverRow === null || hoverRow === void 0 ? void 0 : (_hoverRow$style = hoverRow.style) === null || _hoverRow$style === void 0 ? void 0 : _hoverRow$style.setProperty("--".concat(blockClass, "--indicator-height"), totalNestedRowIndicatorHeight);
70
+ hoverRow === null || hoverRow === void 0 ? void 0 : (_hoverRow$style2 = hoverRow.style) === null || _hoverRow$style2 === void 0 ? void 0 : _hoverRow$style2.setProperty("--".concat(blockClass, "--row-height"), px(rowHeights[rowSizeValue]));
71
+ hoverRow === null || hoverRow === void 0 ? void 0 : (_hoverRow$style3 = hoverRow.style) === null || _hoverRow$style3 === void 0 ? void 0 : _hoverRow$style3.setProperty("--".concat(blockClass, "--indicator-offset-amount"), px((rowExpanderButton === null || rowExpanderButton === void 0 ? void 0 : rowExpanderButton.offsetLeft) || 0));
39
72
  },
40
73
  onMouseLeave: function onMouseLeave(event) {
41
74
  var hoverRow = event.target.closest(".".concat(blockClass, "__carbon-row-expanded"));
@@ -14,6 +14,10 @@ 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 { useContext } from 'react';
19
+ import { FilterContext } from './addons/Filtering/FilterProvider';
20
+ import { CLEAR_FILTERS } from './addons/Filtering/constants';
17
21
  var blockClass = "".concat(pkg.prefix, "--datagrid");
18
22
  var TableToolbar = DataTable.TableToolbar;
19
23
  var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridState, width, ref) {
@@ -129,12 +133,24 @@ var DatagridToolbar = function DatagridToolbar(datagridState) {
129
133
  ref = _useResizeDetector.ref;
130
134
  var DatagridActions = datagridState.DatagridActions,
131
135
  DatagridBatchActions = datagridState.DatagridBatchActions,
132
- batchActions = datagridState.batchActions;
136
+ batchActions = datagridState.batchActions,
137
+ state = datagridState.state;
138
+ var _useContext = useContext(FilterContext),
139
+ filterTags = _useContext.filterTags,
140
+ EventEmitter = _useContext.EventEmitter;
141
+ var renderFilterSummary = function renderFilterSummary() {
142
+ return state.filters.length > 0 && /*#__PURE__*/React.createElement(FilterSummary, {
143
+ filters: filterTags,
144
+ clearFilters: function clearFilters() {
145
+ return EventEmitter.dispatch(CLEAR_FILTERS);
146
+ }
147
+ });
148
+ };
133
149
  return batchActions && DatagridActions ? /*#__PURE__*/React.createElement("div", {
134
150
  ref: ref,
135
151
  className: "".concat(blockClass, "__table-toolbar")
136
- }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref))) : DatagridActions ? /*#__PURE__*/React.createElement("div", {
152
+ }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref)), renderFilterSummary()) : DatagridActions ? /*#__PURE__*/React.createElement("div", {
137
153
  className: "".concat(blockClass, "__table-toolbar")
138
- }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState))) : null;
154
+ }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState)), renderFilterSummary()) : null;
139
155
  };
140
156
  export default DatagridToolbar;
@@ -0,0 +1,381 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ // @flow
8
+ /*
9
+ * Licensed Materials - Property of IBM
10
+ * 5724-Q36
11
+ * (c) Copyright IBM Corp. 2022
12
+ * US Government Users Restricted Rights - Use, duplication or disclosure
13
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
14
+ */
15
+ import { Filter16 } from '@carbon/icons-react';
16
+ import { Button, Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup } from 'carbon-components-react';
17
+ import cx from 'classnames';
18
+ import PropTypes from 'prop-types';
19
+ import React, { useCallback, useRef, useState } from 'react';
20
+ import { useEffect } from 'react';
21
+ import { useContext } from 'react';
22
+ import { useClickOutside } from '../../../../../global/js/hooks';
23
+ import { pkg } from '../../../../../settings';
24
+ import { ActionSet } from '../../../../ActionSet';
25
+ import { BATCH, CHECKBOX, CLEAR_FILTERS, DATE, DROPDOWN, INSTANT, NUMBER, RADIO } from './constants';
26
+ import { FilterContext } from './FilterProvider';
27
+ import useInitialStateFromFilters from './hooks/useInitialStateFromFilters';
28
+ import { getInitialStateFromFilters } from './utils';
29
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
30
+ var componentClass = "".concat(blockClass, "-filter-flyout");
31
+ var FilterFlyout = function FilterFlyout(_ref) {
32
+ var _cx2;
33
+ var _ref$updateMethod = _ref.updateMethod,
34
+ updateMethod = _ref$updateMethod === void 0 ? BATCH : _ref$updateMethod,
35
+ _ref$flyoutIconDescri = _ref.flyoutIconDescription,
36
+ flyoutIconDescription = _ref$flyoutIconDescri === void 0 ? 'Open filters' : _ref$flyoutIconDescri,
37
+ _ref$filters = _ref.filters,
38
+ filters = _ref$filters === void 0 ? [] : _ref$filters,
39
+ _ref$title = _ref.title,
40
+ title = _ref$title === void 0 ? 'Filter' : _ref$title,
41
+ _ref$primaryActionLab = _ref.primaryActionLabel,
42
+ primaryActionLabel = _ref$primaryActionLab === void 0 ? 'Apply' : _ref$primaryActionLab,
43
+ _ref$onFlyoutOpen = _ref.onFlyoutOpen,
44
+ onFlyoutOpen = _ref$onFlyoutOpen === void 0 ? function () {} : _ref$onFlyoutOpen,
45
+ _ref$onFlyoutClose = _ref.onFlyoutClose,
46
+ onFlyoutClose = _ref$onFlyoutClose === void 0 ? function () {} : _ref$onFlyoutClose,
47
+ _ref$onApply = _ref.onApply,
48
+ onApply = _ref$onApply === void 0 ? function () {} : _ref$onApply,
49
+ _ref$onCancel = _ref.onCancel,
50
+ onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel,
51
+ _ref$shouldClickOutsi = _ref.shouldClickOutsideToClose,
52
+ shouldClickOutsideToClose = _ref$shouldClickOutsi === void 0 ? false : _ref$shouldClickOutsi,
53
+ _ref$secondaryActionL = _ref.secondaryActionLabel,
54
+ secondaryActionLabel = _ref$secondaryActionL === void 0 ? 'Cancel' : _ref$secondaryActionL,
55
+ setAllFilters = _ref.setAllFilters,
56
+ setFilter = _ref.setFilter;
57
+ /** Context state and methods */
58
+ var _useContext = useContext(FilterContext),
59
+ EventEmitter = _useContext.EventEmitter;
60
+
61
+ /** State */
62
+ var _useState = useState(false),
63
+ _useState2 = _slicedToArray(_useState, 2),
64
+ open = _useState2[0],
65
+ setOpen = _useState2[1];
66
+ var _useInitialStateFromF = useInitialStateFromFilters(filters),
67
+ _useInitialStateFromF2 = _slicedToArray(_useInitialStateFromF, 2),
68
+ filtersState = _useInitialStateFromF2[0],
69
+ setFiltersState = _useInitialStateFromF2[1];
70
+ var _useState3 = useState([]),
71
+ _useState4 = _slicedToArray(_useState3, 2),
72
+ filtersObjectArray = _useState4[0],
73
+ setFiltersObjectArray = _useState4[1];
74
+
75
+ /** Refs */
76
+ var filterFlyoutRef = useRef(null);
77
+ // When using batch actions we have to store the filters to then apply them later
78
+ var prevFiltersRef = useRef(JSON.stringify(filtersState));
79
+ var prevFiltersObjectArrayRef = useRef(JSON.stringify(filtersObjectArray));
80
+
81
+ /** Memos */
82
+ var showActionSet = updateMethod === BATCH;
83
+
84
+ /** Methods */
85
+ var openFlyout = function openFlyout() {
86
+ setOpen(true);
87
+ onFlyoutOpen();
88
+ };
89
+ var closeFlyout = function closeFlyout() {
90
+ setOpen(false);
91
+ onFlyoutClose();
92
+ };
93
+ var apply = function apply() {
94
+ setAllFilters(filtersObjectArray);
95
+ closeFlyout();
96
+ onApply();
97
+
98
+ // updates the ref so next time the flyout opens we have records of the previous filters
99
+ prevFiltersRef.current = JSON.stringify(filtersState);
100
+ prevFiltersObjectArrayRef.current = JSON.stringify(filtersObjectArray);
101
+ };
102
+ var cancel = function cancel() {
103
+ revertToPreviousFilters();
104
+ onCancel();
105
+ closeFlyout();
106
+ };
107
+ var reset = function reset() {
108
+ // Get the initial values for the filters
109
+ var initialFiltersState = getInitialStateFromFilters(filters);
110
+ var initialFiltersObjectArray = [];
111
+
112
+ // Set the state to the initial values
113
+ setFiltersState(initialFiltersState);
114
+ setFiltersObjectArray(initialFiltersObjectArray);
115
+ setAllFilters([]);
116
+
117
+ // Update their respective refs so everything is in sync
118
+ prevFiltersRef.current = JSON.stringify(initialFiltersState);
119
+ prevFiltersObjectArrayRef.current = JSON.stringify(initialFiltersObjectArray);
120
+ };
121
+
122
+ // If the user decides to cancel or click outside the flyout, it reverts back to the filters that were
123
+ // there when they opened the flyout
124
+ var revertToPreviousFilters = function revertToPreviousFilters() {
125
+ setFiltersState(JSON.parse(prevFiltersRef.current));
126
+ setFiltersObjectArray(JSON.parse(prevFiltersObjectArrayRef.current));
127
+ };
128
+ var applyFilters = useCallback(function (_ref2) {
129
+ var column = _ref2.column,
130
+ value = _ref2.value,
131
+ type = _ref2.type;
132
+ // If no end date is selected return because we need the end date to do computations
133
+ if (type === DATE && !value[1]) {
134
+ return;
135
+ }
136
+ if (updateMethod === BATCH) {
137
+ var filtersObjectArrayCopy = _toConsumableArray(filtersObjectArray);
138
+ // check if the filter already exists in the array
139
+ var filter = filtersObjectArrayCopy.find(function (item) {
140
+ return item.id === column;
141
+ });
142
+
143
+ // if filter exists in array then update the filter's new value
144
+ if (filter) {
145
+ filter.value = value;
146
+ } else {
147
+ filtersObjectArrayCopy.push({
148
+ id: column,
149
+ value: value,
150
+ type: type
151
+ });
152
+ }
153
+ setFiltersObjectArray(filtersObjectArrayCopy);
154
+ } else if (updateMethod === INSTANT) {
155
+ setFilter(column, value);
156
+ }
157
+ }, [setFilter, updateMethod, filtersObjectArray]);
158
+
159
+ /** Effects */
160
+ useClickOutside(filterFlyoutRef, function (target) {
161
+ if (shouldClickOutsideToClose === false) {
162
+ return;
163
+ }
164
+ var hasClickedOnDatePicker = target.closest('.flatpickr-calendar');
165
+ if (!open || hasClickedOnDatePicker) {
166
+ return;
167
+ }
168
+ cancel();
169
+ });
170
+ useEffect(function subscribeToEmitter() {
171
+ // This event is emitted from the DatagridToolbar component when clearFilters is clicked in FilterSummary
172
+ EventEmitter.subscribe(CLEAR_FILTERS, reset);
173
+ });
174
+
175
+ /** Render the individual filter component */
176
+ var renderFilter = useCallback(function (_ref3) {
177
+ var type = _ref3.type,
178
+ column = _ref3.column,
179
+ components = _ref3.props;
180
+ if (type === DATE) {
181
+ return /*#__PURE__*/React.createElement(DatePicker, _extends({}, components.DatePicker, {
182
+ onChange: function onChange(value) {
183
+ var _components$DatePicke, _components$DatePicke2;
184
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, value)));
185
+ applyFilters({
186
+ column: column,
187
+ value: value,
188
+ type: type
189
+ });
190
+ (_components$DatePicke = (_components$DatePicke2 = components.DatePicker).onChange) === null || _components$DatePicke === void 0 ? void 0 : _components$DatePicke.call(_components$DatePicke2, value);
191
+ },
192
+ value: filtersState[column],
193
+ datePickerType: "range"
194
+ }), /*#__PURE__*/React.createElement(DatePickerInput, _extends({
195
+ placeholder: "mm/dd/yyyy",
196
+ labelText: "Start date"
197
+ }, components.DatePickerInput.start)), /*#__PURE__*/React.createElement(DatePickerInput, _extends({
198
+ placeholder: "mm/dd/yyyy",
199
+ labelText: "End date"
200
+ }, components.DatePickerInput.end)));
201
+ } else if (type === NUMBER) {
202
+ return /*#__PURE__*/React.createElement(NumberInput, _extends({
203
+ step: 1,
204
+ allowEmpty: true,
205
+ hideSteppers: true
206
+ }, components.NumberInput, {
207
+ onChange: function onChange(event) {
208
+ var _components$NumberInp, _components$NumberInp2;
209
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, event.target.value)));
210
+ applyFilters({
211
+ column: column,
212
+ value: event.target.value,
213
+ type: type
214
+ });
215
+ (_components$NumberInp = (_components$NumberInp2 = components.NumberInput).onChange) === null || _components$NumberInp === void 0 ? void 0 : _components$NumberInp.call(_components$NumberInp2, event);
216
+ },
217
+ value: filtersState[column]
218
+ }));
219
+ } else if (type === CHECKBOX) {
220
+ return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, filtersState[column].map(function (option) {
221
+ return /*#__PURE__*/React.createElement(Checkbox, _extends({
222
+ key: option.labelText
223
+ }, option, {
224
+ onChange: function onChange(isSelected) {
225
+ var _option$onChange;
226
+ var checkboxCopy = filtersState[column];
227
+ var foundCheckbox = checkboxCopy.find(function (checkbox) {
228
+ return checkbox.value === option.value;
229
+ });
230
+ foundCheckbox.selected = isSelected;
231
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, checkboxCopy)));
232
+ applyFilters({
233
+ column: column,
234
+ value: _toConsumableArray(filtersState[column]),
235
+ type: type
236
+ });
237
+ (_option$onChange = option.onChange) === null || _option$onChange === void 0 ? void 0 : _option$onChange.call(option, isSelected);
238
+ },
239
+ checked: option.selected
240
+ }));
241
+ }));
242
+ } else if (type === RADIO) {
243
+ return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, /*#__PURE__*/React.createElement(RadioButtonGroup, _extends({}, components.RadioButtonGroup, {
244
+ valueSelected: filtersState[column],
245
+ onChange: function onChange(selected) {
246
+ var _components$RadioButt, _components$RadioButt2;
247
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, selected)));
248
+ applyFilters({
249
+ column: column,
250
+ value: selected,
251
+ type: type
252
+ });
253
+ (_components$RadioButt = (_components$RadioButt2 = components.RadioButtonGroup).onChange) === null || _components$RadioButt === void 0 ? void 0 : _components$RadioButt.call(_components$RadioButt2, selected);
254
+ }
255
+ }), components.RadioButton.map(function (radio) {
256
+ var _ref4, _radio$id;
257
+ return /*#__PURE__*/React.createElement(RadioButton, _extends({
258
+ key: (_ref4 = (_radio$id = radio.id) !== null && _radio$id !== void 0 ? _radio$id : radio.labelText) !== null && _ref4 !== void 0 ? _ref4 : radio.value
259
+ }, radio));
260
+ })));
261
+ } else if (type === DROPDOWN) {
262
+ return /*#__PURE__*/React.createElement(Dropdown, _extends({}, components.Dropdown, {
263
+ selectedItem: filtersState[column],
264
+ onChange: function onChange(_ref5) {
265
+ var _components$Dropdown$, _components$Dropdown;
266
+ var selectedItem = _ref5.selectedItem;
267
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, selectedItem)));
268
+ applyFilters({
269
+ column: column,
270
+ value: selectedItem,
271
+ type: type
272
+ });
273
+ (_components$Dropdown$ = (_components$Dropdown = components.Dropdown).onChange) === null || _components$Dropdown$ === void 0 ? void 0 : _components$Dropdown$.call(_components$Dropdown, selectedItem);
274
+ }
275
+ }));
276
+ }
277
+ }, [filtersState, applyFilters, setFiltersState]);
278
+
279
+ /** Renders all filters */
280
+ var renderFilters = useCallback(function () {
281
+ return filters.map(renderFilter);
282
+ }, [filters, renderFilter]);
283
+ var renderActionSet = function renderActionSet() {
284
+ return showActionSet && /*#__PURE__*/React.createElement(ActionSet, {
285
+ actions: [{
286
+ key: 1,
287
+ kind: 'primary',
288
+ label: primaryActionLabel,
289
+ onClick: apply,
290
+ isExpressive: false
291
+ }, {
292
+ key: 3,
293
+ kind: 'secondary',
294
+ label: secondaryActionLabel,
295
+ onClick: cancel,
296
+ isExpressive: false
297
+ }],
298
+ size: "md",
299
+ buttonSize: "md"
300
+ });
301
+ };
302
+ return /*#__PURE__*/React.createElement("div", {
303
+ className: "".concat(componentClass, "__container")
304
+ }, /*#__PURE__*/React.createElement(Button, {
305
+ kind: "ghost",
306
+ hasIconOnly: true,
307
+ tooltipPosition: "bottom",
308
+ renderIcon: Filter16,
309
+ iconDescription: flyoutIconDescription,
310
+ onClick: open ? closeFlyout : openFlyout,
311
+ className: cx("".concat(componentClass, "__trigger"), _defineProperty({}, "".concat(componentClass, "__trigger--open"), open))
312
+ }), /*#__PURE__*/React.createElement("div", {
313
+ ref: filterFlyoutRef,
314
+ className: cx(componentClass, (_cx2 = {}, _defineProperty(_cx2, "".concat(componentClass, "--open"), open), _defineProperty(_cx2, "".concat(componentClass, "--batch"), showActionSet), _defineProperty(_cx2, "".concat(componentClass, "--instant"), !showActionSet), _cx2))
315
+ }, /*#__PURE__*/React.createElement("div", {
316
+ className: "".concat(componentClass, "__inner-container")
317
+ }, /*#__PURE__*/React.createElement("span", {
318
+ className: "".concat(componentClass, "__title")
319
+ }, title), /*#__PURE__*/React.createElement("div", {
320
+ className: "".concat(componentClass, "__filters")
321
+ }, renderFilters())), renderActionSet()));
322
+ };
323
+ FilterFlyout.propTypes = {
324
+ /**
325
+ * Array of filters to render
326
+ */
327
+ filters: PropTypes.arrayOf(PropTypes.shape({
328
+ type: PropTypes.string.isRequired,
329
+ column: PropTypes.string.isRequired,
330
+ props: PropTypes.object.isRequired
331
+ })).isRequired,
332
+ /**
333
+ * Icon description for the filter flyout button
334
+ */
335
+ flyoutIconDescription: PropTypes.string,
336
+ /**
337
+ * Callback when the apply button is clicked
338
+ */
339
+ onApply: PropTypes.func,
340
+ /**
341
+ * Callback when the cancel button is clicked
342
+ */
343
+ onCancel: PropTypes.func,
344
+ /**
345
+ * Callback when the flyout closes
346
+ */
347
+ onFlyoutClose: PropTypes.func,
348
+ /**
349
+ * Callback when the flyout opens
350
+ */
351
+ onFlyoutOpen: PropTypes.func,
352
+ /**
353
+ * Label text of the primary action in the flyout
354
+ */
355
+ primaryActionLabel: PropTypes.string,
356
+ /**
357
+ * Label text of the secondary action in the flyout
358
+ */
359
+ secondaryActionLabel: PropTypes.string,
360
+ /**
361
+ * Function that sets all the filters, this comes from the datagridState
362
+ */
363
+ setAllFilters: PropTypes.func.isRequired,
364
+ /**
365
+ * Function that sets an individual filter, this comes from the datagridState
366
+ */
367
+ setFilter: PropTypes.func.isRequired,
368
+ /**
369
+ * Boolean if you want the flyout to close when clicked outside of the parent
370
+ */
371
+ shouldClickOutsideToClose: PropTypes.bool,
372
+ /**
373
+ * Title of the filter flyout
374
+ */
375
+ title: PropTypes.string,
376
+ /**
377
+ * The update method used to apply the filters
378
+ */
379
+ updateMethod: PropTypes.oneOf([BATCH, INSTANT]).isRequired
380
+ };
381
+ export default FilterFlyout;
@@ -1,5 +1,4 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
2
  /**
4
3
  * Copyright IBM Corp. 2022, 2022
5
4
  *
@@ -10,6 +9,24 @@ import React, { createContext } from 'react';
10
9
  import PropTypes from 'prop-types';
11
10
  import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX } from './constants';
12
11
  export var FilterContext = /*#__PURE__*/createContext();
12
+ var EventEmitter = {
13
+ events: {},
14
+ dispatch: function dispatch(event, data) {
15
+ if (!this.events[event]) {
16
+ return;
17
+ }
18
+ this.events[event].forEach(function (callback) {
19
+ return callback(data);
20
+ });
21
+ },
22
+ subscribe: function subscribe(event, callback) {
23
+ if (!this.events[event]) {
24
+ this.events[event] = [];
25
+ } else {
26
+ this.events[event].push(callback);
27
+ }
28
+ }
29
+ };
13
30
  var prepareFiltersForTags = function prepareFiltersForTags(filters) {
14
31
  var tags = [];
15
32
  filters.forEach(function (_ref) {
@@ -17,15 +34,26 @@ var prepareFiltersForTags = function prepareFiltersForTags(filters) {
17
34
  type = _ref.type,
18
35
  value = _ref.value;
19
36
  if (type === DROPDOWN || type === RADIO || type === NUMBER) {
20
- tags.push(_defineProperty({}, id, value));
37
+ tags.push({
38
+ key: id,
39
+ value: value
40
+ });
21
41
  } else if (type === DATE) {
22
42
  var _value = _slicedToArray(value, 2),
23
43
  startDate = _value[0],
24
44
  endDate = _value[1];
25
- tags.push(_defineProperty({}, id, "".concat(startDate.toLocaleString(), " - ").concat(endDate.toLocaleString())));
45
+ tags.push({
46
+ key: id,
47
+ value: "".concat(startDate.toLocaleDateString(), " - ").concat(endDate.toLocaleDateString())
48
+ });
26
49
  } else if (type === CHECKBOX) {
27
50
  value.forEach(function (checkbox) {
28
- tags.push(_defineProperty({}, id, checkbox.value));
51
+ if (checkbox.selected) {
52
+ tags.push({
53
+ key: id,
54
+ value: checkbox.value
55
+ });
56
+ }
29
57
  });
30
58
  }
31
59
  });
@@ -34,13 +62,10 @@ var prepareFiltersForTags = function prepareFiltersForTags(filters) {
34
62
  export var FilterProvider = function FilterProvider(_ref2) {
35
63
  var children = _ref2.children,
36
64
  filters = _ref2.filters;
37
- console.log(filters);
38
65
  var filterTags = prepareFiltersForTags(filters);
39
- console.log({
40
- filterTags: filterTags
41
- });
42
66
  var value = {
43
- filterTags: filterTags
67
+ filterTags: filterTags,
68
+ EventEmitter: EventEmitter
44
69
  };
45
70
  return /*#__PURE__*/React.createElement(FilterContext.Provider, {
46
71
  value: value
@@ -49,40 +74,4 @@ export var FilterProvider = function FilterProvider(_ref2) {
49
74
  FilterProvider.propTypes = {
50
75
  children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
51
76
  filters: PropTypes.arrayOf(PropTypes.object).isRequired
52
- };
53
- [{
54
- id: 'joined',
55
- value: ['2022-10-02T04:00:00.000Z', '2022-10-26T04:00:00.000Z'],
56
- type: 'date'
57
- }, {
58
- id: 'visits',
59
- value: '1',
60
- type: 'number'
61
- }, {
62
- id: 'passwordStrength',
63
- value: [{
64
- id: 'normal',
65
- labelText: 'Normal',
66
- value: 'normal',
67
- selected: true
68
- }, {
69
- id: 'minor-warning',
70
- labelText: 'Minor warning',
71
- value: 'minor-warning',
72
- selected: true
73
- }, {
74
- id: 'critical',
75
- labelText: 'Critical',
76
- value: 'critical',
77
- selected: false
78
- }],
79
- type: 'checkbox'
80
- }, {
81
- id: 'role',
82
- value: 'developer',
83
- type: 'radio'
84
- }, {
85
- id: 'status',
86
- value: 'complicated',
87
- type: 'dropdown'
88
- }];
77
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /** Constants for update methods can either be batch or instant */
8
+ export var BATCH = 'batch';
9
+ export var INSTANT = 'instant';
10
+
11
+ /** Constants for filter type */
12
+ export var DATE = 'date';
13
+ export var NUMBER = 'number';
14
+ export var CHECKBOX = 'checkbox';
15
+ export var RADIO = 'radio';
16
+ export var DROPDOWN = 'dropdown';
17
+
18
+ /** Constants for event emitters */
19
+ export var CLEAR_FILTERS = 'clearFilters';
@@ -0,0 +1,18 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /*
3
+ * Licensed Materials - Property of IBM
4
+ * 5724-Q36
5
+ * (c) Copyright IBM Corp. 2022
6
+ * US Government Users Restricted Rights - Use, duplication or disclosure
7
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
8
+ */
9
+ import { useState } from 'react';
10
+ import { getInitialStateFromFilters } from '../utils';
11
+ var useInitialStateFromFilters = function useInitialStateFromFilters(filters) {
12
+ var _useState = useState(getInitialStateFromFilters(filters)),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ state = _useState2[0],
15
+ setState = _useState2[1];
16
+ return [state, setState];
17
+ };
18
+ export default useInitialStateFromFilters;