qualiteer/src/views/catalog/CatalogBox.jsx

139 lines
3.9 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";
2022-10-15 11:47:47 +00:00
import { useJobCore, jobStatus } from "@qltr/jobcore";
2022-05-23 00:24:21 +00:00
2022-10-08 17:47:46 +00:00
import useMediaQuery from "@mui/material/useMediaQuery";
import { useTheme } from "@mui/material/styles";
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
2022-10-17 08:00:03 -04:00
import CatalogItemDetails from "./CatalogItemDetails.jsx";
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);
2022-10-15 11:47:47 +00:00
const { jobCompose, toPipeline, toJob, jobIcon, pipelineIcon } = useJobCore();
2022-05-23 00:24:21 +00:00
const [open, setOpen] = useState(false);
const toggleOpen = () => setOpen(!open);
2022-10-08 17:47:46 +00:00
const theme = useTheme();
const minifyActions = useMediaQuery(theme.breakpoints.down("sm"));
2022-06-22 00:47:19 +00:00
2022-08-12 13:08:00 +00:00
const navigateToJob = () => {
2022-10-15 11:47:47 +00:00
if (pipeline) return toPipeline(pipeline.id);
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-10-15 11:47:47 +00:00
const jobId = jobCompose({
2022-10-08 17:47:46 +00:00
testNames: [testName],
isTriage: store.triageFailing,
});
2022-10-15 11:47:47 +00:00
if (store.focusJob) 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,
};
2022-10-15 11:47:47 +00:00
const pipeline = jobCompose(builderCache);
if (store.focusJob) 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();
};
2022-10-15 11:47:47 +00:00
function boxIcon() {
if (pipeline) return pipelineIcon(pipeline);
2022-08-12 13:08:00 +00:00
if (!job) return <PlayArrowIcon />;
2022-10-15 11:47:47 +00:00
return jobIcon(job);
2022-08-12 13:08:00 +00:00
}
2022-05-23 00:24:21 +00:00
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
2022-10-08 17:47:46 +00:00
direction={minifyActions ? "column" : "row"}
sx={{ ml: "auto", mb: "auto", mt: "auto", whiteSpace: "nowrap" }}
2022-05-23 00:24:21 +00:00
>
2022-10-08 17:47:46 +00:00
<IconButton
color="success"
aria-label="play"
component="span"
onClick={jobOnClick}
>
2022-10-15 11:47:47 +00:00
{boxIcon()}
2022-10-08 17:47:46 +00:00
</IconButton>
2022-05-23 00:24:21 +00:00
</Stack>
</AccordionSummary>
2022-06-22 00:47:19 +00:00
<AccordionDetails>
2022-10-17 08:00:03 -04:00
<CatalogItemDetails catalogTest={catalogTest} />
2022-06-22 00:47:19 +00:00
</AccordionDetails>
2022-05-23 00:24:21 +00:00
</Accordion>
);
}