qualiteer/src/views/catalog/Catalog.jsx

65 lines
1.8 KiB
React
Raw Normal View History

2022-05-23 00:24:21 +00:00
import { useEffect, useContext } from "react";
2022-08-12 13:08:00 +00:00
import StoreContext from "@qltr/store";
import JobContext from "@qltr/jobs";
2022-07-12 21:48:05 +00:00
import CatalogBox from "./CatalogBox.jsx";
import CatalogSearch from "./CatalogSearch.jsx";
2022-08-12 13:08:00 +00:00
import { useCatalogTests } from "@qltr/queries";
2022-05-17 12:32:04 +00:00
import TextField from "@mui/material/TextField";
export default function Catalog() {
const { state: store, updateStore } = useContext(StoreContext);
2022-08-12 13:08:00 +00:00
const { state: jobState } = useContext(JobContext);
2022-08-09 04:29:10 +00:00
const { isLoading, data: tests } = useCatalogTests();
2022-05-23 00:24:21 +00:00
const handleSearchChange = (e) =>
updateStore({ catalogSearch: e.target.value });
const handleSearchClear = () => updateStore({ catalogSearch: "" });
useEffect(() => {
return function unmount() {
handleSearchClear();
};
}, []);
2022-08-12 13:08:00 +00:00
const catalogWithJobs = () => {
for (var test of tests) {
if (test.isPipeline) {
const pipeline = jobState.pipelines.find((p) =>
p.selectedBranches.includes(test.name)
);
if (!pipeline) continue;
const pipelineJob = jobState.jobs.find(
(j) =>
j.isPipeline &&
j.pipelineId === pipeline.id &&
j.branchId === test.name
);
if (!pipelineJob) test.pipeline = pipeline;
test.job = pipelineJob;
continue;
}
const job = jobState.jobs.find(
(j) => !j.isPipeline && j.builderCache.testNames.includes(test.name)
);
if (job) test.job = job;
}
return tests;
};
2022-05-17 12:32:04 +00:00
return (
<div className="catalog">
2022-05-23 00:24:21 +00:00
<CatalogSearch
onChange={handleSearchChange}
onClear={handleSearchClear}
clearOnUnmount
/>
<h6>{store.catalogSearch}</h6>
2022-08-09 04:29:10 +00:00
{isLoading
? null
2022-08-12 13:08:00 +00:00
: catalogWithJobs().map((v, i) => (
<CatalogBox key={i} catalogTest={v} />
))}
2022-05-17 12:32:04 +00:00
</div>
);
}