2020-12-23 19:10:25 -05:00
|
|
|
const unwrapGroups = (stages) => {
|
|
|
|
return stages.map((stage) => {
|
2020-12-02 19:09:53 -05:00
|
|
|
const {
|
|
|
|
groups: { nodes: groups },
|
|
|
|
} = stage;
|
|
|
|
return { ...stage, groups };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const unwrapNodesWithName = (jobArray, prop, field = 'name') => {
|
2020-12-23 19:10:25 -05:00
|
|
|
return jobArray.map((job) => {
|
|
|
|
return { ...job, [prop]: job[prop].nodes.map((item) => item[field]) };
|
2020-12-02 19:09:53 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const unwrapJobWithNeeds = (denodedJobArray) => {
|
2020-12-02 19:09:53 -05:00
|
|
|
return unwrapNodesWithName(denodedJobArray, 'needs');
|
|
|
|
};
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const unwrapStagesWithNeeds = (denodedStages) => {
|
2020-12-02 19:09:53 -05:00
|
|
|
const unwrappedNestedGroups = unwrapGroups(denodedStages);
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const nodes = unwrappedNestedGroups.map((node) => {
|
2020-12-02 19:09:53 -05:00
|
|
|
const { groups } = node;
|
2020-12-23 19:10:25 -05:00
|
|
|
const groupsWithJobs = groups.map((group) => {
|
2020-12-02 19:09:53 -05:00
|
|
|
const jobs = unwrapJobWithNeeds(group.jobs.nodes);
|
|
|
|
return { ...group, jobs };
|
|
|
|
});
|
|
|
|
|
|
|
|
return { ...node, groups: groupsWithJobs };
|
|
|
|
});
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
export { unwrapGroups, unwrapNodesWithName, unwrapJobWithNeeds, unwrapStagesWithNeeds };
|