merge-conflicts
[arvados-workbench2.git] / src / store / collection / collection-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Collection } from "../../models/collection";
6 import { default as unionize, ofType, UnionOf } from "unionize";
7 import { Dispatch } from "redux";
8 import { collectionService } from "../../services/services";
9
10 const actions = unionize({
11     CREATE_COLLECTION: ofType<Collection>(),
12     REMOVE_COLLECTION: ofType<string>(),
13     COLLECTIONS_REQUEST: ofType<any>(),
14     COLLECTIONS_SUCCESS: ofType<{ collections: Collection[] }>(),
15 }, {
16     tag: 'type',
17     value: 'payload'
18 });
19
20 export const getCollectionList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Collection[]> => {
21     dispatch(actions.COLLECTIONS_REQUEST());
22     return collectionService.getCollectionList(parentUuid).then(collections => {
23         dispatch(actions.COLLECTIONS_SUCCESS({collections}));
24         return collections;
25     });
26 };
27
28 export type CollectionAction = UnionOf<typeof actions>;
29 export default actions;