@carbon/ibm-products 1.8.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/index-full-carbon.css +270 -5656
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -6
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +58 -3432
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +3 -3
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +238 -3922
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +6 -6
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +238 -3923
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -6
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +147 -53
- package/es/components/AddSelect/AddSelectBreadcrumbs.js +4 -4
- package/es/components/AddSelect/AddSelectColumn.js +195 -0
- package/es/components/AddSelect/AddSelectList.js +67 -8
- package/es/components/AddSelect/AddSelectSidebar.js +8 -15
- package/es/components/AddSelect/add-select-utils.js +64 -0
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/es/components/ButtonMenu/ButtonMenu.js +1 -1
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +505 -167
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +244 -17
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +74 -8
- package/es/components/DataSpreadsheet/hooks/useMoveActiveCell.js +27 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +28 -0
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +41 -0
- package/es/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +34 -0
- package/es/components/DataSpreadsheet/utils/createActiveCellFn.js +58 -0
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +49 -0
- package/es/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/es/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +46 -0
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +82 -0
- package/es/components/DataSpreadsheet/utils/removeCellSelections.js +30 -0
- package/es/components/InlineEdit/InlineEdit.js +80 -39
- package/es/components/OptionsTile/OptionsTile.js +31 -21
- package/es/components/OptionsTile/index.js +1 -1
- package/es/components/PageHeader/PageHeader.js +26 -15
- package/es/components/PageHeader/PageHeaderTitle.js +2 -1
- package/es/components/PageHeader/PageHeaderUtils.js +24 -29
- package/es/components/TagSet/TagSet.js +12 -3
- package/es/components/UserProfileImage/UserProfileImage.js +2 -1
- package/es/global/js/utils/DisplayBox.js +31 -0
- package/es/global/js/utils/deepCloneObject.js +26 -0
- package/lib/components/AddSelect/AddSelect.js +150 -54
- package/lib/components/AddSelect/AddSelectBreadcrumbs.js +2 -3
- package/lib/components/AddSelect/AddSelectColumn.js +219 -0
- package/lib/components/AddSelect/AddSelectList.js +65 -8
- package/lib/components/AddSelect/AddSelectSidebar.js +14 -15
- package/lib/components/AddSelect/add-select-utils.js +78 -0
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/lib/components/ButtonMenu/ButtonMenu.js +1 -1
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +514 -170
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +251 -18
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +82 -9
- package/lib/components/DataSpreadsheet/hooks/useMoveActiveCell.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +39 -0
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +52 -0
- package/lib/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +45 -0
- package/lib/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +22 -9
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +60 -0
- package/lib/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/lib/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +59 -0
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +92 -0
- package/lib/components/DataSpreadsheet/utils/removeCellSelections.js +41 -0
- package/lib/components/InlineEdit/InlineEdit.js +82 -40
- package/lib/components/OptionsTile/OptionsTile.js +30 -20
- package/lib/components/PageHeader/PageHeader.js +25 -15
- package/lib/components/PageHeader/PageHeaderTitle.js +2 -1
- package/lib/components/PageHeader/PageHeaderUtils.js +24 -29
- package/lib/components/TagSet/TagSet.js +13 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +2 -1
- package/lib/global/js/utils/DisplayBox.js +46 -0
- package/lib/global/js/utils/deepCloneObject.js +37 -0
- package/package.json +17 -17
- package/scss/components/ActionBar/_storybook-styles.scss +8 -0
- package/scss/components/ActionSet/_storybook-styles.scss +1 -3
- package/scss/components/AddSelect/_add-select.scss +99 -14
- package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +7 -3
- package/scss/components/BreadcrumbWithOverflow/_storybook-styles.scss +8 -0
- package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
- package/scss/components/CreateInfluencer/_create-influencer.scss +2 -0
- package/scss/components/CreateModal/_create-modal.scss +1 -0
- package/scss/components/CreateSidePanel/_create-side-panel.scss +1 -1
- package/scss/components/CreateSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
- package/scss/components/CreateTearsheetNarrow/_create-tearsheet-narrow.scss +1 -0
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +42 -6
- package/scss/components/EditSidePanel/_edit-side-panel.scss +9 -0
- package/scss/components/EditSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/InlineEdit/_inline-edit.scss +53 -43
- package/scss/components/InlineEdit/_storybook-styles.scss +2 -0
- package/scss/components/LoadingBar/_loading-bar.scss +13 -0
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -0
- package/scss/components/OptionsTile/_index.scss +1 -1
- package/scss/components/OptionsTile/_options-tile.scss +17 -17
- package/scss/components/OptionsTile/_storybook-styles.scss +4 -4
- package/scss/components/PageHeader/_page-header.scss +5 -2
- package/scss/components/SidePanel/_side-panel.scss +19 -12
- package/scss/components/StatusIcon/_status-icon.scss +1 -0
- package/scss/components/TagSet/_storybook-styles.scss +8 -0
- package/scss/components/Tearsheet/_tearsheet.scss +1 -2
- package/scss/components/UserProfileImage/_user-profile-image.scss +9 -0
- package/scss/components/WebTerminal/_web-terminal.scss +2 -0
- package/scss/global/styles/_display-box.scss +62 -0
- package/es/components/DataSpreadsheet/createActiveCellFn.js +0 -45
|
@@ -2,14 +2,14 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["className", "description", "influencerTitle", "inputPlaceholder", "items", "itemsLabel", "multi", "noResultsDescription", "noResultsTitle", "noSelectionDescription", "noSelectionTitle", "onClose", "onCloseButtonText", "onSearchFilter", "onSubmit", "onSubmitButtonText", "open", "removeIconDescription", "textInputLabel", "title"];
|
|
5
|
+
var _excluded = ["className", "columnInputPlaceholder", "description", "influencerTitle", "inputPlaceholder", "items", "itemsLabel", "multi", "noResultsDescription", "noResultsTitle", "noSelectionDescription", "noSelectionTitle", "onClose", "onCloseButtonText", "onSearchFilter", "onSubmit", "onSubmitButtonText", "open", "removeIconDescription", "textInputLabel", "title"];
|
|
6
6
|
//
|
|
7
7
|
// Copyright IBM Corp. 2022
|
|
8
8
|
//
|
|
9
9
|
// This source code is licensed under the Apache-2.0 license found in the
|
|
10
10
|
// LICENSE file in the root directory of this source tree.
|
|
11
11
|
//
|
|
12
|
-
import React, { forwardRef, useState } from 'react';
|
|
12
|
+
import React, { forwardRef, useState, useEffect } from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import cx from 'classnames';
|
|
15
15
|
import { TextInput, Tag } from 'carbon-components-react';
|
|
@@ -19,20 +19,18 @@ import { pkg } from '../../settings';
|
|
|
19
19
|
import { AddSelectSidebar } from './AddSelectSidebar';
|
|
20
20
|
import { AddSelectBreadcrumbs } from './AddSelectBreadcrumbs';
|
|
21
21
|
import { AddSelectList } from './AddSelectList';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
items: Object.freeze([])
|
|
26
|
-
};
|
|
22
|
+
import { AddSelectColumn } from './AddSelectColumn';
|
|
23
|
+
import { normalize, flatten } from './add-select-utils';
|
|
24
|
+
var componentName = 'AddSelect';
|
|
27
25
|
export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
28
26
|
var _cx;
|
|
29
27
|
|
|
30
28
|
var className = _ref.className,
|
|
29
|
+
columnInputPlaceholder = _ref.columnInputPlaceholder,
|
|
31
30
|
description = _ref.description,
|
|
32
31
|
influencerTitle = _ref.influencerTitle,
|
|
33
32
|
inputPlaceholder = _ref.inputPlaceholder,
|
|
34
|
-
|
|
35
|
-
items = _ref$items === void 0 ? defaults.items : _ref$items,
|
|
33
|
+
items = _ref.items,
|
|
36
34
|
itemsLabel = _ref.itemsLabel,
|
|
37
35
|
multi = _ref.multi,
|
|
38
36
|
noResultsDescription = _ref.noResultsDescription,
|
|
@@ -70,15 +68,76 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
70
68
|
var _useState7 = useState(''),
|
|
71
69
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
72
70
|
searchTerm = _useState8[0],
|
|
73
|
-
setSearchTerm = _useState8[1];
|
|
71
|
+
setSearchTerm = _useState8[1];
|
|
74
72
|
|
|
73
|
+
var _useState9 = useState({}),
|
|
74
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
75
|
+
normalizedItems = _useState10[0],
|
|
76
|
+
setNormalizedItems = _useState10[1];
|
|
75
77
|
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
+
var _useState11 = useState(false),
|
|
79
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
80
|
+
useNormalizedItems = _useState12[0],
|
|
81
|
+
setUsedNormalizedItems = _useState12[1];
|
|
82
|
+
|
|
83
|
+
var _useState13 = useState([]),
|
|
84
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
85
|
+
sidebarItems = _useState14[0],
|
|
86
|
+
setSidebarItems = _useState14[1];
|
|
87
|
+
|
|
88
|
+
useEffect(function () {
|
|
89
|
+
var entries = items.entries;
|
|
90
|
+
setSidebarItems(flatten(entries)); // multi select with nested data needs to be normalized
|
|
91
|
+
|
|
92
|
+
if (multi && entries.find(function (entry) {
|
|
93
|
+
return entry.children;
|
|
94
|
+
})) {
|
|
95
|
+
var newItems = normalize(items);
|
|
96
|
+
setNormalizedItems(newItems);
|
|
97
|
+
setUsedNormalizedItems(true);
|
|
98
|
+
}
|
|
99
|
+
}, [items, multi]); // used to generate columns of results for multi select with hierarchy
|
|
100
|
+
|
|
101
|
+
var getPages = function getPages() {
|
|
102
|
+
var pages = [];
|
|
103
|
+
var itemIds = Object.keys(normalizedItems); // top level items are just items with no parents so they're the top results
|
|
104
|
+
|
|
105
|
+
var topLevelItems = [];
|
|
106
|
+
itemIds.forEach(function (itemId) {
|
|
107
|
+
if (!normalizedItems[itemId].parent) {
|
|
108
|
+
topLevelItems.push(normalizedItems[itemId]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
pages.push(topLevelItems);
|
|
112
|
+
|
|
113
|
+
if (path.length) {
|
|
114
|
+
/**
|
|
115
|
+
* the path is set when you initially traverse the child entries
|
|
116
|
+
* path is an array of item id's
|
|
117
|
+
* when a path is present the normalized items are searched
|
|
118
|
+
* any item who's has a matching parent id is added to the results
|
|
119
|
+
* in the end you have an array of arrays for each column of the hierarchy
|
|
120
|
+
*/
|
|
121
|
+
var pathIds = path.map(function (p) {
|
|
122
|
+
return p.id;
|
|
123
|
+
});
|
|
124
|
+
pathIds.forEach(function (pathId) {
|
|
125
|
+
var entries = [];
|
|
126
|
+
itemIds.forEach(function (itemId) {
|
|
127
|
+
if (normalizedItems[itemId].parent === pathId) {
|
|
128
|
+
entries.push(normalizedItems[itemId]);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
pages.push(entries);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return pages;
|
|
78
136
|
}; // item filtering
|
|
79
137
|
|
|
80
138
|
|
|
81
139
|
var getFilteredItems = function getFilteredItems() {
|
|
140
|
+
var entries = items.entries;
|
|
82
141
|
var hasPath = path.length > 0;
|
|
83
142
|
/**
|
|
84
143
|
* how to traverse the levels of items-
|
|
@@ -87,10 +146,12 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
87
146
|
*/
|
|
88
147
|
|
|
89
148
|
var itemsToFilter = hasPath ? path.reduce(function (prev, cur) {
|
|
90
|
-
|
|
149
|
+
var _prev$find, _prev$find$children;
|
|
150
|
+
|
|
151
|
+
return (_prev$find = prev.find(function (item) {
|
|
91
152
|
return item.id === cur.id;
|
|
92
|
-
}).children;
|
|
93
|
-
},
|
|
153
|
+
})) === null || _prev$find === void 0 ? void 0 : (_prev$find$children = _prev$find.children) === null || _prev$find$children === void 0 ? void 0 : _prev$find$children.entries;
|
|
154
|
+
}, entries) : entries;
|
|
94
155
|
var results = itemsToFilter.filter(function (item) {
|
|
95
156
|
if (!searchTerm) {
|
|
96
157
|
return item;
|
|
@@ -105,32 +166,11 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
105
166
|
return item.title.toLowerCase().includes(searchTerm);
|
|
106
167
|
});
|
|
107
168
|
return results;
|
|
108
|
-
};
|
|
169
|
+
}; // only multi select with hierarchy requires the the normalized items
|
|
109
170
|
|
|
110
|
-
var filteredItems = getFilteredItems(); // main content
|
|
111
171
|
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
}, /*#__PURE__*/React.createElement(TextInput, {
|
|
115
|
-
id: "temp-id",
|
|
116
|
-
labelText: textInputLabel,
|
|
117
|
-
placeholder: inputPlaceholder,
|
|
118
|
-
value: searchTerm,
|
|
119
|
-
onChange: handleSearch
|
|
120
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
121
|
-
className: "".concat(blockClass, "__items-label-container")
|
|
122
|
-
}, path.length ? /*#__PURE__*/React.createElement(AddSelectBreadcrumbs, {
|
|
123
|
-
itemsLabel: itemsLabel,
|
|
124
|
-
path: path,
|
|
125
|
-
setPath: setPath
|
|
126
|
-
}) : /*#__PURE__*/React.createElement("p", {
|
|
127
|
-
className: "".concat(blockClass, "__items-label")
|
|
128
|
-
}, itemsLabel), /*#__PURE__*/React.createElement(Tag, {
|
|
129
|
-
type: "gray",
|
|
130
|
-
size: "sm",
|
|
131
|
-
className: "".concat(blockClass, "__items-label-tag")
|
|
132
|
-
}, filteredItems.length))), filteredItems.length > 0 ? /*#__PURE__*/React.createElement(AddSelectList, {
|
|
133
|
-
filteredItems: filteredItems,
|
|
172
|
+
var itemsToDisplay = useNormalizedItems ? getPages() : getFilteredItems();
|
|
173
|
+
var commonListProps = {
|
|
134
174
|
multi: multi,
|
|
135
175
|
multiSelection: multiSelection,
|
|
136
176
|
path: path,
|
|
@@ -138,12 +178,16 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
138
178
|
setPath: setPath,
|
|
139
179
|
setSingleSelection: setSingleSelection,
|
|
140
180
|
singleSelection: singleSelection
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
181
|
+
}; // handlers
|
|
182
|
+
|
|
183
|
+
var handleSearch = function handleSearch(e) {
|
|
184
|
+
setSearchTerm(e.target.value);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
var submitHandler = function submitHandler() {
|
|
188
|
+
onSubmit(multi ? multiSelection : singleSelection);
|
|
189
|
+
};
|
|
190
|
+
|
|
147
191
|
var commonTearsheetProps = {
|
|
148
192
|
open: open,
|
|
149
193
|
title: title,
|
|
@@ -156,20 +200,59 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
156
200
|
}, {
|
|
157
201
|
label: onSubmitButtonText,
|
|
158
202
|
kind: 'primary',
|
|
159
|
-
onClick:
|
|
203
|
+
onClick: submitHandler,
|
|
160
204
|
disabled: multi ? multiSelection.length === 0 : !singleSelection
|
|
161
205
|
}]
|
|
162
206
|
};
|
|
163
207
|
var sidebarProps = {
|
|
164
208
|
influencerTitle: influencerTitle,
|
|
165
|
-
items:
|
|
209
|
+
items: sidebarItems,
|
|
166
210
|
multiSelection: multiSelection,
|
|
167
211
|
noSelectionDescription: noSelectionDescription,
|
|
168
212
|
noSelectionTitle: noSelectionTitle,
|
|
169
213
|
removeIconDescription: removeIconDescription,
|
|
170
214
|
setMultiSelection: setMultiSelection
|
|
171
215
|
};
|
|
172
|
-
var classNames = cx(className, blockClass, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__single"), !multi), _defineProperty(_cx, "".concat(blockClass, "__multi"), multi), _cx));
|
|
216
|
+
var classNames = cx(className, blockClass, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__single"), !multi), _defineProperty(_cx, "".concat(blockClass, "__multi"), multi), _cx)); // main content
|
|
217
|
+
|
|
218
|
+
var body = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
219
|
+
className: "".concat(blockClass, "__header")
|
|
220
|
+
}, /*#__PURE__*/React.createElement(TextInput, {
|
|
221
|
+
id: "temp-id",
|
|
222
|
+
labelText: textInputLabel,
|
|
223
|
+
placeholder: inputPlaceholder,
|
|
224
|
+
value: searchTerm,
|
|
225
|
+
onChange: handleSearch
|
|
226
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
227
|
+
className: "".concat(blockClass, "__tag-container")
|
|
228
|
+
}, path.length ? /*#__PURE__*/React.createElement(AddSelectBreadcrumbs, {
|
|
229
|
+
itemsLabel: itemsLabel,
|
|
230
|
+
path: path,
|
|
231
|
+
setPath: setPath
|
|
232
|
+
}) : /*#__PURE__*/React.createElement("p", {
|
|
233
|
+
className: "".concat(blockClass, "__tag-container-label")
|
|
234
|
+
}, itemsLabel), !useNormalizedItems && /*#__PURE__*/React.createElement(Tag, {
|
|
235
|
+
type: "gray",
|
|
236
|
+
size: "sm"
|
|
237
|
+
}, itemsToDisplay.length))), useNormalizedItems ? /*#__PURE__*/React.createElement("div", {
|
|
238
|
+
className: "".concat(blockClass, "__columns")
|
|
239
|
+
}, itemsToDisplay.map(function (page, idx) {
|
|
240
|
+
var _path;
|
|
241
|
+
|
|
242
|
+
return /*#__PURE__*/React.createElement(AddSelectColumn, _extends({}, commonListProps, {
|
|
243
|
+
key: idx,
|
|
244
|
+
filteredItems: page,
|
|
245
|
+
header: idx === 0 ? itemsLabel : (_path = path[idx - 1]) === null || _path === void 0 ? void 0 : _path.title,
|
|
246
|
+
columnInputPlaceholder: columnInputPlaceholder
|
|
247
|
+
}));
|
|
248
|
+
})) : /*#__PURE__*/React.createElement("div", null, itemsToDisplay.length > 0 ? /*#__PURE__*/React.createElement(AddSelectList, _extends({}, commonListProps, {
|
|
249
|
+
filteredItems: itemsToDisplay
|
|
250
|
+
})) : /*#__PURE__*/React.createElement("div", {
|
|
251
|
+
className: "".concat(blockClass, "__body")
|
|
252
|
+
}, /*#__PURE__*/React.createElement(NoDataEmptyState, {
|
|
253
|
+
subtitle: noResultsDescription,
|
|
254
|
+
title: noResultsTitle
|
|
255
|
+
}))));
|
|
173
256
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
174
257
|
ref: ref,
|
|
175
258
|
className: classNames
|
|
@@ -180,14 +263,20 @@ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
180
263
|
});
|
|
181
264
|
AddSelect.propTypes = {
|
|
182
265
|
className: PropTypes.string,
|
|
266
|
+
columnInputPlaceholder: PropTypes.string,
|
|
183
267
|
description: PropTypes.string,
|
|
184
268
|
influencerTitle: PropTypes.string,
|
|
185
269
|
inputPlaceholder: PropTypes.string,
|
|
186
|
-
items: PropTypes.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
270
|
+
items: PropTypes.shape({
|
|
271
|
+
sortBy: PropTypes.array,
|
|
272
|
+
filterBy: PropTypes.array,
|
|
273
|
+
entries: PropTypes.arrayOf(PropTypes.shape({
|
|
274
|
+
id: PropTypes.string.isRequired,
|
|
275
|
+
title: PropTypes.string.isRequired,
|
|
276
|
+
value: PropTypes.string.isRequired,
|
|
277
|
+
children: PropTypes.object
|
|
278
|
+
}))
|
|
279
|
+
}),
|
|
191
280
|
itemsLabel: PropTypes.string,
|
|
192
281
|
multi: PropTypes.bool,
|
|
193
282
|
noResultsDescription: PropTypes.string,
|
|
@@ -204,4 +293,9 @@ AddSelect.propTypes = {
|
|
|
204
293
|
textInputLabel: PropTypes.string,
|
|
205
294
|
title: PropTypes.string
|
|
206
295
|
};
|
|
296
|
+
AddSelect.defaultProps = {
|
|
297
|
+
items: {
|
|
298
|
+
entries: []
|
|
299
|
+
}
|
|
300
|
+
};
|
|
207
301
|
AddSelect.displayName = componentName;
|
|
@@ -15,12 +15,12 @@ export var AddSelectBreadcrumbs = function AddSelectBreadcrumbs(_ref) {
|
|
|
15
15
|
setPath = _ref.setPath;
|
|
16
16
|
|
|
17
17
|
var clickHandler = function clickHandler(id) {
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var pathIdx = newPath.findIndex(function (entry) {
|
|
18
|
+
var pathIdx = path.findIndex(function (entry) {
|
|
21
19
|
return entry.id === id;
|
|
22
20
|
});
|
|
23
|
-
|
|
21
|
+
|
|
22
|
+
var finalPath = _toConsumableArray(path).splice(0, pathIdx + 1);
|
|
23
|
+
|
|
24
24
|
setPath(finalPath);
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
var _excluded = ["columnInputPlaceholder", "filteredItems", "header"];
|
|
6
|
+
//
|
|
7
|
+
// Copyright IBM Corp. 2022
|
|
8
|
+
//
|
|
9
|
+
// This source code is licensed under the Apache-2.0 license found in the
|
|
10
|
+
// LICENSE file in the root directory of this source tree.
|
|
11
|
+
//
|
|
12
|
+
import React, { useState } from 'react';
|
|
13
|
+
import PropTypes from 'prop-types';
|
|
14
|
+
import { TextInput, Tag, OverflowMenu, OverflowMenuItem, Checkbox } from 'carbon-components-react';
|
|
15
|
+
import { Filter32, ArrowsVertical32, ArrowUp16, ArrowDown16 } from '@carbon/icons-react';
|
|
16
|
+
import { pkg, carbon } from '../../settings';
|
|
17
|
+
import { AddSelectList } from './AddSelectList';
|
|
18
|
+
import uuidv4 from '../../global/js/utils/uuidv4';
|
|
19
|
+
var componentName = 'AddSelect';
|
|
20
|
+
export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
21
|
+
var _filteredItems$find, _filteredItems$find2;
|
|
22
|
+
|
|
23
|
+
var columnInputPlaceholder = _ref.columnInputPlaceholder,
|
|
24
|
+
filteredItems = _ref.filteredItems,
|
|
25
|
+
header = _ref.header,
|
|
26
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
|
|
28
|
+
var _useState = useState(''),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
searchTerm = _useState2[0],
|
|
31
|
+
setSearchTerm = _useState2[1];
|
|
32
|
+
|
|
33
|
+
var _useState3 = useState(''),
|
|
34
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
+
sortDirection = _useState4[0],
|
|
36
|
+
setSortDirection = _useState4[1];
|
|
37
|
+
|
|
38
|
+
var _useState5 = useState(''),
|
|
39
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
40
|
+
sortAttribute = _useState6[0],
|
|
41
|
+
setSortAttribute = _useState6[1];
|
|
42
|
+
|
|
43
|
+
var _useState7 = useState([]),
|
|
44
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
45
|
+
filters = _useState8[0],
|
|
46
|
+
setFilters = _useState8[1];
|
|
47
|
+
|
|
48
|
+
var blockClass = "".concat(pkg.prefix, "--add-select");
|
|
49
|
+
var colClass = "".concat(blockClass, "__column"); // sorting
|
|
50
|
+
|
|
51
|
+
var colSortBy = (_filteredItems$find = filteredItems.find(function (item) {
|
|
52
|
+
return item.sortBy;
|
|
53
|
+
})) === null || _filteredItems$find === void 0 ? void 0 : _filteredItems$find.sortBy;
|
|
54
|
+
var sortByOpts = colSortBy ? colSortBy.reduce(function (acc, cur) {
|
|
55
|
+
var opts = [{
|
|
56
|
+
id: "".concat(cur, "-asc"),
|
|
57
|
+
itemText: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ArrowUp16, null), cur),
|
|
58
|
+
direction: 'asc',
|
|
59
|
+
attribute: cur
|
|
60
|
+
}, {
|
|
61
|
+
id: "".concat(cur, "-desc"),
|
|
62
|
+
itemText: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ArrowDown16, null), cur),
|
|
63
|
+
direction: 'desc',
|
|
64
|
+
attribute: cur
|
|
65
|
+
}];
|
|
66
|
+
return [].concat(_toConsumableArray(acc), opts);
|
|
67
|
+
}, []) : []; // filtering
|
|
68
|
+
|
|
69
|
+
var colFilterBy = (_filteredItems$find2 = filteredItems.find(function (item) {
|
|
70
|
+
return item.filterBy;
|
|
71
|
+
})) === null || _filteredItems$find2 === void 0 ? void 0 : _filteredItems$find2.filterBy;
|
|
72
|
+
var filterByOpts = colFilterBy ? filteredItems.map(function (item) {
|
|
73
|
+
return item[colFilterBy];
|
|
74
|
+
}) : []; // handlers
|
|
75
|
+
|
|
76
|
+
var sortHandler = function sortHandler(_ref2) {
|
|
77
|
+
var direction = _ref2.direction,
|
|
78
|
+
attribute = _ref2.attribute;
|
|
79
|
+
setSortAttribute(attribute);
|
|
80
|
+
setSortDirection(direction);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
var filterHandler = function filterHandler(checked, opt) {
|
|
84
|
+
if (checked) {
|
|
85
|
+
var newFilters = [].concat(_toConsumableArray(filters), [opt]);
|
|
86
|
+
setFilters(newFilters);
|
|
87
|
+
} else {
|
|
88
|
+
var _newFilters = filters.filter(function (o) {
|
|
89
|
+
return o !== opt;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
setFilters(_newFilters);
|
|
93
|
+
}
|
|
94
|
+
}; // filter and sort array functions
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
var filterBySearch = function filterBySearch(item) {
|
|
98
|
+
return item.title.toLowerCase().includes(searchTerm);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var filterByAttribute = function filterByAttribute(item) {
|
|
102
|
+
if (filters.length === 0) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var filterBy = item.filterBy;
|
|
107
|
+
var filterByValue = item[filterBy];
|
|
108
|
+
return filters.some(function (filter) {
|
|
109
|
+
return filter === filterByValue;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
var sortItems = function sortItems(a, b) {
|
|
114
|
+
var _a$sortAttribute, _b$sortAttribute;
|
|
115
|
+
|
|
116
|
+
var valueA = (_a$sortAttribute = a[sortAttribute]) === null || _a$sortAttribute === void 0 ? void 0 : _a$sortAttribute.split(' ').join('');
|
|
117
|
+
var valueB = (_b$sortAttribute = b[sortAttribute]) === null || _b$sortAttribute === void 0 ? void 0 : _b$sortAttribute.split(' ').join('');
|
|
118
|
+
|
|
119
|
+
if (sortDirection === 'desc') {
|
|
120
|
+
return valueA > valueB ? -1 : 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return valueA < valueB ? -1 : 1;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var colItems = filteredItems.filter(filterBySearch) // first check if the item meets the search
|
|
127
|
+
.filter(filterByAttribute) // then check if the item is included in the filter
|
|
128
|
+
.sort(sortItems); // then sort the items by whatever criteria
|
|
129
|
+
|
|
130
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
131
|
+
className: colClass
|
|
132
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
133
|
+
className: "".concat(colClass, "-search-bar")
|
|
134
|
+
}, /*#__PURE__*/React.createElement(TextInput, {
|
|
135
|
+
value: searchTerm,
|
|
136
|
+
onChange: function onChange(e) {
|
|
137
|
+
return setSearchTerm(e.target.value);
|
|
138
|
+
},
|
|
139
|
+
light: true,
|
|
140
|
+
placeholder: columnInputPlaceholder,
|
|
141
|
+
className: "".concat(colClass, "-input"),
|
|
142
|
+
id: uuidv4(),
|
|
143
|
+
labelText: columnInputPlaceholder
|
|
144
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
145
|
+
className: "".concat(colClass, "-sort-filter")
|
|
146
|
+
}, sortByOpts.length > 0 && /*#__PURE__*/React.createElement(OverflowMenu, {
|
|
147
|
+
renderIcon: ArrowsVertical32,
|
|
148
|
+
className: "".concat(colClass, "-overflow"),
|
|
149
|
+
flipped: true
|
|
150
|
+
}, sortByOpts.map(function (opt) {
|
|
151
|
+
return /*#__PURE__*/React.createElement(OverflowMenuItem, {
|
|
152
|
+
key: opt.id,
|
|
153
|
+
itemText: opt.itemText,
|
|
154
|
+
onClick: function onClick() {
|
|
155
|
+
return sortHandler(opt);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
})), filterByOpts.length > 0 && /*#__PURE__*/React.createElement(OverflowMenu, {
|
|
159
|
+
renderIcon: Filter32,
|
|
160
|
+
className: "".concat(colClass, "-overflow"),
|
|
161
|
+
flipped: true
|
|
162
|
+
}, filterByOpts.map(function (opt) {
|
|
163
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
164
|
+
key: opt,
|
|
165
|
+
className: "".concat(carbon.prefix, "--overflow-menu-options__option")
|
|
166
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
167
|
+
className: "".concat(carbon.prefix, "--overflow-menu-options__btn")
|
|
168
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
169
|
+
id: opt,
|
|
170
|
+
labelText: opt,
|
|
171
|
+
onChange: function onChange(checked) {
|
|
172
|
+
return filterHandler(checked, opt);
|
|
173
|
+
},
|
|
174
|
+
checked: filters.find(function (o) {
|
|
175
|
+
return o === opt;
|
|
176
|
+
}) ? true : false
|
|
177
|
+
})));
|
|
178
|
+
})))), /*#__PURE__*/React.createElement("div", {
|
|
179
|
+
className: "".concat(blockClass, "__tag-container")
|
|
180
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
181
|
+
className: "".concat(blockClass, "__tag-container-label")
|
|
182
|
+
}, header), /*#__PURE__*/React.createElement(Tag, {
|
|
183
|
+
type: "gray",
|
|
184
|
+
size: "sm"
|
|
185
|
+
}, colItems.length)), /*#__PURE__*/React.createElement(AddSelectList, _extends({}, props, {
|
|
186
|
+
inColumn: true,
|
|
187
|
+
filteredItems: colItems
|
|
188
|
+
})));
|
|
189
|
+
};
|
|
190
|
+
AddSelectColumn.propTypes = {
|
|
191
|
+
columnInputPlaceholder: PropTypes.string,
|
|
192
|
+
filteredItems: PropTypes.array,
|
|
193
|
+
header: PropTypes.string
|
|
194
|
+
};
|
|
195
|
+
AddSelectColumn.displayName = componentName;
|
|
@@ -13,6 +13,7 @@ import { pkg } from '../../settings';
|
|
|
13
13
|
var componentName = 'AddSelectList';
|
|
14
14
|
export var AddSelectList = function AddSelectList(_ref) {
|
|
15
15
|
var filteredItems = _ref.filteredItems,
|
|
16
|
+
inColumn = _ref.inColumn,
|
|
16
17
|
multi = _ref.multi,
|
|
17
18
|
multiSelection = _ref.multiSelection,
|
|
18
19
|
path = _ref.path,
|
|
@@ -41,11 +42,61 @@ export var AddSelectList = function AddSelectList(_ref) {
|
|
|
41
42
|
|
|
42
43
|
var onNavigateItem = function onNavigateItem(_ref2) {
|
|
43
44
|
var id = _ref2.id,
|
|
44
|
-
title = _ref2.title
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
title = _ref2.title,
|
|
46
|
+
parent = _ref2.parent;
|
|
47
|
+
|
|
48
|
+
// if multi select
|
|
49
|
+
if (multi) {
|
|
50
|
+
// if top level reset the path
|
|
51
|
+
if (!parent) {
|
|
52
|
+
setPath([{
|
|
53
|
+
id: id,
|
|
54
|
+
title: title
|
|
55
|
+
}]);
|
|
56
|
+
} else {
|
|
57
|
+
var pathIds = path.map(function (p) {
|
|
58
|
+
return p.id;
|
|
59
|
+
}); // if item is already selected somewhere go back to that item
|
|
60
|
+
|
|
61
|
+
if (pathIds.includes(id)) {
|
|
62
|
+
var pathIdx = pathIds.findIndex(function (pathId) {
|
|
63
|
+
return pathId === id;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
var newPath = _toConsumableArray(path).splice(0, pathIdx + 1);
|
|
67
|
+
|
|
68
|
+
setPath(_toConsumableArray(newPath));
|
|
69
|
+
} else {
|
|
70
|
+
// if the item is on the same level as another selected item start from the parent level
|
|
71
|
+
if (path.find(function (p) {
|
|
72
|
+
return p.parent === parent;
|
|
73
|
+
})) {
|
|
74
|
+
var parentIdx = path.findIndex(function (p) {
|
|
75
|
+
return p.id === parent;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
var _newPath = _toConsumableArray(path).splice(0, parentIdx + 1);
|
|
79
|
+
|
|
80
|
+
setPath([].concat(_toConsumableArray(_newPath), [{
|
|
81
|
+
id: id,
|
|
82
|
+
title: title,
|
|
83
|
+
parent: parent
|
|
84
|
+
}]));
|
|
85
|
+
} else {
|
|
86
|
+
setPath([].concat(_toConsumableArray(path), [{
|
|
87
|
+
id: id,
|
|
88
|
+
title: title,
|
|
89
|
+
parent: parent
|
|
90
|
+
}]));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
setPath([].concat(_toConsumableArray(path), [{
|
|
96
|
+
id: id,
|
|
97
|
+
title: title
|
|
98
|
+
}]));
|
|
99
|
+
}
|
|
49
100
|
};
|
|
50
101
|
|
|
51
102
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -55,15 +106,22 @@ export var AddSelectList = function AddSelectList(_ref) {
|
|
|
55
106
|
className: "".concat(blockClass)
|
|
56
107
|
}, /*#__PURE__*/React.createElement(StructuredListBody, null, filteredItems.map(function (item) {
|
|
57
108
|
return /*#__PURE__*/React.createElement(StructuredListRow, {
|
|
58
|
-
key: item.id
|
|
59
|
-
|
|
109
|
+
key: item.id,
|
|
110
|
+
className: "".concat(blockClass, "-row")
|
|
111
|
+
}, /*#__PURE__*/React.createElement(StructuredListCell, {
|
|
112
|
+
className: "".concat(blockClass, "-cell")
|
|
113
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
60
114
|
className: "".concat(blockClass, "-cell-wrapper")
|
|
61
115
|
}, multi ? /*#__PURE__*/React.createElement(Checkbox, {
|
|
62
116
|
className: "".concat(blockClass, "-checkbox"),
|
|
63
117
|
onChange: function onChange(value) {
|
|
64
118
|
return handleMultiSelection(item.id, value);
|
|
65
119
|
},
|
|
66
|
-
labelText:
|
|
120
|
+
labelText: !inColumn ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
121
|
+
className: "".concat(blockClass, "-cell-title")
|
|
122
|
+
}, item.title), /*#__PURE__*/React.createElement("span", {
|
|
123
|
+
className: "".concat(blockClass, "-cell-subtitle")
|
|
124
|
+
}, item.subtitle)) : item.title,
|
|
67
125
|
id: item.id,
|
|
68
126
|
checked: multiSelection.includes(item.id)
|
|
69
127
|
}) : /*#__PURE__*/React.createElement(RadioButton, {
|
|
@@ -83,6 +141,7 @@ export var AddSelectList = function AddSelectList(_ref) {
|
|
|
83
141
|
};
|
|
84
142
|
AddSelectList.propTypes = {
|
|
85
143
|
filteredItems: PropTypes.array,
|
|
144
|
+
inColumn: PropTypes.bool,
|
|
86
145
|
multi: PropTypes.bool,
|
|
87
146
|
multiSelection: PropTypes.array,
|
|
88
147
|
path: PropTypes.array,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
-
var _excluded = ["children"];
|
|
3
1
|
//
|
|
4
2
|
// Copyright IBM Corp. 2022
|
|
5
3
|
//
|
|
@@ -28,21 +26,10 @@ export var AddSelectSidebar = function AddSelectSidebar(_ref) {
|
|
|
28
26
|
return v !== id;
|
|
29
27
|
});
|
|
30
28
|
setMultiSelection(newSelections);
|
|
31
|
-
}; // utility to flatten the list of items and their children into a single searchable array
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var flattenItems = function flattenItems(arr) {
|
|
35
|
-
return arr.reduce(function (prev, cur) {
|
|
36
|
-
var children = cur.children,
|
|
37
|
-
item = _objectWithoutProperties(cur, _excluded);
|
|
38
|
-
|
|
39
|
-
return prev.concat(item).concat(children ? flattenItems(children) : []);
|
|
40
|
-
}, []);
|
|
41
29
|
};
|
|
42
30
|
|
|
43
|
-
var flattenedItems = flattenItems(items);
|
|
44
31
|
var sidebarItems = multiSelection.map(function (selectedId) {
|
|
45
|
-
return
|
|
32
|
+
return items.find(function (item) {
|
|
46
33
|
return item.id === selectedId;
|
|
47
34
|
});
|
|
48
35
|
});
|
|
@@ -53,7 +40,13 @@ export var AddSelectSidebar = function AddSelectSidebar(_ref) {
|
|
|
53
40
|
id = _ref2.id;
|
|
54
41
|
return /*#__PURE__*/React.createElement("div", {
|
|
55
42
|
className: "".concat(blockClass, "-accordion-title")
|
|
56
|
-
}, /*#__PURE__*/React.createElement("div",
|
|
43
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
44
|
+
className: "".concat(blockClass, "-selected-item")
|
|
45
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
46
|
+
className: "".concat(blockClass, "-selected-item-title")
|
|
47
|
+
}, title), /*#__PURE__*/React.createElement("p", {
|
|
48
|
+
className: "".concat(blockClass, "-selected-item-subtitle")
|
|
49
|
+
}, subtitle)), /*#__PURE__*/React.createElement(Button, {
|
|
57
50
|
renderIcon: SubtractAlt32,
|
|
58
51
|
iconDescription: removeIconDescription,
|
|
59
52
|
hasIconOnly: true,
|