Skip to content
Snippets Groups Projects
Commit d51f16d5 authored by Johanna Szepanski's avatar Johanna Szepanski
Browse files

generalized JobHost to be more reusable

parent c06ddfe1
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!593CE-3465: Ui not existing host
...@@ -58,7 +58,12 @@ const createRow = (job: JobDetails, action: string | undefined) => { ...@@ -58,7 +58,12 @@ const createRow = (job: JobDetails, action: string | undefined) => {
</Stack> </Stack>
</Stack> </Stack>
), ),
host: <JobHost job={job} /> host: (
<JobHost
url={job.host?.externalIdValid ? job.host.hostId : undefined}
label={job.host?.fqdn}
/>
)
}; };
}; };
......
...@@ -8,13 +8,13 @@ interface JobDetailsSingleJobProps { ...@@ -8,13 +8,13 @@ interface JobDetailsSingleJobProps {
job: JobDetails; job: JobDetails;
} }
const getRevision = (operation: JobDetails) => { const getRevision = (job: JobDetails) => {
return { return {
revision: revision:
operation.gitReference && operation.gitProjectId ? ( job.gitReference && job.gitProjectId ? (
<JobRevisionChip <JobRevisionChip
gitReference={operation.gitReference} gitReference={job.gitReference}
gitProjectId={operation.gitProjectId} gitProjectId={job.gitProjectId}
/> />
) : ( ) : (
"Unknown" "Unknown"
...@@ -22,21 +22,23 @@ const getRevision = (operation: JobDetails) => { ...@@ -22,21 +22,23 @@ const getRevision = (operation: JobDetails) => {
}; };
}; };
const getSingleOperationFields = ( const getSingleOperationFields = (job: JobDetails, isDeployJob: boolean) => {
operation: JobDetails,
isDeployJob: boolean
) => {
return { return {
ioc: ( ioc: (
<InternalLink <InternalLink
to={`/iocs/${operation.iocName}`} to={`/iocs/${job.iocName}`}
label={`IOC details, ${operation.iocName}`} label={`IOC details, ${job.iocName}`}
> >
{operation.iocName} {job.iocName}
</InternalLink> </InternalLink>
), ),
...(isDeployJob && getRevision(operation)), ...(isDeployJob && getRevision(job)),
host: <JobHost job={operation} /> host: (
<JobHost
url={job.host?.externalIdValid ? job.host.hostId : undefined}
label={job.host?.fqdn}
/>
)
}; };
}; };
......
import { useMemo } from "react";
import {
EllipsisText,
InternalLink,
Table,
SimpleAccordion
} from "@ess-ics/ce-ui-common";
import { Typography, Stack } from "@mui/material";
import { getNoOfIOCs, getNoOfHosts, isBatchJob } from "./JobUtils";
import { JobRevisionChip } from "./JobRevisionChip";
import { JobHost } from "./JobHost";
import { JobDetails, JobDetailsEntry } from "../../store/deployApi";
const columns = [
{
field: "ioc",
headerName: "IOC",
flex: 1
},
{
field: "revision",
headerName: "Revision",
flex: 1
},
{
field: "host",
headerName: "Host",
flex: 1
}
];
const createRow = (job: JobDetailsEntry) => {
const { iocId, iocName, host, gitReference, gitProjectId } = job;
return {
id: `${iocId}${host?.hostId}`,
ioc: (
<InternalLink
to={`/iocs/${iocId}`}
label={`Ioc details, ${iocName}`}
width="100%"
>
<EllipsisText>{iocName}</EllipsisText>
</InternalLink>
),
host: <JobHost job={job} />,
revision: gitReference && gitProjectId && (
<JobRevisionChip
gitReference={gitReference}
gitProjectId={gitProjectId}
/>
)
};
};
export const JobDetailsTable = ({ operation }: { operation: JobDetails }) => {
const isBatchOperation = isBatchJob(operation.action);
const noOfIOCs = useMemo(() => {
if (isBatchOperation) {
return getNoOfIOCs(operation.jobs);
}
}, [operation, isBatchOperation]);
const noOfHosts = useMemo(() => {
if (isBatchOperation) {
return getNoOfHosts(operation.jobs);
}
}, [operation, isBatchOperation]);
return (
<>
{isBatchJob(operation.action) ? (
<SimpleAccordion
summary={
<Stack
flexDirection="row"
alignItems="end"
sx={{ width: "100%" }}
gap={1}
>
{" "}
<Typography
component="h2"
variant="h3"
>
Batch
</Typography>
<Typography
variant="body2"
sx={{ fontWeight: "600", marginRight: "10px" }}
>
{noOfIOCs} {noOfIOCs && noOfIOCs > 1 ? "IOCs" : "IOC"}
{", "}
{noOfHosts} {noOfHosts && noOfHosts > 1 ? "Hosts" : "Host"}
</Typography>
</Stack>
}
>
<Table
columns={columns}
disableColumnSorting
rows={operation?.jobs?.map((job) => createRow(job))}
/>
</SimpleAccordion>
) : (
<Table
columns={columns}
disableColumnSorting
rows={[operation].map((job) => createRow(job))}
/>
)}
</>
);
};
import { EllipsisText, InternalLink } from "@ess-ics/ce-ui-common"; import { EllipsisText, InternalLink } from "@ess-ics/ce-ui-common";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import { JobDetails } from "../../store/deployApi";
interface JobHostProps { interface JobHostProps {
job: JobDetails; url: string | undefined;
label: string | undefined;
} }
export const JobHost = ({ job }: JobHostProps) => { export const JobHost = ({ url, label }: JobHostProps) => {
// host is resolvable => show link for users // host is resolvable => show link for users
if (job?.host?.hostId && job?.host?.externalIdValid) { if (url) {
return ( return (
<InternalLink <InternalLink
to={`/hosts/${job.host.hostId}`} to={`/hosts/${url}`}
label={`Host Details, ${job.host.fqdn}`} label={`Host Details, ${label}`}
width="100%" width="100%"
> >
<EllipsisText>{job.host.fqdn}</EllipsisText> <EllipsisText>{label}</EllipsisText>
</InternalLink> </InternalLink>
); );
} }
// gray out hostname if it is from cache
return ( return (
<Typography color="gray"> <Typography color="gray">
<EllipsisText>{job?.host?.fqdn}</EllipsisText> <EllipsisText>{label}</EllipsisText>
</Typography> </Typography>
); );
}; };
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
} from "../JobUtils"; } from "../JobUtils";
import { ActionTypeIconText } from "../JobIcons"; import { ActionTypeIconText } from "../JobIcons";
import { JobRevisionChip } from "../JobRevisionChip"; import { JobRevisionChip } from "../JobRevisionChip";
import { JobHost } from "../JobHost";
export const JobDetailsColumn = ({ job }: { job: Job }) => { export const JobDetailsColumn = ({ job }: { job: Job }) => {
const isBatchOperation = isBatchJob(job.action); const isBatchOperation = isBatchJob(job.action);
...@@ -69,16 +70,14 @@ export const JobDetailsColumn = ({ job }: { job: Job }) => { ...@@ -69,16 +70,14 @@ export const JobDetailsColumn = ({ job }: { job: Job }) => {
flexWrap="wrap" flexWrap="wrap"
> >
<Box sx={{ minWidth: "112px" }}> <Box sx={{ minWidth: "112px" }}>
{!checkHostExistsLoading && isSuccess ? ( <JobHost
<InternalLink url={
to={`/hosts/${job?.host?.hostId}`} !checkHostExistsLoading && isSuccess
label={`Host details, ${job.host?.hostName}`} ? job?.host?.hostId
> : undefined
{job.host?.hostName} }
</InternalLink> label={job.host?.hostName}
) : ( />
<Typography>{job.host?.hostName}</Typography>
)}
</Box> </Box>
<Typography variant="body2">{job?.host?.network}</Typography> <Typography variant="body2">{job?.host?.network}</Typography>
</Stack> </Stack>
......
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