1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from '~/store/store';
7 import { ServiceRepository } from '~/services/services';
8 import { updateResources } from '~/store/resources/resources-actions';
9 import { FilterBuilder } from '~/services/api/filter-builder';
10 import { ContainerRequestResource } from '~/models/container-request';
11 import { Process } from './process';
12 import { dialogActions } from '~/store/dialog/dialog-actions';
13 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
14 import { projectPanelActions } from '~/store/project-panel/project-panel-action';
16 export const loadProcess = (containerRequestUuid: string) =>
17 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<Process> => {
18 const containerRequest = await services.containerRequestService.get(containerRequestUuid);
19 dispatch<any>(updateResources([containerRequest]));
20 if (containerRequest.containerUuid) {
21 const container = await services.containerService.get(containerRequest.containerUuid);
22 dispatch<any>(updateResources([container]));
23 await dispatch<any>(loadSubprocesses(containerRequest.containerUuid));
24 return { containerRequest, container };
26 return { containerRequest };
29 export const loadSubprocesses = (containerUuid: string) =>
30 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
31 const containerRequests = await dispatch<any>(loadContainerRequests(
32 new FilterBuilder().addEqual('requestingContainerUuid', containerUuid).getFilters()
33 )) as ContainerRequestResource[];
35 const containerUuids: string[] = containerRequests.reduce((uuids, { containerUuid }) =>
37 ? [...uuids, containerUuid]
40 if (containerUuids.length > 0) {
41 await dispatch<any>(loadContainers(
42 new FilterBuilder().addIn('uuid', containerUuids).getFilters()
47 export const loadContainerRequests = (filters: string) =>
48 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
49 const { items } = await services.containerRequestService.list({ filters });
50 dispatch<any>(updateResources(items));
54 export const loadContainers = (filters: string) =>
55 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
56 const { items } = await services.containerService.list({ filters });
57 dispatch<any>(updateResources(items));
61 export const openRemoveProcessDialog = (uuid: string) =>
62 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
63 dispatch(dialogActions.OPEN_DIALOG({
64 id: REMOVE_PROCESS_DIALOG,
66 title: 'Remove process permanently',
67 text: 'Are you sure you want to remove this process?',
68 confirmButtonLabel: 'Remove',
74 export const REMOVE_PROCESS_DIALOG = 'removeProcessDialog';
76 export const removeProcessPermanently = (uuid: string) =>
77 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) =>{
78 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
79 await services.containerRequestService.delete(uuid);
80 dispatch(projectPanelActions.REQUEST_ITEMS());
81 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000 }));