Pipeline Magic
This commit is contained in:
parent
d5ea0981e5
commit
643b4cdc20
4 changed files with 68 additions and 65 deletions
31
lib/jobs/pipelines.js
Normal file
31
lib/jobs/pipelines.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
const nest = (arr) => {
|
||||||
|
const obj = {};
|
||||||
|
arr.reduce((o, s) => (o[s] = {}), obj);
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const asTree = (branches) => {
|
||||||
|
const nests = branches.map((b)=>nest(b));
|
||||||
|
return _.merge(...nests);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const asBranches = (array) => {
|
||||||
|
const merged = [];
|
||||||
|
array.forEach((p, i) => {
|
||||||
|
p.forEach((v, i) => {
|
||||||
|
if (!merged[i]) merged[i] = [];
|
||||||
|
if (!merged[i].includes(v)) merged[i].push(v);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const as1d = (a) => [].concat.apply([], a);
|
||||||
|
|
||||||
|
export const selectBranch = (map,test) => {
|
||||||
|
const pipeline = map.find((pm)=>pm.includes(test));
|
||||||
|
const testIndex = pipeline.findIndex((t) => t === test);
|
||||||
|
return pipeline.slice(0, testIndex + 1);
|
||||||
|
}
|
|
@ -2,26 +2,24 @@ import { useQuery } from '@tanstack/react-query'
|
||||||
|
|
||||||
const QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api";
|
const QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api";
|
||||||
|
|
||||||
export const useCatalogTests = () => useQuery(['catalogTests'], () =>
|
const useMock = true;
|
||||||
fetch(`${QUALITEER_URL}/catalog/tests`).then(res =>
|
|
||||||
res.json()
|
const asMock = (data) => ({ data });
|
||||||
)
|
|
||||||
|
const fetchApi = (subPath)=> async ()=> fetch(`${QUALITEER_URL}${subPath}`).then((res)=>res.json());
|
||||||
|
|
||||||
|
export const useCatalogTests = () => useMock ? asMock([]): useQuery(['catalogTests'], fetchApi("/catalog/tests")
|
||||||
)
|
)
|
||||||
|
|
||||||
export const usePipelineMappings = () => useQuery(['pipelineMappings'], () =>
|
export const usePipelineMappings = () => useMock ? asMock([
|
||||||
fetch(`${QUALITEER_URL}/catalog/pipeline-mappings`).then(res =>
|
["primary", "secondary1", "tertiary1"],
|
||||||
res.json()
|
["primary", "secondary1", "tertiary2"],
|
||||||
)
|
["primary", "secondary2", "tertiary3"],
|
||||||
|
]) : useQuery(['pipelineMappings'], fetchApi("/catalog/pipeline-mappings")
|
||||||
)
|
)
|
||||||
|
|
||||||
export const useSilencedAlerts = () => useQuery(['silenced'], () =>
|
export const useSilencedAlerts = () => useMock? asMock([]) : useQuery(['silenced'], fetchApi("/alerting/silenced")
|
||||||
fetch(`${QUALITEER_URL}/alerting/silenced`).then(res =>
|
|
||||||
res.json()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export const useCurrentlyFailing = () => useQuery(['failing'], () =>
|
export const useCurrentlyFailing = () => useQuery(['failing'], useMock? asMock([]) : fetchApi("/results/failing")
|
||||||
fetch(`${QUALITEER_URL}/results/failing`).then(res =>
|
|
||||||
res.json()
|
|
||||||
)
|
|
||||||
)
|
)
|
|
@ -94,11 +94,11 @@ export const JobProvider = ({ children }) => {
|
||||||
function pipelineFactory(builderCache) {
|
function pipelineFactory(builderCache) {
|
||||||
console.log("Would create pipeline with cache");
|
console.log("Would create pipeline with cache");
|
||||||
console.log(builderCache);
|
console.log(builderCache);
|
||||||
return jobFactory({testNames: ["single"]});
|
return jobFactory({testNames: ["primary"]});
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobFactory(builderCache) {
|
function jobFactory(builderCache) {
|
||||||
if(builderCache.pipelineMasterTrack) return pipelineFactory(builderCache);
|
if(builderCache.tracks) return pipelineFactory(builderCache);
|
||||||
// Find test
|
// Find test
|
||||||
const i = new Initiator(url);
|
const i = new Initiator(url);
|
||||||
const jobId = `j${Date.now()}`;
|
const jobId = `j${Date.now()}`;
|
||||||
|
|
|
@ -8,72 +8,46 @@ import AccordionSummary from "@mui/material/AccordionSummary";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
|
import {selectBranch, asTree, asBranches, as1d} from "../../../../lib/jobs/pipelines.js";
|
||||||
|
|
||||||
function PipelineTrackSelector(props) {
|
function PipelineTrackSelector(props) {
|
||||||
const { cache, setCache, back, next } = props;
|
const { cache, setCache, back, next } = props;
|
||||||
|
const {primarySelectedMappings: primaries} = cache;
|
||||||
const pipelineTracks = [];
|
|
||||||
for (var track of cache.primarySelectedMappings) {
|
|
||||||
for (var i in track) {
|
|
||||||
if (!pipelineTracks[i]) pipelineTracks[i] = [];
|
|
||||||
if (pipelineTracks[i].includes(track[i])) continue;
|
|
||||||
pipelineTracks[i].push(track[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const addTrack = (test) => {
|
const addTrack = (test) => {
|
||||||
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
|
const tracks = cache.tracks ?? []; tracks.push(selectBranch(primaries, test));
|
||||||
for (var track of cache.primarySelectedMappings) {
|
setCache({ ...cache, tracks});
|
||||||
const trackIndex = track.indexOf(test);
|
|
||||||
if (trackIndex === -1) continue;
|
|
||||||
const trackSlice = track.slice(0, trackIndex + 1);
|
|
||||||
trackSlice.forEach((t, i) => {
|
|
||||||
if (!pipelineMasterTrack[i]) pipelineMasterTrack[i] = [];
|
|
||||||
if (!pipelineMasterTrack[i].includes(t)) pipelineMasterTrack[i].push(t);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(pipelineMasterTrack);
|
|
||||||
setCache({ ...cache, pipelineMasterTrack });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTrack = (test) => {
|
const removeTrack = (test) => {
|
||||||
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
|
const {tracks} = cache;
|
||||||
const toRemove = [];
|
for(var i in tracks){
|
||||||
for (var mapping of cache.primarySelectedMappings) {
|
const index = tracks[i].indexOf(test);
|
||||||
const testIndex = mapping.indexOf(test);
|
if(index===-1) continue;
|
||||||
if (testIndex === -1) continue;
|
tracks[i] = tracks[i].slice(0,index);
|
||||||
const removeSlice = mapping.slice(testIndex, mapping.length);
|
|
||||||
toRemove.push(...removeSlice);
|
|
||||||
}
|
}
|
||||||
|
setCache({ ...cache, tracks});
|
||||||
for (var i in pipelineMasterTrack) {
|
|
||||||
pipelineMasterTrack[i] = pipelineMasterTrack[i].filter(
|
|
||||||
(t) => !toRemove.includes(t)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setCache({ ...cache, pipelineMasterTrack });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectTrack = (test) => () => {
|
const selectTrack = (test) => () => {
|
||||||
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
|
if(as1d(cache.tracks).includes(test)) return removeTrack(test);
|
||||||
if (![].concat.apply([], pipelineMasterTrack).includes(test))
|
addTrack(test);
|
||||||
return addTrack(test);
|
|
||||||
removeTrack(test);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getColor = (test) => {
|
const getColor = (test) => as1d(cache.tracks).includes(test)
|
||||||
return [].concat.apply([], cache.pipelineMasterTrack).includes(test)
|
|
||||||
? "primary"
|
? "primary"
|
||||||
: null;
|
: null;
|
||||||
};
|
|
||||||
|
const nextClick = () => {
|
||||||
|
|
||||||
|
setCache({...cache, branches: asBranches(primaries), tree: asTree(cache.tracks)});
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<h3>Select Track</h3>
|
<h3>Select Track</h3>
|
||||||
{pipelineTracks.map((track, i) => (
|
{asBranches(primaries).map((track, i) => (
|
||||||
<React.Fragment key={i}>
|
<React.Fragment key={i}>
|
||||||
<Typography variant="h6">{i + 1}</Typography>
|
<Typography variant="h6">{i + 1}</Typography>
|
||||||
<Box>
|
<Box>
|
||||||
|
@ -108,7 +82,7 @@ function PipelineTrackSelector(props) {
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={back}>Back</Button>
|
<Button onClick={back}>Back</Button>
|
||||||
<Button onClick={next} autoFocus>
|
<Button onClick={nextClick} autoFocus>
|
||||||
Next
|
Next
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue