@carbon/ibm-products 1.59.0 → 1.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. package/css/index-full-carbon.css +97 -65
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon.css +53 -21
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +2 -2
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +97 -65
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +3 -3
  12. package/css/index.min.css.map +1 -1
  13. package/es/components/Checklist/ChecklistChart.js +2 -2
  14. package/es/components/Datagrid/Datagrid/Datagrid.js +2 -1
  15. package/es/components/Datagrid/Datagrid/DatagridContent.js +15 -7
  16. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +3 -2
  17. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -13
  18. package/es/components/Datagrid/Datagrid/DatagridRow.js +41 -33
  19. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  20. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  21. package/es/components/Datagrid/Datagrid/DraggableElement.js +32 -135
  22. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +14 -38
  23. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  24. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +128 -40
  25. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  26. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -18
  27. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +1 -0
  28. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +37 -4
  29. package/es/components/Datagrid/useExpandedRow.js +1 -1
  30. package/es/components/Datagrid/useFiltering.js +4 -1
  31. package/es/components/Datagrid/useNestedRowExpander.js +22 -9
  32. package/es/components/Datagrid/useRowExpander.js +22 -9
  33. package/es/components/Datagrid/utils/DatagridPagination.js +1 -1
  34. package/es/components/Datagrid/utils/getArgTypes.js +12 -0
  35. package/es/components/EmptyStates/EmptyState.js +1 -1
  36. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  37. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  38. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  39. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  40. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  41. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  42. package/es/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  43. package/es/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  44. package/es/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  45. package/es/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  46. package/es/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  47. package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  48. package/es/components/FilterSummary/FilterSummary.js +9 -3
  49. package/es/components/TagSet/TagSet.js +3 -7
  50. package/es/global/js/hooks/useWindowScroll.js +5 -0
  51. package/lib/components/Checklist/ChecklistChart.js +2 -2
  52. package/lib/components/Datagrid/Datagrid/Datagrid.js +2 -1
  53. package/lib/components/Datagrid/Datagrid/DatagridContent.js +14 -6
  54. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +2 -1
  55. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -13
  56. package/lib/components/Datagrid/Datagrid/DatagridRow.js +41 -33
  57. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  58. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  59. package/lib/components/Datagrid/Datagrid/DraggableElement.js +34 -140
  60. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +17 -38
  61. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  62. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +128 -47
  63. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  64. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -24
  65. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +4 -2
  66. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +36 -3
  67. package/lib/components/Datagrid/useExpandedRow.js +1 -1
  68. package/lib/components/Datagrid/useFiltering.js +4 -1
  69. package/lib/components/Datagrid/useNestedRowExpander.js +24 -9
  70. package/lib/components/Datagrid/useRowExpander.js +24 -9
  71. package/lib/components/Datagrid/utils/DatagridPagination.js +1 -1
  72. package/lib/components/Datagrid/utils/getArgTypes.js +12 -0
  73. package/lib/components/EmptyStates/EmptyState.js +1 -1
  74. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  75. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  76. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  77. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  78. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  79. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  80. package/lib/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  81. package/lib/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  82. package/lib/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  83. package/lib/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  84. package/lib/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  85. package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  86. package/lib/components/FilterSummary/FilterSummary.js +9 -10
  87. package/lib/components/TagSet/TagSet.js +2 -6
  88. package/lib/global/js/hooks/useWindowScroll.js +6 -0
  89. package/package.json +8 -7
  90. package/scss/components/Datagrid/_datagrid.scss +1 -1
  91. package/scss/components/Datagrid/styles/_datagrid.scss +5 -0
  92. package/scss/components/Datagrid/styles/_draggableElement.scss +44 -20
  93. package/scss/components/Datagrid/styles/_useExpandedRow.scss +10 -0
  94. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsTearsheet.scss +0 -1
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  /**
2
5
  * Copyright IBM Corp. 2023, 2023
3
6
  *
@@ -12,18 +15,21 @@ import { isColumnVisible } from './common';
12
15
  import DraggableElement from '../../DraggableElement';
13
16
  import { pkg } from '../../../../../settings';
14
17
  import getColTitle from '../../../utils/getColTitle';
18
+ import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors } from '@dnd-kit/core';
19
+ import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
15
20
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
+ var matchedColsById = function matchedColsById(col1, col2) {
22
+ return col1 && col2 && col1.id === col2.id;
23
+ };
16
24
  export var DraggableItemsList = function DraggableItemsList(_ref) {
17
25
  var columns = _ref.columns,
18
26
  filterString = _ref.filterString,
19
- focusIndex = _ref.focusIndex,
20
- getNextIndex = _ref.getNextIndex,
27
+ id = _ref.id,
21
28
  moveElement = _ref.moveElement,
22
29
  onSelectColumn = _ref.onSelectColumn,
23
- setAriaRegionText = _ref.setAriaRegionText,
24
- setColumnsObject = _ref.setColumnsObject,
25
- setFocusIndex = _ref.setFocusIndex;
26
- return /*#__PURE__*/React.createElement(React.Fragment, null, columns
30
+ setAriaRegionText = _ref.setAriaRegionText;
31
+ var draggableClass = "".concat(blockClass, "__draggable-item");
32
+ var visibleCols = columns
27
33
  // hide the columns without Header, e.g the sticky actions, spacer
28
34
  .filter(function (colDef) {
29
35
  return !!getColTitle(colDef);
@@ -32,7 +38,108 @@ export var DraggableItemsList = function DraggableItemsList(_ref) {
32
38
  }).filter(function (colDef) {
33
39
  var _getColTitle;
34
40
  return filterString.length === 0 || ((_getColTitle = getColTitle(colDef)) === null || _getColTitle === void 0 ? void 0 : _getColTitle.toLowerCase().includes(filterString)) && colDef.id !== 'spacer';
35
- }).map(function (colDef, i) {
41
+ });
42
+
43
+ // let localRefCopy;
44
+ var handleDragEnd = function handleDragEnd(event) {
45
+ var active = event.active,
46
+ over = event.over;
47
+ var fromVisibleIndex = columns.findIndex(function (col) {
48
+ return matchedColsById(col, active);
49
+ });
50
+ var toVisibleIndex = columns.findIndex(function (col) {
51
+ return matchedColsById(col, over);
52
+ });
53
+ var colTitle = getColTitle(visibleCols[fromVisibleIndex]);
54
+ setAriaRegionText("".concat(colTitle, " dropped. New position ").concat(toVisibleIndex + 1, " of ").concat(visibleCols.length, "."));
55
+ var fromIndex = columns.findIndex(function (col) {
56
+ return matchedColsById(col, active);
57
+ });
58
+ var toIndex = columns.findIndex(function (col) {
59
+ return matchedColsById(col, over);
60
+ });
61
+ moveElement(fromIndex, toIndex);
62
+ };
63
+ var handleDragStart = function handleDragStart(event) {
64
+ var active = event.active;
65
+ var fromIndex = visibleCols.findIndex(function (col) {
66
+ return matchedColsById(col, active);
67
+ });
68
+ var colTitle = getColTitle(visibleCols[fromIndex]);
69
+ setAriaRegionText("".concat(colTitle, " grabbed. Current position ").concat(fromIndex + 1, " of ").concat(visibleCols.length, "."));
70
+ };
71
+ var handleDragUpdate = function handleDragUpdate(event) {
72
+ var active = event.active,
73
+ over = event.over;
74
+ var fromIndex = visibleCols.findIndex(function (col) {
75
+ return matchedColsById(col, active);
76
+ });
77
+ var toIndex = visibleCols.findIndex(function (col) {
78
+ return matchedColsById(col, over);
79
+ });
80
+ var colTitle = getColTitle(visibleCols[fromIndex]);
81
+ setAriaRegionText("".concat(colTitle, " grabbed. Original position ").concat(fromIndex + 1, ", new position ").concat(toIndex + 1, " of ").concat(visibleCols.length, "."));
82
+ };
83
+ var pointerSensor = useSensor(PointerSensor, {
84
+ // Require the mouse to move by 10 pixels before activating
85
+ activationConstraint: {
86
+ distance: 4
87
+ }
88
+ });
89
+ var keyboardSensor = useSensor(KeyboardSensor, {
90
+ coordinateGetter: function coordinateGetter(event, args) {
91
+ var currentCoordinates = args.currentCoordinates;
92
+ var target = event.target;
93
+ while (target && !target.classList.contains(draggableClass)) {
94
+ target = target.parentNode;
95
+ }
96
+ var delta = target.offsetHeight;
97
+ switch (event.code) {
98
+ case 'ArrowRight':
99
+ case 'ArrowLeft':
100
+ // ignore right and left
101
+ return currentCoordinates;
102
+ case 'ArrowUp':
103
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
104
+ y: currentCoordinates.y - delta
105
+ });
106
+ case 'ArrowDown':
107
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
108
+ y: currentCoordinates.y + delta
109
+ });
110
+ case 'Space':
111
+ break;
112
+ }
113
+ }
114
+ });
115
+ var sensors = useSensors(pointerSensor, keyboardSensor);
116
+ var handleCheckboxKeydown = function handleCheckboxKeydown(event, colDef) {
117
+ if (event.code === 'Space') {
118
+ onSelectColumn(colDef, !isColumnVisible(colDef));
119
+ event.preventDefault();
120
+ event.stopPropagation();
121
+ return false;
122
+ }
123
+ };
124
+ return /*#__PURE__*/React.createElement(DndContext, {
125
+ collisionDetection: closestCenter,
126
+ onDragEnd: handleDragEnd,
127
+ onDragStart: handleDragStart,
128
+ onDragMove: handleDragUpdate,
129
+ sensors: sensors
130
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
131
+ className: "".concat(blockClass, "__draggable-underlay"),
132
+ "aria-hidden": "true",
133
+ key: "draggable-underlay-".concat(id)
134
+ }, visibleCols.map(function (colDef) {
135
+ return /*#__PURE__*/React.createElement("div", {
136
+ className: "".concat(blockClass, "__draggable-underlay-item"),
137
+ key: colDef.id
138
+ });
139
+ })), /*#__PURE__*/React.createElement(SortableContext, {
140
+ items: visibleCols,
141
+ strategy: verticalListSortingStrategy
142
+ }, visibleCols.map(function (colDef) {
36
143
  var colHeaderTitle = getColTitle(colDef);
37
144
  var searchString = new RegExp('(' + filterString + ')');
38
145
  var res = filterString.length ? colHeaderTitle.toLowerCase().split(searchString) : null;
@@ -40,60 +147,41 @@ export var DraggableItemsList = function DraggableItemsList(_ref) {
40
147
  var highlightedText = res !== null ? res[0] === '' ? "<strong>".concat(firstWord, "</strong>") + res[2] : firstWord + "<strong>".concat(res[1], "</strong>") + res[2] : colHeaderTitle;
41
148
  var isFrozenColumn = !!colDef.sticky;
42
149
  var listContents = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
43
- wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox-wrapper"),
44
150
  checked: isColumnVisible(colDef),
45
151
  disabled: isFrozenColumn,
46
- onChange: onSelectColumn.bind(null, colDef),
152
+ onChange: function onChange(checked) {
153
+ return onSelectColumn(colDef, checked);
154
+ },
47
155
  id: "".concat(blockClass, "__customization-column-").concat(colDef.id),
48
156
  labelText: colHeaderTitle,
49
157
  title: colHeaderTitle,
50
158
  className: "".concat(blockClass, "__customize-columns-checkbox"),
51
- hideLabel: true
159
+ hideLabel: true,
160
+ onKeyDown: function onKeyDown(event) {
161
+ return handleCheckboxKeydown(event, colDef);
162
+ }
52
163
  }), /*#__PURE__*/React.createElement("div", {
53
164
  dangerouslySetInnerHTML: {
54
165
  __html: highlightedText
55
- }
166
+ },
167
+ className: "".concat(blockClass, "__customize-columns-checkbox-visible-label")
56
168
  }));
