From 92429e5147b97e116cab941d094fd06094493958 Mon Sep 17 00:00:00 2001
From: Max Frederiksen <maxfrederiksen@Maxs-MacBook-Air.local>
Date: Mon, 30 Dec 2024 11:15:32 +0100
Subject: [PATCH] Add typing /components/deployments

---
 .../deployments/DeploymentJobOutput.tsx       | 49 +++++++++++--------
 src/components/deployments/index.ts           |  3 +-
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/components/deployments/DeploymentJobOutput.tsx b/src/components/deployments/DeploymentJobOutput.tsx
index 5d20b54a..b184e54a 100644
--- a/src/components/deployments/DeploymentJobOutput.tsx
+++ b/src/components/deployments/DeploymentJobOutput.tsx
@@ -1,47 +1,54 @@
-import { useState, useRef, useEffect, useMemo } from "react";
+import { useState, useRef, useEffect } from "react";
 import { Alert, LinearProgress, Stack } from "@mui/material";
 import { LogStreamConsole } from "../common/LogStream/LogStreamConsole";
 import { LogStreamConsoleDialog } from "../common/LogStream/LogStreamConsoleDialog";
 import { PopoutButton } from "../common/Buttons/PopoutButton";
-import { getErrorMessage, isAbortError } from "../common/Helper";
-import { useLazyFetchDeploymentJobLogQuery } from "../../store/deployApi";
+import { getErrorState } from "../common/Alerts/AlertsData";
+import {
+  JobDetails,
+  useLazyFetchDeploymentJobLogQuery
+} from "../../store/deployApi";
 
 const LOG_POLL_INTERVAL = 5000;
 
-export function DeploymentJobOutput({ job, isExpanded }) {
+interface DeploymentJobOutputProps {
+  job: JobDetails;
+  isExpanded: boolean;
+}
+export function DeploymentJobOutput({
+  job,
+  isExpanded
+}: DeploymentJobOutputProps) {
   const [consoleDialogOpen, setConsoleDialogOpen] = useState(false);
   const finalResultsNeeded = useRef(true);
-  const params = useMemo(
-    () => ({
-      awxJobId: job.awxJobId
-    }),
-    [job]
-  );
   const [getLogById, { data: log, isSuccess: logDataReady, error: logError }] =
     useLazyFetchDeploymentJobLogQuery({
       pollingInterval: isExpanded ? LOG_POLL_INTERVAL : 0
     });
 
   useEffect(() => {
-    if (isExpanded) {
-      if (!job.finishedAt || finalResultsNeeded.current) {
-        getLogById(params);
-        finalResultsNeeded.current = !job.finishedAt;
-      }
+    if (
+      !isExpanded ||
+      (job.finishedAt && !finalResultsNeeded.current) ||
+      !job.awxJobId
+    ) {
+      return;
     }
-  }, [job.finishedAt, job.jobId, isExpanded, getLogById, params]);
 
-  const hasAbortError = isAbortError(logError);
+    getLogById({ awxJobId: job.awxJobId });
+    finalResultsNeeded.current = !job.finishedAt;
+  }, [job.finishedAt, job, isExpanded, getLogById, job.awxJobId]);
+
   const showLoading = !log || !job.startTime;
 
   useEffect(() => {
     finalResultsNeeded.current = true;
-  }, [job.jobId]);
+  }, [job]);
 
-  if (logError && !hasAbortError) {
+  if (logError) {
     return (
       <Stack>
-        <Alert severity="error">{getErrorMessage(logError)}</Alert>
+        <Alert severity="error">{getErrorState(logError).message}</Alert>
       </Stack>
     );
   }
@@ -76,7 +83,7 @@ export function DeploymentJobOutput({ job, isExpanded }) {
         onDialogClose={() => setConsoleDialogOpen(false)}
       />
       <LogStreamConsole
-        log={log.stdoutHtml}
+        log={log?.stdoutHtml}
         dataReady={logDataReady}
         height="500px"
       />
diff --git a/src/components/deployments/index.ts b/src/components/deployments/index.ts
index f38ca23c..b54017e0 100644
--- a/src/components/deployments/index.ts
+++ b/src/components/deployments/index.ts
@@ -1,4 +1,3 @@
-import { DeploymentStatusIcon } from "./DeploymentIcons";
 import { DeploymentJobOutput } from "./DeploymentJobOutput";
 
-export { DeploymentStatusIcon, DeploymentJobOutput };
+export { DeploymentJobOutput };
-- 
GitLab