Merge branch 'master' into 13903-edit-collection-popup
[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 { RootState } from "../store";
10 import { ServiceRepository } from "../../services/services";
11
12 export const collectionPanelActions = unionize({
13     LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
14     LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>()
15 }, { tag: 'type', value: 'payload' });
16
17 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
18
19 export const loadCollection = (uuid: string, kind: ResourceKind) =>
20     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
21         dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
22         return services.collectionService
23             .get(uuid)
24             .then(item => {
25                 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: item as CollectionResource }));
26             });
27     };
28
29
30