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';
15 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
17 export const collectionPanelActions = unionize({
18 SET_COLLECTION: ofType<CollectionResource>(),
21 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
23 export const loadCollectionPanel = (uuid: string, forceReload = false) =>
24 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
25 const { collectionPanel: { item } } = getState();
26 let collection: CollectionResource | null = null;
27 if (!item || item.uuid !== uuid || forceReload) {
29 dispatch(progressIndicatorActions.START_WORKING(uuid + "-panel"));
30 collection = await services.collectionService.get(uuid);
31 dispatch(collectionPanelActions.SET_COLLECTION(collection));
32 dispatch(resourcesActions.SET_RESOURCES([collection]));
34 dispatch(progressIndicatorActions.STOP_WORKING(uuid + "-panel"));
39 dispatch<any>(loadDetailsPanel(collection.uuid));
43 export const navigateToProcess = (uuid: string) =>
44 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
46 await services.containerRequestService.get(uuid);
47 dispatch<any>(navigateTo(uuid));
49 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exist!', hideDuration: 2000, kind: SnackbarKind.ERROR }));