18692: Fixed error formatting
[arvados.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 });
19
20 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
21
22 export const loadCollectionPanel = (uuid: string, forceReload = false) =>
23     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24         const { collectionPanel: { item } } = getState();
25         let collection: CollectionResource | null = null;
26         if (!item || item.uuid !== uuid || forceReload) {
27             collection = await services.collectionService.get(uuid);
28             dispatch(collectionPanelActions.SET_COLLECTION(collection));
29             dispatch(resourcesActions.SET_RESOURCES([collection]));
30         } else {
31             collection = item;
32         }
33         dispatch<any>(loadDetailsPanel(collection.uuid));
34         return collection;
35     };
36
37 export const navigateToProcess = (uuid: string) =>
38     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
39         try {
40             await services.containerRequestService.get(uuid);
41             dispatch<any>(navigateTo(uuid));
42         } catch {
43             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exist!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
44         }
45     };