Merge branch '13858-process-view-information-card' into 13860-status-for-subprocesses
[arvados-workbench2.git] / src / store / collection-panel / collection-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { collectionPanelActions, CollectionPanelAction } from "./collection-panel-action";
6 import { CollectionResource } from "~/models/collection";
7 import { TagResource } from "~/models/tag";
8
9 export interface CollectionPanelState {
10     item: CollectionResource | null;
11     tags: TagResource[];
12 }
13
14 const initialState = {
15     item: null,
16     tags: []
17 };
18
19 export const collectionPanelReducer = (state: CollectionPanelState = initialState, action: CollectionPanelAction) =>
20     collectionPanelActions.match(action, {
21         default: () => state,
22         LOAD_COLLECTION_SUCCESS: ({ item }) => ({ ...state, item }),
23         LOAD_COLLECTION_TAGS_SUCCESS: ({ tags }) => ({...state, tags }),
24         CREATE_COLLECTION_TAG_SUCCESS: ({ tag }) => ({...state, tags: [...state.tags, tag] }),
25         DELETE_COLLECTION_TAG_SUCCESS: ({ uuid }) => ({...state, tags: state.tags.filter(tag => tag.uuid !== uuid) })
26     });