@carbon/ibm-products 1.22.0 → 1.23.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/components/Datagrid/styles/datagrid.css +4 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -1
- package/css/components/Datagrid/styles/index.css +15 -0
- package/css/components/Datagrid/styles/index.css.map +1 -1
- package/css/components/Datagrid/styles/useExpandedRow.css +12 -0
- package/css/components/Datagrid/styles/useExpandedRow.css.map +1 -0
- package/css/index-full-carbon.css +46 -143
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +3 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +25 -16
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +41 -16
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +2 -2
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +44 -139
- package/css/index.css.map +1 -1
- package/css/index.min.css +3 -3
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +57 -422
- package/es/components/AddSelect/AddSelectBody.js +349 -0
- package/es/components/AddSelect/AddSelectBreadcrumbs.js +11 -31
- package/es/components/AddSelect/AddSelectColumn.js +91 -41
- package/es/components/AddSelect/AddSelectFilter.js +1 -2
- package/es/components/AddSelect/AddSelectList.js +10 -61
- package/es/components/AddSelect/AddSelectMetaPanel.js +1 -1
- package/es/components/AddSelect/AddSelectSidebar.js +20 -13
- package/es/components/AddSelect/AddSelectSort.js +2 -2
- package/es/components/AddSelect/add-select-utils.js +85 -59
- package/es/components/AddSelect/hooks/useParentSelect.js +16 -0
- package/es/components/AddSelect/hooks/usePath.js +66 -0
- package/es/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +1 -5
- package/es/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +1 -5
- package/es/components/Datagrid/Datagrid/Datagrid.js +1 -1
- package/es/components/Datagrid/useExpandedRow.js +12 -4
- package/es/components/PageHeader/PageHeaderUtils.js +5 -0
- package/es/components/TagSet/TagSet.js +15 -5
- package/lib/components/AddSelect/AddSelect.js +54 -430
- package/lib/components/AddSelect/AddSelectBody.js +384 -0
- package/lib/components/AddSelect/AddSelectBreadcrumbs.js +11 -30
- package/lib/components/AddSelect/AddSelectColumn.js +90 -39
- package/lib/components/AddSelect/AddSelectFilter.js +1 -2
- package/lib/components/AddSelect/AddSelectList.js +11 -60
- package/lib/components/AddSelect/AddSelectMetaPanel.js +1 -1
- package/lib/components/AddSelect/AddSelectSidebar.js +20 -13
- package/lib/components/AddSelect/AddSelectSort.js +2 -2
- package/lib/components/AddSelect/add-select-utils.js +88 -64
- package/lib/components/AddSelect/hooks/useParentSelect.js +27 -0
- package/lib/components/AddSelect/hooks/usePath.js +75 -0
- package/lib/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +1 -5
- package/lib/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +1 -5
- package/lib/components/Datagrid/Datagrid/Datagrid.js +1 -1
- package/lib/components/Datagrid/useExpandedRow.js +20 -4
- package/lib/components/PageHeader/PageHeaderUtils.js +5 -0
- package/lib/components/TagSet/TagSet.js +15 -5
- package/package.json +16 -16
- package/scss/components/Cascade/_cascade.scss +2 -1
- package/scss/components/CreateInfluencer/_create-influencer.scss +0 -2
- package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -1
- package/scss/components/Datagrid/_storybook-styles.scss +4 -0
- package/scss/components/Datagrid/styles/datagrid.scss +4 -0
- package/scss/components/Datagrid/styles/index.scss +1 -0
- package/scss/components/Datagrid/styles/useExpandedRow.scss +13 -0
- package/scss/components/InlineEdit/_inline-edit.scss +2 -1
- package/scss/components/OptionsTile/_options-tile.scss +1 -0
- package/scss/components/PageHeader/_page-header.scss +9 -4
- package/scss/components/SidePanel/_side-panel.scss +1 -2
- package/scss/components/TagSet/_tag-set.scss +4 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
var _excluded = ["className", "clearFiltersText", "closeIconDescription", "columnInputPlaceholder", "defaultModifiers", "description", "globalFilterOpts", "globalFiltersIconDescription", "globalFiltersPlaceholderText", "globalFiltersPrimaryButtonText", "globalFiltersSecondaryButtonText", "globalSearchLabel", "globalSearchPlaceholder", "globalSortBy", "influencerTitle", "items", "itemsLabel", "metaIconDescription", "metaPanelTitle", "multi", "navIconDescription", "noResultsDescription", "noResultsTitle", "noSelectionDescription", "noSelectionTitle", "normalizedItems", "onClose", "onCloseButtonText", "onSubmit", "onSubmitButtonText", "open", "portalTarget", "removeIconDescription", "searchResultsLabel", "title", "useNormalizedItems"];
|
|
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 cx from 'classnames';
|
|
15
|
+
import { Tag } from 'carbon-components-react';
|
|
16
|
+
import { Tearsheet, TearsheetNarrow } from '../../components/Tearsheet';
|
|
17
|
+
import { NoDataEmptyState } from '../../components/EmptyStates/NoDataEmptyState';
|
|
18
|
+
import { AddSelectSidebar } from './AddSelectSidebar';
|
|
19
|
+
import { AddSelectBreadcrumbs } from './AddSelectBreadcrumbs';
|
|
20
|
+
import { AddSelectList } from './AddSelectList';
|
|
21
|
+
import { AddSelectColumn } from './AddSelectColumn';
|
|
22
|
+
import { AddSelectFilter } from './AddSelectFilter';
|
|
23
|
+
import { AddSelectSort } from './AddSelectSort';
|
|
24
|
+
import { sortItems, getFilteredItems } from './add-select-utils';
|
|
25
|
+
import { useItemSort } from './hooks/useItemSort';
|
|
26
|
+
import useParentSelect from './hooks/useParentSelect';
|
|
27
|
+
import usePath from './hooks/usePath';
|
|
28
|
+
import { pkg } from '../../settings';
|
|
29
|
+
var blockClass = "".concat(pkg.prefix, "--add-select");
|
|
30
|
+
var componentName = 'AddSelectBody';
|
|
31
|
+
export var AddSelectBody = function AddSelectBody(_ref) {
|
|
32
|
+
var _cx, _path$;
|
|
33
|
+
|
|
34
|
+
var className = _ref.className,
|
|
35
|
+
clearFiltersText = _ref.clearFiltersText,
|
|
36
|
+
closeIconDescription = _ref.closeIconDescription,
|
|
37
|
+
columnInputPlaceholder = _ref.columnInputPlaceholder,
|
|
38
|
+
defaultModifiers = _ref.defaultModifiers,
|
|
39
|
+
description = _ref.description,
|
|
40
|
+
globalFilterOpts = _ref.globalFilterOpts,
|
|
41
|
+
globalFiltersIconDescription = _ref.globalFiltersIconDescription,
|
|
42
|
+
globalFiltersPlaceholderText = _ref.globalFiltersPlaceholderText,
|
|
43
|
+
globalFiltersPrimaryButtonText = _ref.globalFiltersPrimaryButtonText,
|
|
44
|
+
globalFiltersSecondaryButtonText = _ref.globalFiltersSecondaryButtonText,
|
|
45
|
+
globalSearchLabel = _ref.globalSearchLabel,
|
|
46
|
+
globalSearchPlaceholder = _ref.globalSearchPlaceholder,
|
|
47
|
+
globalSortBy = _ref.globalSortBy,
|
|
48
|
+
influencerTitle = _ref.influencerTitle,
|
|
49
|
+
items = _ref.items,
|
|
50
|
+
itemsLabel = _ref.itemsLabel,
|
|
51
|
+
metaIconDescription = _ref.metaIconDescription,
|
|
52
|
+
metaPanelTitle = _ref.metaPanelTitle,
|
|
53
|
+
multi = _ref.multi,
|
|
54
|
+
navIconDescription = _ref.navIconDescription,
|
|
55
|
+
noResultsDescription = _ref.noResultsDescription,
|
|
56
|
+
noResultsTitle = _ref.noResultsTitle,
|
|
57
|
+
noSelectionDescription = _ref.noSelectionDescription,
|
|
58
|
+
noSelectionTitle = _ref.noSelectionTitle,
|
|
59
|
+
normalizedItems = _ref.normalizedItems,
|
|
60
|
+
onClose = _ref.onClose,
|
|
61
|
+
onCloseButtonText = _ref.onCloseButtonText,
|
|
62
|
+
onSubmit = _ref.onSubmit,
|
|
63
|
+
onSubmitButtonText = _ref.onSubmitButtonText,
|
|
64
|
+
open = _ref.open,
|
|
65
|
+
portalTarget = _ref.portalTarget,
|
|
66
|
+
removeIconDescription = _ref.removeIconDescription,
|
|
67
|
+
searchResultsLabel = _ref.searchResultsLabel,
|
|
68
|
+
title = _ref.title,
|
|
69
|
+
useNormalizedItems = _ref.useNormalizedItems,
|
|
70
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
71
|
+
|
|
72
|
+
// hooks
|
|
73
|
+
var _useState = useState(''),
|
|
74
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
75
|
+
singleSelection = _useState2[0],
|
|
76
|
+
setSingleSelection = _useState2[1];
|
|
77
|
+
|
|
78
|
+
var _useState3 = useState([]),
|
|
79
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
80
|
+
multiSelection = _useState4[0],
|
|
81
|
+
setMultiSelection = _useState4[1];
|
|
82
|
+
|
|
83
|
+
var _useState5 = useState(''),
|
|
84
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
85
|
+
searchTerm = _useState6[0],
|
|
86
|
+
setSearchTerm = _useState6[1];
|
|
87
|
+
|
|
88
|
+
var _useState7 = useState({}),
|
|
89
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
90
|
+
appliedGlobalFilters = _useState8[0],
|
|
91
|
+
setAppliedGlobalFilters = _useState8[1];
|
|
92
|
+
|
|
93
|
+
var _useState9 = useState({}),
|
|
94
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
95
|
+
displayMetalPanel = _useState10[0],
|
|
96
|
+
setDisplayMetaPanel = _useState10[1];
|
|
97
|
+
|
|
98
|
+
var _useState11 = useState(defaultModifiers),
|
|
99
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
100
|
+
appliedModifiers = _useState12[0],
|
|
101
|
+
setAppliedModifiers = _useState12[1];
|
|
102
|
+
|
|
103
|
+
var _useItemSort = useItemSort(),
|
|
104
|
+
sortDirection = _useItemSort.sortDirection,
|
|
105
|
+
setSortDirection = _useItemSort.setSortDirection,
|
|
106
|
+
sortAttribute = _useItemSort.sortAttribute,
|
|
107
|
+
setSortAttribute = _useItemSort.setSortAttribute;
|
|
108
|
+
|
|
109
|
+
var _useParentSelect = useParentSelect(),
|
|
110
|
+
parentSelected = _useParentSelect.parentSelected,
|
|
111
|
+
setParentSelected = _useParentSelect.setParentSelected;
|
|
112
|
+
|
|
113
|
+
var _usePath = usePath(itemsLabel),
|
|
114
|
+
path = _usePath.path,
|
|
115
|
+
setPath = _usePath.setPath,
|
|
116
|
+
pathOnclick = _usePath.pathOnclick;
|
|
117
|
+
|
|
118
|
+
var classNames = cx(className, blockClass, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__single"), !multi), _defineProperty(_cx, "".concat(blockClass, "__multi"), multi), _cx));
|
|
119
|
+
var globalFilterKeys = Object.keys(appliedGlobalFilters);
|
|
120
|
+
var globalFiltersApplied = globalFilterKeys.length > 0; // handlers
|
|
121
|
+
|
|
122
|
+
var handleSearch = function handleSearch(term) {
|
|
123
|
+
setSearchTerm(term);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var handleFilter = function handleFilter(filters) {
|
|
127
|
+
setAppliedGlobalFilters(filters);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
var submitHandler = function submitHandler() {
|
|
131
|
+
if (multi && appliedModifiers.length > 0) {
|
|
132
|
+
var selections = multiSelection.map(function (item) {
|
|
133
|
+
return appliedModifiers.find(function (mod) {
|
|
134
|
+
return mod.id === item;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
onSubmit(selections);
|
|
138
|
+
} else if (multi && appliedModifiers.length === 0) {
|
|
139
|
+
onSubmit(multiSelection);
|
|
140
|
+
} else {
|
|
141
|
+
onSubmit(singleSelection);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
var setShowBreadsCrumbs = function setShowBreadsCrumbs() {
|
|
146
|
+
if (searchTerm || globalFiltersApplied || !path || path.length === 0) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var setShowTags = function setShowTags() {
|
|
154
|
+
if (searchTerm) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (useNormalizedItems) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return true;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
var parentSelectionHandler = function parentSelectionHandler(id, title, parentId) {
|
|
166
|
+
setParentSelected(id);
|
|
167
|
+
setPath(id, title, parentId);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var sortFn = sortItems(sortAttribute, sortDirection);
|
|
171
|
+
var itemsToDisplay = getFilteredItems(useNormalizedItems, normalizedItems, searchTerm, globalFiltersApplied, globalFilterKeys, appliedGlobalFilters, sortFn, multi, items, path);
|
|
172
|
+
var hasResults = itemsToDisplay.length > 0;
|
|
173
|
+
var showBreadsCrumbs = setShowBreadsCrumbs();
|
|
174
|
+
var showSort = (searchTerm || globalFiltersApplied) && hasResults;
|
|
175
|
+
var showTags = setShowTags();
|
|
176
|
+
var commonListProps = {
|
|
177
|
+
metaIconDescription: metaIconDescription,
|
|
178
|
+
multi: multi,
|
|
179
|
+
multiSelection: multiSelection,
|
|
180
|
+
navIconDescription: navIconDescription,
|
|
181
|
+
path: path,
|
|
182
|
+
setMultiSelection: setMultiSelection,
|
|
183
|
+
setPath: setPath,
|
|
184
|
+
setSingleSelection: setSingleSelection,
|
|
185
|
+
singleSelection: singleSelection,
|
|
186
|
+
setDisplayMetaPanel: setDisplayMetaPanel,
|
|
187
|
+
parentId: path[0].id
|
|
188
|
+
};
|
|
189
|
+
var commonTearsheetProps = {
|
|
190
|
+
className: classNames,
|
|
191
|
+
open: open,
|
|
192
|
+
title: title,
|
|
193
|
+
description: description,
|
|
194
|
+
closeIconDescription: 'temp description',
|
|
195
|
+
actions: [{
|
|
196
|
+
label: onCloseButtonText,
|
|
197
|
+
kind: 'secondary',
|
|
198
|
+
onClick: onClose
|
|
199
|
+
}, {
|
|
200
|
+
label: onSubmitButtonText,
|
|
201
|
+
kind: 'primary',
|
|
202
|
+
onClick: submitHandler,
|
|
203
|
+
disabled: multi ? multiSelection.length === 0 : !singleSelection
|
|
204
|
+
}],
|
|
205
|
+
portalTarget: portalTarget
|
|
206
|
+
};
|
|
207
|
+
var sidebarProps = {
|
|
208
|
+
closeIconDescription: closeIconDescription,
|
|
209
|
+
influencerTitle: influencerTitle,
|
|
210
|
+
items: useNormalizedItems ? normalizedItems : items.entries,
|
|
211
|
+
metaPanelTitle: metaPanelTitle,
|
|
212
|
+
multiSelection: multiSelection,
|
|
213
|
+
noSelectionDescription: noSelectionDescription,
|
|
214
|
+
noSelectionTitle: noSelectionTitle,
|
|
215
|
+
removeIconDescription: removeIconDescription,
|
|
216
|
+
setMultiSelection: setMultiSelection,
|
|
217
|
+
displayMetalPanel: displayMetalPanel,
|
|
218
|
+
setDisplayMetaPanel: setDisplayMetaPanel,
|
|
219
|
+
modifiers: items.modifiers,
|
|
220
|
+
appliedModifiers: appliedModifiers
|
|
221
|
+
};
|
|
222
|
+
var displayColumnView = multi && useNormalizedItems && !searchTerm && !globalFiltersApplied; // main content
|
|
223
|
+
|
|
224
|
+
var body = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
225
|
+
className: "".concat(blockClass, "__header")
|
|
226
|
+
}, /*#__PURE__*/React.createElement(AddSelectFilter, {
|
|
227
|
+
inputLabel: globalSearchLabel,
|
|
228
|
+
inputPlaceholder: globalSearchPlaceholder,
|
|
229
|
+
searchTerm: searchTerm,
|
|
230
|
+
handleSearch: handleSearch,
|
|
231
|
+
multi: multi,
|
|
232
|
+
filterOpts: globalFilterOpts,
|
|
233
|
+
handleFilter: handleFilter,
|
|
234
|
+
primaryButtonText: globalFiltersPrimaryButtonText,
|
|
235
|
+
secondaryButtonText: globalFiltersSecondaryButtonText,
|
|
236
|
+
placeholder: globalFiltersPlaceholderText,
|
|
237
|
+
iconDescription: globalFiltersIconDescription,
|
|
238
|
+
appliedFilters: appliedGlobalFilters,
|
|
239
|
+
hasFiltersApplied: globalFiltersApplied,
|
|
240
|
+
clearFiltersText: clearFiltersText
|
|
241
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
242
|
+
className: "".concat(blockClass, "__sub-header")
|
|
243
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
244
|
+
className: "".concat(blockClass, "__tag-container")
|
|
245
|
+
}, showBreadsCrumbs ? /*#__PURE__*/React.createElement(AddSelectBreadcrumbs, {
|
|
246
|
+
path: path,
|
|
247
|
+
onClick: pathOnclick
|
|
248
|
+
}) : /*#__PURE__*/React.createElement("p", {
|
|
249
|
+
className: "".concat(blockClass, "__tag-container-label")
|
|
250
|
+
}, searchTerm ? searchResultsLabel : itemsLabel), showTags && /*#__PURE__*/React.createElement(Tag, {
|
|
251
|
+
type: "gray",
|
|
252
|
+
size: "sm"
|
|
253
|
+
}, itemsToDisplay.length)), showSort && /*#__PURE__*/React.createElement(AddSelectSort, {
|
|
254
|
+
items: itemsToDisplay,
|
|
255
|
+
setSortAttribute: setSortAttribute,
|
|
256
|
+
setSortDirection: setSortDirection,
|
|
257
|
+
sortAttribute: sortAttribute,
|
|
258
|
+
sortDirection: sortDirection,
|
|
259
|
+
sortBy: globalSortBy
|
|
260
|
+
}))), displayColumnView ? /*#__PURE__*/React.createElement("div", {
|
|
261
|
+
className: "".concat(blockClass, "__columns")
|
|
262
|
+
}, /*#__PURE__*/React.createElement(AddSelectColumn, _extends({}, commonListProps, {
|
|
263
|
+
items: itemsToDisplay,
|
|
264
|
+
columnInputPlaceholder: columnInputPlaceholder,
|
|
265
|
+
header: (_path$ = path[0]) === null || _path$ === void 0 ? void 0 : _path$.title
|
|
266
|
+
}))) : /*#__PURE__*/React.createElement("div", null, hasResults ? /*#__PURE__*/React.createElement(AddSelectList, _extends({}, commonListProps, {
|
|
267
|
+
filteredItems: itemsToDisplay,
|
|
268
|
+
modifiers: items.modifiers,
|
|
269
|
+
appliedModifiers: appliedModifiers,
|
|
270
|
+
setAppliedModifiers: setAppliedModifiers,
|
|
271
|
+
setParentSelected: parentSelectionHandler,
|
|
272
|
+
parentSelected: parentSelected,
|
|
273
|
+
parentId: parentSelected || path[0].id
|
|
274
|
+
})) : /*#__PURE__*/React.createElement("div", {
|
|
275
|
+
className: "".concat(blockClass, "__body")
|
|
276
|
+
}, /*#__PURE__*/React.createElement(NoDataEmptyState, {
|
|
277
|
+
subtitle: noResultsDescription,
|
|
278
|
+
title: noResultsTitle
|
|
279
|
+
}))));
|
|
280
|
+
return /*#__PURE__*/React.createElement("div", rest, multi ? /*#__PURE__*/React.createElement(Tearsheet, _extends({}, commonTearsheetProps, {
|
|
281
|
+
influencer: multi && /*#__PURE__*/React.createElement(AddSelectSidebar, sidebarProps),
|
|
282
|
+
influencerPosition: "right"
|
|
283
|
+
}), body) : /*#__PURE__*/React.createElement(TearsheetNarrow, commonTearsheetProps, body));
|
|
284
|
+
};
|
|
285
|
+
AddSelectBody.propTypes = {
|
|
286
|
+
className: PropTypes.string,
|
|
287
|
+
clearFiltersText: PropTypes.string,
|
|
288
|
+
closeIconDescription: PropTypes.string,
|
|
289
|
+
columnInputPlaceholder: PropTypes.string,
|
|
290
|
+
defaultModifiers: PropTypes.array,
|
|
291
|
+
description: PropTypes.string,
|
|
292
|
+
globalFilterOpts: PropTypes.array,
|
|
293
|
+
globalFiltersIconDescription: PropTypes.string,
|
|
294
|
+
globalFiltersPlaceholderText: PropTypes.string,
|
|
295
|
+
globalFiltersPrimaryButtonText: PropTypes.string,
|
|
296
|
+
globalFiltersSecondaryButtonText: PropTypes.string,
|
|
297
|
+
globalSearchLabel: PropTypes.string,
|
|
298
|
+
globalSearchPlaceholder: PropTypes.string,
|
|
299
|
+
globalSortBy: PropTypes.array,
|
|
300
|
+
influencerTitle: PropTypes.string,
|
|
301
|
+
items: PropTypes.shape({
|
|
302
|
+
modifiers: PropTypes.shape({
|
|
303
|
+
id: PropTypes.string,
|
|
304
|
+
label: PropTypes.string,
|
|
305
|
+
options: PropTypes.array
|
|
306
|
+
}),
|
|
307
|
+
sortBy: PropTypes.array,
|
|
308
|
+
filterBy: PropTypes.array,
|
|
309
|
+
entries: PropTypes.arrayOf(PropTypes.shape({
|
|
310
|
+
avatar: PropTypes.shape({
|
|
311
|
+
alt: PropTypes.string,
|
|
312
|
+
icon: PropTypes.object,
|
|
313
|
+
src: PropTypes.string
|
|
314
|
+
}),
|
|
315
|
+
children: PropTypes.object,
|
|
316
|
+
icon: PropTypes.object,
|
|
317
|
+
id: PropTypes.string.isRequired,
|
|
318
|
+
meta: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
|
|
319
|
+
id: PropTypes.string,
|
|
320
|
+
title: PropTypes.string,
|
|
321
|
+
value: PropTypes.string
|
|
322
|
+
})), PropTypes.node]),
|
|
323
|
+
subtitle: PropTypes.string,
|
|
324
|
+
title: PropTypes.string.isRequired,
|
|
325
|
+
value: PropTypes.string.isRequired
|
|
326
|
+
}))
|
|
327
|
+
}),
|
|
328
|
+
itemsLabel: PropTypes.string,
|
|
329
|
+
metaIconDescription: PropTypes.string,
|
|
330
|
+
metaPanelTitle: PropTypes.string,
|
|
331
|
+
multi: PropTypes.bool,
|
|
332
|
+
navIconDescription: PropTypes.string,
|
|
333
|
+
noResultsDescription: PropTypes.string,
|
|
334
|
+
noResultsTitle: PropTypes.string,
|
|
335
|
+
noSelectionDescription: PropTypes.string,
|
|
336
|
+
noSelectionTitle: PropTypes.string,
|
|
337
|
+
normalizedItems: PropTypes.object,
|
|
338
|
+
onClose: PropTypes.func,
|
|
339
|
+
onCloseButtonText: PropTypes.string,
|
|
340
|
+
onSubmit: PropTypes.func,
|
|
341
|
+
onSubmitButtonText: PropTypes.string,
|
|
342
|
+
open: PropTypes.bool,
|
|
343
|
+
portalTarget: PropTypes.node,
|
|
344
|
+
removeIconDescription: PropTypes.string,
|
|
345
|
+
searchResultsLabel: PropTypes.string,
|
|
346
|
+
title: PropTypes.string,
|
|
347
|
+
useNormalizedItems: PropTypes.bool
|
|
348
|
+
};
|
|
349
|
+
AddSelectBreadcrumbs.displayName = componentName;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
1
|
//
|
|
3
2
|
// Copyright IBM Corp. 2022
|
|
4
3
|
//
|
|
@@ -10,47 +9,28 @@ import { Breadcrumb, BreadcrumbItem } from 'carbon-components-react';
|
|
|
10
9
|
import PropTypes from 'prop-types';
|
|
11
10
|
var componentName = 'AddSelectBreadcrumbs';
|
|
12
11
|
export var AddSelectBreadcrumbs = function AddSelectBreadcrumbs(_ref) {
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
setPath = _ref.setPath;
|
|
12
|
+
var path = _ref.path,
|
|
13
|
+
onClick = _ref.onClick;
|
|
16
14
|
|
|
17
|
-
var clickHandler = function clickHandler(
|
|
18
|
-
|
|
19
|
-
return entry.id === id;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
var finalPath = _toConsumableArray(path).splice(0, pathIdx + 1);
|
|
23
|
-
|
|
24
|
-
setPath(finalPath);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
var resetPath = function resetPath() {
|
|
28
|
-
setPath([]);
|
|
15
|
+
var clickHandler = function clickHandler(idx) {
|
|
16
|
+
onClick(idx);
|
|
29
17
|
};
|
|
30
18
|
|
|
31
19
|
return /*#__PURE__*/React.createElement(Breadcrumb, {
|
|
32
20
|
noTrailingSlash: true
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
}, itemsLabel), path.map(function (entry, idx, arr) {
|
|
36
|
-
var isCurrentPage = idx === arr.length - 1;
|
|
37
|
-
|
|
38
|
-
var crumbHandler = function crumbHandler() {
|
|
39
|
-
if (!isCurrentPage) {
|
|
40
|
-
clickHandler(entry.id);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
21
|
+
}, path.map(function (entry, idx) {
|
|
22
|
+
var isCurrentPage = idx === path.length - 1;
|
|
44
23
|
return /*#__PURE__*/React.createElement(BreadcrumbItem, {
|
|
45
24
|
key: entry.id,
|
|
46
25
|
isCurrentPage: isCurrentPage,
|
|
47
|
-
onClick:
|
|
26
|
+
onClick: function onClick() {
|
|
27
|
+
return clickHandler(idx);
|
|
28
|
+
}
|
|
48
29
|
}, entry.title);
|
|
49
30
|
}));
|
|
50
31
|
};
|
|
51
32
|
AddSelectBreadcrumbs.propTypes = {
|
|
52
|
-
|
|
53
|
-
path: PropTypes.array
|
|
54
|
-
setPath: PropTypes.func
|
|
33
|
+
onClick: PropTypes.func,
|
|
34
|
+
path: PropTypes.array
|
|
55
35
|
};
|
|
56
36
|
AddSelectBreadcrumbs.displayName = componentName;
|
|
@@ -2,43 +2,46 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["columnInputPlaceholder", "
|
|
5
|
+
var _excluded = ["columnInputPlaceholder", "header", "items", "multiSelection", "parentId", "path", "setMultiSelection", "setPath"];
|
|
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, { useState
|
|
12
|
+
import React, { useState } from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import { TextInput, Tag, OverflowMenu, Checkbox } from 'carbon-components-react';
|
|
15
15
|
import { Filter32 } from '@carbon/icons-react';
|
|
16
16
|
import { pkg, carbon } from '../../settings';
|
|
17
17
|
import { AddSelectList } from './AddSelectList';
|
|
18
18
|
import { AddSelectSort } from './AddSelectSort';
|
|
19
|
-
import { sortItems
|
|
19
|
+
import { sortItems } from './add-select-utils';
|
|
20
20
|
import { useItemSort } from './hooks/useItemSort';
|
|
21
21
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
|
22
|
-
|
|
22
|
+
import useParentSelect from './hooks/useParentSelect';
|
|
23
|
+
var blockClass = "".concat(pkg.prefix, "--add-select");
|
|
24
|
+
var colClass = "".concat(blockClass, "__column");
|
|
25
|
+
var componentName = 'AddSelectColumn';
|
|
23
26
|
export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
24
|
-
var _filteredItems$find;
|
|
25
|
-
|
|
26
27
|
var columnInputPlaceholder = _ref.columnInputPlaceholder,
|
|
27
|
-
filteredItems = _ref.filteredItems,
|
|
28
28
|
header = _ref.header,
|
|
29
|
+
items = _ref.items,
|
|
29
30
|
multiSelection = _ref.multiSelection,
|
|
31
|
+
parentId = _ref.parentId,
|
|
32
|
+
path = _ref.path,
|
|
30
33
|
setMultiSelection = _ref.setMultiSelection,
|
|
34
|
+
setPath = _ref.setPath,
|
|
31
35
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
36
|
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
setAllSelected = _useState2[1];
|
|
37
|
+
var _useParentSelect = useParentSelect(),
|
|
38
|
+
parentSelected = _useParentSelect.parentSelected,
|
|
39
|
+
setParentSelected = _useParentSelect.setParentSelected;
|
|
37
40
|
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
searchTerm =
|
|
41
|
-
setSearchTerm =
|
|
41
|
+
var _useState = useState(''),
|
|
42
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
+
searchTerm = _useState2[0],
|
|
44
|
+
setSearchTerm = _useState2[1];
|
|
42
45
|
|
|
43
46
|
var _useItemSort = useItemSort(),
|
|
44
47
|
sortDirection = _useItemSort.sortDirection,
|
|
@@ -46,29 +49,59 @@ export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
|
46
49
|
sortAttribute = _useItemSort.sortAttribute,
|
|
47
50
|
setSortAttribute = _useItemSort.setSortAttribute;
|
|
48
51
|
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
filters =
|
|
52
|
-
setFilters =
|
|
52
|
+
var _useState3 = useState([]),
|
|
53
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
54
|
+
filters = _useState4[0],
|
|
55
|
+
setFilters = _useState4[1];
|
|
56
|
+
|
|
57
|
+
var entries = items.entries,
|
|
58
|
+
filterBy = items.filterBy,
|
|
59
|
+
sortBy = items.sortBy;
|
|
53
60
|
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
return
|
|
61
|
+
var getSelectedItem = function getSelectedItem() {
|
|
62
|
+
var _entries$find;
|
|
63
|
+
|
|
64
|
+
var parentInPath = path.find(function (entry) {
|
|
65
|
+
return entry.parentId === parentId;
|
|
59
66
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
/**
|
|
68
|
+
* this check helps ensure that when the state of the open columns is cleared by global search
|
|
69
|
+
* that the columns are rebuilt from the data in the path array
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
if (parentInPath && !parentSelected) {
|
|
73
|
+
return entries.find(function (item) {
|
|
74
|
+
return item.id === parentInPath.id;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (_entries$find = entries.find(function (item) {
|
|
79
|
+
return item.id === parentSelected;
|
|
80
|
+
})) !== null && _entries$find !== void 0 ? _entries$find : null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
var selectedItem = getSelectedItem();
|
|
84
|
+
/**
|
|
85
|
+
* this check helps prevent children from already being open when you switch from parents
|
|
86
|
+
* on the same level. for example- using the storybook example, if you click on folder 1,
|
|
87
|
+
* file 1, folder 2, and then folder 1 again file 1 children shouldn't be expanded. this
|
|
88
|
+
* check ensures that when a user navigates to parents on the same level that the open state
|
|
89
|
+
* of their children is cleared by referencing the path array.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
var itemInPath = selectedItem && path.find(function (entry) {
|
|
93
|
+
return entry.id === selectedItem.id;
|
|
94
|
+
});
|
|
95
|
+
var allSelected = entries.every(function (item) {
|
|
96
|
+
return multiSelection.includes(item.id);
|
|
97
|
+
}); // filtering
|
|
98
|
+
|
|
99
|
+
var filterByOpts = filterBy ? entries.map(function (item) {
|
|
100
|
+
return item[filterBy];
|
|
68
101
|
}) : [];
|
|
69
102
|
|
|
70
103
|
var selectAllHandler = function selectAllHandler(checked) {
|
|
71
|
-
var itemIds =
|
|
104
|
+
var itemIds = entries.map(function (item) {
|
|
72
105
|
return item.id;
|
|
73
106
|
});
|
|
74
107
|
|
|
@@ -113,12 +146,16 @@ export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
|
113
146
|
};
|
|
114
147
|
|
|
115
148
|
var sortFn = sortItems(sortAttribute, sortDirection);
|
|
116
|
-
var
|
|
117
|
-
var colItems = filteredItems.filter(filterBySearch) // first check if the item meets the search
|
|
149
|
+
var colItems = entries.filter(filterBySearch) // first check if the item meets the search
|
|
118
150
|
.filter(filterByAttribute) // then check if the item is included in the filter
|
|
119
151
|
.sort(sortFn); // then sort the items by whatever criteria
|
|
120
152
|
|
|
121
|
-
|
|
153
|
+
var parentSelectionHandler = function parentSelectionHandler(id, title) {
|
|
154
|
+
setParentSelected(id);
|
|
155
|
+
setPath(id, title, parentId);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
122
159
|
className: colClass
|
|
123
160
|
}, /*#__PURE__*/React.createElement("div", {
|
|
124
161
|
className: "".concat(colClass, "-search-bar")
|
|
@@ -135,7 +172,7 @@ export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
|
135
172
|
}), /*#__PURE__*/React.createElement("div", {
|
|
136
173
|
className: "".concat(colClass, "-sort-filter")
|
|
137
174
|
}, /*#__PURE__*/React.createElement(AddSelectSort, {
|
|
138
|
-
items:
|
|
175
|
+
items: entries,
|
|
139
176
|
setSortAttribute: setSortAttribute,
|
|
140
177
|
setSortDirection: setSortDirection,
|
|
141
178
|
sortAttribute: sortAttribute,
|
|
@@ -176,14 +213,27 @@ export var AddSelectColumn = function AddSelectColumn(_ref) {
|
|
|
176
213
|
})), /*#__PURE__*/React.createElement(AddSelectList, _extends({}, props, {
|
|
177
214
|
filteredItems: colItems,
|
|
178
215
|
setMultiSelection: setMultiSelection,
|
|
179
|
-
multiSelection: multiSelection
|
|
180
|
-
|
|
216
|
+
multiSelection: multiSelection,
|
|
217
|
+
setParentSelected: parentSelectionHandler
|
|
218
|
+
}))), selectedItem && itemInPath && /*#__PURE__*/React.createElement(AddSelectColumn, _extends({
|
|
219
|
+
columnInputPlaceholder: columnInputPlaceholder,
|
|
220
|
+
header: selectedItem.title,
|
|
221
|
+
items: selectedItem.children,
|
|
222
|
+
multiSelection: multiSelection,
|
|
223
|
+
setMultiSelection: setMultiSelection,
|
|
224
|
+
parentId: selectedItem.id,
|
|
225
|
+
setPath: setPath,
|
|
226
|
+
path: path
|
|
227
|
+
}, props)));
|
|
181
228
|
};
|
|
182
229
|
AddSelectColumn.propTypes = {
|
|
183
230
|
columnInputPlaceholder: PropTypes.string,
|
|
184
|
-
filteredItems: PropTypes.array,
|
|
185
231
|
header: PropTypes.string,
|
|
232
|
+
items: PropTypes.object,
|
|
186
233
|
multiSelection: PropTypes.array,
|
|
187
|
-
|
|
234
|
+
parentId: PropTypes.string,
|
|
235
|
+
path: PropTypes.array,
|
|
236
|
+
setMultiSelection: PropTypes.func,
|
|
237
|
+
setPath: PropTypes.func
|
|
188
238
|
};
|
|
189
239
|
AddSelectColumn.displayName = componentName;
|
|
@@ -17,6 +17,7 @@ import cx from 'classnames';
|
|
|
17
17
|
import PropTypes from 'prop-types';
|
|
18
18
|
import { Filter16 } from '@carbon/icons-react';
|
|
19
19
|
import { pkg } from '../../settings';
|
|
20
|
+
var blockClass = "".concat(pkg.prefix, "--add-select__global-filter");
|
|
20
21
|
var componentName = 'AddSelectFilter';
|
|
21
22
|
export var AddSelectFilter = function AddSelectFilter(_ref) {
|
|
22
23
|
var appliedFilters = _ref.appliedFilters,
|
|
@@ -44,8 +45,6 @@ export var AddSelectFilter = function AddSelectFilter(_ref) {
|
|
|
44
45
|
open = _useState4[0],
|
|
45
46
|
setOpen = _useState4[1];
|
|
46
47
|
|
|
47
|
-
var blockClass = "".concat(pkg.prefix, "--add-select__global-filter");
|
|
48
|
-
|
|
49
48
|
var searchHandler = function searchHandler(e) {
|
|
50
49
|
handleSearch(e.target.value);
|
|
51
50
|
};
|