Change default table view to be displayed only after data fetch
[arvados-workbench2.git] / src / store / progress-indicator / progress-indicator-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
6
7 export type ProgressIndicatorState = { id: string, working: boolean }[];
8
9 const initialState: ProgressIndicatorState = [];
10
11 export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => {
12     const startWorking = (id: string) => state.find(p => p.working) ? state : state.concat({ id, working: true });
13     const stopWorking = (id: string) => state.filter(p => p.id !== id);
14
15     return progressIndicatorActions.match(action, {
16         START: id => startWorking(id),
17         STOP: id => stopWorking(id),
18         PERSIST_STOP: id => state.map(p => ({
19             id,
20             working: p.id === id ? false : p.working
21         })),
22         TOGGLE: ({ id, working }) => working ? startWorking(id) : stopWorking(id),
23         default: () => state,
24     });
25 };
26
27 export function isSystemWorking(state: ProgressIndicatorState): boolean {
28     return state.length > 0 && state.reduce((working, p) => working ? true : p.working, false);
29 }