import React, { useContext, useEffect } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import JobContext from "@qltr/jobctx"; import JobBox from "./JobBox.jsx"; import JobPipelineBox from "./JobPipelineBox.jsx"; import JobView from "./JobView.jsx"; import JobPipelineDisplay from "./JobPipelineDisplay.jsx"; import JobBuilder from "./builder/JobBuilder.jsx"; import Typography from "@mui/material/Typography"; import Box from "@mui/material/Box"; export default function Jobs() { const { state: jobState } = useContext(JobContext); const location = useLocation(); const navigate = useNavigate(); const jobViewPrefix = "#job-"; const pipelineViewPrefix = "#pipeline-"; const cachePrefix = "#cache-"; function jobHashLoader() { const { hash } = location; if (!hash) return { hash }; 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, hash }; } const jobHash = jobHashLoader(); useEffect(() => { const { job, pipeline, builderCache, hash } = jobHash; if (!hash) return; if (!job && !pipeline && !builderCache) navigate("/qualiteer/jobs"); }); return (
); }