qualiteer/src/views/catalog/CatalogBox.jsx

156 lines
4 KiB
React
Raw Normal View History

2022-05-23 00:24:21 +00:00
import React, { useState, useContext } from "react";
2022-08-13 20:43:35 +00:00
2022-08-12 13:08:00 +00:00
import { usePipelineMappings } from "@qltr/queries";
import StoreContext from "@qltr/store";
import JobContext, { jobStatus } from "@qltr/jobs";
2022-08-13 20:43:35 +00:00
import {
useJobIconState,
usePipelineIconState,
useJobNav,
} from "@qltr/util/JobTools";
2022-05-23 00:24:21 +00:00
import Accordion from "@mui/material/Accordion";
import AccordionDetails from "@mui/material/AccordionDetails";
import AccordionSummary from "@mui/material/AccordionSummary";
import Typography from "@mui/material/Typography";
import IconButton from "@mui/material/IconButton";
2022-06-22 00:47:19 +00:00
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
2022-08-12 13:08:00 +00:00
import ViewColumnIcon from "@mui/icons-material/ViewColumn";
2022-05-23 00:24:21 +00:00
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
2022-08-12 13:08:00 +00:00
import { asTree, asBranches, as1d } from "@qltr/util/pipelines.js";
2022-05-23 00:24:21 +00:00
export default function CatalogBox(props) {
const { catalogTest } = props;
2022-08-06 12:25:56 +00:00
2022-05-23 00:24:21 +00:00
const {
name: testName,
class: testClass,
repo: testRepo,
2022-08-10 12:39:09 +00:00
isPipeline,
2022-06-22 00:47:19 +00:00
type: testType,
2022-08-12 13:08:00 +00:00
job,
pipeline,
2022-05-23 00:24:21 +00:00
} = catalogTest;
2022-08-10 12:39:09 +00:00
const { data: pipelineMappings, isLoading } = usePipelineMappings();
2022-08-12 13:08:00 +00:00
const { state: store } = useContext(StoreContext);
const { jobFactory } = useContext(JobContext);
2022-08-13 20:43:35 +00:00
const jobNav = useJobNav();
2022-05-23 00:24:21 +00:00
const [open, setOpen] = useState(false);
const toggleOpen = () => setOpen(!open);
2022-06-22 00:47:19 +00:00
2022-08-12 13:08:00 +00:00
const navigateToJob = () => {
2022-08-13 20:43:35 +00:00
if (pipeline) return jobNav.toPipeline(pipeline.id);
jobNav.toJob(job.jobId);
2022-08-12 13:08:00 +00:00
};
const runTest = () => {
2022-08-10 12:39:09 +00:00
if (isPipeline) return runPipelineTest();
2022-08-12 13:08:00 +00:00
const jobId = jobFactory({ testNames: [testName], isTriage: true });
2022-08-13 20:43:35 +00:00
if (store.focusJob) jobNav.toJob(jobId);
2022-07-06 20:20:27 +00:00
};
2022-08-10 12:39:09 +00:00
const runPipelineTest = () => {
2022-08-12 20:10:57 +00:00
if (isLoading) {
console.log("Pipeline mappings are loading, retrying in 5 seconds");
setTimeout(runPipelineTest, 5000);
}
const primaries = pipelineMappings.filter((m) =>
m.find((t) => t.name === testName)
);
2022-08-10 12:39:09 +00:00
const builderCache = {
branches: asBranches(primaries),
tree: asTree(primaries),
selectedBranches: as1d(primaries),
isTriage: true,
};
const pipeline = jobFactory(builderCache);
2022-08-13 20:43:35 +00:00
if (store.focusJob) jobNav.toPipeline(pipeline.id);
2022-08-10 12:39:09 +00:00
};
2022-08-12 13:08:00 +00:00
const jobOnClick = (e) => {
e.preventDefault();
e.stopPropagation();
if (pipeline) return navigateToJob();
if (!job) return runTest();
navigateToJob();
};
function jobIcon() {
if (pipeline) return usePipelineIconState(pipeline);
if (!job) return <PlayArrowIcon />;
return useJobIconState(job);
}
2022-05-23 00:24:21 +00:00
function Actions() {
return (
<React.Fragment>
2022-07-06 20:20:27 +00:00
<IconButton
color="success"
aria-label="play"
component="span"
2022-08-12 13:08:00 +00:00
onClick={jobOnClick}
2022-07-06 20:20:27 +00:00
>
2022-08-12 13:08:00 +00:00
{jobIcon()}
2022-05-23 00:24:21 +00:00
</IconButton>
</React.Fragment>
);
}
return (
2022-06-22 00:47:19 +00:00
<Accordion
expanded={open}
disableGutters={true}
onChange={toggleOpen}
square
>
2022-05-23 00:24:21 +00:00
<AccordionSummary
style={{
backgroundColor: "rgba(0, 0, 0, .03)",
flexWrap: "wrap",
}}
>
2022-06-22 00:47:19 +00:00
<Typography
component={"span"}
style={{ wordBreak: "break-word", margin: "auto 0" }}
>
2022-05-23 00:24:21 +00:00
{`${testClass}#`}
<Box fontWeight="bold" display="inline">
{testName}
2022-08-12 13:08:00 +00:00
{isPipeline && (
<IconButton component="span">
<ViewColumnIcon />
</IconButton>
)}
2022-05-23 00:24:21 +00:00
</Box>
<br />
</Typography>
<Stack
sx={{ ml: "auto", display: { md: "none", lg: "none", xl: "none" } }}
>
<Actions />
</Stack>
<Stack
direction="row"
sx={{
ml: "auto",
display: { xs: "none", sm: "none", md: "flex", lg: "flex" },
}}
>
<Actions />
</Stack>
</AccordionSummary>
2022-06-22 00:47:19 +00:00
<AccordionDetails>
<Typography component={"span"} style={{ wordBreak: "break-word" }}>
2022-08-12 13:08:00 +00:00
{"Test info"}
2022-06-22 00:47:19 +00:00
</Typography>
</AccordionDetails>
2022-05-23 00:24:21 +00:00
</Accordion>
);
}