57
169
  return /*#__PURE__*/React.createElement(DraggableElement, {
170
+ classList: draggableClass,
58
171
  key: colDef.id,
59
- index: i,
60
- listData: columns,
61
- setListData: setColumnsObject,
62
- id: "dnd-datagrid-columns-".concat(colDef.id),
63
- type: "column-customization",
172
+ id: colDef.id,
64
173
  disabled: filterString.length > 0 || isFrozenColumn,
65
174
  ariaLabel: colHeaderTitle,
66
- onGrab: setAriaRegionText,
67
- isFocused: focusIndex === i,
68
- moveElement: moveElement,
69
- onArrowKeyDown: function onArrowKeyDown(e, isGrabbed, currentIndex) {
70
- if (isGrabbed) {
71
- var _columns$nextIndex;
72
- var nextIndex = getNextIndex(columns, currentIndex, e.key);
73
- e.preventDefault();
74
- e.stopPropagation();
75
- if (nextIndex >= 0 && !((_columns$nextIndex = columns[nextIndex]) !== null && _columns$nextIndex !== void 0 && _columns$nextIndex.sticky)) {
76
- setFocusIndex(nextIndex);
77
- moveElement(currentIndex, nextIndex);
78
- e.target.scrollIntoView({
79
- block: 'center'
80
- });
81
- }
82
- }
83
- },
84
175
  isSticky: isFrozenColumn,
85
176
  selected: isColumnVisible(colDef)
86
177
  }, listContents);
