@synerise/ds-item-picker 2.3.0 → 2.4.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/CHANGELOG.md +24 -0
- package/CLAUDE.md +67 -9
- package/README.md +42 -0
- package/dist/components/ItemPickerList/ItemPickerList.js +40 -8
- package/dist/components/ItemPickerList/ItemPickerList.styles.d.ts +4 -1
- package/dist/components/ItemPickerList/ItemPickerList.styles.js +21 -6
- package/dist/components/ItemPickerList/components/EmptyListMessage.d.ts +3 -2
- package/dist/components/ItemPickerList/components/EmptyListMessage.js +4 -0
- package/dist/components/ItemPickerList/components/ItemPickerListRow.js +1 -1
- package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.d.ts +3 -1
- package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.js +17 -10
- package/dist/components/ItemPickerList/components/ListSearchInput.d.ts +3 -1
- package/dist/components/ItemPickerList/components/ListSearchInput.js +10 -3
- package/dist/components/ItemPickerList/constants.d.ts +2 -0
- package/dist/components/ItemPickerList/constants.js +4 -0
- package/dist/components/ItemPickerList/hooks/index.d.ts +1 -0
- package/dist/components/ItemPickerList/hooks/index.js +2 -0
- package/dist/components/ItemPickerList/hooks/useFolderLevel.d.ts +9 -0
- package/dist/components/ItemPickerList/hooks/useFolderLevel.js +31 -0
- package/dist/components/ItemPickerList/hooks/useItemsInSections.d.ts +5 -0
- package/dist/components/ItemPickerList/hooks/useItemsInSections.js +208 -68
- package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.d.ts +9 -1
- package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.js +33 -1
- package/dist/components/ItemPickerList/types/renderMode.d.ts +1 -0
- package/dist/components/ItemPickerList/types/renderMode.js +2 -1
- package/dist/components/ItemPickerList/utils/actionItemsUtils.js +6 -2
- package/dist/components/ItemPickerList/utils/formatFolderPath.d.ts +4 -0
- package/dist/components/ItemPickerList/utils/formatFolderPath.js +13 -0
- package/dist/components/ItemPickerList/utils/index.d.ts +1 -0
- package/dist/components/ItemPickerList/utils/index.js +5 -1
- package/dist/components/ItemPickerList/utils/typeguards.utils.d.ts +7 -2
- package/dist/components/ItemPickerList/utils/typeguards.utils.js +4 -0
- package/dist/components/ItemPickerNew/ItemPickerNew.js +5 -3
- package/dist/components/ItemPickerNew/ItemPickerNew.types.d.ts +2 -1
- package/dist/components/ItemPickerNew/types/actions.types.d.ts +5 -0
- package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.d.ts +1 -1
- package/dist/components/ItemPickerNew/types/mixedLoader.types.d.ts +52 -0
- package/dist/components/ItemPickerNew/types/mixedLoader.types.js +1 -0
- package/dist/hooks/useDefaultTexts.js +8 -0
- package/dist/index.d.ts +1 -0
- package/package.json +23 -23
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
const useFolderLevel = () => {
|
|
3
|
+
const [folderId, setFolderId] = useState(null);
|
|
4
|
+
const [path, setPath] = useState([]);
|
|
5
|
+
const openFolder = useCallback((folder) => {
|
|
6
|
+
setFolderId(folder.id);
|
|
7
|
+
setPath((current) => [...current, {
|
|
8
|
+
id: folder.id,
|
|
9
|
+
text: folder.text
|
|
10
|
+
}]);
|
|
11
|
+
}, []);
|
|
12
|
+
const goUp = useCallback(() => {
|
|
13
|
+
setFolderId(path.length > 1 ? path[path.length - 2].id : null);
|
|
14
|
+
setPath((current) => current.slice(0, -1));
|
|
15
|
+
}, [path]);
|
|
16
|
+
const reset = useCallback(() => {
|
|
17
|
+
setFolderId(null);
|
|
18
|
+
setPath((current) => current.slice(0, 1));
|
|
19
|
+
}, []);
|
|
20
|
+
return {
|
|
21
|
+
folderId,
|
|
22
|
+
path,
|
|
23
|
+
setPath,
|
|
24
|
+
openFolder,
|
|
25
|
+
goUp,
|
|
26
|
+
reset
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
useFolderLevel
|
|
31
|
+
};
|
|
@@ -43,5 +43,10 @@ export declare const useItemsInSections: <ItemType extends BaseItemType, Section
|
|
|
43
43
|
canPerformListActions: boolean;
|
|
44
44
|
reloadActiveSection: () => void;
|
|
45
45
|
activeSectionId: string | undefined;
|
|
46
|
+
isMixedMode: boolean;
|
|
47
|
+
mixedRowSize: "default" | "large" | undefined;
|
|
48
|
+
isInFolder: boolean;
|
|
49
|
+
folderId: string | null;
|
|
50
|
+
folderPath: import('../../..').PathStep[];
|
|
46
51
|
};
|
|
47
52
|
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useState, useRef, useMemo, useCallback, useEffect } from "react";
|
|
2
2
|
import { itemSizes } from "@synerise/ds-list-item";
|
|
3
3
|
import { generateUuid } from "@synerise/ds-utils";
|
|
4
|
-
import {
|
|
4
|
+
import { ACTION_TYPES } from "../../ItemPickerNew/types/actions.types.js";
|
|
5
|
+
import { FIRST_PAGE, ITEMS_PER_SECTION_IN_SEARCH, ITEMS_PER_SECTION, ITEM_SIZE, SECTION_HEADER_HEIGHT, GET_ITEM_KEY, FOLDER_ITEMS_PER_PAGE, ITEMS_PER_PAGE, SECOND_PAGE } from "../constants.js";
|
|
5
6
|
import { RENDER_MODES } from "../types/renderMode.js";
|
|
6
|
-
import { isItems, isItemsConfig, isWithOutSections } from "../utils/typeguards.utils.js";
|
|
7
|
+
import { isItems, isItemsConfig, isMixedLoaderConfig, isWithOutSections, isItemLoaderConfig } from "../utils/typeguards.utils.js";
|
|
7
8
|
import { getActionItems, getSectionActionItems } from "../utils/actionItemsUtils.js";
|
|
8
9
|
import { getSearchByActionItems } from "../utils/getSearchByActionItems.js";
|
|
9
10
|
import { resolveSectionId } from "../utils/resolveSectionId.js";
|
|
10
11
|
import { useFlattenFolders } from "./useFlattenFolders.js";
|
|
11
|
-
import {
|
|
12
|
+
import { useFolderLevel } from "./useFolderLevel.js";
|
|
13
|
+
import { matchesSearchQuery, getRecentItems, getFolderLevelRow, getListItem, getInformationCardTooltip, getTitleItem, getFolderItems, getItems } from "./useItemsInSections.utils.js";
|
|
12
14
|
const EMPTY_ITEMS = [];
|
|
13
15
|
const getSectionHeight = (itemsCount, withTitle) => {
|
|
14
16
|
const itemsHeight = itemsCount * ITEM_SIZE[itemSizes.DEFAULT];
|
|
@@ -52,6 +54,18 @@ const useItemsInSections = ({
|
|
|
52
54
|
const sectionTotals = useRef({});
|
|
53
55
|
const abortControllerRef = useRef();
|
|
54
56
|
const isFixedItemsList = isItems(items) || isItemsConfig(items);
|
|
57
|
+
const itemLoader = isItemLoaderConfig(items) ? items : void 0;
|
|
58
|
+
const mixedLoader = isMixedLoaderConfig(items) ? items : void 0;
|
|
59
|
+
const {
|
|
60
|
+
folderId,
|
|
61
|
+
path: folderPath,
|
|
62
|
+
setPath: setFolderPath,
|
|
63
|
+
openFolder,
|
|
64
|
+
goUp,
|
|
65
|
+
reset: resetFolder
|
|
66
|
+
} = useFolderLevel();
|
|
67
|
+
const [levelEntries, setLevelEntries] = useState([]);
|
|
68
|
+
const availableActions = useMemo(() => mixedLoader ? actions?.filter((action) => action.actionType !== ACTION_TYPES.searchIn) : actions, [mixedLoader, actions]);
|
|
55
69
|
const [contentHeight, setContentHeight] = useState();
|
|
56
70
|
const [isInitialDataLoaded, setIsInitialDataLoaded] = useState(isFixedItemsList);
|
|
57
71
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -102,11 +116,16 @@ const useItemsInSections = ({
|
|
|
102
116
|
if (isFixedItemsList) {
|
|
103
117
|
return isItemsConfig(items) ? items.limitPerSection ?? fallbackLimit : fallbackLimit;
|
|
104
118
|
}
|
|
105
|
-
return
|
|
106
|
-
}, [isFixedItemsList, searchQuery, items]);
|
|
119
|
+
return itemLoader?.limitPerSection ?? fallbackLimit;
|
|
120
|
+
}, [isFixedItemsList, searchQuery, items, itemLoader]);
|
|
107
121
|
const {
|
|
108
122
|
listRenderingMode
|
|
109
123
|
} = useMemo(() => {
|
|
124
|
+
if (mixedLoader) {
|
|
125
|
+
return {
|
|
126
|
+
listRenderingMode: RENDER_MODES.LIST_MIXED
|
|
127
|
+
};
|
|
128
|
+
}
|
|
110
129
|
if (isListItemsRenderingMode) {
|
|
111
130
|
return {
|
|
112
131
|
listRenderingMode: RENDER_MODES.LIST_ITEMS
|
|
@@ -135,7 +154,7 @@ const useItemsInSections = ({
|
|
|
135
154
|
return {
|
|
136
155
|
listRenderingMode: RENDER_MODES.LIST_ITEMS
|
|
137
156
|
};
|
|
138
|
-
}, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders, isListItemsRenderingMode]);
|
|
157
|
+
}, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders, isListItemsRenderingMode, mixedLoader]);
|
|
139
158
|
const globalActionsLength = actions?.filter((action) => !action.sectionId).length || 0;
|
|
140
159
|
const recentsLength = recents?.length || 0;
|
|
141
160
|
const currentItemsLength = currentItems.length;
|
|
@@ -144,7 +163,8 @@ const useItemsInSections = ({
|
|
|
144
163
|
setSearchInItem(void 0);
|
|
145
164
|
setCurrentSection(void 0);
|
|
146
165
|
setPreviousSection(void 0);
|
|
147
|
-
|
|
166
|
+
resetFolder();
|
|
167
|
+
}, [resetFolder]);
|
|
148
168
|
const goBack = useCallback(() => {
|
|
149
169
|
if (searchByAction) {
|
|
150
170
|
setSearchByAction(void 0);
|
|
@@ -161,6 +181,13 @@ const useItemsInSections = ({
|
|
|
161
181
|
setSearchInAction(void 0);
|
|
162
182
|
return;
|
|
163
183
|
}
|
|
184
|
+
if (mixedLoader) {
|
|
185
|
+
if (folderId !== null) {
|
|
186
|
+
changeSearchQuery("");
|
|
187
|
+
goUp();
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
164
191
|
if (searchQuery) {
|
|
165
192
|
setCurrentSection(previousSection);
|
|
166
193
|
setPreviousSection(void 0);
|
|
@@ -171,7 +198,7 @@ const useItemsInSections = ({
|
|
|
171
198
|
return;
|
|
172
199
|
}
|
|
173
200
|
setCurrentSection(void 0);
|
|
174
|
-
}, [searchInAction, searchByAction, searchQuery, parentFolder, previousSection, searchInItem, changeSearchQuery]);
|
|
201
|
+
}, [searchInAction, searchByAction, searchQuery, parentFolder, previousSection, searchInItem, changeSearchQuery, mixedLoader, folderId, goUp]);
|
|
175
202
|
const handleCurrentSectionChange = useCallback((section) => {
|
|
176
203
|
setPreviousSection(currentSection);
|
|
177
204
|
setCurrentSection(section);
|
|
@@ -244,14 +271,68 @@ const useItemsInSections = ({
|
|
|
244
271
|
const currentRequestId = generateUuid();
|
|
245
272
|
requestIdRef.current = currentRequestId;
|
|
246
273
|
const abortController = abortControllerRef.current;
|
|
274
|
+
const isStale = () => currentRequestId !== requestIdRef.current;
|
|
275
|
+
const markFirstPageLoaded = (total, limit) => {
|
|
276
|
+
setIsLoading(false);
|
|
277
|
+
setIsInitialDataLoaded(true);
|
|
278
|
+
pageToLoad.current = FIRST_PAGE + 1;
|
|
279
|
+
if (total <= limit) {
|
|
280
|
+
setIsLoadedAll(true);
|
|
281
|
+
setIsSinglePage(true);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const handleFirstPageError = () => {
|
|
285
|
+
if (isStale()) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
setIsLoading(false);
|
|
289
|
+
setIsInitialDataLoaded(true);
|
|
290
|
+
if (!abortController?.signal.aborted) {
|
|
291
|
+
setIsLoadingError(true);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
if (mixedLoader) {
|
|
295
|
+
try {
|
|
296
|
+
const limit = mixedLoader.limitPerPage || FOLDER_ITEMS_PER_PAGE;
|
|
297
|
+
const {
|
|
298
|
+
entries,
|
|
299
|
+
total,
|
|
300
|
+
path
|
|
301
|
+
} = await mixedLoader.loadLevel({
|
|
302
|
+
folderId,
|
|
303
|
+
searchQuery: searchQuery ?? "",
|
|
304
|
+
searchKey: searchByParamConfig?.paramKey,
|
|
305
|
+
page: FIRST_PAGE,
|
|
306
|
+
limit,
|
|
307
|
+
abortController
|
|
308
|
+
});
|
|
309
|
+
if (isStale()) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
markFirstPageLoaded(total, limit);
|
|
313
|
+
setFolderPath(path);
|
|
314
|
+
onLoadedData?.({
|
|
315
|
+
sectionId: folderId ?? void 0,
|
|
316
|
+
meta: void 0,
|
|
317
|
+
renderMode: listRenderingMode
|
|
318
|
+
});
|
|
319
|
+
setLevelEntries(entries);
|
|
320
|
+
} catch (_event) {
|
|
321
|
+
handleFirstPageError();
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (!itemLoader) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
247
328
|
if (listRenderingMode === RENDER_MODES.LIST_ITEMS) {
|
|
248
329
|
try {
|
|
249
|
-
const limit =
|
|
330
|
+
const limit = itemLoader.limitPerPage || ITEMS_PER_PAGE;
|
|
250
331
|
const {
|
|
251
332
|
items: fetchedItems2,
|
|
252
333
|
total,
|
|
253
334
|
meta
|
|
254
|
-
} = await
|
|
335
|
+
} = await itemLoader.loadItems({
|
|
255
336
|
page: FIRST_PAGE,
|
|
256
337
|
searchQuery,
|
|
257
338
|
sectionId: activeSectionIdWithFallback,
|
|
@@ -261,42 +342,29 @@ const useItemsInSections = ({
|
|
|
261
342
|
searchKey: searchByParamConfig?.paramKey,
|
|
262
343
|
searchInItem
|
|
263
344
|
});
|
|
264
|
-
if (
|
|
345
|
+
if (isStale()) {
|
|
265
346
|
return;
|
|
266
347
|
}
|
|
267
|
-
|
|
268
|
-
pageToLoad.current = FIRST_PAGE + 1;
|
|
269
|
-
if (total <= limit) {
|
|
270
|
-
setIsLoadedAll(true);
|
|
271
|
-
setIsSinglePage(true);
|
|
272
|
-
}
|
|
348
|
+
markFirstPageLoaded(total, limit);
|
|
273
349
|
metaRef.current[activeSectionIdWithFallback] = meta;
|
|
274
350
|
onLoadedData?.({
|
|
275
351
|
sectionId: activeSectionIdWithFallback,
|
|
276
352
|
meta,
|
|
277
353
|
renderMode: listRenderingMode
|
|
278
354
|
});
|
|
279
|
-
setIsInitialDataLoaded(true);
|
|
280
355
|
setCurrentItems(fetchedItems2);
|
|
281
356
|
} catch (_event) {
|
|
282
|
-
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
setIsLoading(false);
|
|
286
|
-
setIsInitialDataLoaded(true);
|
|
287
|
-
if (!abortController?.signal.aborted) {
|
|
288
|
-
setIsLoadingError(true);
|
|
289
|
-
}
|
|
357
|
+
handleFirstPageError();
|
|
290
358
|
}
|
|
291
359
|
return;
|
|
292
360
|
}
|
|
293
361
|
let fetchedItems = [];
|
|
294
362
|
const requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders?.map((folder) => {
|
|
295
363
|
const sectionId = folder.id;
|
|
296
|
-
return
|
|
364
|
+
return itemLoader.loadItems({
|
|
297
365
|
page: FIRST_PAGE,
|
|
298
366
|
searchQuery,
|
|
299
|
-
limit: (
|
|
367
|
+
limit: (itemLoader.limitPerSection || ITEMS_PER_SECTION) + 1,
|
|
300
368
|
sectionId,
|
|
301
369
|
meta: void 0,
|
|
302
370
|
abortController: abortControllerRef.current,
|
|
@@ -334,7 +402,7 @@ const useItemsInSections = ({
|
|
|
334
402
|
setIsInitialDataLoaded(true);
|
|
335
403
|
setIsLoadingError(true);
|
|
336
404
|
}
|
|
337
|
-
}, [searchByParamConfig, isFixedItemsList, currentFolders, listRenderingMode,
|
|
405
|
+
}, [searchByParamConfig, isFixedItemsList, currentFolders, listRenderingMode, listActions, searchQuery, searchByAction, onLoadedData, activeSectionIdWithFallback, searchInItem, itemLoader, mixedLoader, folderId, setFolderPath]);
|
|
338
406
|
useEffect(() => {
|
|
339
407
|
if (listActions) {
|
|
340
408
|
return;
|
|
@@ -369,7 +437,7 @@ const useItemsInSections = ({
|
|
|
369
437
|
abortControllerRef.current?.abort();
|
|
370
438
|
abortControllerRef.current = new AbortController();
|
|
371
439
|
};
|
|
372
|
-
}, [activeSectionId, isFixedItemsList, searchQuery, listActions, refreshTrigger]);
|
|
440
|
+
}, [activeSectionId, folderId, isFixedItemsList, searchQuery, listActions, refreshTrigger]);
|
|
373
441
|
useEffect(() => {
|
|
374
442
|
let timeout;
|
|
375
443
|
if (!hasSearchQuery && !hasCurrentSection && calculatedContentHeight) {
|
|
@@ -379,7 +447,7 @@ const useItemsInSections = ({
|
|
|
379
447
|
timeout && clearTimeout(timeout);
|
|
380
448
|
};
|
|
381
449
|
}, [calculatedContentHeight, hasCurrentSection, hasSearchQuery]);
|
|
382
|
-
const hasInfiniteScroll = !listActions && !isFixedItemsList && listRenderingMode === RENDER_MODES.LIST_ITEMS;
|
|
450
|
+
const hasInfiniteScroll = !listActions && !isFixedItemsList && (listRenderingMode === RENDER_MODES.LIST_ITEMS || listRenderingMode === RENDER_MODES.LIST_MIXED);
|
|
383
451
|
const refreshItems = useMemo(() => {
|
|
384
452
|
if (!isFixedItemsList) {
|
|
385
453
|
return () => setRefreshTrigger(Date.now());
|
|
@@ -390,48 +458,76 @@ const useItemsInSections = ({
|
|
|
390
458
|
if (pageToLoad.current < SECOND_PAGE) {
|
|
391
459
|
return;
|
|
392
460
|
}
|
|
393
|
-
if (hasInfiniteScroll) {
|
|
394
|
-
|
|
461
|
+
if (!hasInfiniteScroll || isLoadedAll || isLoadingMore) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
setIsLoadingMore(true);
|
|
465
|
+
const pageRequestId = requestIdRef.current;
|
|
466
|
+
const isStale = () => pageRequestId !== requestIdRef.current;
|
|
467
|
+
const page = pageToLoad.current;
|
|
468
|
+
const settlePage = (total, pageSize) => {
|
|
469
|
+
setIsLoadingMore(false);
|
|
470
|
+
setIsLoadingMoreError(false);
|
|
471
|
+
if (total <= (page + 1) * pageSize) {
|
|
472
|
+
setIsLoadedAll(true);
|
|
473
|
+
}
|
|
474
|
+
pageToLoad.current = page + 1;
|
|
475
|
+
};
|
|
476
|
+
const handlePageError = () => {
|
|
477
|
+
if (isStale()) {
|
|
395
478
|
return;
|
|
396
479
|
}
|
|
397
|
-
setIsLoadingMore(
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
meta: metaRef.current[activeSectionIdWithFallback],
|
|
406
|
-
abortController: abortControllerRef.current,
|
|
480
|
+
setIsLoadingMore(false);
|
|
481
|
+
setIsLoadingMoreError(true);
|
|
482
|
+
};
|
|
483
|
+
if (mixedLoader) {
|
|
484
|
+
const limit2 = mixedLoader.limitPerPage || FOLDER_ITEMS_PER_PAGE;
|
|
485
|
+
mixedLoader.loadLevel({
|
|
486
|
+
folderId,
|
|
487
|
+
searchQuery: searchQuery ?? "",
|
|
407
488
|
searchKey: searchByParamConfig?.paramKey,
|
|
408
|
-
|
|
489
|
+
page,
|
|
490
|
+
limit: limit2,
|
|
491
|
+
abortController: abortControllerRef.current
|
|
409
492
|
}).then(({
|
|
410
|
-
|
|
411
|
-
total
|
|
412
|
-
meta
|
|
493
|
+
entries,
|
|
494
|
+
total
|
|
413
495
|
}) => {
|
|
414
496
|
if (isStale()) {
|
|
415
497
|
return;
|
|
416
498
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
pageToLoad.current += 1;
|
|
425
|
-
setCurrentItems([...currentItems, ...fetchedItems]);
|
|
426
|
-
}).catch(() => {
|
|
427
|
-
if (isStale()) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
setIsLoadingMore(false);
|
|
431
|
-
setIsLoadingMoreError(true);
|
|
432
|
-
});
|
|
499
|
+
settlePage(total, limit2);
|
|
500
|
+
setLevelEntries((current) => [...current, ...entries]);
|
|
501
|
+
}).catch(handlePageError);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (!itemLoader) {
|
|
505
|
+
return;
|
|
433
506
|
}
|
|
434
|
-
|
|
507
|
+
const limit = itemLoader.limitPerPage || ITEMS_PER_PAGE;
|
|
508
|
+
itemLoader.loadItems({
|
|
509
|
+
page,
|
|
510
|
+
limit,
|
|
511
|
+
searchQuery,
|
|
512
|
+
sectionId: activeSectionIdWithFallback,
|
|
513
|
+
meta: metaRef.current[activeSectionIdWithFallback],
|
|
514
|
+
abortController: abortControllerRef.current,
|
|
515
|
+
searchKey: searchByParamConfig?.paramKey,
|
|
516
|
+
searchInItem
|
|
517
|
+
}).then(({
|
|
518
|
+
items: fetchedItems,
|
|
519
|
+
total,
|
|
520
|
+
meta
|
|
521
|
+
}) => {
|
|
522
|
+
if (isStale()) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
sectionTotals.current[activeSectionIdWithFallback] = total;
|
|
526
|
+
metaRef.current[activeSectionIdWithFallback] = meta;
|
|
527
|
+
settlePage(total, limit);
|
|
528
|
+
setCurrentItems((current) => [...current, ...fetchedItems]);
|
|
529
|
+
}).catch(handlePageError);
|
|
530
|
+
}, [searchByParamConfig, isLoadingMore, hasInfiniteScroll, isLoadedAll, itemLoader, mixedLoader, folderId, searchQuery, activeSectionIdWithFallback, searchInItem]);
|
|
435
531
|
const mergedItemsList = useMemo(() => {
|
|
436
532
|
const isSearchInItemActive = !!searchInItem;
|
|
437
533
|
if (searchByAction) {
|
|
@@ -445,7 +541,7 @@ const useItemsInSections = ({
|
|
|
445
541
|
}
|
|
446
542
|
if (listActions) {
|
|
447
543
|
return getActionItems({
|
|
448
|
-
actions,
|
|
544
|
+
actions: availableActions,
|
|
449
545
|
texts,
|
|
450
546
|
sectionId: activeSectionId,
|
|
451
547
|
setSearchByAction,
|
|
@@ -457,7 +553,7 @@ const useItemsInSections = ({
|
|
|
457
553
|
});
|
|
458
554
|
}
|
|
459
555
|
const sectionActions = getSectionActionItems({
|
|
460
|
-
actions,
|
|
556
|
+
actions: availableActions,
|
|
461
557
|
texts,
|
|
462
558
|
searchQuery,
|
|
463
559
|
sectionId: activeSectionId,
|
|
@@ -468,6 +564,45 @@ const useItemsInSections = ({
|
|
|
468
564
|
searchByParamConfig,
|
|
469
565
|
setSearchByParamConfig
|
|
470
566
|
});
|
|
567
|
+
if (mixedLoader) {
|
|
568
|
+
const isTopLevel = folderId === null;
|
|
569
|
+
const rowSize = mixedLoader.rowSize ?? itemSizes.DEFAULT;
|
|
570
|
+
const isSearchParam = !!searchByParamConfig;
|
|
571
|
+
const levelActions = isTopLevel || searchQuery ? sectionActions : [];
|
|
572
|
+
const levelRecents = isTopLevel && !isSearchParam ? getRecentItems({
|
|
573
|
+
recents,
|
|
574
|
+
texts,
|
|
575
|
+
isSelected,
|
|
576
|
+
searchQuery,
|
|
577
|
+
handleItemSelect,
|
|
578
|
+
isSearchParam
|
|
579
|
+
}) : [];
|
|
580
|
+
const entryRows = levelEntries.map((entry) => {
|
|
581
|
+
const location = searchQuery && rowSize === itemSizes.LARGE ? entry.location : void 0;
|
|
582
|
+
if (entry.type === "folder") {
|
|
583
|
+
return getFolderLevelRow({
|
|
584
|
+
folder: entry.folder,
|
|
585
|
+
rowSize,
|
|
586
|
+
location,
|
|
587
|
+
highlight: isSearchParam ? void 0 : searchQuery,
|
|
588
|
+
onOpen: () => {
|
|
589
|
+
changeSearchQuery("");
|
|
590
|
+
openFolder(entry.folder);
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
const row = getListItem(entry.item, isSelected, searchQuery, handleItemSelect, getInformationCardTooltip(entry.item), isSearchParam);
|
|
595
|
+
return {
|
|
596
|
+
...row,
|
|
597
|
+
size: row.size ?? rowSize,
|
|
598
|
+
...location !== void 0 && {
|
|
599
|
+
description: location
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
});
|
|
603
|
+
const levelTitle = searchQuery ? texts.resultsSectionLabel : isTopLevel && showItemsSectionLabel ? folderPath[0]?.text : void 0;
|
|
604
|
+
return [...levelActions, ...levelRecents, ...entryRows.length && levelTitle ? [getTitleItem(levelTitle)] : [], ...entryRows];
|
|
605
|
+
}
|
|
471
606
|
const recentItems = activeSectionId || isSearchInItemActive || searchByParamConfig ? [] : getRecentItems({
|
|
472
607
|
recents,
|
|
473
608
|
texts,
|
|
@@ -516,7 +651,7 @@ const useItemsInSections = ({
|
|
|
516
651
|
default:
|
|
517
652
|
return [...composedList, ...listItems];
|
|
518
653
|
}
|
|
519
|
-
}, [listActions, activeSectionId,
|
|
654
|
+
}, [listActions, activeSectionId, texts, searchQuery, recents, currentItems, showItemsSectionLabel, sections, currentFolders, itemsLimitPerSection, listRenderingMode, isSelected, handleItemSelect, handleSectionChange, setSearchByParamConfig, searchByAction, searchByParamConfig, changeSearchQuery, handleItemSelectExtended, isSearchInActionActive, searchInItem, isListItemsRenderingMode, availableActions, mixedLoader, folderId, folderPath, levelEntries, openFolder]);
|
|
520
655
|
const reloadActiveSection = useCallback(() => {
|
|
521
656
|
pageToLoad.current = FIRST_PAGE;
|
|
522
657
|
metaRef.current = {};
|
|
@@ -555,7 +690,12 @@ const useItemsInSections = ({
|
|
|
555
690
|
searchInAction,
|
|
556
691
|
canPerformListActions,
|
|
557
692
|
reloadActiveSection,
|
|
558
|
-
activeSectionId
|
|
693
|
+
activeSectionId,
|
|
694
|
+
isMixedMode: !!mixedLoader,
|
|
695
|
+
mixedRowSize: mixedLoader?.rowSize,
|
|
696
|
+
isInFolder: !!mixedLoader && folderId !== null,
|
|
697
|
+
folderId,
|
|
698
|
+
folderPath
|
|
559
699
|
};
|
|
560
700
|
};
|
|
561
701
|
export {
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { ListItemProps } from '@synerise/ds-list-item';
|
|
2
|
+
import { ItemSize, ListItemProps } from '@synerise/ds-list-item';
|
|
3
3
|
import { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders } from '../../ItemPickerNew/types/baseItemSectionType.types';
|
|
4
4
|
import { ItemPickerListTexts } from '../../ItemPickerNew/types/itemPickerListTexts.types';
|
|
5
|
+
import { FolderNode } from '../../ItemPickerNew/types/mixedLoader.types';
|
|
5
6
|
import { TitleListItemProps } from '../ItemPickerList.types';
|
|
6
7
|
export declare const getFolderItem: (item: ListItemProps & Pick<BaseSectionType, "tooltip">, onClick: ListItemProps["onClick"]) => ListItemProps;
|
|
8
|
+
export declare const getFolderLevelRow: ({ folder, rowSize, location, highlight, onOpen, }: {
|
|
9
|
+
folder: FolderNode;
|
|
10
|
+
rowSize: ItemSize;
|
|
11
|
+
location?: ReactNode;
|
|
12
|
+
highlight?: string;
|
|
13
|
+
onOpen: () => void;
|
|
14
|
+
}) => ListItemProps;
|
|
7
15
|
export declare const getShowMoreItem: (label: ReactNode, onClick: ListItemProps["onClick"]) => ListItemProps;
|
|
8
16
|
export declare const getTitleItem: (titleText: ReactNode, tooltip?: ReactNode) => TitleListItemProps;
|
|
9
17
|
export declare const getListItem: <ItemType extends ListItemProps>(item: ItemType, isSelected: (item: ItemType) => boolean, searchQuery?: string, onItemSelect?: (item: ItemType) => void, renderHoverTooltip?: () => JSX.Element, isSearchParam?: boolean) => ListItemProps;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { ObjectAvatar } from "@synerise/ds-avatar";
|
|
3
|
+
import Icon, { AngleRightS, FolderM, ArrowRightCircleM } from "@synerise/ds-icon";
|
|
3
4
|
import InformationCard from "@synerise/ds-information-card";
|
|
5
|
+
import { itemSizes } from "@synerise/ds-list-item";
|
|
6
|
+
import { FOLDER_ROW_CLASS } from "../constants.js";
|
|
7
|
+
import { FolderDisabledReason } from "../ItemPickerList.styles.js";
|
|
4
8
|
import { createTitleFromTitlePath } from "../utils/createTitleFromTitlePath.js";
|
|
5
9
|
import "../../ItemPickerNew/types/actions.types.js";
|
|
6
10
|
const getFolderItem = (item, onClick) => {
|
|
@@ -14,6 +18,33 @@ const getFolderItem = (item, onClick) => {
|
|
|
14
18
|
onClick
|
|
15
19
|
};
|
|
16
20
|
};
|
|
21
|
+
const getFolderLevelRow = ({
|
|
22
|
+
folder,
|
|
23
|
+
rowSize,
|
|
24
|
+
location,
|
|
25
|
+
highlight,
|
|
26
|
+
onOpen
|
|
27
|
+
}) => {
|
|
28
|
+
const isLarge = rowSize === itemSizes.LARGE;
|
|
29
|
+
const icon = /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(FolderM, {}) });
|
|
30
|
+
const reason = folder.disabled && folder.disabledReason && !isLarge ? /* @__PURE__ */ jsx(FolderDisabledReason, { children: folder.disabledReason }) : void 0;
|
|
31
|
+
const {
|
|
32
|
+
informationCardProps
|
|
33
|
+
} = folder;
|
|
34
|
+
return {
|
|
35
|
+
itemKey: `folder-${folder.id}`,
|
|
36
|
+
className: FOLDER_ROW_CLASS,
|
|
37
|
+
text: folder.text,
|
|
38
|
+
size: rowSize,
|
|
39
|
+
description: isLarge ? folder.disabled ? folder.disabledReason : location ?? folder.description : void 0,
|
|
40
|
+
prefixel: isLarge ? /* @__PURE__ */ jsx(ObjectAvatar, { size: "medium", iconComponent: icon }) : icon,
|
|
41
|
+
suffixel: folder.disabled ? reason : /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(AngleRightS, {}) }),
|
|
42
|
+
disabled: folder.disabled,
|
|
43
|
+
highlight,
|
|
44
|
+
renderHoverTooltip: informationCardProps ? () => /* @__PURE__ */ jsx(InformationCard, { ...informationCardProps }) : void 0,
|
|
45
|
+
onClick: folder.disabled ? void 0 : onOpen
|
|
46
|
+
};
|
|
47
|
+
};
|
|
17
48
|
const getShowMoreItem = (label, onClick) => {
|
|
18
49
|
return {
|
|
19
50
|
text: label,
|
|
@@ -104,6 +135,7 @@ const getInformationCardTooltip = (item) => {
|
|
|
104
135
|
export {
|
|
105
136
|
getFolderItem,
|
|
106
137
|
getFolderItems,
|
|
138
|
+
getFolderLevelRow,
|
|
107
139
|
getInformationCardTooltip,
|
|
108
140
|
getItems,
|
|
109
141
|
getItemsSectionTitle,
|
|
@@ -2,5 +2,6 @@ export declare const RENDER_MODES: {
|
|
|
2
2
|
readonly LIST_ITEMS_IN_SECTIONS: "ITEMS_IN_SECTIONS";
|
|
3
3
|
readonly LIST_FOLDERS_IN_SECTIONS: "LIST_FOLDERS_IN_SECTION";
|
|
4
4
|
readonly LIST_ITEMS: "LIST_ITEMS";
|
|
5
|
+
readonly LIST_MIXED: "LIST_MIXED";
|
|
5
6
|
};
|
|
6
7
|
export type RenderMode = (typeof RENDER_MODES)[keyof typeof RENDER_MODES];
|
|
@@ -4,8 +4,12 @@ import "../constants.js";
|
|
|
4
4
|
import { isSearchInAction, isSearchByAction, isTruthy } from "./typeguards.utils.js";
|
|
5
5
|
import { getContextAwareActions } from "./getContextAwareActions.js";
|
|
6
6
|
const getActionItem = (action, searchQuery) => {
|
|
7
|
+
const {
|
|
8
|
+
showInList: _showInList,
|
|
9
|
+
...item
|
|
10
|
+
} = action;
|
|
7
11
|
return {
|
|
8
|
-
...
|
|
12
|
+
...item,
|
|
9
13
|
highlight: searchQuery,
|
|
10
14
|
onClick: "onClick" in action && action.onClick ? () => action.onClick?.(action) : void 0
|
|
11
15
|
};
|
|
@@ -94,7 +98,7 @@ const getSectionActionItems = ({
|
|
|
94
98
|
searchByParamConfig,
|
|
95
99
|
setSearchByParamConfig
|
|
96
100
|
}) => {
|
|
97
|
-
const filteredActions = actions?.filter((action) => (action.actionType === ACTION_TYPES.searchBy || action.actionType === ACTION_TYPES.searchIn || action.sectionId === sectionId) && (!searchQuery || matchesSearchQuery(action.text, searchQuery)));
|
|
101
|
+
const filteredActions = actions?.filter((action) => action.showInList !== false && (action.actionType === ACTION_TYPES.searchBy || action.actionType === ACTION_TYPES.searchIn || action.sectionId === sectionId) && (!searchQuery || matchesSearchQuery(action.text, searchQuery)));
|
|
98
102
|
return getActionItems({
|
|
99
103
|
actions: filteredActions,
|
|
100
104
|
texts,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const FOLDER_PATH_SEPARATOR = " / ";
|
|
2
|
+
const MAX_UNCOLLAPSED_STEPS = 4;
|
|
3
|
+
const formatFolderPath = (steps) => {
|
|
4
|
+
const fullPath = steps.join(FOLDER_PATH_SEPARATOR);
|
|
5
|
+
const label = steps.length <= MAX_UNCOLLAPSED_STEPS ? fullPath : [steps[0], "…", ...steps.slice(-2)].join(FOLDER_PATH_SEPARATOR);
|
|
6
|
+
return {
|
|
7
|
+
label,
|
|
8
|
+
fullPath
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
formatFolderPath
|
|
13
|
+
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createTitleFromTitlePath } from "./createTitleFromTitlePath.js";
|
|
2
2
|
import { findSectionById } from "./findSectionById.js";
|
|
3
|
+
import { formatFolderPath } from "./formatFolderPath.js";
|
|
3
4
|
import { isNavKey } from "./isNavKey.js";
|
|
4
|
-
import { isItems, isItemsConfig, isSearchByAction, isSearchInAction, isTitle, isTruthy, isWithOutSections } from "./typeguards.utils.js";
|
|
5
|
+
import { isItemLoaderConfig, isItems, isItemsConfig, isMixedLoaderConfig, isSearchByAction, isSearchInAction, isTitle, isTruthy, isWithOutSections } from "./typeguards.utils.js";
|
|
5
6
|
export {
|
|
6
7
|
createTitleFromTitlePath,
|
|
7
8
|
findSectionById,
|
|
9
|
+
formatFolderPath,
|
|
10
|
+
isItemLoaderConfig,
|
|
8
11
|
isItems,
|
|
9
12
|
isItemsConfig,
|
|
13
|
+
isMixedLoaderConfig,
|
|
10
14
|
isNavKey,
|
|
11
15
|
isSearchByAction,
|
|
12
16
|
isSearchInAction,
|
|
@@ -2,11 +2,16 @@ import { ListItemProps } from '@synerise/ds-list-item';
|
|
|
2
2
|
import { ItemLoaderConfig, ItemsConfig } from '../../ItemPickerNew/ItemPickerNew.types';
|
|
3
3
|
import { Action, SearchByAction, SearchInAction } from '../../ItemPickerNew/types/actions.types';
|
|
4
4
|
import { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders } from '../../ItemPickerNew/types/baseItemSectionType.types';
|
|
5
|
+
import { MixedLoaderConfig } from '../../ItemPickerNew/types/mixedLoader.types';
|
|
5
6
|
import { TitleListItemProps } from '../ItemPickerList.types';
|
|
6
7
|
export declare const isTitle: (item: TitleListItemProps | ListItemProps) => item is TitleListItemProps;
|
|
7
|
-
|
|
8
|
-
export declare const
|
|
8
|
+
type ItemsProp<ItemType extends BaseItemType> = ItemType[] | ItemsConfig<ItemType> | ItemLoaderConfig<ItemType> | MixedLoaderConfig<ItemType>;
|
|
9
|
+
export declare const isItems: <ItemType extends BaseItemType>(items: ItemsProp<ItemType>) => items is ItemType[];
|
|
10
|
+
export declare const isItemsConfig: <ItemType extends BaseItemType>(items: ItemsProp<ItemType>) => items is ItemsConfig<ItemType>;
|
|
11
|
+
export declare const isMixedLoaderConfig: <ItemType extends BaseItemType>(items: ItemsProp<ItemType>) => items is MixedLoaderConfig<ItemType>;
|
|
12
|
+
export declare const isItemLoaderConfig: <ItemType extends BaseItemType>(items: ItemsProp<ItemType>) => items is ItemLoaderConfig<ItemType>;
|
|
9
13
|
export declare const isWithOutSections: <SectionType extends BaseSectionTypeWithFolders<BaseSectionType> | undefined>(sections?: SectionType[]) => sections is undefined;
|
|
10
14
|
export declare const isTruthy: <T>(value: T) => value is NonNullable<T>;
|
|
11
15
|
export declare const isSearchByAction: (action?: Action) => action is SearchByAction;
|
|
12
16
|
export declare const isSearchInAction: (action?: Action) => action is SearchInAction;
|
|
17
|
+
export {};
|