refs #13828 Merge branch 'origin/13828-trash-view'
[arvados.git] / src / store / processes / process.ts
index 0f12b3fe2f30c3f9821292b946ee0fbe2c74509b..467fc8a92ef83a7c7dd3358ee3f9d860ff3e56fa 100644 (file)
@@ -7,6 +7,9 @@ import { ContainerResource } from '../../models/container';
 import { ResourcesState, getResource } from '~/store/resources/resources';
 import { filterResources } from '../resources/resources';
 import { ResourceKind, Resource } from '~/models/resource';
+import { getTimeDiff } from '~/common/formatters';
+import { SubprocessesStatus } from '~/views/process-panel/process-subprocesses-card';
+import { ArvadosTheme } from '~/common/custom-theme';
 
 export interface Process {
     containerRequest: ContainerRequestResource;
@@ -41,6 +44,28 @@ export const getSubprocesses = (uuid: string) => (resources: ResourcesState) =>
     return [];
 };
 
+export const getProcessRuntime = ({ container }: Process) =>
+    container
+        ? getTimeDiff(container.finishedAt || '', container.startedAt || '')
+        : 0;
+
+export const getProcessStatusColor = (status: string, { customs }: ArvadosTheme) => {
+    switch (status) {
+        case SubprocessesStatus.COMPLETED:
+            return customs.colors.green700;
+        case SubprocessesStatus.CANCELED:
+            return customs.colors.red900;
+        case SubprocessesStatus.QUEUED:
+            return customs.colors.grey500;
+        case SubprocessesStatus.FAILED:
+            return customs.colors.red900;
+        case SubprocessesStatus.ACTIVE:
+            return customs.colors.blue500;
+        default:
+            return customs.colors.grey500;
+    }
+};
+
 export const getProcessStatus = (process: Process) =>
     process.container
         ? process.container.state
@@ -49,3 +74,4 @@ export const getProcessStatus = (process: Process) =>
 const isSubprocess = (containerUuid: string) => (resource: Resource) =>
     resource.kind === ResourceKind.CONTAINER_REQUEST
     && (resource as ContainerRequestResource).requestingContainerUuid === containerUuid;
+