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 '~/common/api/filter-builder';
10 import { ContainerRequestResource } from '../../models/container-request';
11 import { Process } from './process';
13 export const loadProcess = (containerRequestUuid: string) =>
14 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<Process> => {
15 const containerRequest = await services.containerRequestService.get(containerRequestUuid);
16 dispatch<any>(updateResources([containerRequest]));
17 if (containerRequest.containerUuid) {
18 const container = await services.containerService.get(containerRequest.containerUuid);
19 dispatch<any>(updateResources([container]));
20 await dispatch<any>(loadSubprocesses(containerRequest.containerUuid));
21 return { containerRequest, container };
23 return { containerRequest };
26 export const loadSubprocesses = (containerUuid: string) =>
27 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
28 const containerRequests = await dispatch<any>(loadContainerRequests(
29 new FilterBuilder().addEqual('requestingContainerUuid', containerUuid).getFilters()
30 )) as ContainerRequestResource[];
32 const containerUuids: string[] = containerRequests.reduce((uuids, { containerUuid }) =>
34 ? [...uuids, containerUuid]
37 if (containerUuids.length > 0) {
38 await dispatch<any>(loadContainers(
39 new FilterBuilder().addIn('uuid', containerUuids).getFilters()
44 export const loadContainerRequests = (filters: string) =>
45 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
46 const { items } = await services.containerRequestService.list({ filters });
47 dispatch<any>(updateResources(items));
51 export const loadContainers = (filters: string) =>
52 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
53 const { items } = await services.containerService.list({ filters });
54 dispatch<any>(updateResources(items));