X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e49daa4deeadf74cb0737501ed64bc41ba7a56d9..06454ba23d896ba99d1f8ddca101088b96806966:/src/store/progress-indicator/progress-indicator-reducer.ts diff --git a/src/store/progress-indicator/progress-indicator-reducer.ts b/src/store/progress-indicator/progress-indicator-reducer.ts index f6a73472..89885afb 100644 --- a/src/store/progress-indicator/progress-indicator-reducer.ts +++ b/src/store/progress-indicator/progress-indicator-reducer.ts @@ -9,17 +9,25 @@ export type ProgressIndicatorState = { id: string, working: boolean }[]; const initialState: ProgressIndicatorState = []; export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => { - const startWorking = (id: string) => state.find(p => p.working) ? state : state.concat({ id, working: true }); + 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: id => startWorking(id), - STOP: id => stopWorking(id), - TOGGLE: ({ id, working }) => working ? startWorking(id) : stopWorking(id), + 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; + 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);