@orangelogic/orange-dam-content-browser-sdk 2.1.55 → 2.2.0-alpha
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/.env +1 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +82 -0
- package/.releaserc +17 -0
- package/.travis.yml +20 -0
- package/CBSDKdemo.html +315 -0
- package/GitVersion.yml +18 -0
- package/azure-pipeline.yaml +94 -0
- package/clientlib.config.js +36 -0
- package/config/env.js +105 -0
- package/config/getHttpsConfig.js +67 -0
- package/config/jest/babelTransform.js +30 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +41 -0
- package/config/modules.js +135 -0
- package/config/paths.js +79 -0
- package/config/webpack/persistentCache/createEnvironmentHash.js +10 -0
- package/config/webpack.config.js +762 -0
- package/config/webpackDevServer.config.js +128 -0
- package/config-overrides.js +8 -0
- package/gab_extension/GAB.html +85 -0
- package/gab_extension/GoogleChrome/manifest.json +28 -0
- package/gab_extension/GoogleChrome/src/assets/icon48.png +0 -0
- package/gab_extension/GoogleChrome/src/background/index.js +6 -0
- package/gab_extension/GoogleChrome/src/scripts/index.js +347 -0
- package/gab_extension/MozillaFirefox/manifest.json +20 -0
- package/gab_extension/MozillaFirefox/src/assets/icon.png +0 -0
- package/gab_extension/MozillaFirefox/src/background/index.js +5 -0
- package/gab_extension/MozillaFirefox/src/scripts/index.js +347 -0
- package/gab_extension/README.md +11 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.pbxproj +927 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/xcuserdata/oldevmac01.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/xcuserdata/oldevmac01.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +63 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/Contents.json +6 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +20 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Base.lproj/Main.html +23 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Icon.png +0 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Script.js +24 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Style.css +61 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/ViewController.swift +81 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (Extension)/SafariWebExtensionHandler.swift +26 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/AppDelegate.swift +24 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Base.lproj/LaunchScreen.storyboard +36 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Base.lproj/Main.storyboard +38 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Info.plist +27 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/SceneDelegate.swift +18 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (Extension)/Info.plist +13 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/AppDelegate.swift +21 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Base.lproj/Main.storyboard +125 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Info.plist +8 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Orange DAM Asset Browser Extension.entitlements +12 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (Extension)/Info.plist +13 -0
- package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (Extension)/Orange DAM Asset Browser Extension.entitlements +10 -0
- package/package.json +8 -49
- package/public/index.html +92 -0
- package/scripts/build.js +218 -0
- package/scripts/start.js +154 -0
- package/scripts/test.js +53 -0
- package/src/App.tsx +98 -0
- package/src/AppContext.ts +18 -0
- package/src/GlobalConfigContext.ts +46 -0
- package/src/components/ArrayClamp/ArrayClamp.styled.ts +42 -0
- package/src/components/ArrayClamp/ArrayClamp.tsx +167 -0
- package/src/components/ArrayClamp/index.ts +1 -0
- package/src/components/Browser/Browser.styled.ts +82 -0
- package/src/components/Browser/Browser.tsx +284 -0
- package/src/components/Browser/BrowserItem.tsx +98 -0
- package/src/components/ControlBar/ControlBar.constants.tsx +66 -0
- package/src/components/ControlBar/ControlBar.styled.ts +82 -0
- package/src/components/ControlBar/ControlBar.tsx +528 -0
- package/src/components/ControlBar/Facet/Facet.tsx +113 -0
- package/src/components/ControlBar/Facet/index.ts +1 -0
- package/src/components/FormatDialog/CropPreviewer/CropPreviewer.tsx +224 -0
- package/{build/components/FormatDialog/CropPreviewer/index.d.ts → src/components/FormatDialog/CropPreviewer/index.ts} +1 -1
- package/src/components/FormatDialog/CustomRendition/CustomRendition.constants.ts +24 -0
- package/src/components/FormatDialog/CustomRendition/CustomRendition.styled.ts +57 -0
- package/src/components/FormatDialog/CustomRendition/CustomRendition.tsx +178 -0
- package/src/components/FormatDialog/CustomRendition/index.ts +1 -0
- package/src/components/FormatDialog/CustomRendition/transformations/Crop.tsx +249 -0
- package/src/components/FormatDialog/CustomRendition/transformations/Extension.tsx +54 -0
- package/src/components/FormatDialog/CustomRendition/transformations/Format.tsx +86 -0
- package/src/components/FormatDialog/CustomRendition/transformations/Resize.tsx +176 -0
- package/src/components/FormatDialog/CustomRendition/transformations/Rotate.tsx +101 -0
- package/{build/components/FormatDialog/CustomRendition/transformations/index.d.ts → src/components/FormatDialog/CustomRendition/transformations/index.ts} +1 -3
- package/src/components/FormatDialog/FormatDialog.styled.ts +137 -0
- package/src/components/FormatDialog/FormatDialog.tsx +1533 -0
- package/src/components/FormatDialog/Previewer/Previewer.styled.ts +31 -0
- package/src/components/FormatDialog/Previewer/Previewer.tsx +143 -0
- package/src/components/FormatDialog/Previewer/index.ts +1 -0
- package/src/components/FormatDialog/ProxyMenu/ProxyMenu.styled.ts +88 -0
- package/src/components/FormatDialog/ProxyMenu/ProxyMenu.tsx +74 -0
- package/src/components/FormatDialog/ProxyMenu/index.ts +1 -0
- package/src/components/FormatDialog/TrackingParameters/TrackingParameters.tsx +59 -0
- package/src/components/FormatDialog/TrackingParameters/index.ts +1 -0
- package/src/components/FormatDialog/index.ts +1 -0
- package/src/components/Header/Header.styled.ts +51 -0
- package/src/components/Header/Header.tsx +118 -0
- package/src/components/Loader/Loader.tsx +37 -0
- package/src/components/Loader/index.ts +1 -0
- package/src/components/NoResult/NoResult.tsx +37 -0
- package/src/components/NoResult/index.tsx +1 -0
- package/src/components/Result/AssetCard/AssetCard.styled.ts +120 -0
- package/src/components/Result/AssetCard/AssetCard.tsx +192 -0
- package/src/components/Result/AssetCard/AssetCardWrapper.styled.ts +35 -0
- package/src/components/Result/AssetCard/AssetCardWrapper.tsx +165 -0
- package/src/components/Result/AssetCard/index.ts +1 -0
- package/src/components/Result/AssetPreview/AssetPreview.styled.ts +108 -0
- package/src/components/Result/AssetPreview/AssetPreview.tsx +78 -0
- package/src/components/Result/AssetPreview/ImagePreview/ImagePreview.tsx +42 -0
- package/src/components/Result/AssetPreview/ImagePreview/index.ts +1 -0
- package/src/components/Result/AssetPreview/OtherPreview/OtherPreview.styled.ts +23 -0
- package/src/components/Result/AssetPreview/OtherPreview/OtherPreview.tsx +28 -0
- package/src/components/Result/AssetPreview/OtherPreview/index.ts +1 -0
- package/src/components/Result/AssetPreview/VideoPreview/VideoPreview.tsx +132 -0
- package/src/components/Result/AssetPreview/VideoPreview/index.ts +1 -0
- package/src/components/Result/AssetPreview/index.ts +1 -0
- package/src/consts/asset.ts +16 -0
- package/src/consts/data.ts +17 -0
- package/src/index.tsx +305 -0
- package/src/page/Authenticate/Authenticate.tsx +232 -0
- package/src/page/Authenticate/ConnectingBackground.tsx +44 -0
- package/src/page/Authenticate/index.tsx +94 -0
- package/src/page/Home/Home.styled.ts +46 -0
- package/src/page/Home/Home.tsx +941 -0
- package/src/react-web-component.d.ts +4617 -0
- package/src/store/assets/assets.api.ts +167 -0
- package/src/store/assets/assets.service.ts +223 -0
- package/src/store/assets/assets.slice.ts +104 -0
- package/src/store/auth/auth.service.ts +71 -0
- package/src/store/auth/auth.slice.ts +295 -0
- package/src/store/index.ts +27 -0
- package/src/store/search/search.api.ts +319 -0
- package/src/store/search/search.slice.ts +28 -0
- package/src/store/user/user.api.ts +29 -0
- package/src/styles.css +42 -0
- package/src/types/assets.ts +71 -0
- package/src/types/auth.ts +42 -0
- package/src/types/common.ts +11 -0
- package/src/types/download.ts +8 -0
- package/src/types/navigation.ts +3 -0
- package/src/types/search.ts +116 -0
- package/{build/types/storage.d.ts → src/types/storage.ts} +1 -1
- package/src/types/user.ts +6 -0
- package/src/utils/api.ts +186 -0
- package/src/utils/array.ts +25 -0
- package/src/utils/constants.ts +12 -0
- package/src/utils/fetch.ts +116 -0
- package/src/utils/getRequestUrl.ts +15 -0
- package/src/utils/hooks.ts +36 -0
- package/src/utils/icon.ts +22 -0
- package/src/utils/image.ts +157 -0
- package/src/utils/number.ts +11 -0
- package/src/utils/rotate.ts +23 -0
- package/src/utils/storage.ts +184 -0
- package/src/utils/string.ts +24 -0
- package/src/view/AssetsPicker.tsx +24 -0
- package/src/web-component.d.ts +8151 -0
- package/tsconfig.eslint.json +10 -0
- package/tsconfig.json +37 -0
- package/build/ApiService.d.ts +0 -15
- package/build/App.d.ts +0 -62
- package/build/AppContext.d.ts +0 -18
- package/build/GlobalConfigContext.d.ts +0 -32
- package/build/OrangeDAMContentBrowserSDK.min.css +0 -2
- package/build/OrangeDAMContentBrowserSDK.min.css.map +0 -1
- package/build/OrangeDAMContentBrowserSDK.min.js +0 -11468
- package/build/OrangeDAMContentBrowserSDK.min.js.map +0 -1
- package/build/asset-manifest.json +0 -13
- package/build/components/ArrayClamp/ArrayClamp.d.ts +0 -10
- package/build/components/ArrayClamp/ArrayClamp.styled.d.ts +0 -1
- package/build/components/ArrayClamp/index.d.ts +0 -1
- package/build/components/Browser/Browser.constants.d.ts +0 -3
- package/build/components/Browser/Browser.d.ts +0 -21
- package/build/components/Browser/Browser.styled.d.ts +0 -2
- package/build/components/Browser/BrowserItem.d.ts +0 -13
- package/build/components/Browser/LoadMoreButton.d.ts +0 -9
- package/build/components/ControlBar/ControlBar.constants.d.ts +0 -10
- package/build/components/ControlBar/ControlBar.d.ts +0 -23
- package/build/components/ControlBar/ControlBar.styled.d.ts +0 -1
- package/build/components/ControlBar/Facet/Facet.d.ts +0 -14
- package/build/components/ControlBar/Facet/index.d.ts +0 -1
- package/build/components/FormatDialog/CropPreviewer/CropPreviewer.d.ts +0 -41
- package/build/components/FormatDialog/CustomRendition/CustomRendition.constants.d.ts +0 -5
- package/build/components/FormatDialog/CustomRendition/CustomRendition.d.ts +0 -56
- package/build/components/FormatDialog/CustomRendition/CustomRendition.styled.d.ts +0 -1
- package/build/components/FormatDialog/CustomRendition/index.d.ts +0 -1
- package/build/components/FormatDialog/CustomRendition/transformations/Crop.d.ts +0 -26
- package/build/components/FormatDialog/CustomRendition/transformations/Extension.d.ts +0 -11
- package/build/components/FormatDialog/CustomRendition/transformations/Format.d.ts +0 -10
- package/build/components/FormatDialog/CustomRendition/transformations/Metadata.d.ts +0 -7
- package/build/components/FormatDialog/CustomRendition/transformations/Quality.d.ts +0 -7
- package/build/components/FormatDialog/CustomRendition/transformations/Resize.d.ts +0 -18
- package/build/components/FormatDialog/CustomRendition/transformations/Rotate.d.ts +0 -8
- package/build/components/FormatDialog/FormatDialog.d.ts +0 -49
- package/build/components/FormatDialog/FormatDialog.styled.d.ts +0 -3
- package/build/components/FormatDialog/Previewer/Previewer.d.ts +0 -17
- package/build/components/FormatDialog/Previewer/Previewer.styled.d.ts +0 -1
- package/build/components/FormatDialog/Previewer/index.d.ts +0 -1
- package/build/components/FormatDialog/ProxyMenu/ProxyMenu.d.ts +0 -20
- package/build/components/FormatDialog/ProxyMenu/ProxyMenu.styled.d.ts +0 -2
- package/build/components/FormatDialog/ProxyMenu/index.d.ts +0 -1
- package/build/components/FormatDialog/TrackingParameters/TrackingParameters.d.ts +0 -13
- package/build/components/FormatDialog/TrackingParameters/index.d.ts +0 -1
- package/build/components/FormatDialog/VersionHistory/VersionHistory.d.ts +0 -6
- package/build/components/FormatDialog/VersionHistory/VersionHistory.styled.d.ts +0 -1
- package/build/components/FormatDialog/VersionHistory/index.d.ts +0 -1
- package/build/components/FormatDialog/index.d.ts +0 -1
- package/build/components/Header/Header.d.ts +0 -15
- package/build/components/Header/Header.styled.d.ts +0 -5
- package/build/components/Loader/Loader.d.ts +0 -7
- package/build/components/Loader/index.d.ts +0 -1
- package/build/components/NoResult/NoResult.d.ts +0 -7
- package/build/components/NoResult/index.d.ts +0 -1
- package/build/components/Result/AssetCard/AssetCard.d.ts +0 -15
- package/build/components/Result/AssetCard/AssetCard.styled.d.ts +0 -2
- package/build/components/Result/AssetCard/AssetCardWrapper.d.ts +0 -18
- package/build/components/Result/AssetCard/AssetCardWrapper.styled.d.ts +0 -1
- package/build/components/Result/AssetCard/index.d.ts +0 -1
- package/build/components/Result/AssetPreview/AssetPreview.d.ts +0 -11
- package/build/components/Result/AssetPreview/AssetPreview.styled.d.ts +0 -1
- package/build/components/Result/AssetPreview/ImagePreview/ImagePreview.d.ts +0 -11
- package/build/components/Result/AssetPreview/ImagePreview/index.d.ts +0 -1
- package/build/components/Result/AssetPreview/OtherPreview/OtherPreview.d.ts +0 -9
- package/build/components/Result/AssetPreview/OtherPreview/OtherPreview.styled.d.ts +0 -1
- package/build/components/Result/AssetPreview/OtherPreview/index.d.ts +0 -1
- package/build/components/Result/AssetPreview/VideoPreview/VideoPreview.d.ts +0 -11
- package/build/components/Result/AssetPreview/VideoPreview/index.d.ts +0 -1
- package/build/components/Result/AssetPreview/index.d.ts +0 -1
- package/build/consts/asset.d.ts +0 -14
- package/build/consts/auth.d.ts +0 -4
- package/build/consts/data.d.ts +0 -21
- package/build/index.d.ts +0 -225
- package/build/index.html +0 -1
- package/build/page/Authenticate/Authenticate.d.ts +0 -2
- package/build/page/Authenticate/ConnectingBackground.d.ts +0 -8
- package/build/page/Authenticate/index.d.ts +0 -2
- package/build/page/Home/Home.d.ts +0 -6
- package/build/page/Home/Home.styled.d.ts +0 -2
- package/build/setupTests.d.ts +0 -1
- package/build/store/assets/assets.api.d.ts +0 -66
- package/build/store/assets/assets.service.d.ts +0 -23
- package/build/store/assets/assets.slice.d.ts +0 -65
- package/build/store/auth/auth.service.d.ts +0 -10
- package/build/store/auth/auth.slice.d.ts +0 -76
- package/build/store/index.d.ts +0 -368
- package/build/store/search/search.api.d.ts +0 -39
- package/build/store/search/search.slice.d.ts +0 -12
- package/build/store/user/user.api.d.ts +0 -5
- package/build/types/assets.d.ts +0 -68
- package/build/types/auth.d.ts +0 -35
- package/build/types/common.d.ts +0 -11
- package/build/types/download.d.ts +0 -8
- package/build/types/navigation.d.ts +0 -3
- package/build/types/search.d.ts +0 -148
- package/build/types/user.d.ts +0 -7
- package/build/utils/api.d.ts +0 -27
- package/build/utils/array.d.ts +0 -13
- package/build/utils/constants.d.ts +0 -11
- package/build/utils/function.d.ts +0 -1
- package/build/utils/getRequestUrl.d.ts +0 -1
- package/build/utils/hooks.d.ts +0 -1
- package/build/utils/icon.d.ts +0 -3
- package/build/utils/image.d.ts +0 -24
- package/build/utils/number.d.ts +0 -4
- package/build/utils/rotate.d.ts +0 -4
- package/build/utils/storage.d.ts +0 -23
- package/build/utils/string.d.ts +0 -12
- package/build/view/AssetsPicker.d.ts +0 -6
- /package/{build → public}/favicon.ico +0 -0
- /package/{build → public}/logo192.png +0 -0
- /package/{build → public}/logo512.png +0 -0
- /package/{build → public}/manifest.json +0 -0
- /package/{build → public}/robots.txt +0 -0
- /package/{build/components/Browser/index.d.ts → src/components/Browser/index.ts} +0 -0
- /package/{build/components/ControlBar/index.d.ts → src/components/ControlBar/index.ts} +0 -0
- /package/{build/components/Header/index.d.ts → src/components/Header/index.ts} +0 -0
- /package/{build/page/Home/index.d.ts → src/page/Home/index.ts} +0 -0
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import _debounce from 'lodash-es/debounce';
|
|
2
|
+
import _intersection from 'lodash-es/intersection';
|
|
3
|
+
import _isEqual from 'lodash-es/isEqual';
|
|
4
|
+
import {
|
|
5
|
+
FC, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import { Size } from 'react-easy-crop';
|
|
8
|
+
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
9
|
+
|
|
10
|
+
import { AppContext } from '@/AppContext';
|
|
11
|
+
import { Browser } from '@/components/Browser';
|
|
12
|
+
import ControlBar from '@/components/ControlBar';
|
|
13
|
+
import FormatDialog from '@/components/FormatDialog';
|
|
14
|
+
import Header from '@/components/Header/Header';
|
|
15
|
+
import AssetCardWrapper from '@/components/Result/AssetCard';
|
|
16
|
+
import { ASSET_SIZE } from '@/consts/asset';
|
|
17
|
+
import { GlobalConfigContext } from '@/GlobalConfigContext';
|
|
18
|
+
import { useAppDispatch, useAppSelector } from '@/store';
|
|
19
|
+
import {
|
|
20
|
+
useGetAvailableExtensionsQuery,
|
|
21
|
+
useGetAvailableProxiesQuery, useGetParametersQuery, useGetSortOrdersQuery,
|
|
22
|
+
} from '@/store/assets/assets.api';
|
|
23
|
+
import { importAssets } from '@/store/assets/assets.slice';
|
|
24
|
+
import { authenticatedSelector, logout, useSessionSelector } from '@/store/auth/auth.slice';
|
|
25
|
+
import { useGetAssetsQuery } from '@/store/search/search.api';
|
|
26
|
+
import { explorePath, RootFolder } from '@/store/search/search.slice';
|
|
27
|
+
import { FormatLoaderState } from '@/types/assets';
|
|
28
|
+
import {
|
|
29
|
+
Asset, Filter, Folder, GetAssetLinkResponse, GridView, SortDirection,
|
|
30
|
+
} from '@/types/search';
|
|
31
|
+
import { MOBILE_THRESHOLD, PAGE_SIZE } from '@/utils/constants';
|
|
32
|
+
import { getData, storeData } from '@/utils/storage';
|
|
33
|
+
import { CxResizeEvent, CxResizeObserver } from '@/web-component';
|
|
34
|
+
import { skipToken } from '@reduxjs/toolkit/query';
|
|
35
|
+
|
|
36
|
+
import { Container } from './Home.styled';
|
|
37
|
+
|
|
38
|
+
type Props = {
|
|
39
|
+
multiSelect?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type State = {
|
|
43
|
+
containerSize: {
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
};
|
|
47
|
+
currentCount: number;
|
|
48
|
+
currentFolder: Folder;
|
|
49
|
+
defaultPageSize: number;
|
|
50
|
+
extensions: string[];
|
|
51
|
+
facets: Record<string, Record<string, number>>;
|
|
52
|
+
hasScrolled: boolean;
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
isSeeThrough: boolean;
|
|
55
|
+
mediaTypes: string[];
|
|
56
|
+
openBrowser: boolean;
|
|
57
|
+
start: number;
|
|
58
|
+
pageSize: number;
|
|
59
|
+
maxPageSize: number;
|
|
60
|
+
searchText: string;
|
|
61
|
+
selectedAsset: Asset | null;
|
|
62
|
+
shouldResetFilters: boolean;
|
|
63
|
+
sortDirection?: 'ascending' | 'descending';
|
|
64
|
+
sortOrder: string;
|
|
65
|
+
statuses: string[];
|
|
66
|
+
totalCount: number;
|
|
67
|
+
view: GridView;
|
|
68
|
+
visibilityClasses: string[];
|
|
69
|
+
newlySelectedFacet: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type Action =
|
|
73
|
+
| { type: 'RESET_SEARCH' }
|
|
74
|
+
| { type: 'SET_CONTAINER_SIZE'; payload: { width: number; height: number } }
|
|
75
|
+
| { type: 'SET_CURRENT_COUNT'; payload: number }
|
|
76
|
+
| { type: 'SET_CURRENT_FOLDER'; payload: {
|
|
77
|
+
folder: Folder,
|
|
78
|
+
shouldResetFilters?: boolean;
|
|
79
|
+
} }
|
|
80
|
+
| { type: 'SET_FACETS'; payload: Record<string, Record<string, number>> }
|
|
81
|
+
| { type: 'SET_FILTERS'; payload: Filter }
|
|
82
|
+
| { type: 'SET_HAS_SCROLLED'; payload: boolean }
|
|
83
|
+
| { type: 'SET_IS_LOADING'; payload: boolean }
|
|
84
|
+
| { type: 'SET_IS_SEE_THROUGH'; payload: boolean }
|
|
85
|
+
| { type: 'SET_OPEN_BROWSER'; payload: boolean }
|
|
86
|
+
| { type: 'SET_START'; payload: number }
|
|
87
|
+
| { type: 'SET_PAGE_SIZE'; payload: {
|
|
88
|
+
pageSize: number;
|
|
89
|
+
returnToFirstPage: boolean;
|
|
90
|
+
} }
|
|
91
|
+
| { type: 'SET_SEARCH_TEXT'; payload: string }
|
|
92
|
+
| { type: 'SET_SELECTED_ASSET'; payload: Asset | null }
|
|
93
|
+
| { type: 'SET_SORT_DIRECTION'; payload: 'ascending' | 'descending' | undefined }
|
|
94
|
+
| { type: 'SET_SORT_ORDER'; payload: string }
|
|
95
|
+
| { type: 'SET_TOTAL_COUNT'; payload: number }
|
|
96
|
+
| { type: 'SET_VIEW'; payload: GridView }
|
|
97
|
+
| { type: 'SET_NEWLY_SELECTED_FACET'; payload: string };
|
|
98
|
+
|
|
99
|
+
const initialState: State = {
|
|
100
|
+
containerSize: {
|
|
101
|
+
width: 0,
|
|
102
|
+
height: 0,
|
|
103
|
+
},
|
|
104
|
+
currentCount: 0,
|
|
105
|
+
currentFolder: RootFolder,
|
|
106
|
+
defaultPageSize: PAGE_SIZE,
|
|
107
|
+
extensions: [],
|
|
108
|
+
facets: {},
|
|
109
|
+
hasScrolled: false,
|
|
110
|
+
isLoading: false,
|
|
111
|
+
isSeeThrough: true,
|
|
112
|
+
mediaTypes: [],
|
|
113
|
+
openBrowser: false,
|
|
114
|
+
start: 0,
|
|
115
|
+
pageSize: 0,
|
|
116
|
+
maxPageSize: 0,
|
|
117
|
+
searchText: '',
|
|
118
|
+
selectedAsset: null,
|
|
119
|
+
shouldResetFilters: true,
|
|
120
|
+
sortDirection: undefined,
|
|
121
|
+
sortOrder: '',
|
|
122
|
+
statuses: [],
|
|
123
|
+
totalCount: 0,
|
|
124
|
+
view: GridView.Medium,
|
|
125
|
+
visibilityClasses: [],
|
|
126
|
+
newlySelectedFacet:'',
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const reducer = (state: State, action: Action): State => {
|
|
130
|
+
const resetPageState = {
|
|
131
|
+
start: 0,
|
|
132
|
+
pageSize: state.maxPageSize,
|
|
133
|
+
};
|
|
134
|
+
switch (action.type) {
|
|
135
|
+
case 'SET_CONTAINER_SIZE':
|
|
136
|
+
return { ...state, containerSize: action.payload };
|
|
137
|
+
case 'SET_CURRENT_COUNT':
|
|
138
|
+
return { ...state, currentCount: action.payload };
|
|
139
|
+
case 'SET_CURRENT_FOLDER':
|
|
140
|
+
return { ...state, currentFolder: action.payload.folder, shouldResetFilters: !!action.payload.shouldResetFilters, ...resetPageState };
|
|
141
|
+
case 'SET_FACETS':
|
|
142
|
+
return { ...state, facets: action.payload };
|
|
143
|
+
case 'SET_FILTERS':
|
|
144
|
+
return {
|
|
145
|
+
...state,
|
|
146
|
+
mediaTypes: action.payload.mediaTypes,
|
|
147
|
+
visibilityClasses: action.payload.visibilityClasses,
|
|
148
|
+
shouldResetFilters: false,
|
|
149
|
+
statuses: action.payload.statuses,
|
|
150
|
+
extensions: action.payload.extensions,
|
|
151
|
+
...resetPageState,
|
|
152
|
+
};
|
|
153
|
+
case 'SET_HAS_SCROLLED':
|
|
154
|
+
return { ...state, hasScrolled: action.payload };
|
|
155
|
+
case 'SET_IS_LOADING':
|
|
156
|
+
return { ...state, isLoading: action.payload };
|
|
157
|
+
case 'SET_IS_SEE_THROUGH':
|
|
158
|
+
return { ...state, isSeeThrough: action.payload, ...resetPageState };
|
|
159
|
+
case 'SET_OPEN_BROWSER':
|
|
160
|
+
return { ...state, openBrowser: action.payload };
|
|
161
|
+
case 'SET_START':{
|
|
162
|
+
return { ...state, start: state.start + state.pageSize, pageSize: state.defaultPageSize };
|
|
163
|
+
}
|
|
164
|
+
case 'SET_PAGE_SIZE': {
|
|
165
|
+
const result = { ...state, pageSize: action.payload.pageSize, maxPageSize: action.payload.pageSize };
|
|
166
|
+
if (action.payload.returnToFirstPage) {
|
|
167
|
+
result.start = 0;
|
|
168
|
+
} else {
|
|
169
|
+
result.start = state.start + state.pageSize;
|
|
170
|
+
result.pageSize = Math.abs(action.payload.pageSize - result.start);
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
case 'SET_SEARCH_TEXT':
|
|
175
|
+
return { ...state, ...resetPageState, searchText: action.payload };
|
|
176
|
+
case 'SET_SELECTED_ASSET':
|
|
177
|
+
return { ...state, selectedAsset: action.payload };
|
|
178
|
+
case 'SET_SORT_DIRECTION':
|
|
179
|
+
return { ...state, ...resetPageState, sortDirection: action.payload };
|
|
180
|
+
case 'SET_SORT_ORDER':
|
|
181
|
+
return { ...state, ...resetPageState, sortOrder: action.payload };
|
|
182
|
+
case 'SET_TOTAL_COUNT':
|
|
183
|
+
return { ...state, totalCount: action.payload };
|
|
184
|
+
case 'SET_VIEW': {
|
|
185
|
+
let defaultPageSize = PAGE_SIZE;
|
|
186
|
+
switch (action.payload) {
|
|
187
|
+
case GridView.Large:
|
|
188
|
+
defaultPageSize = 15;
|
|
189
|
+
break;
|
|
190
|
+
case GridView.Medium:
|
|
191
|
+
defaultPageSize = 20;
|
|
192
|
+
break;
|
|
193
|
+
case GridView.Small:
|
|
194
|
+
defaultPageSize = 30;
|
|
195
|
+
break;
|
|
196
|
+
default:
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return { ...state, view: action.payload, defaultPageSize };
|
|
200
|
+
}
|
|
201
|
+
case 'RESET_SEARCH':
|
|
202
|
+
return {
|
|
203
|
+
...state,
|
|
204
|
+
currentCount: 0,
|
|
205
|
+
currentFolder: RootFolder,
|
|
206
|
+
searchText: '',
|
|
207
|
+
selectedAsset: null,
|
|
208
|
+
totalCount: 0,
|
|
209
|
+
};
|
|
210
|
+
case 'SET_NEWLY_SELECTED_FACET':
|
|
211
|
+
return { ...state, newlySelectedFacet: action.payload };
|
|
212
|
+
default:
|
|
213
|
+
return state;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const HomePage: FC<Props> = () => {
|
|
218
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
219
|
+
const authenticated = useAppSelector(authenticatedSelector);
|
|
220
|
+
const useSession = useAppSelector(useSessionSelector);
|
|
221
|
+
const {
|
|
222
|
+
availableRepresentativeSubtypes,
|
|
223
|
+
availableDocTypes,
|
|
224
|
+
ctaText,
|
|
225
|
+
lastLocationMode,
|
|
226
|
+
persistMode,
|
|
227
|
+
searchInDrive,
|
|
228
|
+
showCollections,
|
|
229
|
+
allowTracking,
|
|
230
|
+
} = useContext(GlobalConfigContext);
|
|
231
|
+
const { extraFields } = useContext(AppContext);
|
|
232
|
+
const { data: availableProxies, isFetching: isFetchingAvailableProxies } = useGetAvailableProxiesQuery(state.selectedAsset ? {
|
|
233
|
+
assetImages: state.selectedAsset ? [state.selectedAsset] : [],
|
|
234
|
+
useSession,
|
|
235
|
+
} : skipToken);
|
|
236
|
+
const { data: availableExtensions } = useGetAvailableExtensionsQuery();
|
|
237
|
+
const { data: params } = useGetParametersQuery({
|
|
238
|
+
useSession,
|
|
239
|
+
});
|
|
240
|
+
const {
|
|
241
|
+
ATSEnabled,
|
|
242
|
+
autoExtension = '.auto',
|
|
243
|
+
collectionPath,
|
|
244
|
+
supportedDocTypes,
|
|
245
|
+
supportedExtensions,
|
|
246
|
+
supportedRepresentativeSubtypes,
|
|
247
|
+
} = params || {};
|
|
248
|
+
const { data: sortOrders } = useGetSortOrdersQuery({
|
|
249
|
+
useSession,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const [browserMounted, setBrowserMounted] = useState(false);
|
|
253
|
+
const [isResized, setIsResized] = useState(false);
|
|
254
|
+
const [showFormatLoader, setShowFormatLoader] = useState<FormatLoaderState>(FormatLoaderState.Hide);
|
|
255
|
+
|
|
256
|
+
const browserMountedRef = useRef(browserMounted);
|
|
257
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
258
|
+
const resultRef = useRef<HTMLDivElement>(null);
|
|
259
|
+
const containerResizeObserverRef = useRef<CxResizeObserver>(null);
|
|
260
|
+
const loadedFromStorage = useRef(false);
|
|
261
|
+
const facetsRef = useRef<Record<string, Record<string, number>>>({});
|
|
262
|
+
const appDispatch = useAppDispatch();
|
|
263
|
+
|
|
264
|
+
const pageSizeRef = useRef(state.pageSize);
|
|
265
|
+
const viewRef = useRef(state.view);
|
|
266
|
+
const isWindowResizing = useRef(false);
|
|
267
|
+
browserMountedRef.current = browserMounted;
|
|
268
|
+
facetsRef.current = state.facets;
|
|
269
|
+
viewRef.current = state.view;
|
|
270
|
+
pageSizeRef.current = state.pageSize;
|
|
271
|
+
const formatDialogTimeoutRef = useRef<number | null>(null);
|
|
272
|
+
|
|
273
|
+
const mappedMediaTypes = useMemo(() => {
|
|
274
|
+
const globalIntersection = availableDocTypes?.length ? _intersection(availableDocTypes, supportedDocTypes) : supportedDocTypes;
|
|
275
|
+
if (!globalIntersection || globalIntersection.length === 0) return state.mediaTypes;
|
|
276
|
+
const intersection = state.mediaTypes.reduce((acc, mediaType) => {
|
|
277
|
+
const [parent] = mediaType.split('>>');
|
|
278
|
+
|
|
279
|
+
if (globalIntersection.includes(`${parent}*`) || globalIntersection.includes(parent)) {
|
|
280
|
+
if (!mediaType.includes('>>')) {
|
|
281
|
+
return acc.concat(`${parent}*`);
|
|
282
|
+
}
|
|
283
|
+
return acc.concat(mediaType);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return acc;
|
|
287
|
+
}, [] as string[]);
|
|
288
|
+
if (intersection.length > 0) return intersection;
|
|
289
|
+
return globalIntersection;
|
|
290
|
+
}, [availableDocTypes, state.mediaTypes, supportedDocTypes]);
|
|
291
|
+
|
|
292
|
+
const isConfigError = useMemo(() => (!mappedMediaTypes?.length || mappedMediaTypes.length === 0) && !!supportedDocTypes, [mappedMediaTypes, supportedDocTypes]);
|
|
293
|
+
|
|
294
|
+
const selectedSortOrder = useMemo(() => {
|
|
295
|
+
if (!sortOrders) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const defaultSortOrder = Object.values(sortOrders).find(
|
|
300
|
+
(sortOrder) => sortOrder.some((order) => order.isDefault),
|
|
301
|
+
)?.[0];
|
|
302
|
+
|
|
303
|
+
if (!state.sortOrder || !sortOrders[state.sortOrder] || sortOrders[state.sortOrder].length === 0) {
|
|
304
|
+
if (defaultSortOrder) {
|
|
305
|
+
dispatch({ type: 'SET_SORT_DIRECTION', payload: defaultSortOrder.sortDirection.toLowerCase() as 'ascending' | 'descending' });
|
|
306
|
+
dispatch({ type: 'SET_SORT_ORDER', payload: defaultSortOrder.sortDirectionGroupKey.toLowerCase() });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return defaultSortOrder;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (sortOrders[state.sortOrder].length === 1) {
|
|
313
|
+
return sortOrders[state.sortOrder][0];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return sortOrders[state.sortOrder].find(
|
|
317
|
+
({ sortDirection }) => sortDirection.toLowerCase() === state.sortDirection,
|
|
318
|
+
);
|
|
319
|
+
}, [sortOrders, state.sortDirection, state.sortOrder]);
|
|
320
|
+
|
|
321
|
+
const { data, isFetching, isError } = useGetAssetsQuery(isResized && sortOrders && mappedMediaTypes?.length && browserMounted ? {
|
|
322
|
+
extensions: state.extensions,
|
|
323
|
+
folderID: state.currentFolder.id,
|
|
324
|
+
isSeeThrough: state.isSeeThrough,
|
|
325
|
+
mediaTypes: mappedMediaTypes,
|
|
326
|
+
start: state.start,
|
|
327
|
+
pageSize: state.pageSize,
|
|
328
|
+
searchText: state.searchText,
|
|
329
|
+
sortOrder: selectedSortOrder?.id,
|
|
330
|
+
statuses: state.statuses ?? [],
|
|
331
|
+
visibilityClasses: state.visibilityClasses,
|
|
332
|
+
useSession,
|
|
333
|
+
} : skipToken);
|
|
334
|
+
|
|
335
|
+
useEffect(() => {
|
|
336
|
+
// isFetching is constantly switched between true and false due to the changed parameters
|
|
337
|
+
// Set isLoading to true when isFetching is true for at least 200ms and set it to false when isFetching is false for at least 200ms
|
|
338
|
+
let timer = null;
|
|
339
|
+
|
|
340
|
+
if (isFetching) {
|
|
341
|
+
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
|
342
|
+
} else {
|
|
343
|
+
timer = setTimeout(() => {
|
|
344
|
+
dispatch({ type: 'SET_IS_LOADING', payload: isFetching });
|
|
345
|
+
}, 200);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return () => {
|
|
349
|
+
if (timer) {
|
|
350
|
+
clearTimeout(timer);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}, [isFetching]);
|
|
354
|
+
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
if (authenticated) {
|
|
357
|
+
dispatch({ type: 'RESET_SEARCH' });
|
|
358
|
+
|
|
359
|
+
Promise.all([
|
|
360
|
+
getData('selectedSortOrder'),
|
|
361
|
+
getData('selectedSortDirection'),
|
|
362
|
+
getData('selectedView'),
|
|
363
|
+
getData('newlySelectedFacet'),
|
|
364
|
+
getData('newFacets'),
|
|
365
|
+
getData('selectedFilter'),
|
|
366
|
+
getData('selectedIsSeeThrough'),
|
|
367
|
+
getData('searchText'),
|
|
368
|
+
]).then(([sortOrder, sortDirection, view, newlySelectedFacet, newFacets, selectedFilter, selectedIsSeeThrough, searchText]) => {
|
|
369
|
+
if (sortOrder) {
|
|
370
|
+
dispatch({ type: 'SET_SORT_ORDER', payload: sortOrder });
|
|
371
|
+
}
|
|
372
|
+
if (sortDirection === 'ascending' || sortDirection === 'descending') {
|
|
373
|
+
dispatch({ type: 'SET_SORT_DIRECTION', payload: sortDirection });
|
|
374
|
+
}
|
|
375
|
+
if (typeof view === 'string') {
|
|
376
|
+
dispatch({ type: 'SET_VIEW', payload: view as GridView });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (lastLocationMode) {
|
|
380
|
+
if (newlySelectedFacet) {
|
|
381
|
+
dispatch({ type: 'SET_NEWLY_SELECTED_FACET', payload: newlySelectedFacet });
|
|
382
|
+
}
|
|
383
|
+
if (newFacets) {
|
|
384
|
+
const parsedFacets = JSON.parse(newFacets);
|
|
385
|
+
dispatch({ type: 'SET_FACETS', payload: parsedFacets });
|
|
386
|
+
}
|
|
387
|
+
if (selectedFilter) {
|
|
388
|
+
const parsedFilter = JSON.parse(selectedFilter);
|
|
389
|
+
dispatch({ type: 'SET_FILTERS', payload: parsedFilter });
|
|
390
|
+
}
|
|
391
|
+
if (selectedIsSeeThrough) {
|
|
392
|
+
dispatch({ type: 'SET_IS_SEE_THROUGH', payload: selectedIsSeeThrough === 'true' });
|
|
393
|
+
}
|
|
394
|
+
if (searchText) {
|
|
395
|
+
dispatch({ type: 'SET_SEARCH_TEXT', payload: searchText });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
loadedFromStorage.current = true;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}, [authenticated, lastLocationMode]);
|
|
403
|
+
|
|
404
|
+
useEffect(() => {
|
|
405
|
+
const resizeObserver = containerResizeObserverRef.current;
|
|
406
|
+
if (!resizeObserver) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const onResize = (e: CxResizeEvent) => {
|
|
410
|
+
const entries = e.detail.entries;
|
|
411
|
+
|
|
412
|
+
window.requestAnimationFrame((): void | undefined => {
|
|
413
|
+
if (!Array.isArray(entries) || !entries.length) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (entries[0].target === containerRef.current) {
|
|
417
|
+
dispatch({
|
|
418
|
+
type: 'SET_CONTAINER_SIZE',
|
|
419
|
+
payload: {
|
|
420
|
+
width: entries[0].contentRect.width,
|
|
421
|
+
height: entries[0].contentRect.height,
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
resizeObserver.addEventListener('cx-resize', onResize);
|
|
429
|
+
|
|
430
|
+
return () => {
|
|
431
|
+
resizeObserver.removeEventListener('cx-resize', onResize);
|
|
432
|
+
};
|
|
433
|
+
}, []);
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
useEffect(() => {
|
|
437
|
+
if (!selectedSortOrder && loadedFromStorage.current) {
|
|
438
|
+
dispatch({ type: 'SET_SORT_ORDER', payload: initialState.sortOrder });
|
|
439
|
+
}
|
|
440
|
+
}, [selectedSortOrder, sortOrders]);
|
|
441
|
+
|
|
442
|
+
useEffect(() => {
|
|
443
|
+
if (!loadedFromStorage.current) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
storeData('selectedSortOrder', state.sortOrder);
|
|
448
|
+
if (state.sortDirection) {
|
|
449
|
+
storeData('selectedSortDirection', state.sortDirection);
|
|
450
|
+
}
|
|
451
|
+
storeData('selectedView', state.view);
|
|
452
|
+
storeData('newlySelectedFacet', state.newlySelectedFacet);
|
|
453
|
+
storeData('newFacets', JSON.stringify(state.facets));
|
|
454
|
+
storeData(
|
|
455
|
+
'selectedFilter',
|
|
456
|
+
JSON.stringify({
|
|
457
|
+
mediaTypes: state.mediaTypes,
|
|
458
|
+
visibilityClasses: state.visibilityClasses,
|
|
459
|
+
shouldResetFilters: false,
|
|
460
|
+
statuses: state.statuses,
|
|
461
|
+
extensions: state.extensions,
|
|
462
|
+
}),
|
|
463
|
+
);
|
|
464
|
+
storeData('selectedIsSeeThrough', state.isSeeThrough.toString());
|
|
465
|
+
storeData('searchText', state.searchText);
|
|
466
|
+
}, [
|
|
467
|
+
state.currentFolder,
|
|
468
|
+
state.extensions,
|
|
469
|
+
state.facets,
|
|
470
|
+
state.isSeeThrough,
|
|
471
|
+
state.mediaTypes,
|
|
472
|
+
state.newlySelectedFacet,
|
|
473
|
+
state.sortDirection,
|
|
474
|
+
state.sortOrder,
|
|
475
|
+
state.searchText,
|
|
476
|
+
state.statuses,
|
|
477
|
+
state.view,
|
|
478
|
+
state.visibilityClasses,
|
|
479
|
+
]);
|
|
480
|
+
|
|
481
|
+
const isMobile = state.containerSize.width <= MOBILE_THRESHOLD;
|
|
482
|
+
|
|
483
|
+
const onItemSelect = (item: Asset) => {
|
|
484
|
+
dispatch({ type: 'SET_SELECTED_ASSET', payload: item });
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const onSearchChange = useCallback((value: string) => {
|
|
488
|
+
dispatch({ type: 'SET_SELECTED_ASSET', payload: null });
|
|
489
|
+
dispatch({ type: 'SET_SEARCH_TEXT', payload: value });
|
|
490
|
+
}, []);
|
|
491
|
+
|
|
492
|
+
const lastHeightRef = useRef(0);
|
|
493
|
+
const lastWidthRef = useRef(0);
|
|
494
|
+
|
|
495
|
+
const defaultPageSizeRef = useRef(state.defaultPageSize);
|
|
496
|
+
defaultPageSizeRef.current = state.defaultPageSize;
|
|
497
|
+
|
|
498
|
+
const handleResize = useCallback((rect: Size, options?:{ returnToFirstPage?: boolean, force?: boolean }) => {
|
|
499
|
+
const { width, height } = rect;
|
|
500
|
+
const containerWidth = width || 0;
|
|
501
|
+
const containerHeight = height || 0;
|
|
502
|
+
if (containerWidth * containerHeight === 0 || !loadedFromStorage.current) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const lastHeight = lastHeightRef.current;
|
|
506
|
+
const lastWidth = lastWidthRef.current;
|
|
507
|
+
if (Math.abs(lastHeight - containerHeight) < 10 && Math.abs(lastWidth - containerWidth) < 10 && !options?.force) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
lastHeightRef.current = containerHeight;
|
|
511
|
+
lastWidthRef.current = containerWidth;
|
|
512
|
+
const gutter = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--cx-spacing-medium') || '16', 10);
|
|
513
|
+
const breakpoint = ASSET_SIZE[viewRef.current]?.minWidth || ASSET_SIZE[GridView.Large].minWidth;
|
|
514
|
+
const columnCount = Math.max(1, Math.floor((containerWidth + gutter) / (breakpoint + gutter)));
|
|
515
|
+
const rowCount = Math.ceil(containerHeight / (breakpoint + gutter));
|
|
516
|
+
const newPageSize = Math.ceil((rowCount * columnCount) / defaultPageSizeRef.current + 1) * defaultPageSizeRef.current;
|
|
517
|
+
setIsResized(true);
|
|
518
|
+
if (newPageSize !== pageSizeRef.current) {
|
|
519
|
+
dispatch({
|
|
520
|
+
type: 'SET_PAGE_SIZE',
|
|
521
|
+
payload: {
|
|
522
|
+
pageSize: newPageSize,
|
|
523
|
+
returnToFirstPage: !!options?.returnToFirstPage,
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}, []);
|
|
528
|
+
|
|
529
|
+
const debouncedHandleResize = useMemo(() => {
|
|
530
|
+
return _debounce(handleResize, 300, {
|
|
531
|
+
leading: false,
|
|
532
|
+
});
|
|
533
|
+
}, [handleResize]);
|
|
534
|
+
|
|
535
|
+
useEffect(() => {
|
|
536
|
+
if (loadedFromStorage.current) {
|
|
537
|
+
const container = resultRef.current;
|
|
538
|
+
viewRef.current = state.view;
|
|
539
|
+
if (container) {
|
|
540
|
+
debouncedHandleResize({
|
|
541
|
+
width: container.clientWidth,
|
|
542
|
+
height: container.clientHeight,
|
|
543
|
+
}, {
|
|
544
|
+
returnToFirstPage: true,
|
|
545
|
+
force: true,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}, [debouncedHandleResize, state.view]);
|
|
550
|
+
|
|
551
|
+
const onSettingChange = useCallback(
|
|
552
|
+
(
|
|
553
|
+
setting: string,
|
|
554
|
+
value: GridView | SortDirection | Filter | string | boolean | string[],
|
|
555
|
+
) => {
|
|
556
|
+
switch (setting) {
|
|
557
|
+
case 'view':
|
|
558
|
+
dispatch({ type: 'SET_VIEW', payload: value as GridView });
|
|
559
|
+
break;
|
|
560
|
+
case 'sortDirection':
|
|
561
|
+
dispatch({
|
|
562
|
+
type: 'SET_SORT_DIRECTION',
|
|
563
|
+
payload: value as SortDirection,
|
|
564
|
+
});
|
|
565
|
+
break;
|
|
566
|
+
case 'sortOrder':
|
|
567
|
+
dispatch({ type: 'SET_SORT_ORDER', payload: value.toString() });
|
|
568
|
+
break;
|
|
569
|
+
case 'isSeeThrough':
|
|
570
|
+
dispatch({ type: 'SET_IS_SEE_THROUGH', payload: Boolean(value) });
|
|
571
|
+
break;
|
|
572
|
+
case 'filter':
|
|
573
|
+
dispatch({ type: 'SET_FILTERS', payload: value as Filter });
|
|
574
|
+
break;
|
|
575
|
+
default:
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
[],
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
const onDataChange = useCallback(
|
|
583
|
+
(newData: {
|
|
584
|
+
facets: Record<string, Record<string, number>>;
|
|
585
|
+
items: Asset[];
|
|
586
|
+
totalCount: number;
|
|
587
|
+
currentCount: number;
|
|
588
|
+
}) => {
|
|
589
|
+
dispatch({ type: 'SET_CURRENT_COUNT', payload: newData.currentCount });
|
|
590
|
+
if (state.shouldResetFilters) {
|
|
591
|
+
dispatch({ type: 'SET_FACETS', payload: newData.facets });
|
|
592
|
+
} else if (state.newlySelectedFacet === '') {
|
|
593
|
+
dispatch({ type: 'SET_FACETS', payload: newData.facets });
|
|
594
|
+
} else {
|
|
595
|
+
const newFacets: Record<string, Record<string, number>> = {};
|
|
596
|
+
Object.entries(facetsRef.current).forEach(([filter, facets]) => {
|
|
597
|
+
newFacets[filter] = {};
|
|
598
|
+
if (filter !== state.newlySelectedFacet) {
|
|
599
|
+
Object.keys(facets).forEach((facet) => {
|
|
600
|
+
if (newData?.facets?.[filter]?.[facet]) {
|
|
601
|
+
newFacets[filter][facet] = newData.facets[filter][facet];
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
} else {
|
|
605
|
+
Object.keys(facets).forEach((facet) => {
|
|
606
|
+
newFacets[filter][facet] = facetsRef.current?.[filter]?.[facet];
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
Object.entries(newData.facets).forEach(([filter, facets]) => {
|
|
611
|
+
if (!newFacets[filter]) {
|
|
612
|
+
newFacets[filter] = {};
|
|
613
|
+
}
|
|
614
|
+
Object.keys(facets).forEach((facet) => {
|
|
615
|
+
newFacets[filter][facet] = newData.facets?.[filter]?.[facet];
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
if (_isEqual(newFacets, facetsRef.current)) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
dispatch({
|
|
624
|
+
type: 'SET_FACETS',
|
|
625
|
+
payload: {
|
|
626
|
+
...newFacets,
|
|
627
|
+
},
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
dispatch({ type: 'SET_TOTAL_COUNT', payload: newData.totalCount });
|
|
632
|
+
},
|
|
633
|
+
[state.shouldResetFilters, state.newlySelectedFacet],
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const onFolderSelect = useCallback(
|
|
637
|
+
async (folder: Folder) => {
|
|
638
|
+
if (!browserMountedRef.current) {
|
|
639
|
+
setBrowserMounted(true);
|
|
640
|
+
}
|
|
641
|
+
if (folder.id === state.currentFolder.id) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const resultAction = await appDispatch(explorePath(folder));
|
|
645
|
+
if (explorePath.fulfilled.match(resultAction)) {
|
|
646
|
+
dispatch({ type: 'SET_CURRENT_FOLDER', payload: {
|
|
647
|
+
folder,
|
|
648
|
+
shouldResetFilters: browserMountedRef.current,
|
|
649
|
+
} });
|
|
650
|
+
dispatch({ type: 'SET_SELECTED_ASSET', payload: null });
|
|
651
|
+
dispatch({ type: 'SET_OPEN_BROWSER', payload: false });
|
|
652
|
+
storeData('lastLocation', JSON.stringify(folder));
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
[appDispatch, state.currentFolder.id],
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
const onLoadMore = useCallback(() => {
|
|
659
|
+
if (isWindowResizing.current) {
|
|
660
|
+
isWindowResizing.current = false;
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
dispatch({ type: 'SET_START', payload: 1 });
|
|
664
|
+
}, []);
|
|
665
|
+
|
|
666
|
+
const onScroll = useCallback((e: MouseEvent) => {
|
|
667
|
+
if (!e.target) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if ((e.target as HTMLElement).scrollTop === 0) {
|
|
672
|
+
dispatch({ type: 'SET_HAS_SCROLLED', payload: false });
|
|
673
|
+
} else {
|
|
674
|
+
dispatch({ type: 'SET_HAS_SCROLLED', payload: true });
|
|
675
|
+
}
|
|
676
|
+
}, []);
|
|
677
|
+
|
|
678
|
+
const handleSelectedAsset = useCallback((images: GetAssetLinkResponse[]) => {
|
|
679
|
+
window.OrangeDAMContentBrowser._onAssetSelected?.(images);
|
|
680
|
+
if (persistMode) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
window.OrangeDAMContentBrowser._onClose?.();
|
|
684
|
+
}, [persistMode]);
|
|
685
|
+
|
|
686
|
+
const hasNextPage = useMemo(
|
|
687
|
+
() => (data ? state.start + state.pageSize < state.totalCount : false),
|
|
688
|
+
[data, state.pageSize, state.start, state.totalCount],
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
const setNewlySelectedFacet = useCallback((newFacet: string) => {
|
|
692
|
+
dispatch({ type: 'SET_NEWLY_SELECTED_FACET', payload: newFacet });
|
|
693
|
+
}, []);
|
|
694
|
+
|
|
695
|
+
useEffect(() => {
|
|
696
|
+
if (onDataChange) {
|
|
697
|
+
onDataChange({
|
|
698
|
+
currentCount: data?.items.length ?? 0,
|
|
699
|
+
items: data?.items || [],
|
|
700
|
+
facets: data?.facets || {},
|
|
701
|
+
totalCount: data?.totalCount ?? 0,
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}, [data, onDataChange]);
|
|
705
|
+
|
|
706
|
+
useEffect(() => {
|
|
707
|
+
const onWindowResize = () => {
|
|
708
|
+
isWindowResizing.current = true;
|
|
709
|
+
};
|
|
710
|
+
window.addEventListener('resize', onWindowResize);
|
|
711
|
+
return () => {
|
|
712
|
+
window.removeEventListener('resize', onWindowResize);
|
|
713
|
+
};
|
|
714
|
+
}, []);
|
|
715
|
+
|
|
716
|
+
useEffect(() => {
|
|
717
|
+
const timeout = formatDialogTimeoutRef.current;
|
|
718
|
+
const clearTimeout = () => {
|
|
719
|
+
if (timeout) {
|
|
720
|
+
window.clearTimeout(timeout);
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
clearTimeout();
|
|
724
|
+
|
|
725
|
+
if (isFetchingAvailableProxies) {
|
|
726
|
+
setShowFormatLoader(FormatLoaderState.Hide); // Hide the loader and the dialog when starting to fetch proxies
|
|
727
|
+
formatDialogTimeoutRef.current = window.setTimeout(() => {
|
|
728
|
+
setShowFormatLoader(FormatLoaderState.ShowLoader); // Show loader after 800ms
|
|
729
|
+
}, 800);
|
|
730
|
+
} else if (!isFetchingAvailableProxies && availableProxies?.proxies) {
|
|
731
|
+
if (formatDialogTimeoutRef.current) {
|
|
732
|
+
clearTimeout();
|
|
733
|
+
setShowFormatLoader(FormatLoaderState.ShowDialog); // Hide loader when proxies are fetched
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return () => {
|
|
738
|
+
clearTimeout();
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
}, [availableProxies, isFetchingAvailableProxies]);
|
|
742
|
+
|
|
743
|
+
useEffect(() =>{
|
|
744
|
+
if (!state.selectedAsset) {
|
|
745
|
+
// If no asset is selected, set this to ShowDialog so the dialog can be shown when there is no need to fetch availableProxies.
|
|
746
|
+
setShowFormatLoader(FormatLoaderState.ShowDialog);
|
|
747
|
+
}
|
|
748
|
+
}, [state.selectedAsset]);
|
|
749
|
+
|
|
750
|
+
return (
|
|
751
|
+
<cx-resize-observer ref={containerResizeObserverRef}>
|
|
752
|
+
<Container ref={containerRef}>
|
|
753
|
+
<Header
|
|
754
|
+
authenticated={authenticated}
|
|
755
|
+
bordered={state.hasScrolled}
|
|
756
|
+
currentFolder={state.currentFolder}
|
|
757
|
+
onMenuClick={() =>
|
|
758
|
+
dispatch({ type: 'SET_OPEN_BROWSER', payload: true })
|
|
759
|
+
}
|
|
760
|
+
onLogout={() => {
|
|
761
|
+
appDispatch(logout());
|
|
762
|
+
dispatch({ type: 'RESET_SEARCH' });
|
|
763
|
+
}}
|
|
764
|
+
>
|
|
765
|
+
<ControlBar
|
|
766
|
+
allowSorting={selectedSortOrder?.sortDirection !== 'Mono' && !!selectedSortOrder}
|
|
767
|
+
currentCount={state.currentCount}
|
|
768
|
+
extensions={state.extensions}
|
|
769
|
+
facets={state.facets}
|
|
770
|
+
isMobile={isMobile}
|
|
771
|
+
isSeeThrough={state.isSeeThrough}
|
|
772
|
+
loading={state.isLoading}
|
|
773
|
+
mediaTypes={state.mediaTypes}
|
|
774
|
+
searchValue={state.searchText}
|
|
775
|
+
sortDirection={state.sortDirection}
|
|
776
|
+
sortOrder={state.sortOrder}
|
|
777
|
+
sortOrders={sortOrders}
|
|
778
|
+
statuses={state.statuses}
|
|
779
|
+
totalCount={state.totalCount}
|
|
780
|
+
view={state.view}
|
|
781
|
+
visibilityClasses={state.visibilityClasses}
|
|
782
|
+
onChangeNewlySelectedFacet={setNewlySelectedFacet}
|
|
783
|
+
onSearchChange={onSearchChange}
|
|
784
|
+
onSettingChange={onSettingChange}
|
|
785
|
+
/>
|
|
786
|
+
</Header>
|
|
787
|
+
<Browser
|
|
788
|
+
collectionPath={collectionPath}
|
|
789
|
+
currentFolder={state.currentFolder}
|
|
790
|
+
lastLocationMode={lastLocationMode}
|
|
791
|
+
open={state.openBrowser}
|
|
792
|
+
showCollections={showCollections}
|
|
793
|
+
useSession={useSession}
|
|
794
|
+
onFolderSelect={onFolderSelect}
|
|
795
|
+
onClose={() => dispatch({ type: 'SET_OPEN_BROWSER', payload: false })}
|
|
796
|
+
/>
|
|
797
|
+
<div style={{
|
|
798
|
+
flex: 1,
|
|
799
|
+
minHeight: '320px',
|
|
800
|
+
padding: '0 var(--cx-spacing-medium)',
|
|
801
|
+
position: 'relative',
|
|
802
|
+
}}>
|
|
803
|
+
<AutoSizer onResize={debouncedHandleResize}>
|
|
804
|
+
{({ height, width }: Size) => {
|
|
805
|
+
return (
|
|
806
|
+
<div
|
|
807
|
+
style={{
|
|
808
|
+
height: height + 'px',
|
|
809
|
+
width: width + 'px',
|
|
810
|
+
}}
|
|
811
|
+
>
|
|
812
|
+
<AssetCardWrapper
|
|
813
|
+
ref={resultRef}
|
|
814
|
+
isError={isError}
|
|
815
|
+
isConfigError={isConfigError}
|
|
816
|
+
hasNextPage={hasNextPage}
|
|
817
|
+
height={height}
|
|
818
|
+
isLoadingData={state.isLoading || !data}
|
|
819
|
+
isFetched={!!data || isConfigError}
|
|
820
|
+
items={data?.items || []}
|
|
821
|
+
selectedAsset={state.selectedAsset}
|
|
822
|
+
view={state.view}
|
|
823
|
+
width={width}
|
|
824
|
+
onItemSelect={onItemSelect}
|
|
825
|
+
onLoadMore={onLoadMore}
|
|
826
|
+
onScroll={onScroll}
|
|
827
|
+
key={
|
|
828
|
+
state.currentFolder.id +
|
|
829
|
+
state.searchText +
|
|
830
|
+
state.mediaTypes.join('+') +
|
|
831
|
+
state.extensions.join('+') +
|
|
832
|
+
state.statuses.join('+') +
|
|
833
|
+
state.visibilityClasses.join('+') +
|
|
834
|
+
state.isSeeThrough +
|
|
835
|
+
state.view
|
|
836
|
+
}
|
|
837
|
+
/>
|
|
838
|
+
</div>
|
|
839
|
+
);
|
|
840
|
+
}}
|
|
841
|
+
</AutoSizer>
|
|
842
|
+
</div>
|
|
843
|
+
{showFormatLoader === FormatLoaderState.ShowLoader && (
|
|
844
|
+
<cx-space className='format-loader'>
|
|
845
|
+
<cx-spinner></cx-spinner>
|
|
846
|
+
</cx-space>
|
|
847
|
+
)}
|
|
848
|
+
<FormatDialog
|
|
849
|
+
allowTracking={allowTracking}
|
|
850
|
+
allowCustomFormat={!!ATSEnabled && !!state.selectedAsset?.allowATSLink}
|
|
851
|
+
autoExtension={autoExtension}
|
|
852
|
+
availableExtensions={availableExtensions}
|
|
853
|
+
availableProxies={isFetchingAvailableProxies ? undefined : availableProxies?.proxies}
|
|
854
|
+
ctaText={ctaText}
|
|
855
|
+
extensions={supportedExtensions ?? []}
|
|
856
|
+
maxHeight={state.containerSize.height}
|
|
857
|
+
open={!!state.selectedAsset && showFormatLoader === FormatLoaderState.ShowDialog}
|
|
858
|
+
previewUrl={isFetchingAvailableProxies ? undefined : availableProxies?.previewUrl}
|
|
859
|
+
searchInDrive={searchInDrive}
|
|
860
|
+
selectedAsset={state.selectedAsset}
|
|
861
|
+
supportedRepresentativeSubtypes={
|
|
862
|
+
availableRepresentativeSubtypes?.length
|
|
863
|
+
? _intersection(
|
|
864
|
+
availableRepresentativeSubtypes,
|
|
865
|
+
supportedRepresentativeSubtypes,
|
|
866
|
+
)
|
|
867
|
+
: supportedRepresentativeSubtypes
|
|
868
|
+
}
|
|
869
|
+
variant={isMobile ? 'drawer' : 'dialog'}
|
|
870
|
+
onClose={() =>
|
|
871
|
+
dispatch({ type: 'SET_SELECTED_ASSET', payload: null })
|
|
872
|
+
}
|
|
873
|
+
onProxyConfirm={async ({ extension, value, permanentLink, parameters, useRepresentative }) => {
|
|
874
|
+
if (!state.selectedAsset) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const images = await appDispatch(
|
|
879
|
+
importAssets({
|
|
880
|
+
extension,
|
|
881
|
+
extraFields,
|
|
882
|
+
parameters,
|
|
883
|
+
permanentLink,
|
|
884
|
+
proxiesPreference: value,
|
|
885
|
+
selectedAsset: state.selectedAsset,
|
|
886
|
+
useRepresentative,
|
|
887
|
+
useSession,
|
|
888
|
+
}),
|
|
889
|
+
);
|
|
890
|
+
|
|
891
|
+
if (importAssets.fulfilled.match(images)) {
|
|
892
|
+
handleSelectedAsset(images.payload);
|
|
893
|
+
}
|
|
894
|
+
}}
|
|
895
|
+
onFormatConfirm={async ({ value, parameters, proxiesPreference, extension }) => {
|
|
896
|
+
if (!state.selectedAsset) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
const maxWidth = state.selectedAsset?.width
|
|
901
|
+
? parseInt(state.selectedAsset.width, 10)
|
|
902
|
+
: 0;
|
|
903
|
+
const maxHeight = state.selectedAsset?.height
|
|
904
|
+
? parseInt(state.selectedAsset.height, 10)
|
|
905
|
+
: 0;
|
|
906
|
+
const images = await appDispatch(
|
|
907
|
+
importAssets({
|
|
908
|
+
extraFields,
|
|
909
|
+
extension,
|
|
910
|
+
maxHeight,
|
|
911
|
+
maxWidth,
|
|
912
|
+
parameters,
|
|
913
|
+
proxiesPreference,
|
|
914
|
+
selectedAsset: state.selectedAsset,
|
|
915
|
+
useSession,
|
|
916
|
+
transformations: value,
|
|
917
|
+
}),
|
|
918
|
+
);
|
|
919
|
+
|
|
920
|
+
if (importAssets.fulfilled.match(images)) {
|
|
921
|
+
handleSelectedAsset(images.payload);
|
|
922
|
+
}
|
|
923
|
+
}}
|
|
924
|
+
onOpenInDriveConfirm={() => {
|
|
925
|
+
if (!state.selectedAsset) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
window.OrangeDAMContentBrowser._onAssetSelected?.([
|
|
930
|
+
{
|
|
931
|
+
imageUrl: state.selectedAsset.imageUrl,
|
|
932
|
+
},
|
|
933
|
+
]);
|
|
934
|
+
}}
|
|
935
|
+
/>
|
|
936
|
+
</Container>
|
|
937
|
+
</cx-resize-observer>
|
|
938
|
+
);
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
export default HomePage;
|