init and save form, modify store
[arvados.git] / src / store / collection-panel / collection-panel-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
7 import { ResourceKind } from "../../models/resource";
8 import { CollectionResource } from "../../models/collection";
9 import { collectionService } from "../../services/services";
10
11 export const collectionPanelActions = unionize({
12     LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
13     LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>()
14 }, { tag: 'type', value: 'payload' });
15
16 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
17
18 export const loadCollection = (uuid: string, kind: ResourceKind) =>
19     (dispatch: Dispatch) => {
20         dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
21         return collectionService
22             .get(uuid)
23             .then(item => {
24                 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item }));
25             });
26     };
27
28
29