87
- }));
178
+ }))));
88
179
  };
89
180
  DraggableItemsList.propTypes = {
90
181
  columns: PropTypes.array.isRequired,
91
182
  filterString: PropTypes.string.isRequired,
92
- focusIndex: PropTypes.number.isRequired,
93
- getNextIndex: PropTypes.func.isRequired,
183
+ id: PropTypes.string.isRequired,
94
184
  moveElement: PropTypes.func.isRequired,
95
185
  onSelectColumn: PropTypes.func.isRequired,
96
- setAriaRegionText: PropTypes.func.isRequired,
97
- setColumnsObject: PropTypes.func.isRequired,
98
- setFocusIndex: PropTypes.func.isRequired
186
+ setAriaRegionText: PropTypes.func.isRequired
99
187
  };
@@ -61,13 +61,19 @@ var FilterPanel = function FilterPanel(_ref) {
61
61
  _useState2 = _slicedToArray(_useState, 2),
62
62
  showDividerLine = _useState2[0],
63
63
  setShowDividerLine = _useState2[1];
64
+
65
+ /** Context */
66
+ var _useContext = useContext(FilterContext),
67
+ panelOpen = _useContext.panelOpen,
68
+ setPanelOpen = _useContext.setPanelOpen;
64
69
  var _useFilters = useFilters({
65
70
  updateMethod: updateMethod,
66
71
  filters: filterSections,
67
72
  setAllFilters: setAllFilters,
68
73
  variation: PANEL,
69
74
  reactTableFiltersState: reactTableFiltersState,
70
- onCancel: onCancel
75
+ onCancel: onCancel,
76
+ panelOpen: panelOpen
71
77
  }),
72
78
  filtersState = _useFilters.filtersState,
73
79
  prevFiltersObjectArrayRef = _useFilters.prevFiltersObjectArrayRef,
@@ -99,11 +105,6 @@ var FilterPanel = function FilterPanel(_ref) {
99
105
  return updateMethod === BATCH;
100
106
  }, [updateMethod]);
