From 9753ae1782a60f139bb7c1931f82fd6793fb0cf8 Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Mon, 13 Jan 2025 09:21:35 +0100
Subject: [PATCH] moved ACTION TYPES from jobData to jobUtils

---
 src/components/Job/JobData.ts                 |  8 ----
 .../Job/JobTable/JobDetailsColumn.tsx         |  8 +++-
 src/components/Job/JobUtils.jsx               | 45 +++++++++++++++++++
 3 files changed, 51 insertions(+), 10 deletions(-)
 delete mode 100644 src/components/Job/JobData.ts
 create mode 100644 src/components/Job/JobUtils.jsx

diff --git a/src/components/Job/JobData.ts b/src/components/Job/JobData.ts
deleted file mode 100644
index 8b77ed29..00000000
--- a/src/components/Job/JobData.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export const ACTION_TYPES = {
-  DEPLOY: "DEPLOY",
-  UNDEPLOY: "UNDEPLOY",
-  BATCH_DEPLOY: "BATCH_DEPLOY",
-  BATCH_UNDEPLOY: "BATCH_UNDEPLOY",
-  START: "START",
-  STOP: "STOP"
-};
diff --git a/src/components/Job/JobTable/JobDetailsColumn.tsx b/src/components/Job/JobTable/JobDetailsColumn.tsx
index 30916658..fa2423c5 100644
--- a/src/components/Job/JobTable/JobDetailsColumn.tsx
+++ b/src/components/Job/JobTable/JobDetailsColumn.tsx
@@ -1,9 +1,13 @@
 import { useMemo } from "react";
 import { Stack, Typography } from "@mui/material";
 import { InternalLink } from "@ess-ics/ce-ui-common";
-import { getNoOfIOCs, getNoOfHosts, isBatchJob } from "../JobUtils";
+import {
+  ACTION_TYPES,
+  getNoOfIOCs,
+  getNoOfHosts,
+  isBatchJob
+} from "../JobUtils";
 import { ActionTypeIconText } from "../JobIcons";
-import { ACTION_TYPES } from "../JobData";
 import { JobRevisionChip } from "../JobRevisionChip";
 import { Job } from "../../../store/deployApi";
 
diff --git a/src/components/Job/JobUtils.jsx b/src/components/Job/JobUtils.jsx
new file mode 100644
index 00000000..4d76a2de
--- /dev/null
+++ b/src/components/Job/JobUtils.jsx
@@ -0,0 +1,45 @@
+import { EllipsisText, InternalLink } from "@ess-ics/ce-ui-common";
+import { Typography } from "@mui/material";
+
+export const ACTION_TYPES = {
+  DEPLOY: "DEPLOY",
+  UNDEPLOY: "UNDEPLOY",
+  BATCH_DEPLOY: "BATCH_DEPLOY",
+  BATCH_UNDEPLOY: "BATCH_UNDEPLOY",
+  START: "START",
+  STOP: "STOP"
+};
+
+export const isBatchJob = (action) =>
+  action === ACTION_TYPES.BATCH_DEPLOY ||
+  action === ACTION_TYPES.BATCH_UNDEPLOY;
+
+export const isDeploymentJob = (action) =>
+  action === ACTION_TYPES.BATCH_DEPLOY || action === ACTION_TYPES.DEPLOY;
+
+export const getNoOfIOCs = (jobs) =>
+  [...new Set(jobs.map((job) => job.iocId))].length;
+
+export const getNoOfHosts = (jobs) =>
+  [...new Set(jobs.map((job) => job.host.hostId))].length;
+
+export const calculateHostText = (job) => {
+  // host is resolvable => show link for users
+  if (job?.host?.hostId && job?.host?.externalIdValid) {
+    return (
+      <InternalLink
+        to={`/hosts/${job.host.hostId}`}
+        label={`Host Details, ${job.host.fqdn}`}
+        width="100%"
+      >
+        <EllipsisText>{job.host.fqdn}</EllipsisText>
+      </InternalLink>
+    );
+  }
+  // gray out hostname if it is from cache
+  return (
+    <Typography color="gray">
+      <EllipsisText>{job?.host?.fqdn}</EllipsisText>
+    </Typography>
+  );
+};
-- 
GitLab