Add typescript paths to top level folders
[arvados-workbench2.git] / src / store / collections / updater / collection-updater-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
7
8 import { RootState } from "../../store";
9 import { ServiceRepository } from "~/services/services";
10 import { CollectionResource } from '~/models/collection';
11 import { initialize } from 'redux-form';
12 import { collectionPanelActions } from "../../collection-panel/collection-panel-action";
13 import { ContextMenuResource } from "../../context-menu/context-menu-reducer";
14
15 export const collectionUpdaterActions = unionize({
16     OPEN_COLLECTION_UPDATER: ofType<{ uuid: string }>(),
17     CLOSE_COLLECTION_UPDATER: ofType<{}>(),
18     UPDATE_COLLECTION_SUCCESS: ofType<{}>(),
19 }, {
20     tag: 'type',
21     value: 'payload'
22 });
23
24
25 export const COLLECTION_FORM_NAME = 'collectionEditDialog';
26
27 export const openUpdater = (item: ContextMenuResource) =>
28     (dispatch: Dispatch, getState: () => RootState) => {
29         if (item) {
30             dispatch(collectionUpdaterActions.OPEN_COLLECTION_UPDATER({ uuid: item.uuid }));
31             dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description }));
32         }
33     };
34
35 export const updateCollection = (collection: Partial<CollectionResource>) =>
36     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
37         const { uuid } = getState().collections.updater;
38         return services.collectionService
39             .update(uuid, collection)
40             .then(collection => {
41                     dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection as CollectionResource }));
42                     dispatch(collectionUpdaterActions.UPDATE_COLLECTION_SUCCESS());
43                 }
44             );
45     };
46
47 export type CollectionUpdaterAction = UnionOf<typeof collectionUpdaterActions>;