101
107
 
102
- /** Context */
103
- var _useContext = useContext(FilterContext),
104
- panelOpen = _useContext.panelOpen,
105
- setPanelOpen = _useContext.setPanelOpen;
106
-
107
108
  /** Methods */
108
109
  var closePanel = function closePanel() {
109
110
  cancel();
@@ -1,13 +1,17 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ 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; }
5
+ 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; }
2
6
  /**
3
- * Copyright IBM Corp. 2022, 2022
7
+ * Copyright IBM Corp. 2022, 2023
4
8
  *
5
9
  * This source code is licensed under the Apache-2.0 license found in the
6
10
  * LICENSE file in the root directory of this source tree.
7
11
  */
8
12
  import React, { createContext, useState } from 'react';
9
13
  import PropTypes from 'prop-types';
10
- import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX } from './constants';
14
+ import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX, CLEAR_SINGLE_FILTER } from './constants';
11
15
  export var FilterContext = /*#__PURE__*/createContext();
12
16
  var EventEmitter = {
13
17
  events: {},
@@ -27,42 +31,123 @@ var EventEmitter = {
27
31
  }
28
32
  }
29
33
  };
30
- var prepareFiltersForTags = function prepareFiltersForTags(filters) {
34
+ var removeFilterItem = function removeFilterItem(state, index) {
35
+ return state.splice(index, 1);
36
+ };
37
+ var updateFilterState = function updateFilterState(state, type, value) {
38
+ if (type === CHECKBOX) {
39
+ return;
40
+ }
41
+ if (type === DATE) {
42
+ var _filterTagIndex = state.findIndex(function (val) {
43
+ return formatDateRange(val.value[0], val.value[1]) === formatDateRange(value[0], value[1]);
44
+ });
45
+ return removeFilterItem(state, _filterTagIndex);
46
+ }
47
+ var filterTagIndex = state.findIndex(function (val) {
48
+ return val.value === value;
49
+ });
50
+ return removeFilterItem(state, filterTagIndex);
51
+ };
52
+ export var clearSingleFilter = function clearSingleFilter(_ref, setAllFilters, state) {
53
+ var key = _ref.key,
54
+ value = _ref.value;
55
+ var tempState = _toConsumableArray(state.filters);
56
+ tempState.forEach(function (f, filterIndex) {
57
+ if (f.id === key) {
58
+ var filterValues = f.value;
59
+ var filterType = f.type;
60
+ updateFilterState(tempState, filterType, value);
61
+ if (filterType === CHECKBOX) {
62
+ /**
63
+ When all checkboxes of a group are all unselected the value still exists in the filtersObjectArray
64
+ This checks if all the checkboxes are selected = false and removes it from the array
65
+ */
66
+ var valueIndex = filterValues.findIndex(function (val) {
67
+ return val.id === value;
68
+ });
69
+ filterValues[valueIndex].selected = false;
70
+ var updatedFilterObject = _objectSpread(_objectSpread({}, f), {}, {
71
+ value: _toConsumableArray(filterValues)
72
+ });
73
+ tempState[filterIndex] = updatedFilterObject;
74
+ var index = tempState.findIndex(function (filter) {
75
+ return filter.id === key;
76
+ });
77
+
78
+ // If all the selected state is false remove from array
79
+ var shouldRemoveFromArray = tempState[index].value.every(function (val) {
80
+ return val.selected === false;
81
+ });
82
+ if (shouldRemoveFromArray) {
83
+ removeFilterItem(tempState, index);
84
+ }
85
+ }
86
+ }
87
+ });
88
+ setAllFilters(tempState);
89
+ };
90
+ var handleSingleFilterRemoval = function handleSingleFilterRemoval(key, value) {
91
+ EventEmitter.dispatch(CLEAR_SINGLE_FILTER, {
92
+ key: key,
93
+ value: value
94
+ });
95
+ };
96
+ var formatDateRange = function formatDateRange(startDate, endDate) {
97
+ var startDateObj = new Date(startDate);
98
+ var endDateObj = new Date(endDate);
99
+ return "".concat(startDateObj.toLocaleDateString(), " - ").concat(endDateObj.toLocaleDateString());
100
+ };
101
+ var prepareFiltersForTags = function prepareFiltersForTags(filters, renderDateLabel) {
31
102
  var tags = [];
32
- filters.forEach(function (_ref) {
33
- var id = _ref.id,
34
- type = _ref.type,
35
- value = _ref.value;
103
+ filters.forEach(function (_ref2) {
104
+ var id = _ref2.id,
105
+ type = _ref2.type,
106
+ value = _ref2.value;
107
+ var sharedFilterProps = {
108
+ filter: true,
109
+ onClose: function onClose() {
110
+ return handleSingleFilterRemoval(id, value);
111
+ }
112
+ };
36
113
  if (type === DROPDOWN || type === RADIO || type === NUMBER) {
37
- tags.push({
114
+ tags.push(_objectSpread({
38
115
  key: id,
39
116
  value: value
40
- });
117
+ }, sharedFilterProps));
41
118
  } else if (type === DATE) {
119
+ var _renderDateLabel;
42
120
  var _value = _slicedToArray(value, 2),
43
121
  startDate = _value[0],
44
122
  endDate = _value[1];
45
- tags.push({
123
+ tags.push(_objectSpread({
46
124
  key: id,
47
- value: "".concat(startDate.toLocaleDateString(), " - ").concat(endDate.toLocaleDateString())
48
- });
125
+ value: (_renderDateLabel = renderDateLabel === null || renderDateLabel === void 0 ? void 0 : renderDateLabel(startDate, endDate)) !== null && _renderDateLabel !== void 0 ? _renderDateLabel : formatDateRange(startDate, endDate)
126
+ }, sharedFilterProps));
49
127
  } else if (type === CHECKBOX) {
50
128
  value.forEach(function (checkbox) {
51
129
  if (checkbox.selected) {
52
- tags.push({
130
+ tags.push(_objectSpread(_objectSpread({
53
131
  key: id,
54
132
  value: checkbox.value
55
- });
133
+ }, sharedFilterProps), {}, {
134
+ onClose: function onClose() {
135
+ return handleSingleFilterRemoval(id, checkbox.value);
136
+ }
137
+ }));
56
138
  }
57
139
  });
58
140
  }
59
141
  });
60
142
  return tags;
61
143
  };
62
- export var FilterProvider = function FilterProvider(_ref2) {
63
- var children = _ref2.children,
64
- filters = _ref2.filters;
65
- var filterTags = prepareFiltersForTags(filters);
144
+ export var FilterProvider = function FilterProvider(_ref3) {
145
+ var children = _ref3.children,
146
+ filters = _ref3.filters,
147
+ filterProps = _ref3.filterProps;
148
+ var _ref4 = filterProps || {},
149
+ renderDateLabel = _ref4.renderDateLabel;
150
+ var filterTags = prepareFiltersForTags(filters, renderDateLabel);
66
151
  var _useState = useState(false),
67
152
  _useState2 = _slicedToArray(_useState, 2),
68
153
  panelOpen = _useState2[0],
@@ -79,5 +164,6 @@ export var FilterProvider = function FilterProvider(_ref2) {
79
164
  };
80
165
  FilterProvider.propTypes = {
81
166
  children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
167
+ filterProps: PropTypes.object,
82
168
  filters: PropTypes.arrayOf(PropTypes.object).isRequired
83
169
  };
@@ -21,6 +21,7 @@ export var DROPDOWN = 'dropdown';
21
21
 
22
22
  /** Constants for event emitters */
23
23
  export var CLEAR_FILTERS = 'clearFilters';
24
+ export var CLEAR_SINGLE_FILTER = 'clearSingleFilter';
24
25
 
25
26
  /** Constants for panel dimensions */
26
27
  export var PANEL_WIDTH = 320;
@@ -11,10 +11,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
11
11
  * US Government Users Restricted Rights - Use, duplication or disclosure
12
12
  * restricted by GSA ADP Schedule Contract with IBM Corp.
13
13
  */
14
- import React, { useState, useRef, useEffect } from 'react';
14
+ import React, { useState, useRef, useEffect, useCallback } from 'react';
15
15
  import { Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup } from 'carbon-components-react';
16
16
  import { INSTANT, BATCH, DATE, CHECKBOX, NUMBER, RADIO, DROPDOWN, PANEL } from '../constants';
17
17
  import { getInitialStateFromFilters } from '../utils';
18
+ import { usePreviousValue } from '../../../../../../global/js/hooks';
18
19
  var useFilters = function useFilters(_ref) {
19
20
  var updateMethod = _ref.updateMethod,
20
21
  _ref$filters = _ref.filters,
@@ -23,7 +24,8 @@ var useFilters = function useFilters(_ref) {
23
24
  variation = _ref.variation,
24
25
  reactTableFiltersState = _ref.reactTableFiltersState,
25
26
  _ref$onCancel = _ref.onCancel,
26
- onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel;
27
+ onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel,
28
+ panelOpen = _ref.panelOpen;
27
29
  /** State */
28
30
  var _useState = useState(getInitialStateFromFilters(filters, variation, reactTableFiltersState)),
29
31
  _useState2 = _slicedToArray(_useState, 2),
@@ -33,11 +35,17 @@ var useFilters = function useFilters(_ref) {
33
35
  _useState4 = _slicedToArray(_useState3, 2),
34
36
  filtersObjectArray = _useState4[0],
35
37
  setFiltersObjectArray = _useState4[1];
38
+ var previousState = usePreviousValue({
39
+ panelOpen: panelOpen
40
+ });
36
41
 
37
42
  // When using batch actions we have to store the filters to then apply them later
38
43
  var prevFiltersRef = useRef(JSON.stringify(filtersState));
39
44
  var lastAppliedFilters = useRef(JSON.stringify(reactTableFiltersState));
40
45
  var prevFiltersObjectArrayRef = useRef(JSON.stringify(filtersObjectArray));
46
+ var holdingPrevFiltersRef = useRef();
47
+ var holdingLastAppliedFiltersRef = useRef([]);
48
+ var holdingPrevFiltersObjectArrayRef = useRef([]);
41
49
 
42
50
  /** Methods */
43
51
  // If the user decides to cancel or click outside the flyout, it reverts back to the filters that were
@@ -46,8 +54,14 @@ var useFilters = function useFilters(_ref) {
46
54
  setFiltersState(JSON.parse(prevFiltersRef.current));
47
55
  setFiltersObjectArray(JSON.parse(prevFiltersObjectArrayRef.current));
48
56
  setAllFilters(JSON.parse(lastAppliedFilters.current));
57
+
58
+ // Set the temp prev refs, these will be used to populate the prev values once the
59
+ // panel opens again
60
+ holdingPrevFiltersRef.current = JSON.parse(prevFiltersRef.current);
61
+ holdingLastAppliedFiltersRef.current = JSON.parse(prevFiltersObjectArrayRef.current);
62
+ holdingPrevFiltersObjectArrayRef.current = JSON.parse(lastAppliedFilters.current);
49
63
  };
50
- var reset = function reset() {
64
+ var reset = useCallback(function () {
51
65
  // When we reset we want the "initialFilters" to be an empty array
52
66
  var resetFiltersArray = [];
53
67
 
@@ -63,7 +77,7 @@ var useFilters = function useFilters(_ref) {
63
77
  // Update their respective refs so everything is in sync
64
78
  prevFiltersRef.current = JSON.stringify(initialFiltersState);
65
79
  prevFiltersObjectArrayRef.current = JSON.stringify(initialFiltersObjectArray);
66
- };
80
+ }, [filters, setAllFilters, variation]);
67
81
  var applyFilters = function applyFilters(_ref2) {
68
82
  var column = _ref2.column,
69
83
  value = _ref2.value,
@@ -291,6 +305,25 @@ var useFilters = function useFilters(_ref) {
291
305
  key: column
292
306
  }, filter);
293
307
  };
308
+
309
+ /** This useEffect will properly handle the previous filters when the panel closes
310
+ * 1. If the panel closes we need to call the reset fn but also store the
311
+ * previous filters in a (new) temporary place.
312
+ * 2. When the panel opens again, take the values from the temporary place
313
+ * and populate the filter state with them
314
+ */
315
+ useEffect(function () {
316
+ if (!panelOpen && previousState !== null && previousState !== void 0 && previousState.panelOpen) {
317
+ setAllFilters(holdingLastAppliedFiltersRef.current);
318
+ }
319
+ if (panelOpen && !(previousState !== null && previousState !== void 0 && previousState.panelOpen)) {
320
+ if (holdingPrevFiltersRef.current && holdingLastAppliedFiltersRef.current && holdingPrevFiltersObjectArrayRef.current) {
321
+ setFiltersState(holdingPrevFiltersRef.current);
322
+ setFiltersObjectArray(holdingLastAppliedFiltersRef.current);
323
+ setAllFilters(JSON.parse(prevFiltersObjectArrayRef.current));
324
+ }
325
+ }
326
+ }, [panelOpen, previousState, previousState === null || previousState === void 0 ? void 0 : previousState.panelOpen, reset, setAllFilters]);
294
327
  var cancel = function cancel() {
295
328
  // Reverting to previous filters only applies when using batch actions
296
329
  if (updateMethod === BATCH) {
@@ -33,7 +33,7 @@ var useExpandedRow = function useExpandedRow(hooks) {
33
33
  return _objectSpread(_objectSpread({}, row), {}, {
34
34
  canExpand: row.original && !row.original.notExpandable,
35
35
  expandedContentHeight: expandedRowsHeight[row.index] || expandedContentHeight,
36
- RowRenderer: DatagridExpandedRow(row.RowRenderer, ExpandedRowContentComponent)
36
+ RowExpansionRenderer: DatagridExpandedRow(ExpandedRowContentComponent)
37
37
  });
38
38
  });
39
39
  Object.assign(instance, {
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
2
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  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; }
4
5
  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; }
@@ -25,7 +26,9 @@ var useFiltering = function useFiltering(hooks) {
25
26
  endDate = _ref2[1];
26
27
  return rows.filter(function (row) {
27
28
  var rowValue = row.values[id];
28
- if (rowValue.getTime() <= endDate.getTime() && rowValue.getTime() >= startDate.getTime()) {
29
+ var startDateObj = _typeof(startDate) === 'object' ? startDate : new Date(startDate);
30
+ var endDateObj = _typeof(endDate) === 'object' ? endDate : new Date(endDate);
31
+ if (rowValue.getTime() <= endDateObj.getTime() && rowValue.getTime() >= startDateObj.getTime()) {
29
32
  // In date range
30
33
  return true;
31
34
  } else {
@@ -2,30 +2,42 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  /* eslint-disable react/prop-types */
5
- /*
6
- * Licensed Materials - Property of IBM
7
- * 5724-Q36
8
- * (c) Copyright IBM Corp. 2020
9
- * US Government Users Restricted Rights - Use, duplication or disclosure
10
- * restricted by GSA ADP Schedule Contract with IBM Corp.
5
+ /**
6
+ * Copyright IBM Corp. 2020, 2023
7
+ *
8
+ * This source code is licensed under the Apache-2.0 license found in the
9
+ * LICENSE file in the root directory of this source tree.
11
10
  */
12
- import React from 'react';
11
+
12
+ import React, { useRef } from 'react';
13
13
  import { ChevronRight16 } from '@carbon/icons-react';
14
14
  import cx from 'classnames';
15
15
  import { pkg, carbon } from '../../settings';
16
16
  var blockClass = "".concat(pkg.prefix, "--datagrid");
17
17
  var useNestedRowExpander = function useNestedRowExpander(hooks) {
18
+ var tempState = useRef();
19
+ var useInstance = function useInstance(instance) {
20
+ tempState.current = instance;
21
+ };
18
22
  var visibleColumns = function visibleColumns(columns) {
19
23
  var expanderColumn = {
20
24
  id: 'expander',
21
25
  Cell: function Cell(_ref) {
22
26
  var _cx;
23
27
  var row = _ref.row;
28
+ var _ref2 = (tempState === null || tempState === void 0 ? void 0 : tempState.current) || {},
29
+ _ref2$expanderButtonT = _ref2.expanderButtonTitleExpanded,
30
+ expanderButtonTitleExpanded = _ref2$expanderButtonT === void 0 ? 'Collapse row' : _ref2$expanderButtonT,
31
+ _ref2$expanderButtonT2 = _ref2.expanderButtonTitleCollapsed,
32
+ expanderButtonTitleCollapsed = _ref2$expanderButtonT2 === void 0 ? 'Expand row' : _ref2$expanderButtonT2;
33
+ var expanderTitle = row.isExpanded ? expanderButtonTitleExpanded : expanderButtonTitleCollapsed;
24
34
  return row.canExpand && /*#__PURE__*/React.createElement("button", _extends({
25
35
  type: "button",
26
- "aria-label": "Expand current row",
36
+ "aria-label": expanderTitle,
27
37
  className: cx("".concat(blockClass, "__row-expander"), "".concat(carbon.prefix, "--btn"), "".concat(carbon.prefix, "--btn--ghost"))
28
- }, row.getToggleRowExpandedProps()), /*#__PURE__*/React.createElement(ChevronRight16, {
38
+ }, row.getToggleRowExpandedProps(), {
39
+ title: expanderTitle
40
+ }), /*#__PURE__*/React.createElement(ChevronRight16, {
29
41
  className: cx("".concat(blockClass, "__expander-icon"), "".concat(blockClass, "__row-expander--icon"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__expander-icon--not-open"), !row.isExpanded), _defineProperty(_cx, "".concat(blockClass, "__expander-icon--open"), row.isExpanded), _cx))
30
42
  }));
31
43
  },
@@ -37,5 +49,6 @@ var useNestedRowExpander = function useNestedRowExpander(hooks) {
37
49
  return [expanderColumn].concat(_toConsumableArray(columns));
38
50
  };
39
51
  hooks.visibleColumns.push(visibleColumns);
52
+ hooks.useInstance.push(useInstance);
40
53
  };
41
54
  export default useNestedRowExpander;
@@ -1,29 +1,41 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  /* eslint-disable react/prop-types */
4
- /*
5
- * Licensed Materials - Property of IBM
6
- * 5724-Q36
7
- * (c) Copyright IBM Corp. 2020
8
- * US Government Users Restricted Rights - Use, duplication or disclosure
9
- * restricted by GSA ADP Schedule Contract with IBM Corp.
4
+ /**
5
+ * Copyright IBM Corp. 2020, 2023
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
10
9
  */
11
- import React from 'react';
10
+
11
+ import React, { useRef } from 'react';
12
12
  import { ChevronDown16, ChevronUp16 } from '@carbon/icons-react';
13
13
  import cx from 'classnames';
14
14
  import { pkg, carbon } from '../../settings';
15
15
  var blockClass = "".concat(pkg.prefix, "--datagrid");
16
16
  var useRowExpander = function useRowExpander(hooks) {
17
+ var tempState = useRef();
18
+ var useInstance = function useInstance(instance) {
19
+ tempState.current = instance;
20
+ };
17
21
  var visibleColumns = function visibleColumns(columns) {
18
22
  var expanderColumn = {
19
23
  id: 'expander',
20
24
  Cell: function Cell(_ref) {
21
25
  var row = _ref.row;
26
+ var _ref2 = (tempState === null || tempState === void 0 ? void 0 : tempState.current) || {},
27
+ _ref2$expanderButtonT = _ref2.expanderButtonTitleExpanded,
28
+ expanderButtonTitleExpanded = _ref2$expanderButtonT === void 0 ? 'Collapse row' : _ref2$expanderButtonT,
29
+ _ref2$expanderButtonT2 = _ref2.expanderButtonTitleCollapsed,
30
+ expanderButtonTitleCollapsed = _ref2$expanderButtonT2 === void 0 ? 'Expand row' : _ref2$expanderButtonT2;
31
+ var expanderTitle = row.isExpanded ? expanderButtonTitleExpanded : expanderButtonTitleCollapsed;
22
32
  return row.canExpand && /*#__PURE__*/React.createElement("button", _extends({
23
33
  type: "button",
24
- "aria-label": "Expand current row",
34
+ "aria-label": expanderTitle,
25
35
  className: cx("".concat(blockClass, "__row-expander"), "".concat(carbon.prefix, "--btn"), "".concat(carbon.prefix, "--btn--ghost"))
26
- }, row.getToggleRowExpandedProps()), row.isExpanded ? /*#__PURE__*/React.createElement(ChevronUp16, {
36
+ }, row.getToggleRowExpandedProps(), {
37
+ title: expanderTitle
38
+ }), row.isExpanded ? /*#__PURE__*/React.createElement(ChevronUp16, {
27
39
  className: "".concat(blockClass, "__row-expander--icon")
28
40
  }) : /*#__PURE__*/React.createElement(ChevronDown16, {
29
41
  className: "".concat(blockClass, "__row-expander--icon")
@@ -37,5 +49,6 @@ var useRowExpander = function useRowExpander(hooks) {
37
49
  return [expanderColumn].concat(_toConsumableArray(columns));
38
50
  };
39
51
  hooks.visibleColumns.push(visibleColumns);
52
+ hooks.useInstance.push(useInstance);
40
53
  };
41
54
  export default useRowExpander;