1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
16 export const collectionPanelActions = unionize({
17 SET_COLLECTION: ofType<CollectionResource>(),
20 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
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]));
33 dispatch<any>(loadDetailsPanel(collection.uuid));
37 export const navigateToProcess = (uuid: string) =>
38 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
40 await services.containerRequestService.get(uuid);
41 dispatch<any>(navigateTo(uuid));
43 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exist!', hideDuration: 2000, kind: SnackbarKind.ERROR }));