1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { loadCollectionFiles } from "./collection-panel-files/collection-panel-files-actions";
7 import { CollectionResource } from '~/models/collection';
8 import { collectionPanelFilesAction } from "./collection-panel-files/collection-panel-files-actions";
9 import { createTree } from "~/models/tree";
10 import { RootState } from "~/store/store";
11 import { ServiceRepository } from "~/services/services";
12 import { TagProperty } from "~/models/tag";
13 import { snackbarActions } from "../snackbar/snackbar-actions";
14 import { resourcesActions } from "~/store/resources/resources-actions";
15 import { unionize, ofType, UnionOf } from '~/common/unionize';
16 import { SnackbarKind } from '~/store/snackbar/snackbar-actions';
17 import { navigateTo } from '~/store/navigation/navigation-action';
18 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
20 export const collectionPanelActions = unionize({
21 SET_COLLECTION: ofType<CollectionResource>(),
22 LOAD_COLLECTION: ofType<{ uuid: string }>(),
23 LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>()
26 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
28 export const COLLECTION_TAG_FORM_NAME = 'collectionTagForm';
30 export const loadCollectionPanel = (uuid: string) =>
31 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
32 dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid }));
33 dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() }));
34 const collection = await services.collectionService.get(uuid);
35 dispatch(loadDetailsPanel(collection.uuid));
36 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
37 dispatch(resourcesActions.SET_RESOURCES([collection]));
38 dispatch<any>(loadCollectionFiles(collection.uuid));
42 export const createCollectionTag = (data: TagProperty) =>
43 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
44 const item = getState().collectionPanel.item;
45 const uuid = item ? item.uuid : '';
48 item.properties[data.key] = data.value;
49 const version = 'version';
51 const updatedCollection = await services.collectionService.update(uuid, item);
52 dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
53 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully added.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
54 return updatedCollection;
62 export const navigateToProcess = (uuid: string) =>
63 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
65 await services.containerRequestService.get(uuid);
66 dispatch<any>(navigateTo(uuid));
68 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This process does not exists!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
72 export const deleteCollectionTag = (key: string) =>
73 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
74 const item = getState().collectionPanel.item;
75 const uuid = item ? item.uuid : '';
78 delete item.properties[key];
79 const updatedCollection = await services.collectionService.update(uuid, item);
80 dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
81 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully deleted.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
82 return updatedCollection;