1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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 import { mapManifestToCollectionFilesTree } from "../../models/collection-file";
13 import { getNodeChildren, createTree } from "../../models/tree";
15 export const collectionPanelActions = unionize({
16 LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
17 LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
18 }, { tag: 'type', value: 'payload' });
20 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
22 export const loadCollection = (uuid: string, kind: ResourceKind) =>
23 (dispatch: Dispatch) => {
24 dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
25 dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() }));
26 return collectionService
29 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item }));
30 const files = mapManifestToCollectionFilesTree(parseKeepManifestText(item.manifestText));
31 dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files }));