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 { RootState } from "../store";
10 import { ServiceRepository } from "../../services/services";
11 import { LinkClass, LinkResource } from "../../models/link";
13 export const collectionPanelActions = unionize({
14 LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
15 LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
16 LOAD_COLLECTION_TAGS: ofType<{ uuid: string }>(),
17 LOAD_COLLECTION_TAGS_SUCCESS: ofType<{ tags: LinkResource[] }>(),
18 CREATE_COLLECTION_TAG: ofType<{ data: any }>(),
19 CREATE_COLLECTION_TAG_SUCCESS: ofType<{ tag: LinkResource }>()
20 }, { tag: 'type', value: 'payload' });
22 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
24 export const loadCollection = (uuid: string, kind: ResourceKind) =>
25 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
26 dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
27 return services.collectionService
30 dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: item as CollectionResource }));
34 export const loadCollectionTags = (uuid: string) =>
35 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
36 dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS({ uuid }));
37 return services.tagService
40 dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS_SUCCESS({ tags }));
45 export const createCollectionTag = (uuid: string, data: {}) =>
46 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
47 const linkResource = {
52 dispatch(collectionPanelActions.CREATE_COLLECTION_TAG({ data: linkResource }));
53 return services.tagService
54 .create(uuid, linkResource)
56 console.log('tag: ', tag);
57 dispatch(collectionPanelActions.CREATE_COLLECTION_TAG_SUCCESS({ tag }));