@geotab/zenith 1.18.0 → 1.19.0-beta.1
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/README.md +7 -0
- package/dist/dropdown/dropdown.d.ts +27 -9
- package/dist/dropdown/dropdown.js +105 -42
- package/dist/dropdown/dropdownHelper.d.ts +4 -3
- package/dist/dropdown/dropdownHelper.js +16 -7
- package/dist/dropdown/dropdownSearchableTrigger.js +2 -1
- package/dist/dropdown/stateReducer/stateAction.d.ts +19 -3
- package/dist/dropdown/stateReducer/stateActionType.d.ts +4 -1
- package/dist/dropdown/stateReducer/stateActionType.js +3 -0
- package/dist/dropdown/stateReducer/stateReducer.d.ts +11 -3
- package/dist/dropdown/stateReducer/stateReducer.js +70 -15
- package/dist/filterButton/filterButton.js +2 -1
- package/dist/filtersBar/components/filtersBarDropdown/filtersBarDropdown.d.ts +13 -2
- package/dist/filtersBar/components/filtersBarDropdown/filtersBarDropdown.js +34 -9
- package/dist/filtersBar/filtersBar.d.ts +2 -2
- package/dist/filtersBar/filtersBarInterfaces.d.ts +3 -2
- package/dist/groupsFilter/groupsFilter.js +9 -2
- package/dist/groupsFilter/groupsFilterTrigger.js +1 -1
- package/dist/icons/iconCalendar2.d.ts +4 -0
- package/dist/icons/iconCalendar2.js +4 -0
- package/dist/icons/iconClock2.js +1 -1
- package/dist/icons/iconCornerUpLeft.d.ts +4 -0
- package/dist/icons/iconCornerUpLeft.js +17 -0
- package/dist/icons/iconCornerUpRight2.d.ts +4 -0
- package/dist/icons/iconCornerUpRight2.js +4 -0
- package/dist/icons/iconCup.d.ts +3 -0
- package/dist/icons/iconCup.js +3 -0
- package/dist/icons/iconDriver.js +1 -1
- package/dist/icons/iconImac2.d.ts +4 -0
- package/dist/icons/iconImac2.js +4 -0
- package/dist/icons/iconInbox2.d.ts +4 -0
- package/dist/icons/iconInbox2.js +4 -0
- package/dist/icons/iconLab.d.ts +4 -0
- package/dist/icons/iconLab.js +4 -0
- package/dist/icons/iconMenuCircle2.d.ts +4 -0
- package/dist/icons/iconMenuCircle2.js +4 -0
- package/dist/icons/iconShare2.d.ts +4 -0
- package/dist/icons/iconShare2.js +4 -0
- package/dist/icons/iconVolumeOf.d.ts +4 -0
- package/dist/icons/iconVolumeOf.js +4 -0
- package/dist/icons/iconVolumeOn.d.ts +4 -0
- package/dist/icons/iconVolumeOn.js +17 -0
- package/dist/index.css +9 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +14 -9
- package/dist/textareaRaw/textareaRaw.d.ts +2 -0
- package/dist/textareaRaw/textareaRaw.js +3 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -40,6 +40,13 @@ Zenith library provides components defined in Zenith Design System. It includes
|
|
|
40
40
|
|
|
41
41
|
## Change log
|
|
42
42
|
|
|
43
|
+
## 1.19.0
|
|
44
|
+
|
|
45
|
+
* New interface for dropdown component. For flat data displayed in dropdowns, you can now specify that all items in the dataset are considered selected
|
|
46
|
+
* New properties available in textarea component: 'resize' and 'readOnly'
|
|
47
|
+
* Show selection in GroupsFilter
|
|
48
|
+
* Audit: iconography
|
|
49
|
+
|
|
43
50
|
## 1.18.0
|
|
44
51
|
|
|
45
52
|
* New component `GridLayout`
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "./dropdown.less";
|
|
3
|
-
import { IZenComponentProps } from "../commonHelpers/zenComponent";
|
|
4
3
|
import { IEntityWithId } from "../commonHelpers/entity";
|
|
5
4
|
import { IColor } from "../groupsFilter/groupsFilterInterfaces";
|
|
6
5
|
import { TFilterButton } from "../filterButton/filterButton";
|
|
@@ -16,17 +15,16 @@ export interface IDropdownItem extends IEntityWithId {
|
|
|
16
15
|
color?: IColor;
|
|
17
16
|
disabled?: boolean;
|
|
18
17
|
}
|
|
19
|
-
|
|
18
|
+
interface IDropdownBase {
|
|
20
19
|
/**
|
|
21
20
|
* @deprecated
|
|
22
21
|
* @param translate - will be removed in the next major release
|
|
23
22
|
*/
|
|
24
23
|
translate?: (s: string) => string;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
className?: string;
|
|
25
|
+
dataItems?: IDropdownItem[];
|
|
27
26
|
getData?: (signal?: AbortSignal, searchValue?: string) => Promise<IDropdownItem[]>;
|
|
28
27
|
errorHandler: (e: Error) => void;
|
|
29
|
-
dataItems?: IDropdownItem[];
|
|
30
28
|
getNamedItems?: (fn: (items: string[]) => ISelectionItem[]) => void;
|
|
31
29
|
getSelectedItem?: (id: string) => IDropdownItem | undefined | Promise<IDropdownItem | undefined>;
|
|
32
30
|
placeholder?: string;
|
|
@@ -41,10 +39,7 @@ export interface IDropdown extends IZenComponentProps {
|
|
|
41
39
|
showSelection?: boolean;
|
|
42
40
|
searchField?: boolean;
|
|
43
41
|
fullWidthTriggerButton?: boolean;
|
|
44
|
-
multiselect?: boolean;
|
|
45
|
-
selectAllButton?: boolean;
|
|
46
42
|
hasApplyButton?: boolean;
|
|
47
|
-
defaultValue?: string[];
|
|
48
43
|
listLimit?: number;
|
|
49
44
|
forceSelection?: boolean;
|
|
50
45
|
buttonType?: TFilterButton;
|
|
@@ -54,5 +49,28 @@ export interface IDropdown extends IZenComponentProps {
|
|
|
54
49
|
error?: string;
|
|
55
50
|
sortFn?: (a: IDropdownItem, b: IDropdownItem) => number;
|
|
56
51
|
}
|
|
57
|
-
export
|
|
52
|
+
export interface IDropdownValueFullSelection {
|
|
53
|
+
selected: string[];
|
|
54
|
+
isAllSelected: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface IDropdownFullSelectedValue {
|
|
57
|
+
selected: ISelectionItem[];
|
|
58
|
+
isAllSelected: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface IDropdownFullSelection extends IDropdownBase {
|
|
61
|
+
multiselect: true;
|
|
62
|
+
selectAllButton: true;
|
|
63
|
+
value: IDropdownValueFullSelection;
|
|
64
|
+
onChange: (selected: IDropdownFullSelectedValue) => void;
|
|
65
|
+
defaultValue?: IDropdownValueFullSelection;
|
|
66
|
+
}
|
|
67
|
+
export interface IDropdown extends IDropdownBase {
|
|
68
|
+
value: string[];
|
|
69
|
+
onChange: (selected: ISelectionItem[]) => void;
|
|
70
|
+
multiselect?: boolean;
|
|
71
|
+
selectAllButton?: boolean;
|
|
72
|
+
defaultValue?: string[];
|
|
73
|
+
}
|
|
74
|
+
export declare const Dropdown: React.FC<IDropdown | IDropdownFullSelection>;
|
|
58
75
|
export declare const TRANSLATIONS: string[];
|
|
76
|
+
export {};
|
|
@@ -20,19 +20,22 @@ const useMobile_1 = require("../commonHelpers/hooks/useMobile");
|
|
|
20
20
|
const useDebounce_1 = require("../commonHelpers/hooks/useDebounce");
|
|
21
21
|
const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems, onChange, value, defaultValue, placeholder, dialogAriaLabel, width, isLoading, title, triggerAriaLabel, disabled, inputId, filterName, showCounterPill = true, showSelection, fullWidthTriggerButton, hasApplyButton, searchField = true, multiselect = true, forceSelection = false, selectAllButton = true, getNamedItems, getSelectedItem, buttonType = "secondary", listLimit = 500, alignment = "bottom-left", error, sortFn }) => {
|
|
22
22
|
var _a;
|
|
23
|
-
const
|
|
23
|
+
const isFullSelectionMode = (0, react_1.useMemo)(() => !Array.isArray(value), [value]);
|
|
24
|
+
const [state, dispatchState] = (0, react_1.useReducer)(stateReducer_1.stateReducer, (0, stateReducer_1.getInitialState)(isFullSelectionMode, dataItems || [], isFullSelectionMode ? value.selected : value, defaultValue ? (isFullSelectionMode ? defaultValue.selected : defaultValue) : undefined, isFullSelectionMode ? value.isAllSelected : undefined, defaultValue ? (isFullSelectionMode ? defaultValue.isAllSelected : undefined) : undefined));
|
|
24
25
|
const isMobile = (0, useMobile_1.useMobile)();
|
|
25
26
|
const abortToken = (0, react_1.useRef)(new AbortController());
|
|
26
27
|
const triggerRef = (0, react_1.useRef)(null);
|
|
27
28
|
const comboboxRef = (0, react_1.useRef)(null);
|
|
28
29
|
const inputRef = (0, react_1.useRef)(null);
|
|
29
30
|
const contentRef = (0, react_1.useRef)(null);
|
|
30
|
-
const prevSelectedIds = (0, react_1.useRef)([]);
|
|
31
|
-
const prevSelection = (0, react_1.useRef)([]);
|
|
31
|
+
const prevSelectedIds = (0, react_1.useRef)({ selected: [], isAllSelected: undefined });
|
|
32
|
+
const prevSelection = (0, react_1.useRef)({ selected: [], isAllSelected: undefined });
|
|
32
33
|
const { translate } = (0, useLanguage_1.useLanguage)();
|
|
33
34
|
const getNamedItemsHasBeenCalled = (0, react_1.useRef)(false);
|
|
34
35
|
const selectedItemsLoader = (0, react_1.useRef)(undefined);
|
|
35
36
|
const previousMapDataItems = (0, react_1.useRef)(!getData && (dataItems === null || dataItems === void 0 ? void 0 : dataItems.length) ? dataItems : []);
|
|
37
|
+
const currentAllSelected = (0, react_1.useMemo)(() => (state.isNestedList || !multiselect || !isFullSelectionMode)
|
|
38
|
+
? undefined : state.isAllSelected, [state.isNestedList, state.isAllSelected, multiselect, isFullSelectionMode]);
|
|
36
39
|
(0, react_1.useEffect)(() => {
|
|
37
40
|
const timeoutId = setTimeout(() => {
|
|
38
41
|
if (Object.keys(state.groupsMap).length === 0 && getData) {
|
|
@@ -55,11 +58,16 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
55
58
|
return () => clearTimeout(timeoutId);
|
|
56
59
|
}, [dataItems, getData, state.groupsMap]);
|
|
57
60
|
(0, react_1.useEffect)(() => {
|
|
58
|
-
|
|
61
|
+
const defaultSelectedValue = defaultValue ? (isFullSelectionMode ? defaultValue.selected : defaultValue) : [];
|
|
62
|
+
const defaultAllSelectedValue = defaultValue ? (isFullSelectionMode ? defaultValue.isAllSelected : undefined)
|
|
63
|
+
: (isFullSelectionMode ? false : undefined);
|
|
64
|
+
if ((0, dropdownHelper_1.compareStringsArrays)(defaultSelectedValue, state.defaultValue) && defaultAllSelectedValue === state.defaultValueIsAllSelected) {
|
|
59
65
|
return;
|
|
60
66
|
}
|
|
61
|
-
dispatchState({ type: stateActionType_1.StateActionType.SetDefaultValue, payload:
|
|
62
|
-
|
|
67
|
+
dispatchState({ type: stateActionType_1.StateActionType.SetDefaultValue, payload: defaultSelectedValue });
|
|
68
|
+
isFullSelectionMode && defaultAllSelectedValue !== state.defaultValueIsAllSelected
|
|
69
|
+
&& dispatchState({ type: stateActionType_1.StateActionType.SetDefaultAllSelected, payload: defaultAllSelectedValue });
|
|
70
|
+
}, [defaultValue, isFullSelectionMode, state.defaultValue, state.defaultValueIsAllSelected]);
|
|
63
71
|
const loadSelectedItems = (0, react_1.useCallback)((ids) => {
|
|
64
72
|
if (!getSelectedItem || !ids.size) {
|
|
65
73
|
return;
|
|
@@ -102,13 +110,17 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
102
110
|
dispatchState({ type: stateActionType_1.StateActionType.SetCurrentId, payload: newCurrentId === groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID || state.inputValue ? undefined : newCurrentId });
|
|
103
111
|
}, [state.currentId, state.groupsMap, state.inputValue]);
|
|
104
112
|
const handleSelect = (0, react_1.useCallback)((val) => {
|
|
113
|
+
if (isFullSelectionMode && state.isAllSelected) {
|
|
114
|
+
dispatchState({ type: stateActionType_1.StateActionType.DeselectItemsFromAllSelected, payload: val.id });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
105
117
|
if (val.partial) {
|
|
106
118
|
dispatchState({ type: stateActionType_1.StateActionType.DeselectAllChildren, payload: val.id });
|
|
107
119
|
}
|
|
108
120
|
else {
|
|
109
121
|
dispatchState({ type: stateActionType_1.StateActionType.ChangeSelection, payload: { value: val.state, itemId: val.id } });
|
|
110
122
|
}
|
|
111
|
-
}, []);
|
|
123
|
+
}, [isFullSelectionMode, state.isAllSelected]);
|
|
112
124
|
const handleClose = (0, react_1.useCallback)(() => {
|
|
113
125
|
dispatchState({ type: stateActionType_1.StateActionType.SetInputValue, payload: "" });
|
|
114
126
|
if (!triggerRef.current) {
|
|
@@ -135,13 +147,21 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
135
147
|
shouldBeClosed && handleEscape();
|
|
136
148
|
shouldBeClosed && dispatchState({ type: stateActionType_1.StateActionType.SetInputValue, payload: "" });
|
|
137
149
|
}, [handleEscape, hasApplyButton, memoizedAllowClosing]);
|
|
138
|
-
const handleSelectAllClick = (0, react_1.useCallback)((
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, [
|
|
150
|
+
const handleSelectAllClick = (0, react_1.useCallback)((isAllSelect) => {
|
|
151
|
+
if (isFullSelectionMode) {
|
|
152
|
+
dispatchState({ type: stateActionType_1.StateActionType.ToggleValueForAllSelected, payload: undefined });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
dispatchState({ type: isAllSelect ? stateActionType_1.StateActionType.DeselectAllChildren : stateActionType_1.StateActionType.SelectAllChildren, payload: state.currentId || groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID });
|
|
156
|
+
}, [isFullSelectionMode, state.currentId]);
|
|
157
|
+
const handleSelectAllInSearch = (0, react_1.useCallback)((isAllSelect) => {
|
|
158
|
+
if (isFullSelectionMode && state.isAllSelected) {
|
|
159
|
+
dispatchState({ type: stateActionType_1.StateActionType.DeselectItemsFromAllSelected, payload: undefined });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
(0, dropdownHelper_1.getDataForChange)((0, dropdownHelper_1.getListDataWithDisabled)(state.listData, state.isNestedList), state.selectedIds, isAllSelect)
|
|
163
|
+
.forEach(el => dispatchState({ type: stateActionType_1.StateActionType.ChangeSelection, payload: { itemId: el.id, value: !isAllSelect } }));
|
|
164
|
+
}, [isFullSelectionMode, state.isAllSelected, state.listData, state.isNestedList, state.selectedIds]);
|
|
145
165
|
const handleClearClick = (0, react_1.useCallback)(() => {
|
|
146
166
|
dispatchState({ type: stateActionType_1.StateActionType.ResetSelection, payload: undefined });
|
|
147
167
|
}, []);
|
|
@@ -154,15 +174,21 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
154
174
|
handleClose();
|
|
155
175
|
}, [handleClose]);
|
|
156
176
|
const handleApplyClick = (0, react_1.useCallback)(() => {
|
|
157
|
-
dispatchState({ type: stateActionType_1.StateActionType.SetGlobalState, payload: state.selectedIds });
|
|
177
|
+
dispatchState({ type: stateActionType_1.StateActionType.SetGlobalState, payload: { selected: state.selectedIds, isAllSelected: state.isAllSelected } });
|
|
158
178
|
dispatchState({ type: stateActionType_1.StateActionType.SetIsOpenCombo, payload: false });
|
|
159
179
|
dispatchState({ type: stateActionType_1.StateActionType.SetCurrentId, payload: undefined });
|
|
160
180
|
abortToken.current.abort();
|
|
161
181
|
abortToken.current = new AbortController();
|
|
162
182
|
handleClose();
|
|
163
183
|
dispatchState({ type: stateActionType_1.StateActionType.SetDataProblem, payload: (0, dropdownHelper_1.checkIsDataProblem)(state.selectedIds, state.groupsMap) });
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
const preparedItems = (0, dropdownHelper_1.prepareSelectedIdsToItems)(state.selectedIds, state.groupsMap, state.groupsMapSelected);
|
|
185
|
+
if (isFullSelectionMode) {
|
|
186
|
+
onChange({ selected: preparedItems, isAllSelected: state.isAllSelected || false });
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
onChange(preparedItems);
|
|
190
|
+
}
|
|
191
|
+
}, [state.selectedIds, state.groupsMap, state.groupsMapSelected, state.isAllSelected, handleClose, onChange, isFullSelectionMode]);
|
|
166
192
|
const customGetData = (0, react_1.useCallback)((str) => (str && dataItems
|
|
167
193
|
? Promise.resolve(dataItems.filter(el => { var _a; return (((_a = el.name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) || "").indexOf(str.toLocaleLowerCase()) > -1; }))
|
|
168
194
|
: Promise.resolve(dataItems || [])), [dataItems]);
|
|
@@ -189,27 +215,39 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
189
215
|
if (hasApplyButton) {
|
|
190
216
|
return;
|
|
191
217
|
}
|
|
192
|
-
if ((0, dropdownHelper_1.compareStringsArrays)(prevSelectedIds.current, state.selectedIds)) {
|
|
218
|
+
if ((0, dropdownHelper_1.compareStringsArrays)(prevSelectedIds.current.selected, state.selectedIds) && prevSelectedIds.current.isAllSelected === state.isAllSelected) {
|
|
193
219
|
return;
|
|
194
220
|
}
|
|
195
|
-
prevSelectedIds.current = state.selectedIds;
|
|
196
|
-
if ((0, dropdownHelper_1.compareStringsArrays)(state.selectedIds, value)
|
|
221
|
+
prevSelectedIds.current = { selected: state.selectedIds, isAllSelected: state.isAllSelected };
|
|
222
|
+
if ((0, dropdownHelper_1.compareStringsArrays)(state.selectedIds, isFullSelectionMode ? value.selected : value)
|
|
223
|
+
&& state.isAllSelected === (isFullSelectionMode ? value.isAllSelected : undefined)) {
|
|
197
224
|
return;
|
|
198
225
|
}
|
|
199
226
|
dispatchState({ type: stateActionType_1.StateActionType.SetDataProblem, payload: (0, dropdownHelper_1.checkIsDataProblem)(state.selectedIds, state.groupsMap) });
|
|
200
|
-
|
|
201
|
-
|
|
227
|
+
const preparedItems = (0, dropdownHelper_1.prepareSelectedIdsToItems)(state.selectedIds, state.groupsMap, state.groupsMapSelected);
|
|
228
|
+
if (isFullSelectionMode) {
|
|
229
|
+
onChange({ selected: preparedItems, isAllSelected: state.isAllSelected || false });
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
onChange(preparedItems);
|
|
233
|
+
}
|
|
234
|
+
}, [onChange, value, state.selectedIds, state.groupsMapSelected, state.groupsMap, hasApplyButton, state.isAllSelected, isFullSelectionMode]);
|
|
202
235
|
(0, react_1.useEffect)(() => {
|
|
203
|
-
|
|
236
|
+
const selectedValue = isFullSelectionMode ? value.selected : value;
|
|
237
|
+
const isAllSelectedValue = isFullSelectionMode ? value.isAllSelected : undefined;
|
|
238
|
+
if ((0, dropdownHelper_1.compareStringsArrays)(prevSelection.current.selected, selectedValue) && isAllSelectedValue === prevSelection.current.isAllSelected) {
|
|
204
239
|
return;
|
|
205
240
|
}
|
|
206
|
-
prevSelection.current =
|
|
207
|
-
if ((0, dropdownHelper_1.compareStringsArrays)(hasApplyButton ? state.globalSelectedIds : state.selectedIds,
|
|
241
|
+
prevSelection.current = { selected: selectedValue, isAllSelected: isAllSelectedValue };
|
|
242
|
+
if ((0, dropdownHelper_1.compareStringsArrays)(hasApplyButton ? state.globalSelectedIds : state.selectedIds, selectedValue)
|
|
243
|
+
&& isAllSelectedValue === (hasApplyButton ? state.globalIsAllSelected : state.isAllSelected)) {
|
|
208
244
|
return;
|
|
209
245
|
}
|
|
210
|
-
hasApplyButton && dispatchState({ type: stateActionType_1.StateActionType.SetGlobalState,
|
|
211
|
-
|
|
212
|
-
|
|
246
|
+
hasApplyButton && dispatchState({ type: stateActionType_1.StateActionType.SetGlobalState,
|
|
247
|
+
payload: { selected: selectedValue, isAllSelected: isAllSelectedValue } });
|
|
248
|
+
dispatchState({ type: stateActionType_1.StateActionType.SetState,
|
|
249
|
+
payload: { selected: selectedValue, isAllSelected: isAllSelectedValue } });
|
|
250
|
+
}, [value, state.selectedIds, state.globalSelectedIds, hasApplyButton, isFullSelectionMode, state.isAllSelected, state.globalIsAllSelected]);
|
|
213
251
|
(0, useEscape_1.useEscape)(triggerRef, handleEscape, state.isOpenCombo);
|
|
214
252
|
const onSearchChange = (0, react_1.useCallback)((event) => {
|
|
215
253
|
const newValue = event ? event.currentTarget.value : "";
|
|
@@ -272,14 +310,38 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
272
310
|
return () => clearTimeout(timeoutId);
|
|
273
311
|
}, [getNamedItems, state.groupsMap, state.groupsMapSelected]);
|
|
274
312
|
(0, react_1.useEffect)(() => {
|
|
275
|
-
if (state.hasDataProblem && multiselect) {
|
|
313
|
+
if (state.hasDataProblem && multiselect && state.isNestedList) {
|
|
276
314
|
// eslint-disable-next-line max-len
|
|
277
315
|
console.error("The data retrieved using the getData function could not form a valid object for displaying nested data. The currently displayed data contains nested elements. It is expected that selecting a nested item should deselect its parent, which cannot be achieved with the formed object.");
|
|
278
316
|
}
|
|
279
|
-
}, [state.hasDataProblem, multiselect]);
|
|
317
|
+
}, [state.hasDataProblem, multiselect, state.isNestedList]);
|
|
318
|
+
(0, react_1.useEffect)(() => {
|
|
319
|
+
if (state.isNestedList && isFullSelectionMode) {
|
|
320
|
+
// eslint-disable-next-line max-len
|
|
321
|
+
console.error("The IDropdownFullSelection interface is not designed to handle nested data. The IDropdownFullSelection interface is intended for use with flat data. If you need to use it with nested data, please use the IDropdown interface instead.");
|
|
322
|
+
}
|
|
323
|
+
}, [state.isNestedList, isFullSelectionMode]);
|
|
280
324
|
const memoizedWithFooter = (0, react_1.useMemo)(() => !(forceSelection && !state.defaultValue.length && !hasApplyButton), [forceSelection, hasApplyButton, state.defaultValue.length]);
|
|
281
|
-
const memoizedIsClearButtonDisabled = (0, react_1.useMemo)(() =>
|
|
282
|
-
|
|
325
|
+
const memoizedIsClearButtonDisabled = (0, react_1.useMemo)(() => {
|
|
326
|
+
if (forceSelection && !multiselect && !state.defaultValue.length) {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
const isStringsTheSame = (0, dropdownHelper_1.compareStringsArrays)(state.selectedIds, state.defaultValue);
|
|
330
|
+
if (currentAllSelected !== undefined && state.defaultValueIsAllSelected !== undefined && state.defaultValueIsAllSelected) {
|
|
331
|
+
return currentAllSelected === state.defaultValueIsAllSelected;
|
|
332
|
+
}
|
|
333
|
+
return isStringsTheSame;
|
|
334
|
+
}, [currentAllSelected, forceSelection, multiselect, state.defaultValue, state.defaultValueIsAllSelected, state.selectedIds]);
|
|
335
|
+
const memoizedIsApplyButtonDisabled = (0, react_1.useMemo)(() => (0, dropdownHelper_1.compareStringsArrays)(state.globalSelectedIds, state.selectedIds)
|
|
336
|
+
&& (isFullSelectionMode ? state.globalIsAllSelected === state.isAllSelected : true), [isFullSelectionMode, state.globalIsAllSelected, state.globalSelectedIds, state.isAllSelected, state.selectedIds]);
|
|
337
|
+
const countSelected = (0, react_1.useMemo)(() => {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
if (hasApplyButton && state.globalIsAllSelected || !hasApplyButton && state.isAllSelected) {
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
341
|
+
return ((_b = (_a = state.groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
342
|
+
}
|
|
343
|
+
return (0, dropdownHelper_1.getSelectedCount)(hasApplyButton ? state.globalSelectedIds : state.selectedIds);
|
|
344
|
+
}, [hasApplyButton, state.globalIsAllSelected, state.globalSelectedIds, state.groupsMap, state.isAllSelected, state.selectedIds]);
|
|
283
345
|
// eslint-disable-next-line complexity
|
|
284
346
|
const getPopupContent = (0, react_1.useMemo)(() => {
|
|
285
347
|
var _a, _b, _c;
|
|
@@ -301,27 +363,28 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
301
363
|
const isSearchMode = state.inputValue && !state.currentId;
|
|
302
364
|
const currentListData = (0, dropdownHelper_1.createListDataOptions)(state, translate, isSearchMode ? (0, dropdownHelper_1.sortDropdownItemArray)(state.listData, sortFn).slice(0, listLimit).filter(el => el.id !== groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID)
|
|
303
365
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
304
|
-
: (0, dropdownHelper_1.sortDropdownItemArray)(((_b = state.groupsMap[state.currentId || groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _b === void 0 ? void 0 : _b.children) || [], sortFn).slice(0, listLimit) || [], multiselect);
|
|
366
|
+
: (0, dropdownHelper_1.sortDropdownItemArray)(((_b = state.groupsMap[state.currentId || groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _b === void 0 ? void 0 : _b.children) || [], sortFn).slice(0, listLimit) || [], multiselect, currentAllSelected);
|
|
305
367
|
return (0, jsx_runtime_1.jsx)(dropdownList_1.DropdownList, { onBackButtonClick: handleBackButtonClick, onSelectAllClick: isSearchMode ? handleSelectAllInSearch : handleSelectAllClick, onClearClick: handleClearClick, onCancelClick: handleCancelClick, onApplyClick: handleApplyClick, onChange: handleSelect, onSelect: handleChangeCurrentId, onSingleSelect: handleSingleSelection, activeValue: state.selectedIds.length ? state.selectedIds[0] : "root",
|
|
306
368
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
307
|
-
backButtonName: state.currentId ? (0, groupsHelper_1.getGroupDescription)(state.groupsMap[state.currentId], translate) : undefined, filterName: isMobile ? undefined : filterName, isAllSelected: isSearchMode ? (0, dropdownHelper_1.isEveryItemSelected)((0, dropdownHelper_1.getListDataWithDisabled)(state.listData, state.
|
|
308
|
-
: (0, dropdownHelper_1.isAllChildrenSelected)(state, state.currentId || groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID), isMultiselect: multiselect, forceSelection: forceSelection,
|
|
369
|
+
backButtonName: state.currentId ? (0, groupsHelper_1.getGroupDescription)(state.groupsMap[state.currentId], translate) : undefined, filterName: isMobile ? undefined : filterName, isAllSelected: currentAllSelected ? currentAllSelected : (isSearchMode ? (0, dropdownHelper_1.isEveryItemSelected)((0, dropdownHelper_1.getListDataWithDisabled)(state.listData, state.isNestedList), state.selectedIds)
|
|
370
|
+
: (currentAllSelected === undefined ? (0, dropdownHelper_1.isAllChildrenSelected)(state, state.currentId || groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID) : false)), isMultiselect: multiselect, forceSelection: forceSelection,
|
|
309
371
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
310
372
|
listData: currentListData, width: width || currentWidth === 180 ? undefined : currentWidth, minWidth: currentWidth, hasSelectAllButton: selectAllButton && multiselect, hasApplyButton: hasApplyButton, isApplyDisabled: memoizedIsApplyButtonDisabled, isSelectAllButtonDisable: currentListData.length === 0
|
|
311
|
-
|| isSearchMode !== ""
|
|
373
|
+
|| isSearchMode !== "" && state.isNestedList
|
|
312
374
|
&& (0, dropdownHelper_1.isAllItemsHasOneParent)(state.listData.filter(el => el.id !== groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID),
|
|
313
375
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
314
376
|
(((_c = state.groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _c === void 0 ? void 0 : _c.children) || []).map(el => el.id)), isClearButtonDisabled: memoizedIsClearButtonDisabled, isWithFooter: memoizedWithFooter && !isMobile, isMobile: isMobile });
|
|
315
377
|
}
|
|
316
378
|
return null;
|
|
317
|
-
}, [state, isLoading, translate, handleClearClick, handleCancelClick, handleApplyClick, hasApplyButton, sortFn,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
379
|
+
}, [state, isLoading, translate, handleClearClick, handleCancelClick, handleApplyClick, hasApplyButton, sortFn, listLimit, multiselect, handleBackButtonClick,
|
|
380
|
+
handleSelectAllInSearch, handleSelectAllClick, handleSelect, handleChangeCurrentId, handleSingleSelection, isMobile, filterName, forceSelection, width, selectAllButton,
|
|
381
|
+
memoizedIsApplyButtonDisabled, memoizedIsClearButtonDisabled, memoizedWithFooter, currentAllSelected]);
|
|
382
|
+
const currentStringFromSelected = isFullSelectionMode && hasApplyButton && state.globalIsAllSelected ||
|
|
383
|
+
isFullSelectionMode && !hasApplyButton && state.isAllSelected ? (0, dropdownHelper_1.getStringFromAllSelected)(state.groupsMap, translate)
|
|
384
|
+
: (0, dropdownHelper_1.getStringFromSelected)(hasApplyButton ? state.globalSelectedIds : state.selectedIds, state.groupsMapSelected, translate);
|
|
322
385
|
const memoizedCurrentSelection = (0, react_1.useMemo)(() => showSelection && !state.inputValue ? currentStringFromSelected : "", [showSelection, state.inputValue, currentStringFromSelected]);
|
|
323
386
|
const parentTriggerWidth = ((_a = comboboxRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 420;
|
|
324
|
-
return (0, jsx_runtime_1.jsxs)("div", { className: containerClassName, ref: comboboxRef, children: [(0, jsx_runtime_1.jsx)(dropdownTrigger_1.DropdownTrigger, { className: (0, classNames_1.classNames)([!width && !fullWidthTriggerButton && parentTriggerWidth < 420 && !searchField ? "zen-dropdown__trigger-button--width-parent" : ""]), currentSelection: memoizedCurrentSelection, isActive: state.isOpenCombo, id: inputId, disabled: disabled, count: showCounterPill ?
|
|
387
|
+
return (0, jsx_runtime_1.jsxs)("div", { className: containerClassName, ref: comboboxRef, children: [(0, jsx_runtime_1.jsx)(dropdownTrigger_1.DropdownTrigger, { className: (0, classNames_1.classNames)([!width && !fullWidthTriggerButton && parentTriggerWidth < 420 && !searchField ? "zen-dropdown__trigger-button--width-parent" : ""]), currentSelection: memoizedCurrentSelection, isActive: state.isOpenCombo, id: inputId, disabled: disabled, count: showCounterPill ? countSelected : 0, fullWidth: fullWidthTriggerButton, inputValue: state.inputValue, placeholder: placeholder || translate("Filter by group"), searchField: searchField && !isMobile ? searchField : false, onSearchChange: onSearchChange, handleClick: handleTriggerClick, width: width && width > 420 ? 420 : width, title: title, triggerAriaLabel: triggerAriaLabel, triggerRef: triggerRef, inputRef: inputRef, buttonType: buttonType, error: error }), (0, jsx_runtime_1.jsx)(dropdownPopup_1.DropdownPopup, { alignment: alignment, triggerRef: triggerRef, classNamePopup: classNamePopup, isMobile: isMobile, dialogAriaLabel: dialogAriaLabel, disabled: disabled, filterName: filterName, hasApplyButton: hasApplyButton, inputId: inputId, isClearButtonDisabled: memoizedIsClearButtonDisabled, isApplyButtonDisabled: memoizedIsApplyButtonDisabled, isWithFooter: memoizedWithFooter, isOpenCombo: state.isOpenCombo, searchField: searchField, placeholder: placeholder, inputValue: state.inputValue, handleApplyClick: handleApplyClick, handleClearClick: multiselect ? handleClearClick : handleSingleSelection.bind(this, true), handleTriggerClick: handleTriggerClick, onInputChange: onInputChange, inputRef: inputRef, contentRef: contentRef, children: getPopupContent })] });
|
|
325
388
|
};
|
|
326
389
|
exports.Dropdown = Dropdown;
|
|
327
390
|
exports.TRANSLATIONS = [
|
|
@@ -8,8 +8,8 @@ export declare const isAllChildrenSelected: (stateObj: IDropdownState, currentId
|
|
|
8
8
|
export declare const isEveryItemSelected: (listData: IDropdownItem[], selectedItems: string[]) => boolean;
|
|
9
9
|
export declare const getDataForChange: (listData: IDropdownItem[], selectedItems: string[], isDeselect: boolean) => IDropdownItem[];
|
|
10
10
|
export declare const isAllItemsHasOneParent: (listData: IDropdownItem[], childrenArr: string[]) => boolean;
|
|
11
|
-
export declare function prepareComboOptionsForList(actionListData: Set<string>, translate: (s: string) => string, options: IDropdownItem[], getSelectedFn: () => string[], getSelectedChildFn: (optionId: any) => string[],
|
|
12
|
-
export declare const createOptions: (stateObj: IDropdownState, translate: (s: string) => string, listItem: IDropdownItem[]) => ICheckboxListWithActionOption[];
|
|
11
|
+
export declare function prepareComboOptionsForList(actionListData: Set<string>, translate: (s: string) => string, options: IDropdownItem[], getSelectedFn: () => string[], getSelectedChildFn: (optionId: any) => string[], isFlatList: boolean, getTitle?: (itemId: string) => string, isAllSelected?: boolean): ICheckboxListWithActionOption[];
|
|
12
|
+
export declare const createOptions: (stateObj: IDropdownState, translate: (s: string) => string, listItem: IDropdownItem[], isAllSelected?: boolean) => ICheckboxListWithActionOption[];
|
|
13
13
|
export declare const sortDropdownItemArray: (arr: IDropdownItem[], sortFn?: (a: IDropdownItem, b: IDropdownItem) => number) => IDropdownItem[];
|
|
14
14
|
export declare const createSingleListOptions: (stateObj: IDropdownState, translate: (s: string) => string, listItem: IDropdownItem[]) => {
|
|
15
15
|
id: string;
|
|
@@ -17,7 +17,7 @@ export declare const createSingleListOptions: (stateObj: IDropdownState, transla
|
|
|
17
17
|
disabled: boolean | undefined;
|
|
18
18
|
multiLevel: boolean | undefined;
|
|
19
19
|
}[];
|
|
20
|
-
export declare const createListDataOptions: (stateObj: IDropdownState, translate: (s: string) => string, listItem: IDropdownItem[], isMultiselect: boolean) => ICheckboxListWithActionOption[] | {
|
|
20
|
+
export declare const createListDataOptions: (stateObj: IDropdownState, translate: (s: string) => string, listItem: IDropdownItem[], isMultiselect: boolean, isAllSelected?: boolean) => ICheckboxListWithActionOption[] | {
|
|
21
21
|
id: string;
|
|
22
22
|
children: string;
|
|
23
23
|
disabled: boolean | undefined;
|
|
@@ -28,4 +28,5 @@ export declare const compareObjectsArrays: (arr1: IDropdownItem[], arr2: IDropdo
|
|
|
28
28
|
export declare const prepareSelectedIdsToItems: (selectedIds: string[], groupsMap: ITypedHash<IGroupTree>, groupsMapSelected: Map<string, IDropdownItem>) => IDropdownItem[];
|
|
29
29
|
export declare const checkIsDataProblem: (selectedIds: string[], groupsMap: ITypedHash<IGroupTree>) => boolean;
|
|
30
30
|
export declare const getStringFromSelected: (selectedIds: string[], groupsMapSelected: Map<string, IDropdownItem>, translate: (s: string) => string) => string;
|
|
31
|
+
export declare const getStringFromAllSelected: (groupsMap: ITypedHash<IGroupTree>, translate: (s: string) => string) => string;
|
|
31
32
|
export declare const getSelectedCount: (selectedIds: string[]) => number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSelectedCount = exports.getStringFromSelected = exports.checkIsDataProblem = exports.prepareSelectedIdsToItems = exports.compareObjectsArrays = exports.compareStringsArrays = exports.createListDataOptions = exports.createSingleListOptions = exports.sortDropdownItemArray = exports.createOptions = exports.prepareComboOptionsForList = exports.isAllItemsHasOneParent = exports.getDataForChange = exports.isEveryItemSelected = exports.isAllChildrenSelected = exports.getListDataWithDisabled = exports.getGroupsTreeItem = void 0;
|
|
3
|
+
exports.getSelectedCount = exports.getStringFromAllSelected = exports.getStringFromSelected = exports.checkIsDataProblem = exports.prepareSelectedIdsToItems = exports.compareObjectsArrays = exports.compareStringsArrays = exports.createListDataOptions = exports.createSingleListOptions = exports.sortDropdownItemArray = exports.createOptions = exports.prepareComboOptionsForList = exports.isAllItemsHasOneParent = exports.getDataForChange = exports.isEveryItemSelected = exports.isAllChildrenSelected = exports.getListDataWithDisabled = exports.getGroupsTreeItem = void 0;
|
|
4
4
|
const groupsHelper_1 = require("../groupsFilter/groupsHelper");
|
|
5
5
|
const stateReducerHelper_1 = require("./stateReducer/stateReducerHelper");
|
|
6
6
|
const getGroupsTreeItem = (stateObj, itemId) => {
|
|
@@ -16,7 +16,7 @@ const isAllChildrenSelected = (stateObj, currentId) => {
|
|
|
16
16
|
}
|
|
17
17
|
const selectedIds = new Set(stateObj.selectedIds);
|
|
18
18
|
const currentEl = (0, exports.getGroupsTreeItem)(stateObj, currentId);
|
|
19
|
-
return currentEl && currentEl.children && currentEl.children.length ? (0, exports.getListDataWithDisabled)(currentEl.children, stateObj.
|
|
19
|
+
return currentEl && currentEl.children && currentEl.children.length ? (0, exports.getListDataWithDisabled)(currentEl.children, stateObj.isNestedList).every(el => selectedIds.has(el.id)) : false;
|
|
20
20
|
};
|
|
21
21
|
exports.isAllChildrenSelected = isAllChildrenSelected;
|
|
22
22
|
const isEveryItemSelected = (listData, selectedItems) => {
|
|
@@ -43,11 +43,11 @@ const isAllItemsHasOneParent = (listData, childrenArr) => {
|
|
|
43
43
|
return !listData.every(el => childrenArrSet.has(el.id));
|
|
44
44
|
};
|
|
45
45
|
exports.isAllItemsHasOneParent = isAllItemsHasOneParent;
|
|
46
|
-
function prepareComboOptionsForList(actionListData, translate, options, getSelectedFn, getSelectedChildFn,
|
|
46
|
+
function prepareComboOptionsForList(actionListData, translate, options, getSelectedFn, getSelectedChildFn, isFlatList, getTitle, isAllSelected) {
|
|
47
47
|
const selectedIds = new Set(getSelectedFn());
|
|
48
48
|
const preparedOptions = options && options.length ? options.map(option => {
|
|
49
49
|
const selectedChild = getSelectedChildFn(option.id);
|
|
50
|
-
return Object.assign({ label: (0, groupsHelper_1.getGroupDescription)(option, translate), property: option.id, checked: selectedIds.has(option.id), isWithAction: actionListData.has(option.id), partialChecked: selectedChild.length > 0, countSelectedChild: 0, blocked:
|
|
50
|
+
return Object.assign({ label: (0, groupsHelper_1.getGroupDescription)(option, translate), property: option.id, checked: isAllSelected ? true : selectedIds.has(option.id), isWithAction: actionListData.has(option.id), partialChecked: isAllSelected ? false : selectedChild.length > 0, countSelectedChild: 0, blocked: isFlatList ? option.disabled || false : false }, (getTitle ? { title: getTitle(option.id) } : {}));
|
|
51
51
|
}) : [];
|
|
52
52
|
return preparedOptions;
|
|
53
53
|
}
|
|
@@ -63,7 +63,7 @@ const getSelectedChildren = (stateObj, currentId) => {
|
|
|
63
63
|
});
|
|
64
64
|
return selectedChild;
|
|
65
65
|
};
|
|
66
|
-
const createOptions = (stateObj, translate, listItem) => {
|
|
66
|
+
const createOptions = (stateObj, translate, listItem, isAllSelected) => {
|
|
67
67
|
const actionListData = new Set();
|
|
68
68
|
listItem.forEach(el => {
|
|
69
69
|
const elem = stateObj.groupsMap[el.id];
|
|
@@ -71,7 +71,7 @@ const createOptions = (stateObj, translate, listItem) => {
|
|
|
71
71
|
actionListData.add(el.id);
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
-
const preparedOptions = prepareComboOptionsForList(actionListData, translate, listItem, () => stateObj.selectedIds, (id) => getSelectedChildren(stateObj, id), !stateObj.
|
|
74
|
+
const preparedOptions = prepareComboOptionsForList(actionListData, translate, listItem, () => stateObj.selectedIds, (id) => getSelectedChildren(stateObj, id), !stateObj.isNestedList, (id) => stateObj.groupsMap[id] ? (0, groupsHelper_1.getGroupDescription)(stateObj.groupsMap[id], translate) : "", isAllSelected);
|
|
75
75
|
return preparedOptions;
|
|
76
76
|
};
|
|
77
77
|
exports.createOptions = createOptions;
|
|
@@ -92,7 +92,7 @@ const createSingleListOptions = (stateObj, translate, listItem) => {
|
|
|
92
92
|
return preparedOptions;
|
|
93
93
|
};
|
|
94
94
|
exports.createSingleListOptions = createSingleListOptions;
|
|
95
|
-
const createListDataOptions = (stateObj, translate, listItem, isMultiselect) => isMultiselect ? (0, exports.createOptions)(stateObj, translate, listItem) : (0, exports.createSingleListOptions)(stateObj, translate, listItem);
|
|
95
|
+
const createListDataOptions = (stateObj, translate, listItem, isMultiselect, isAllSelected) => isMultiselect ? (0, exports.createOptions)(stateObj, translate, listItem, isAllSelected) : (0, exports.createSingleListOptions)(stateObj, translate, listItem);
|
|
96
96
|
exports.createListDataOptions = createListDataOptions;
|
|
97
97
|
const compareStringsArrays = (arr1, arr2) => {
|
|
98
98
|
if (arr1.length !== arr2.length) {
|
|
@@ -133,5 +133,14 @@ const getStringFromSelected = (selectedIds, groupsMapSelected, translate) => {
|
|
|
133
133
|
return selectedItems.join(", ");
|
|
134
134
|
};
|
|
135
135
|
exports.getStringFromSelected = getStringFromSelected;
|
|
136
|
+
const getStringFromAllSelected = (groupsMap, translate) => {
|
|
137
|
+
var _a;
|
|
138
|
+
if (!((_a = groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _a === void 0 ? void 0 : _a.children) || groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID].children.length === 0) {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
const selectedItems = groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID].children.map(el => groupsMap[el.id] ? (0, groupsHelper_1.getGroupDescription)(groupsMap[el.id], translate) : undefined).filter(el => el);
|
|
142
|
+
return selectedItems.join(", ");
|
|
143
|
+
};
|
|
144
|
+
exports.getStringFromAllSelected = getStringFromAllSelected;
|
|
136
145
|
const getSelectedCount = (selectedIds) => selectedIds.length === 1 && selectedIds[0] === groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID ? 0 : selectedIds.length;
|
|
137
146
|
exports.getSelectedCount = getSelectedCount;
|
|
@@ -51,6 +51,7 @@ exports.DropdownSearchableTrigger = react_1.default.forwardRef((_a, ref) => {
|
|
|
51
51
|
const driveComponentClass = (0, useDriveClassName_1.useDriveClassName)("zen-dropdown-searchable-trigger");
|
|
52
52
|
const isDrive = (0, useDrive_1.useDrive)();
|
|
53
53
|
const inputStyle = width ? { style: { width: `${width}px` } } : {};
|
|
54
|
+
const isLargeNumber = count && count > 99;
|
|
54
55
|
const clearRef = (0, react_1.useRef)(null);
|
|
55
56
|
const handleKeydown = (e) => {
|
|
56
57
|
if (e.key === "Enter" && !isOpenPopup) {
|
|
@@ -67,7 +68,7 @@ exports.DropdownSearchableTrigger = react_1.default.forwardRef((_a, ref) => {
|
|
|
67
68
|
onChange(undefined);
|
|
68
69
|
};
|
|
69
70
|
return (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger", isError ? "zen-dropdown-searchable-trigger--error" : "",
|
|
70
|
-
driveComponentClass || "", disabled ? "zen-dropdown-searchable-trigger--disabled" : ""]) }, inputStyle, { ref: ref }, otherProps, { onClick: disabled ? () => { } : clickHandler, role: "combobox", "aria-label": placeholder, children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__search-container", className]), children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__input-container", onKeyDown: handleKeydown, children: (0, jsx_runtime_1.jsx)(textInputRaw_1.TextInputRaw, { value: value, placeholder: currentSelection ? currentSelection : placeholder || translate("Filter by group"), className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__input", "zen-ellipsis", currentSelection ? "zen-dropdown-searchable-trigger__input--selected" : ""]), onChange: onChange, disabled: disabled, type: "text", ref: inputRef, id: id || triggerId }) }), count ? (0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__label-element", children: (0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__counter", children: (0, jsx_runtime_1.jsx)("span", { children: count }) }) }) : null, value && (0, jsx_runtime_1.jsx)("button", { type: "button", className: "zen-dropdown-searchable-trigger__close-button", ref: clearRef, title: translate("Clear search"), onClick: handleClearSearch, children: (0, jsx_runtime_1.jsx)(iconCrossThin_1.IconCrossThin, { size: isDrive ? "big" : "small" }) })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__popup-trigger", isOpenPopup ? "zen-dropdown-searchable-trigger__popup-trigger--active" : ""]), title: title || translate("Open filter"), children: (0, jsx_runtime_1.jsx)(iconChevronDownSmall_1.IconChevronDownSmall, { className: isOpenPopup ? "zen-dropdown-searchable-trigger__arrow-icon--up" : "zen-dropdown-searchable-trigger__arrow-icon--down", size: isDrive ? "huge" : "large" }) })] }));
|
|
71
|
+
driveComponentClass || "", disabled ? "zen-dropdown-searchable-trigger--disabled" : ""]) }, inputStyle, { ref: ref }, otherProps, { onClick: disabled ? () => { } : clickHandler, role: "combobox", "aria-label": placeholder, children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__search-container", className]), children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__input-container", onKeyDown: handleKeydown, children: (0, jsx_runtime_1.jsx)(textInputRaw_1.TextInputRaw, { value: value, placeholder: currentSelection ? currentSelection : placeholder || translate("Filter by group"), className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__input", "zen-ellipsis", currentSelection ? "zen-dropdown-searchable-trigger__input--selected" : ""]), onChange: onChange, disabled: disabled, type: "text", ref: inputRef, id: id || triggerId }) }), count ? (0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__label-element", children: (0, jsx_runtime_1.jsx)("div", { className: "zen-dropdown-searchable-trigger__counter", children: (0, jsx_runtime_1.jsx)("span", { children: isLargeNumber ? "99+" : count }) }) }) : null, value && (0, jsx_runtime_1.jsx)("button", { type: "button", className: "zen-dropdown-searchable-trigger__close-button", ref: clearRef, title: translate("Clear search"), onClick: handleClearSearch, children: (0, jsx_runtime_1.jsx)(iconCrossThin_1.IconCrossThin, { size: isDrive ? "big" : "small" }) })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: (0, classNames_1.classNames)(["zen-dropdown-searchable-trigger__popup-trigger", isOpenPopup ? "zen-dropdown-searchable-trigger__popup-trigger--active" : ""]), title: title || translate("Open filter"), children: (0, jsx_runtime_1.jsx)(iconChevronDownSmall_1.IconChevronDownSmall, { className: isOpenPopup ? "zen-dropdown-searchable-trigger__arrow-icon--up" : "zen-dropdown-searchable-trigger__arrow-icon--down", size: isDrive ? "huge" : "large" }) })] }));
|
|
71
72
|
});
|
|
72
73
|
exports.DropdownSearchableTrigger.displayName = "DropdownSearchableTrigger";
|
|
73
74
|
exports.TRANSLATIONS = [
|
|
@@ -12,13 +12,17 @@ interface IPayloadSingleSelectionAction {
|
|
|
12
12
|
reset: boolean;
|
|
13
13
|
value: string | undefined;
|
|
14
14
|
}
|
|
15
|
+
interface IStateActionPayload {
|
|
16
|
+
selected: string[];
|
|
17
|
+
isAllSelected?: boolean;
|
|
18
|
+
}
|
|
15
19
|
interface ISetStateAction {
|
|
16
20
|
type: StateActionType.SetState;
|
|
17
|
-
payload:
|
|
21
|
+
payload: IStateActionPayload;
|
|
18
22
|
}
|
|
19
23
|
interface ISetGlobalStateAction {
|
|
20
24
|
type: StateActionType.SetGlobalState;
|
|
21
|
-
payload:
|
|
25
|
+
payload: IStateActionPayload;
|
|
22
26
|
}
|
|
23
27
|
interface ICreateMapAction {
|
|
24
28
|
type: StateActionType.CreateMap;
|
|
@@ -76,6 +80,14 @@ interface IDeselectAllChildrenAction {
|
|
|
76
80
|
type: StateActionType.DeselectAllChildren;
|
|
77
81
|
payload: string;
|
|
78
82
|
}
|
|
83
|
+
interface IDeselectItemsFromAllSelectedAction {
|
|
84
|
+
type: StateActionType.DeselectItemsFromAllSelected;
|
|
85
|
+
payload: string | undefined;
|
|
86
|
+
}
|
|
87
|
+
interface IToggleValueForAllSelectedAction {
|
|
88
|
+
type: StateActionType.ToggleValueForAllSelected;
|
|
89
|
+
payload: undefined;
|
|
90
|
+
}
|
|
79
91
|
interface ISetCurrentIdAction {
|
|
80
92
|
type: StateActionType.SetCurrentId;
|
|
81
93
|
payload: string | undefined;
|
|
@@ -92,6 +104,10 @@ interface ISetDefaultValueAction {
|
|
|
92
104
|
type: StateActionType.SetDefaultValue;
|
|
93
105
|
payload: string[];
|
|
94
106
|
}
|
|
107
|
+
interface ISetDefaultAllSelectedAction {
|
|
108
|
+
type: StateActionType.SetDefaultAllSelected;
|
|
109
|
+
payload: boolean;
|
|
110
|
+
}
|
|
95
111
|
interface IUpdateSelectedItemsAction {
|
|
96
112
|
type: StateActionType.UpdateSelectedItems;
|
|
97
113
|
payload: IDropdownItem[];
|
|
@@ -104,5 +120,5 @@ interface IUpdateNamelessItemsAction {
|
|
|
104
120
|
type: StateActionType.UpdateNamelessItems;
|
|
105
121
|
payload: undefined;
|
|
106
122
|
}
|
|
107
|
-
export type TStateAction = ICreateMapAction | ISetStateAction | ISetGlobalStateAction | ISetListDataAction | ISetIsOpenComboAction | IShowAction | IShowWaitingAction | IShowEmptyListAction | IShowListAction | ISetInputValueAction | INothingToShowAction | ISetCurrentIdAction | IChangeSelectionAction | IChangeSingleSelectionAction | ISelectAllChildrenAction | IDeselectAllChildrenAction | IResetSelection | IResetStateToGlobal | ISetDataProblemAction | ISetDefaultValueAction | IUpdateSelectedItemsAction | ISetPendingStateAction | IUpdateNamelessItemsAction;
|
|
123
|
+
export type TStateAction = ICreateMapAction | ISetStateAction | ISetGlobalStateAction | ISetListDataAction | ISetIsOpenComboAction | IShowAction | IShowWaitingAction | IShowEmptyListAction | IShowListAction | ISetInputValueAction | INothingToShowAction | ISetCurrentIdAction | IChangeSelectionAction | IChangeSingleSelectionAction | ISelectAllChildrenAction | IDeselectAllChildrenAction | IResetSelection | IResetStateToGlobal | ISetDataProblemAction | ISetDefaultValueAction | IUpdateSelectedItemsAction | ISetPendingStateAction | IUpdateNamelessItemsAction | IToggleValueForAllSelectedAction | IDeselectItemsFromAllSelectedAction | ISetDefaultAllSelectedAction;
|
|
108
124
|
export {};
|
|
@@ -21,5 +21,8 @@ export declare enum StateActionType {
|
|
|
21
21
|
SetDataProblem = "SET_DATA_PROBLEM",
|
|
22
22
|
UpdateSelectedItems = "UPDATE_SELECTED_ITEMS",
|
|
23
23
|
SetPendingState = "SET_PENDING_STATE",
|
|
24
|
-
UpdateNamelessItems = "UPDATE_NAMELESS_ITEMS"
|
|
24
|
+
UpdateNamelessItems = "UPDATE_NAMELESS_ITEMS",
|
|
25
|
+
ToggleValueForAllSelected = "TOGGLE_VALUE_FOR_ALL_SELECTED",
|
|
26
|
+
DeselectItemsFromAllSelected = "DESELECT_ITEMS_FROM_ALL_SELECTED",
|
|
27
|
+
SetDefaultAllSelected = "SET_DEFAULT_ALL_SELECTED"
|
|
25
28
|
}
|
|
@@ -26,4 +26,7 @@ var StateActionType;
|
|
|
26
26
|
StateActionType["UpdateSelectedItems"] = "UPDATE_SELECTED_ITEMS";
|
|
27
27
|
StateActionType["SetPendingState"] = "SET_PENDING_STATE";
|
|
28
28
|
StateActionType["UpdateNamelessItems"] = "UPDATE_NAMELESS_ITEMS";
|
|
29
|
+
StateActionType["ToggleValueForAllSelected"] = "TOGGLE_VALUE_FOR_ALL_SELECTED";
|
|
30
|
+
StateActionType["DeselectItemsFromAllSelected"] = "DESELECT_ITEMS_FROM_ALL_SELECTED";
|
|
31
|
+
StateActionType["SetDefaultAllSelected"] = "SET_DEFAULT_ALL_SELECTED";
|
|
29
32
|
})(StateActionType || (exports.StateActionType = StateActionType = {}));
|
|
@@ -15,14 +15,18 @@ export interface IDropdownState {
|
|
|
15
15
|
inputValue: string;
|
|
16
16
|
isOpenCombo: boolean;
|
|
17
17
|
hasDataProblem: boolean;
|
|
18
|
-
isDisableStateProhibited: boolean;
|
|
19
18
|
groupsMapSelected: Map<string, IDropdownItem>;
|
|
20
19
|
namelessIds: Set<string>;
|
|
21
20
|
pendingNamelessIds: boolean;
|
|
21
|
+
isNestedList: boolean;
|
|
22
|
+
isFullSelectionMode: boolean;
|
|
23
|
+
isAllSelected?: boolean;
|
|
24
|
+
globalIsAllSelected?: boolean;
|
|
25
|
+
defaultValueIsAllSelected?: boolean;
|
|
22
26
|
}
|
|
23
27
|
export interface IStateReducer extends Reducer<IDropdownState, TStateAction> {
|
|
24
28
|
}
|
|
25
|
-
export declare const getInitialState: (comboItems: IDropdownItem[], selection
|
|
29
|
+
export declare const getInitialState: (isFullSelectionMode: boolean, comboItems: IDropdownItem[], selection: string[], defaultValue?: string[], isAllSelected?: boolean, defaultValueIsAllSelected?: boolean) => {
|
|
26
30
|
groupsMap: ITypedHash<IGroupTree>;
|
|
27
31
|
selectedIds: string[];
|
|
28
32
|
globalSelectedIds: string[];
|
|
@@ -35,9 +39,13 @@ export declare const getInitialState: (comboItems: IDropdownItem[], selection?:
|
|
|
35
39
|
inputValue: string;
|
|
36
40
|
isOpenCombo: boolean;
|
|
37
41
|
hasDataProblem: boolean;
|
|
38
|
-
isDisableStateProhibited: boolean;
|
|
39
42
|
groupsMapSelected: Map<any, any>;
|
|
40
43
|
namelessIds: Set<string>;
|
|
41
44
|
pendingNamelessIds: boolean;
|
|
45
|
+
isNestedList: boolean;
|
|
46
|
+
isFullSelectionMode: boolean;
|
|
47
|
+
isAllSelected: boolean | undefined;
|
|
48
|
+
globalIsAllSelected: boolean | undefined;
|
|
49
|
+
defaultValueIsAllSelected: boolean | undefined;
|
|
42
50
|
};
|
|
43
51
|
export declare function stateReducer(state: IDropdownState, action: TStateAction): IDropdownState;
|