init process-view-info-card
[arvados.git] / src / store / collections / updater / collection-updater-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { collectionUpdaterActions, CollectionUpdaterAction } from './collection-updater-action';
6
7 export interface CollectionUpdaterState {
8     opened: boolean;
9     uuid: string;
10 }
11
12 const updateCollection = (state: CollectionUpdaterState, updater?: Partial<CollectionUpdaterState>) => ({
13     ...state,
14     ...updater
15 });
16
17 const initialState: CollectionUpdaterState = {
18     opened: false,
19     uuid: ''
20 };
21
22 export const collectionUpdaterReducer = (state: CollectionUpdaterState = initialState, action: CollectionUpdaterAction) => {
23     return collectionUpdaterActions.match(action, {
24         OPEN_COLLECTION_UPDATER: ({ uuid }) => updateCollection(state, { uuid, opened: true }),
25         CLOSE_COLLECTION_UPDATER: () => updateCollection(state, { opened: false, uuid: "" }),
26         UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, uuid: "" }),
27         default: () => state
28     });
29 };