2022-08-13 20:43:35 +00:00
|
|
|
import React, { useContext, useEffect } from "react";
|
2022-08-05 13:03:48 +00:00
|
|
|
import { useLocation, useNavigate } from "react-router-dom";
|
2022-07-18 21:43:10 +00:00
|
|
|
|
2022-08-12 13:08:00 +00:00
|
|
|
import JobContext from "@qltr/jobs";
|
2022-07-18 21:43:10 +00:00
|
|
|
import JobBox from "./JobBox.jsx";
|
2022-08-09 14:07:53 +00:00
|
|
|
import JobPipelineBox from "./JobPipelineBox.jsx";
|
2022-07-18 21:43:10 +00:00
|
|
|
import JobView from "./JobView.jsx";
|
2022-08-09 14:07:53 +00:00
|
|
|
import JobPipelineDisplay from "./JobPipelineDisplay.jsx";
|
2022-08-01 14:58:11 +00:00
|
|
|
import JobBuilder from "./builder/JobBuilder.jsx";
|
2022-08-06 21:21:41 +00:00
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
import Box from "@mui/material/Box";
|
2022-07-18 21:43:10 +00:00
|
|
|
|
|
|
|
export default function Jobs() {
|
2022-08-05 13:03:48 +00:00
|
|
|
const { state: jobState } = useContext(JobContext);
|
2022-07-18 21:43:10 +00:00
|
|
|
const location = useLocation();
|
2022-08-05 13:03:48 +00:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
2022-08-13 20:43:35 +00:00
|
|
|
const jobViewPrefix = "#job-";
|
|
|
|
const pipelineViewPrefix = "#pipeline-";
|
|
|
|
const cachePrefix = "#cache-";
|
|
|
|
|
|
|
|
function jobHashLoader() {
|
|
|
|
const { hash } = location;
|
|
|
|
if (!hash) return {};
|
|
|
|
const jobIndex = hash.indexOf(jobViewPrefix);
|
|
|
|
const pipelineIndex = hash.indexOf(pipelineViewPrefix);
|
|
|
|
const cacheIndex = hash.indexOf(cachePrefix);
|
|
|
|
const jobId = jobIndex !== 0 ? null : hash.slice(jobViewPrefix.length);
|
|
|
|
const pipelineId =
|
|
|
|
pipelineIndex !== 0 ? null : hash.slice(pipelineViewPrefix.length);
|
|
|
|
const cacheData = cacheIndex !== 0 ? null : hash.slice(cachePrefix.length);
|
|
|
|
const job = !jobId ? null : jobState.jobs.find((j) => j.jobId === jobId);
|
|
|
|
const pipeline = !pipelineId
|
|
|
|
? null
|
|
|
|
: jobState.pipelines.find((p) => p.id === pipelineId);
|
|
|
|
const builderCache = !cacheData ? null : { fakedata: "yep" };
|
|
|
|
return { job, pipeline, builderCache };
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobHash = jobHashLoader();
|
|
|
|
|
2022-08-05 13:03:48 +00:00
|
|
|
useEffect(() => {
|
2022-08-13 20:43:35 +00:00
|
|
|
const { job, pipeline, builderCache } = jobHash;
|
|
|
|
if (!job && !pipeline && !builderCache) navigate("/qualiteer/jobs");
|
2022-08-05 13:03:48 +00:00
|
|
|
});
|
2022-07-18 21:43:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="jobs">
|
2022-08-09 04:29:10 +00:00
|
|
|
{jobState.jobs.length === 0 ? (
|
|
|
|
<React.Fragment>
|
|
|
|
<Box
|
|
|
|
display="flex"
|
|
|
|
alignItems="center"
|
|
|
|
justifyContent="center"
|
|
|
|
sx={{ flexFlow: "wrap" }}
|
|
|
|
>
|
2022-08-12 20:10:57 +00:00
|
|
|
<Typography variant="h4">No jobs found!</Typography>
|
2022-08-09 04:29:10 +00:00
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
display="flex"
|
|
|
|
alignItems="center"
|
|
|
|
justifyContent="center"
|
|
|
|
sx={{ flexFlow: "wrap" }}
|
|
|
|
>
|
|
|
|
<Typography variant="h5">
|
|
|
|
Click the '+' to start a new one!
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
2022-08-06 21:21:41 +00:00
|
|
|
</React.Fragment>
|
2022-08-09 04:29:10 +00:00
|
|
|
) : null}
|
2022-08-12 20:10:57 +00:00
|
|
|
|
2022-08-01 14:58:11 +00:00
|
|
|
<JobBuilder />
|
2022-08-12 20:10:57 +00:00
|
|
|
|
2022-08-09 17:59:36 +00:00
|
|
|
{location.hash === "" && (
|
|
|
|
<React.Fragment>
|
|
|
|
{jobState.jobs
|
|
|
|
.filter((j) => !j.isPipeline)
|
|
|
|
.map((v, i) => (
|
|
|
|
<a
|
|
|
|
key={i}
|
2022-08-13 20:43:35 +00:00
|
|
|
href={`/qualiteer/jobs#job-${v.jobId}`}
|
2022-08-09 17:59:36 +00:00
|
|
|
style={{ textDecoration: "none" }}
|
|
|
|
>
|
|
|
|
<JobBox job={v} />
|
|
|
|
</a>
|
|
|
|
))}
|
|
|
|
{jobState.pipelines.map((p, i) => (
|
2022-08-09 04:29:10 +00:00
|
|
|
<a
|
|
|
|
key={i}
|
|
|
|
style={{ textDecoration: "none" }}
|
2022-08-13 20:43:35 +00:00
|
|
|
href={`/qualiteer/jobs#pipeline-${p.id}`}
|
2022-08-09 04:29:10 +00:00
|
|
|
>
|
2022-08-09 17:59:36 +00:00
|
|
|
<JobPipelineBox pipeline={p} />
|
|
|
|
</a>
|
|
|
|
))}
|
|
|
|
</React.Fragment>
|
2022-07-18 21:43:10 +00:00
|
|
|
)}
|
2022-08-09 17:59:36 +00:00
|
|
|
|
2022-08-13 20:43:35 +00:00
|
|
|
{jobHash.pipeline && <JobPipelineDisplay pipeline={jobHash.pipeline} />}
|
|
|
|
{jobHash.job && <JobView job={jobHash.job} />}
|
2022-07-18 21:43:10 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|