15230: Link to other workbenches when double-clicking search results.
[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
16 export const procesPanelActions = unionize({
17     SET_PROCESS_PANEL_FILTERS: ofType<string[]>(),
18     TOGGLE_PROCESS_PANEL_FILTER: ofType<string>(),
19 });
20
21 export type ProcessPanelAction = UnionOf<typeof procesPanelActions>;
22
23 export const toggleProcessPanelFilter = procesPanelActions.TOGGLE_PROCESS_PANEL_FILTER;
24
25 export const loadProcessPanel = (uuid: string) =>
26     (dispatch: Dispatch) => {
27         dispatch<any>(loadProcess(uuid));
28         dispatch(initProcessPanelFilters);
29     };
30
31 export const navigateToOutput = (uuid: string) =>
32     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
33         try {
34             await services.collectionService.get(uuid);
35             dispatch<any>(navigateTo(uuid));
36         } catch {
37             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This collection does not exists!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
38         }
39     };
40
41 export const openWorkflow = (uuid: string) =>
42     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
43         dispatch<any>(navigateToWorkflows);
44         dispatch<any>(showWorkflowDetails(uuid));
45     };
46
47 export const initProcessPanelFilters = procesPanelActions.SET_PROCESS_PANEL_FILTERS([
48     ProcessStatus.QUEUED,
49     ProcessStatus.COMPLETED,
50     ProcessStatus.FAILED,
51     ProcessStatus.RUNNING,
52     ProcessStatus.LOCKED,
53     ProcessStatus.CANCELLED
54 ]);