qualiteer/src/views/jobs/Jobs.jsx

80 lines
2.7 KiB
React
Raw Normal View History

2022-08-06 21:21:41 +00:00
import React, { useState, 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
import JobContext from "../../ctx/JobContext.jsx";
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();
useEffect(() => {
const jobName = location.hash.slice(1);
2022-08-09 14:07:53 +00:00
const pipelineId = jobName.slice(1);
2022-08-09 15:19:09 +00:00
if(!jobName || !pipelineId) return;
const hasJob = jobState.pipelines.find((p)=>p.id ===pipelineId);
const hasPipeline = jobState.jobs.find((job) => job.name === jobName);
if(hasPipeline || hasJob) return;
if(jobName || pipelineId) 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" }}
>
<Typography variant="h4">No jobs found! </Typography>{" "}
</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-01 14:58:11 +00:00
<JobBuilder />
2022-08-09 14:07:53 +00:00
{location.hash === "" &&(
<React.Fragment>
{jobState.jobs
2022-08-09 04:29:10 +00:00
.filter((j) => !j.isPipeline)
.map((v, i) => (
<a
key={i}
href={`/qualiteer/jobs#${v.name}`}
style={{ textDecoration: "none" }}
>
<JobBox job={v} />
2022-08-09 14:07:53 +00:00
</a>))}
{jobState.pipelines.map((p,i)=><a key={i} style={{textDecoration: "none"}} href={`/qualiteer/jobs#p${p.id}`}>
<JobPipelineBox pipeline={p}/>
</a>)}
</React.Fragment>)
}
2022-08-09 15:19:09 +00:00
{ location.hash[1] === "p"? jobState.pipelines.find((p)=>p.id===location.hash.slice(2)) && (<JobPipelineDisplay pipeline={jobState.pipelines.find((p)=>p.id===location.hash.slice(2))}/>) :
2022-08-09 14:07:53 +00:00
jobState.jobs.find((job) => job.name === location.hash.slice(1)) && (<JobView
2022-07-18 21:43:10 +00:00
job={jobState.jobs.find((job) => job.name === location.hash.slice(1))}
/>
)}
</div>
);
}