Skip to content
Snippets Groups Projects
Commit 92429e51 authored by Max Frederiksen's avatar Max Frederiksen Committed by Max Frederiksen
Browse files

Add typing /components/deployments

parent edcf64c0
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!590CE-3429: Convert to typescript
import { useState, useRef, useEffect, useMemo } from "react"; import { useState, useRef, useEffect } from "react";
import { Alert, LinearProgress, Stack } from "@mui/material"; import { Alert, LinearProgress, Stack } from "@mui/material";
import { LogStreamConsole } from "../common/LogStream/LogStreamConsole"; import { LogStreamConsole } from "../common/LogStream/LogStreamConsole";
import { LogStreamConsoleDialog } from "../common/LogStream/LogStreamConsoleDialog"; import { LogStreamConsoleDialog } from "../common/LogStream/LogStreamConsoleDialog";
import { PopoutButton } from "../common/Buttons/PopoutButton"; import { PopoutButton } from "../common/Buttons/PopoutButton";
import { getErrorMessage, isAbortError } from "../common/Helper"; import { getErrorState } from "../common/Alerts/AlertsData";
import { useLazyFetchDeploymentJobLogQuery } from "../../store/deployApi"; import {
JobDetails,
useLazyFetchDeploymentJobLogQuery
} from "../../store/deployApi";
const LOG_POLL_INTERVAL = 5000; 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 [consoleDialogOpen, setConsoleDialogOpen] = useState(false);
const finalResultsNeeded = useRef(true); const finalResultsNeeded = useRef(true);
const params = useMemo(
() => ({
awxJobId: job.awxJobId
}),
[job]
);
const [getLogById, { data: log, isSuccess: logDataReady, error: logError }] = const [getLogById, { data: log, isSuccess: logDataReady, error: logError }] =
useLazyFetchDeploymentJobLogQuery({ useLazyFetchDeploymentJobLogQuery({
pollingInterval: isExpanded ? LOG_POLL_INTERVAL : 0 pollingInterval: isExpanded ? LOG_POLL_INTERVAL : 0
}); });
useEffect(() => { useEffect(() => {
if (isExpanded) { if (
if (!job.finishedAt || finalResultsNeeded.current) { !isExpanded ||
getLogById(params); (job.finishedAt && !finalResultsNeeded.current) ||
finalResultsNeeded.current = !job.finishedAt; !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; const showLoading = !log || !job.startTime;
useEffect(() => { useEffect(() => {
finalResultsNeeded.current = true; finalResultsNeeded.current = true;
}, [job.jobId]); }, [job]);
if (logError && !hasAbortError) { if (logError) {
return ( return (
<Stack> <Stack>
<Alert severity="error">{getErrorMessage(logError)}</Alert> <Alert severity="error">{getErrorState(logError).message}</Alert>
</Stack> </Stack>
); );
} }
...@@ -76,7 +83,7 @@ export function DeploymentJobOutput({ job, isExpanded }) { ...@@ -76,7 +83,7 @@ export function DeploymentJobOutput({ job, isExpanded }) {
onDialogClose={() => setConsoleDialogOpen(false)} onDialogClose={() => setConsoleDialogOpen(false)}
/> />
<LogStreamConsole <LogStreamConsole
log={log.stdoutHtml} log={log?.stdoutHtml}
dataReady={logDataReady} dataReady={logDataReady}
height="500px" height="500px"
/> />
......
import { DeploymentStatusIcon } from "./DeploymentIcons";
import { DeploymentJobOutput } from "./DeploymentJobOutput"; import { DeploymentJobOutput } from "./DeploymentJobOutput";
export { DeploymentStatusIcon, DeploymentJobOutput }; export { DeploymentJobOutput };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment