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';
12 export const loadProcess = (uuid: string) =>
13 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
14 const containerRequest = await services.containerRequestService.get(uuid);
15 dispatch<any>(updateResources([containerRequest]));
16 if (containerRequest.containerUuid) {
17 const container = await services.containerService.get(containerRequest.containerUuid);
18 dispatch<any>(updateResources([container]));
22 export const loadSubprocesses = (uuid: string) =>
23 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24 const containerRequests = await dispatch<any>(loadContainerRequests(
25 new FilterBuilder().addEqual('requestingContainerUuid', uuid).getFilters()
26 )) as ContainerRequestResource[];
28 const containerUuids: string[] = containerRequests.reduce((uuids, { containerUuid }) =>
30 ? [...uuids, containerUuid]
33 if (containerUuids.length > 0) {
34 await dispatch<any>(loadContainers(
35 new FilterBuilder().addIn('uuid', containerUuids).getFilters()
40 export const loadContainerRequests = (filters: string) =>
41 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
42 const { items } = await services.containerRequestService.list({ filters });
43 dispatch<any>(updateResources(items));
47 export const loadContainers = (filters: string) =>
48 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
49 const { items } = await services.containerService.list({ filters });
50 dispatch<any>(updateResources(items));