Move collection-panel-files to collection-panel
[arvados-workbench2.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 import { collectionPanelFilesAction } from "./collection-panel-files/collection-panel-files-actions";
11 import { parseKeepManifestText } from "../../models/keep-manifest";
12
13 export const collectionPanelActions = unionize({
14     LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
15     LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
16 }, { tag: 'type', value: 'payload' });
17
18 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
19
20 export const loadCollection = (uuid: string, kind: ResourceKind) =>
21     (dispatch: Dispatch) => {
22         dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
23         return collectionService
24             .get(uuid)
25             .then(item => {
26                 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item }));
27                 const manifest = parseKeepManifestText(item.manifestText);
28                 dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ manifest }));
29             });
30     };
31
32
33