@orangelogic/orange-dam-content-browser-sdk 2.1.21 → 2.1.23
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/CBSDKdemo.html +2 -2
- package/gab_extension/GAB.html +2 -2
- package/package.json +1 -1
- package/src/components/ControlBar/ControlBar.cy.tsx +55 -27
- package/src/components/ControlBar/ControlBar.tsx +180 -207
- package/src/components/ControlBar/Facet/Facet.cy.tsx +175 -24
- package/src/components/ControlBar/Facet/Facet.tsx +27 -13
- package/src/consts/data.ts +2 -0
- package/src/page/Home/Home.tsx +103 -79
- package/src/store/assets/assets.api.ts +30 -8
- package/src/store/search/search.api.ts +51 -68
- package/src/types/search.ts +14 -5
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _camelCase from 'lodash-es/camelCase';
|
|
1
|
+
import _uniqBy from 'lodash-es/uniqBy';
|
|
3
2
|
|
|
4
3
|
import {
|
|
5
4
|
DEFAULT_VIEW_SIZE, ORIGINAL_VIEW_SIZE, FIELD_CORTEX_PATH, FIELD_DOC_TYPE, FIELD_EXTENSION, FIELD_FILE_SIZE,
|
|
6
5
|
FIELD_HAS_BROWSER_CHILDREN,
|
|
7
6
|
FIELD_IDENTIFIER, FIELD_KEYWORDS, FIELD_MAX_HEIGHT, FIELD_MAX_WIDTH, FIELD_SCRUB_URL, FIELD_SUBTYPE, FIELD_TITLE_WITH_FALLBACK, FIELD_ALLOW_ATS_LINK,
|
|
8
7
|
FIELD_RECORD_ID,
|
|
8
|
+
FIELD_ORIGINAL_FILE_NAME,
|
|
9
|
+
FIELD_UPDATED_FILE_NAME,
|
|
9
10
|
} from '@/consts/data';
|
|
10
|
-
import { Asset, Folder, GetContentRequest, GetContentResponse, GetFavoritesResponse } from '@/types/search';
|
|
11
|
+
import { Asset, Facet, Folder, GetContentRequest, GetContentResponse, GetFavoritesResponse } from '@/types/search';
|
|
11
12
|
import { AppBaseQuery, GetValueByKeyCaseInsensitive } from '@/utils/api';
|
|
12
13
|
import { isNullOrWhiteSpace } from '@/utils/string';
|
|
13
14
|
import { createApi, retry } from '@reduxjs/toolkit/query/react';
|
|
@@ -38,43 +39,26 @@ const resolveFolderExtraFilters = ({
|
|
|
38
39
|
return baseQuery;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const resolveAssetExtraFilters = ({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
visibilityClasses,
|
|
45
|
-
}: {
|
|
46
|
-
extensions: string[];
|
|
47
|
-
searchText: string;
|
|
48
|
-
statuses: string[];
|
|
49
|
-
visibilityClasses: string[];
|
|
50
|
-
}) => {
|
|
51
|
-
const filterResult: Record<string, string> = {};
|
|
52
|
-
|
|
53
|
-
let statusQuery = '';
|
|
54
|
-
if (statuses?.length) {
|
|
55
|
-
statusQuery = statuses
|
|
56
|
-
.map(status => `WorkflowStatus:${status}`)
|
|
57
|
-
.join(' OR ');
|
|
58
|
-
filterResult.Status = statusQuery;
|
|
42
|
+
const resolveAssetExtraFilters = (selectedFacets?: Record<string, string[]>) => {
|
|
43
|
+
if (!selectedFacets || Object.keys(selectedFacets).length === 0) {
|
|
44
|
+
return [];
|
|
59
45
|
}
|
|
46
|
+
|
|
47
|
+
return Object.entries(selectedFacets).reduce<[string, string][]>((acc, [key, values]) => {
|
|
48
|
+
if (!values || values.length === 0) {
|
|
49
|
+
return acc;
|
|
50
|
+
}
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
filterResult.Extension = extensionsQuery;
|
|
67
|
-
}
|
|
52
|
+
if (key === 'Types') {
|
|
53
|
+
return acc.concat(
|
|
54
|
+
values.map((value) => ['subtypeCriteria', value] as [string, string]),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.join(' OR ');
|
|
74
|
-
filterResult.VisibilityClass = visibilityClassesQuery;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return filterResult;
|
|
58
|
+
return acc.concat(
|
|
59
|
+
values.map((value) => [`facetFilters[${key}]`, value] as [string, string]),
|
|
60
|
+
);
|
|
61
|
+
}, []);
|
|
78
62
|
};
|
|
79
63
|
|
|
80
64
|
const baseQueryWithRetry = retry(AppBaseQuery, {
|
|
@@ -162,7 +146,7 @@ export const searchApi = createApi({
|
|
|
162
146
|
GetValueByKeyCaseInsensitive(item.fields, FIELD_CORTEX_PATH) ?? ''
|
|
163
147
|
).replace(/^Root\//i, ''),
|
|
164
148
|
parents: [...arg.folder.parents, arg.folder],
|
|
165
|
-
hasChildren: (GetValueByKeyCaseInsensitive(item.fields, FIELD_HAS_BROWSER_CHILDREN) ?? '0') === '1'
|
|
149
|
+
hasChildren: (GetValueByKeyCaseInsensitive(item.fields, FIELD_HAS_BROWSER_CHILDREN) ?? '0') === '1',
|
|
166
150
|
};
|
|
167
151
|
}) ?? []
|
|
168
152
|
),
|
|
@@ -277,21 +261,17 @@ export const searchApi = createApi({
|
|
|
277
261
|
}),
|
|
278
262
|
getAssets: builder.query({
|
|
279
263
|
query: ({
|
|
280
|
-
extensions,
|
|
281
264
|
folderID,
|
|
282
265
|
isSeeThrough,
|
|
283
266
|
limitedToDocTypes,
|
|
284
|
-
mediaTypes,
|
|
285
267
|
pageSize,
|
|
286
268
|
searchText,
|
|
269
|
+
selectedFacets,
|
|
287
270
|
sortOrder,
|
|
288
271
|
start,
|
|
289
|
-
statuses,
|
|
290
272
|
useSession,
|
|
291
|
-
visibilityClasses,
|
|
292
273
|
}: GetContentRequest) => {
|
|
293
274
|
const mappedLimitedToDocTypes = limitedToDocTypes.map((docType) => ['limitedToDocTypes', docType]);
|
|
294
|
-
const mappedMediaTypes = mediaTypes.map((mediaType) => ['subtypeCriteria', mediaType]);
|
|
295
275
|
const params = [
|
|
296
276
|
['objectRecordID', folderID],
|
|
297
277
|
['fields', FIELD_TITLE_WITH_FALLBACK],
|
|
@@ -306,19 +286,16 @@ export const searchApi = createApi({
|
|
|
306
286
|
['fields', FIELD_IDENTIFIER],
|
|
307
287
|
['fields', FIELD_EXTENSION],
|
|
308
288
|
['fields', FIELD_RECORD_ID],
|
|
289
|
+
['fields', FIELD_ORIGINAL_FILE_NAME],
|
|
290
|
+
['fields', FIELD_UPDATED_FILE_NAME],
|
|
309
291
|
['seeThru', isSeeThrough],
|
|
310
292
|
['start', start],
|
|
311
293
|
['limit', pageSize],
|
|
312
294
|
];
|
|
313
|
-
const fieldFilters = resolveAssetExtraFilters(
|
|
314
|
-
extensions,
|
|
315
|
-
searchText,
|
|
316
|
-
statuses,
|
|
317
|
-
visibilityClasses,
|
|
318
|
-
});
|
|
295
|
+
const fieldFilters = resolveAssetExtraFilters(selectedFacets);
|
|
319
296
|
|
|
320
|
-
|
|
321
|
-
params.push(
|
|
297
|
+
fieldFilters.forEach((filter) => {
|
|
298
|
+
params.push(filter);
|
|
322
299
|
}, '');
|
|
323
300
|
|
|
324
301
|
if (sortOrder) {
|
|
@@ -327,11 +304,8 @@ export const searchApi = createApi({
|
|
|
327
304
|
if (mappedLimitedToDocTypes.length) {
|
|
328
305
|
params.push(...mappedLimitedToDocTypes);
|
|
329
306
|
}
|
|
330
|
-
if (mappedMediaTypes.length) {
|
|
331
|
-
params.push(...mappedMediaTypes);
|
|
332
|
-
}
|
|
333
307
|
if (searchText) {
|
|
334
|
-
params.push(['
|
|
308
|
+
params.push(['Text', searchText]);
|
|
335
309
|
}
|
|
336
310
|
if (useSession) {
|
|
337
311
|
params.push(['UseSession', useSession]);
|
|
@@ -344,17 +318,23 @@ export const searchApi = createApi({
|
|
|
344
318
|
transformResponse: (
|
|
345
319
|
response: GetContentResponse,
|
|
346
320
|
): {
|
|
347
|
-
facets:
|
|
321
|
+
facets: Facet[];
|
|
348
322
|
items: Asset[];
|
|
349
323
|
totalCount: number;
|
|
350
324
|
} => ({
|
|
351
|
-
facets:
|
|
325
|
+
facets: response.facets,
|
|
352
326
|
items:
|
|
353
327
|
response.contentItems?.map((item) => {
|
|
354
328
|
let extension = GetValueByKeyCaseInsensitive(item.fields, FIELD_EXTENSION) ?? '';
|
|
329
|
+
let name = GetValueByKeyCaseInsensitive(item.fields, FIELD_UPDATED_FILE_NAME);
|
|
355
330
|
if (extension && !extension.startsWith('.')) {
|
|
356
331
|
extension = '.' + extension;
|
|
357
332
|
}
|
|
333
|
+
|
|
334
|
+
if (isNullOrWhiteSpace(name)) {
|
|
335
|
+
name = GetValueByKeyCaseInsensitive(item.fields, FIELD_ORIGINAL_FILE_NAME);
|
|
336
|
+
}
|
|
337
|
+
|
|
358
338
|
return {
|
|
359
339
|
docType: GetValueByKeyCaseInsensitive(item.fields, FIELD_DOC_TYPE) ?? '',
|
|
360
340
|
docSubType: GetValueByKeyCaseInsensitive(item.fields, FIELD_SUBTYPE) ?? '',
|
|
@@ -364,7 +344,7 @@ export const searchApi = createApi({
|
|
|
364
344
|
identifier: GetValueByKeyCaseInsensitive(item.fields, FIELD_IDENTIFIER) ?? '',
|
|
365
345
|
imageUrl: GetValueByKeyCaseInsensitive(item.fields, DEFAULT_VIEW_SIZE) ?? '',
|
|
366
346
|
originalUrl: GetValueByKeyCaseInsensitive(item.fields, ORIGINAL_VIEW_SIZE) ?? '',
|
|
367
|
-
name:
|
|
347
|
+
name: name ?? '',
|
|
368
348
|
scrubUrl: GetValueByKeyCaseInsensitive(item.fields, FIELD_SCRUB_URL) ?? '',
|
|
369
349
|
size: GetValueByKeyCaseInsensitive(item.fields, FIELD_FILE_SIZE) ?? '0 MB',
|
|
370
350
|
tags: GetValueByKeyCaseInsensitive(item.fields, FIELD_KEYWORDS) ?? '',
|
|
@@ -378,41 +358,44 @@ export const searchApi = createApi({
|
|
|
378
358
|
providesTags: (_result, _error, arg) => {
|
|
379
359
|
return [
|
|
380
360
|
{
|
|
381
|
-
|
|
361
|
+
selectedFacets: Object.values(arg.selectedFacets ?? {}),
|
|
382
362
|
id: arg.folderID,
|
|
383
363
|
isSeeThrough: arg.isSeeThrough,
|
|
384
|
-
mediaTypes: arg.mediaTypes,
|
|
385
364
|
searchText: arg.searchText,
|
|
386
365
|
sortOrder: arg.sortOrder,
|
|
387
|
-
statuses: arg.statuses,
|
|
388
366
|
type: 'ImagesInFolders',
|
|
389
|
-
visibilityClasses: arg.visibilityClasses,
|
|
390
367
|
},
|
|
391
368
|
'Images',
|
|
392
369
|
];
|
|
393
370
|
},
|
|
394
371
|
merge: (currentCachedData, responseData, request) => {
|
|
395
372
|
if (request.arg.start > 0) {
|
|
396
|
-
|
|
397
|
-
|
|
373
|
+
return {
|
|
374
|
+
...currentCachedData,
|
|
375
|
+
items: _uniqBy([...currentCachedData.items, ...responseData.items], 'recordId'),
|
|
376
|
+
};
|
|
398
377
|
} else {
|
|
399
378
|
return responseData;
|
|
400
379
|
}
|
|
401
380
|
},
|
|
402
381
|
forceRefetch({ currentArg, previousArg }) {
|
|
382
|
+
if (currentArg?.start === previousArg?.start) {
|
|
383
|
+
/**
|
|
384
|
+
* Handle case when user changes page size by resizing the browser
|
|
385
|
+
* Only refetch when page size is bigger
|
|
386
|
+
*/
|
|
387
|
+
return !!currentArg?.pageSize && !!previousArg?.pageSize && currentArg.pageSize > previousArg.pageSize;
|
|
388
|
+
}
|
|
403
389
|
return currentArg !== previousArg;
|
|
404
390
|
},
|
|
405
391
|
serializeQueryArgs: ({ endpointName, queryArgs }) => {
|
|
406
392
|
return {
|
|
407
393
|
endpointName,
|
|
408
|
-
|
|
394
|
+
selectedFacets: Object.values(queryArgs.selectedFacets ?? {}),
|
|
409
395
|
id: queryArgs.folderID,
|
|
410
396
|
isSeeThrough: queryArgs.isSeeThrough,
|
|
411
|
-
mediaTypes: queryArgs.mediaTypes,
|
|
412
397
|
searchText: queryArgs.searchText,
|
|
413
398
|
sortOrder: queryArgs.sortOrder,
|
|
414
|
-
statuses: queryArgs.statuses,
|
|
415
|
-
visibilityClasses: queryArgs.visibilityClasses,
|
|
416
399
|
type: 'ImagesInFolders',
|
|
417
400
|
};
|
|
418
401
|
},
|
package/src/types/search.ts
CHANGED
|
@@ -34,25 +34,34 @@ export type ContentItem = {
|
|
|
34
34
|
recordID: string;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
export type Facet = {
|
|
38
|
+
facetDetails: {
|
|
39
|
+
displayName: string;
|
|
40
|
+
facetFieldName: string;
|
|
41
|
+
};
|
|
42
|
+
values: {
|
|
43
|
+
count: number;
|
|
44
|
+
displayValue: string;
|
|
45
|
+
value: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
export type GetContentResponse = {
|
|
38
50
|
contentItems?: ContentItem[];
|
|
39
|
-
facets:
|
|
51
|
+
facets: Facet[];
|
|
40
52
|
totalCount: number;
|
|
41
53
|
};
|
|
42
54
|
|
|
43
55
|
export type GetContentRequest = {
|
|
44
|
-
extensions: string[];
|
|
45
56
|
folderID: string;
|
|
46
57
|
isSeeThrough: boolean;
|
|
47
58
|
limitedToDocTypes: string[];
|
|
48
|
-
mediaTypes: string[];
|
|
49
59
|
pageSize: number;
|
|
50
60
|
searchText: string;
|
|
61
|
+
selectedFacets?: Record<string, string[]>;
|
|
51
62
|
sortOrder?: string;
|
|
52
63
|
start: number;
|
|
53
|
-
statuses: string[];
|
|
54
64
|
useSession?: string;
|
|
55
|
-
visibilityClasses: string[];
|
|
56
65
|
};
|
|
57
66
|
|
|
58
67
|
export type GetAssetLinkResponse = {
|