19231: Add smaller page sizes (10 and 20 items) to load faster
[arvados-workbench2.git] / src / store / process-panel / process-panel-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from "common/unionize";
6 import { loadProcess } from 'store/processes/processes-actions';
7 import { Dispatch } from 'redux';
8 import { ProcessStatus } from 'store/processes/process';
9 import { RootState } from 'store/store';
10 import { ServiceRepository } from "services/services";
11 import { navigateTo, navigateToWorkflows } from 'store/navigation/navigation-action';
12 import { snackbarActions } from 'store/snackbar/snackbar-actions';
13 import { SnackbarKind } from '../snackbar/snackbar-actions';
14 import { showWorkflowDetails } from 'store/workflow-panel/workflow-panel-actions';
15 import { loadSubprocessPanel } from "../subprocess-panel/subprocess-panel-actions";
16 import { initProcessLogsPanel, processLogsPanelActions } from "store/process-logs-panel/process-logs-panel-actions";
17
18 export const processPanelActions = unionize({
19     SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: ofType<string>(),
20     SET_PROCESS_PANEL_FILTERS: ofType<string[]>(),
21     TOGGLE_PROCESS_PANEL_FILTER: ofType<string>(),
22 });
23
24 export type ProcessPanelAction = UnionOf<typeof processPanelActions>;
25
26 export const toggleProcessPanelFilter = processPanelActions.TOGGLE_PROCESS_PANEL_FILTER;
27
28 export const loadProcessPanel = (uuid: string) =>
29     async (dispatch: Dispatch) => {
30         dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
31         dispatch<ProcessPanelAction>(processPanelActions.SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID(uuid));
32         await dispatch<any>(loadProcess(uuid));
33         dispatch(initProcessPanelFilters);
34         dispatch<any>(initProcessLogsPanel(uuid));
35         dispatch<any>(loadSubprocessPanel());
36     };
37
38 export const navigateToOutput = (uuid: string) =>
39     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
40         try {
41             await services.collectionService.get(uuid);
42             dispatch<any>(navigateTo(uuid));
43         } catch {
44             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This collection does not exists!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
45         }
46     };
47
48 export const openWorkflow = (uuid: string) =>
49     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
50         dispatch<any>(navigateToWorkflows);
51         dispatch<any>(showWorkflowDetails(uuid));
52     };
53
54 export const initProcessPanelFilters = processPanelActions.SET_PROCESS_PANEL_FILTERS([
55     ProcessStatus.QUEUED,
56     ProcessStatus.COMPLETED,
57     ProcessStatus.FAILED,
58     ProcessStatus.RUNNING,
59     ProcessStatus.ONHOLD,
60     ProcessStatus.FAILING,
61     ProcessStatus.WARNING,
62     ProcessStatus.CANCELLED
63 ]);