Skip to content

Commit 38fff35

Browse files
committed
Rename stuff
1 parent d370cfa commit 38fff35

File tree

8 files changed

+58
-49
lines changed

8 files changed

+58
-49
lines changed
File renamed without changes.
File renamed without changes.

src/main/frontend/common/tree-api.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
22
import { getRunStatusFromPath } from "./RestClient";
33
import { StageInfo } from "../pipeline-graph-view/pipeline-graph/main";
44
import startPollingPipelineStatus from "../pipeline-graph-view/pipeline-graph/main/support/startPollingPipelineStatus";
5-
import PreviousRunThing from "../pipeline-graph-view/pipeline-graph/main/support/PreviousRunThing";
5+
import { mergeStageInfos } from "./utils/stage-merge";
66

77
/**
88
* Polls a run, stopping once the run has completed
@@ -23,7 +23,7 @@ export default function useRunPoller({
2323
complete: boolean;
2424
}) => {
2525
setRun({
26-
stages: mergeStageInfos(markSkeleton(r!.stages), data.stages),
26+
stages: mergeStageInfos(r!.stages, data.stages),
2727
});
2828
};
2929

@@ -78,45 +78,3 @@ interface RunPollerProps {
7878
currentRunPath: string;
7979
previousRunPath?: string;
8080
}
81-
82-
export const markSkeleton = (stages: StageInfo[]): StageInfo[] =>
83-
stages.map((s) => ({
84-
...s,
85-
skeleton: true,
86-
completePercent: 0,
87-
children: markSkeleton(s.children ?? []),
88-
}));
89-
90-
export const mergeStageInfos = (
91-
skeletons: StageInfo[],
92-
incoming: StageInfo[],
93-
): StageInfo[] => {
94-
const previous: PreviousRunThing = new PreviousRunThing(skeletons);
95-
const merged = incoming.map((incomingItem) => {
96-
const match = skeletons.find((s) => s.name === incomingItem.name);
97-
98-
return {
99-
...(match ?? {}),
100-
...incomingItem,
101-
skeleton: false,
102-
completePercent: previous.estimateCompletion(incomingItem),
103-
children: mergeStageInfos(
104-
match?.children ?? [],
105-
incomingItem.children ?? [],
106-
),
107-
};
108-
});
109-
110-
const unmatchedSkeletons = skeletons.filter(
111-
(s) => !incoming.some((i) => i.name === s.name),
112-
);
113-
114-
return [...merged, ...unmatchedSkeletons];
115-
};
116-
117-
export const stripSkeleton = (stage: StageInfo): StageInfo => ({
118-
...stage,
119-
skeleton: false,
120-
completePercent: 0,
121-
children: stage.children?.map(stripSkeleton) ?? [],
122-
});

src/main/frontend/pipeline-graph-view/pipeline-graph/main/support/PreviousRunThing.ts renamed to src/main/frontend/common/utils/run-estimator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { Result, StageInfo } from "../PipelineGraphModel";
1+
import {
2+
Result,
3+
StageInfo,
4+
} from "../../pipeline-graph-view/pipeline-graph/main";
25

3-
export default class PreviousRunThing {
6+
export default class RunEstimator {
47
private stagesLookup: Map<String, StageInfo>;
58

69
constructor(stages: StageInfo[]) {

src/main/frontend/pipeline-graph-view/pipeline-graph/main/merger.spec.ts renamed to src/main/frontend/common/utils/stage-merge.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { Result, StageInfo } from "./PipelineGraphModel";
2-
import { mergeStageInfos } from "../../../common/tree-api";
1+
import {
2+
Result,
3+
StageInfo,
4+
} from "../../pipeline-graph-view/pipeline-graph/main";
5+
import { mergeStageInfos } from "./stage-merge";
36

47
describe("mergeStageInfos", () => {
58
it("merges matching items by name", () => {
@@ -57,7 +60,7 @@ describe("mergeStageInfos", () => {
5760
expect(result[0].name).toBe("Build");
5861
expect(result[0].state).toBe("running");
5962
expect(result[0].skeleton).toBe(false); // Comes from incoming
60-
expect(result[1].skeleton).toBe(false); // Comes from incoming
63+
expect(result[1].skeleton).toBe(true);
6164
});
6265

6366
it("recursively merges children", () => {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { StageInfo } from "../../pipeline-graph-view/pipeline-graph/main";
2+
import RunEstimator from "./run-estimator";
3+
4+
export const mergeStageInfos = (
5+
skeletons: StageInfo[],
6+
incoming: StageInfo[],
7+
): StageInfo[] => {
8+
skeletons = markSkeleton(skeletons);
9+
const previous = new RunEstimator(skeletons);
10+
const merged = incoming.map((incomingItem) => {
11+
const match = skeletons.find((s) => s.name === incomingItem.name);
12+
13+
return {
14+
...(match ?? {}),
15+
...incomingItem,
16+
skeleton: false,
17+
completePercent: previous.estimateCompletion(incomingItem),
18+
children: mergeStageInfos(
19+
match?.children ?? [],
20+
incomingItem.children ?? [],
21+
),
22+
};
23+
});
24+
25+
const unmatchedSkeletons = skeletons.filter(
26+
(s) => !incoming.some((i) => i.name === s.name),
27+
);
28+
29+
return [...merged, ...unmatchedSkeletons];
30+
};
31+
32+
const markSkeleton = (stages: StageInfo[]): StageInfo[] =>
33+
stages.map((s) => ({
34+
...s,
35+
skeleton: true,
36+
completePercent: 0,
37+
children: markSkeleton(s.children ?? []),
38+
}));
39+
40+
const stripSkeleton = (stage: StageInfo): StageInfo => ({
41+
...stage,
42+
skeleton: false,
43+
completePercent: 0,
44+
children: stage.children?.map(stripSkeleton) ?? [],
45+
});
File renamed without changes.

0 commit comments

Comments
 (0)