18787: Removes remaining traces of old big collection loading check.
[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 { CollectionResource } from 'models/collection';
7 import { RootState } from "store/store";
8 import { ServiceRepository } from "services/services";
9 import { snackbarActions } from "../snackbar/snackbar-actions";
10 import { resourcesActions } from "store/resources/resources-actions";
11 import { unionize, ofType, UnionOf } from 'common/unionize';
12 import { SnackbarKind } from 'store/snackbar/snackbar-actions';
13 import { navigateTo } from 'store/navigation/navigation-action';
14 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
15
16 export const collectionPanelActions = unionize({
17     SET_COLLECTION: ofType<CollectionResource>(),
18     LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
19 });
20
21 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
22
23 export const loadCollectionPanel = (uuid: string, forceReload = false) =>
24     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
25         const { collectionPanel: { item } } = getState();
26         const collection = (item && item.uuid === uuid && !forceReload)
27             ? item
28             : await services.collectionService.get(uuid);
29         dispatch<any>(loadDetailsPanel(collection.uuid));
30         dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
31         dispatch(resourcesActions.SET_RESOURCES([collection]));
32         return collection;
33     };
34
35 export const navigateToProcess = (uuid: string) =>
36     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
37         try {
38             await services.containerRequestService.get(uuid);
39             dispatch<any>(navigateTo(uuid));
40         } catch {
41             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exist!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
42         }
43     };