Make use of ahell-quote lib in command window, add copy command button
[arvados-workbench2.git] / src / store / progress-indicator / progress-indicator-reducer.ts
index 7e1c2362802376092c6c458fbf78be191e2bb930..89885afb526ee7b904855e2bfab15c2f8ea8b5fe 100644 (file)
@@ -4,31 +4,30 @@
 
 import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
 
-export interface ProgressIndicatorState {
-    'workbenchProgress': { started: boolean };
-    'contentProgress': { started: boolean };
-    'detailsProgress': { started: boolean };
-}
-
-const initialState: ProgressIndicatorState = {
-    'workbenchProgress': { started: false },
-    'contentProgress': { started: false },
-    'detailsProgress': { started: false }
-};
+export type ProgressIndicatorState = { id: string, working: boolean }[];
 
-export enum ProgressIndicatorData {
-    WORKBENCH_PROGRESS = 'workbenchProgress',
-    CONTENT_PROGRESS = 'contentProgress',
-    DETAILS_PROGRESS = 'detailsProgress'
-}
+const initialState: ProgressIndicatorState = [];
 
 export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => {
+    const startWorking = (id: string) => state.find(p => p.id === id) ? state : state.concat({ id, working: true });
+    const stopWorking = (id: string) => state.filter(p => p.id !== id);
+
     return progressIndicatorActions.match(action, {
-        START_SUBMIT: ({ id }) => ({ ...state, [id]: { started: true } }),
-        STOP_SUBMIT: ({ id }) => ({
-            ...state,
-            [id]: state[id] ? { ...state[id], started: false } : { started: false }
-        }),
+        START_WORKING: id => startWorking(id),
+        STOP_WORKING: id => stopWorking(id),
+        PERSIST_STOP_WORKING: id => state.map(p => ({
+            ...p,
+            working: p.id === id ? false : p.working
+        })),
+        TOGGLE_WORKING: ({ id, working }) => working ? startWorking(id) : stopWorking(id),
         default: () => state,
     });
 };
+
+export function isSystemWorking(state: ProgressIndicatorState): boolean {
+    return state.length > 0 && state.reduce((working, p) => working ? true : p.working, false);
+}
+
+export const getProgressIndicator = (id: string) =>
+    (state: ProgressIndicatorState) =>
+        state.find(state => state.id === id);