Pipeline Magic

This commit is contained in:
Dunemask 2022-08-08 13:01:39 +00:00
parent d5ea0981e5
commit 643b4cdc20
4 changed files with 68 additions and 65 deletions

View file

@ -8,72 +8,46 @@ import AccordionSummary from "@mui/material/AccordionSummary";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import Stack from "@mui/material/Stack";
import {selectBranch, asTree, asBranches, as1d} from "../../../../lib/jobs/pipelines.js";
function PipelineTrackSelector(props) {
const { cache, setCache, back, next } = props;
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 {primarySelectedMappings: primaries} = cache;
const addTrack = (test) => {
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
for (var track of cache.primarySelectedMappings) {
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 tracks = cache.tracks ?? []; tracks.push(selectBranch(primaries, test));
setCache({ ...cache, tracks});
};
const removeTrack = (test) => {
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
const toRemove = [];
for (var mapping of cache.primarySelectedMappings) {
const testIndex = mapping.indexOf(test);
if (testIndex === -1) continue;
const removeSlice = mapping.slice(testIndex, mapping.length);
toRemove.push(...removeSlice);
const {tracks} = cache;
for(var i in tracks){
const index = tracks[i].indexOf(test);
if(index===-1) continue;
tracks[i] = tracks[i].slice(0,index);
}
for (var i in pipelineMasterTrack) {
pipelineMasterTrack[i] = pipelineMasterTrack[i].filter(
(t) => !toRemove.includes(t)
);
}
setCache({ ...cache, pipelineMasterTrack });
setCache({ ...cache, tracks});
};
const selectTrack = (test) => () => {
const pipelineMasterTrack = cache.pipelineMasterTrack ?? [];
if (![].concat.apply([], pipelineMasterTrack).includes(test))
return addTrack(test);
removeTrack(test);
if(as1d(cache.tracks).includes(test)) return removeTrack(test);
addTrack(test);
};
const getColor = (test) => {
return [].concat.apply([], cache.pipelineMasterTrack).includes(test)
const getColor = (test) => as1d(cache.tracks).includes(test)
? "primary"
: null;
};
const nextClick = () => {
setCache({...cache, branches: asBranches(primaries), tree: asTree(cache.tracks)});
next();
}
return (
<React.Fragment>
<DialogContent>
<h3>Select Track</h3>
{pipelineTracks.map((track, i) => (
{asBranches(primaries).map((track, i) => (
<React.Fragment key={i}>
<Typography variant="h6">{i + 1}</Typography>
<Box>
@ -108,7 +82,7 @@ function PipelineTrackSelector(props) {
</DialogContent>
<DialogActions>
<Button onClick={back}>Back</Button>
<Button onClick={next} autoFocus>
<Button onClick={nextClick} autoFocus>
Next
</Button>
</DialogActions>