Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unwrapping_utils.js « components « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa33f622ce6ec535cf71baccaaa15bf87ff48f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * This function takes the stages and add the stage name
 * at the group level as `category` to have an easier
 * implementation while constructions nodes with D3
 * @param {Array} stages
 * @returns {Array} - Array of stages with stage name at the group level as `category`
 */
export const unwrapArrayOfJobs = (stages = []) => {
  return stages
    .map(({ name, groups }) => {
      return groups.map(group => {
        return { category: name, ...group };
      });
    })
    .flat(2);
};

const unwrapGroups = stages => {
  return stages.map(stage => {
    const {
      groups: { nodes: groups },
    } = stage;
    return { ...stage, groups };
  });
};

const unwrapNodesWithName = (jobArray, prop, field = 'name') => {
  return jobArray.map(job => {
    return { ...job, [prop]: job[prop].nodes.map(item => item[field]) };
  });
};

const unwrapJobWithNeeds = denodedJobArray => {
  return unwrapNodesWithName(denodedJobArray, 'needs');
};

const unwrapStagesWithNeeds = denodedStages => {
  const unwrappedNestedGroups = unwrapGroups(denodedStages);

  const nodes = unwrappedNestedGroups.map(node => {
    const { groups } = node;
    const groupsWithJobs = groups.map(group => {
      const jobs = unwrapJobWithNeeds(group.jobs.nodes);
      return { ...group, jobs };
    });

    return { ...node, groups: groupsWithJobs };
  });

  return nodes;
};

export { unwrapGroups, unwrapNodesWithName, unwrapJobWithNeeds, unwrapStagesWithNeeds };