1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
8 import { RootState } from "../../store";
9 import { collectionService } from '../../../services/services';
10 import { CollectionResource } from '../../../models/collection';
11 import { initialize } from 'redux-form';
12 import { collectionPanelActions } from "../../collection-panel/collection-panel-action";
14 export const collectionUpdatorActions = unionize({
15 OPEN_COLLECTION_UPDATOR: ofType<{ uuid: string }>(),
16 CLOSE_COLLECTION_UPDATOR: ofType<{}>(),
17 UPDATE_COLLECTION_SUCCESS: ofType<{}>(),
24 export const COLLECTION_FORM_NAME = 'collectionEditDialog';
26 export const openUpdator = (uuid: string) =>
27 (dispatch: Dispatch, getState: () => RootState) => {
28 dispatch(collectionUpdatorActions.OPEN_COLLECTION_UPDATOR({ uuid }));
29 const item = getState().collectionPanel.item;
31 dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description }));
35 export const updateCollection = (collection: Partial<CollectionResource>) =>
36 (dispatch: Dispatch, getState: () => RootState) => {
37 const { uuid } = getState().collections.updator;
38 return collectionService
39 .update(uuid, collection)
41 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
42 dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS());
47 export type CollectionUpdatorAction = UnionOf<typeof collectionUpdatorActions>;