Merge remote-tracking branch 'origin/main' into 18207-Workbench2-is-not-clearing...
[arvados-workbench2.git] / src / store / collection-panel / collection-panel-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import {
7     COLLECTION_PANEL_LOAD_FILES_THRESHOLD
8 } from "./collection-panel-files/collection-panel-files-actions";
9 import { CollectionResource } from 'models/collection';
10 import { RootState } from "store/store";
11 import { ServiceRepository } from "services/services";
12 import { snackbarActions } from "../snackbar/snackbar-actions";
13 import { resourcesActions } from "store/resources/resources-actions";
14 import { unionize, ofType, UnionOf } from 'common/unionize';
15 import { SnackbarKind } from 'store/snackbar/snackbar-actions';
16 import { navigateTo } from 'store/navigation/navigation-action';
17 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
18
19 export const collectionPanelActions = unionize({
20     SET_COLLECTION: ofType<CollectionResource>(),
21     LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
22     LOAD_BIG_COLLECTIONS: ofType<boolean>(),
23 });
24
25 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
26
27 export const loadCollectionPanel = (uuid: string, forceReload = false) =>
28     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
29         const { collectionPanel: { item } } = getState();
30         const collection = (item && item.uuid === uuid && !forceReload)
31             ? item
32             : await services.collectionService.get(uuid);
33         dispatch<any>(loadDetailsPanel(collection.uuid));
34         dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
35         dispatch(resourcesActions.SET_RESOURCES([collection]));
36         if (collection.fileCount <= COLLECTION_PANEL_LOAD_FILES_THRESHOLD &&
37             !getState().collectionPanel.loadBigCollections) {
38         }
39         return collection;
40     };
41
42 export const navigateToProcess = (uuid: string) =>
43     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
44         try {
45             await services.containerRequestService.get(uuid);
46             dispatch<any>(navigateTo(uuid));
47         } catch {
48             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exist!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
49         }
50     };