Delete unused parameter
[arvados-workbench2.git] / src / store / processes / process.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ContainerRequestResource } from '../../models/container-request';
6 import { ContainerResource } from '../../models/container';
7 import { ResourcesState, getResource } from '~/store/resources/resources';
8 import { filterResources } from '../resources/resources';
9 import { ResourceKind, Resource } from '~/models/resource';
10
11 export interface Process {
12     containerRequest: ContainerRequestResource;
13     container?: ContainerResource;
14 }
15
16 export const getProcess = (uuid: string) => (resources: ResourcesState): Process | undefined => {
17     const containerRequest = getResource<ContainerRequestResource>(uuid)(resources);
18     if (containerRequest) {
19         if (containerRequest.containerUuid) {
20             const container = getResource<ContainerResource>(containerRequest.containerUuid)(resources);
21             if (container) {
22                 return { containerRequest, container };
23             }
24         }
25         return { containerRequest };
26     }
27     return;
28 };
29
30 export const getSubprocesses = (uuid: string) => (resources: ResourcesState) => {
31     const containerRequests = filterResources(isSubprocess(uuid))(resources) as ContainerRequestResource[];
32     return containerRequests.reduce((subprocesses, { uuid }) => {
33         const process = getProcess(uuid)(resources);
34         return process
35             ? [...subprocesses, process]
36             : subprocesses;
37     }, []);
38 };
39
40 export const getProcessStatus = (process: Process) =>
41     process.container
42         ? process.container.state
43         : process.containerRequest.state;
44
45 const isSubprocess = (uuid: string) => (resource: Resource) =>
46     resource.kind === ResourceKind.CONTAINER_REQUEST
47     && (resource as ContainerRequestResource).requestingContainerUuid === uuid;