Skip to content

Commit f1ae3d2

Browse files
authored
remove duplicate small labels (jenkinsci#831)
1 parent 999948f commit f1ae3d2

File tree

2 files changed

+105
-38
lines changed

2 files changed

+105
-38
lines changed

src/main/frontend/pipeline-graph-view/pipeline-graph/main/PipelineGraphLayout.spec.ts

Lines changed: 104 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1-
import { describe } from "vitest";
1+
import { describe, expect } from "vitest";
22

3-
import { createNodeColumns } from "./PipelineGraphLayout.ts";
4-
import { Result, StageInfo, StageType } from "./PipelineGraphModel.tsx";
3+
import { DEFAULT_LOCALE } from "../../../common/i18n/index.ts";
4+
import { defaultMessages } from "../../../common/i18n/messages.ts";
5+
import { createNodeColumns, layoutGraph } from "./PipelineGraphLayout.ts";
6+
import {
7+
LayoutInfo,
8+
Result,
9+
StageInfo,
10+
StageType,
11+
} from "./PipelineGraphModel.tsx";
512

613
describe("PipelineGraphLayout", () => {
7-
describe("createNodeColumns", () => {
8-
const baseStage: StageInfo = {
9-
name: "",
10-
title: "",
11-
state: Result.success,
12-
completePercent: 50,
13-
id: 0,
14-
type: "STAGE",
15-
children: [],
16-
pauseDurationMillis: 0,
17-
startTimeMillis: 0,
18-
totalDurationMillis: 0,
19-
agent: "built-in",
20-
url: "?selected-node=0",
21-
};
14+
const baseStage: StageInfo = {
15+
name: "",
16+
title: "",
17+
state: Result.success,
18+
completePercent: 50,
19+
id: 0,
20+
type: "STAGE",
21+
children: [],
22+
pauseDurationMillis: 0,
23+
startTimeMillis: 0,
24+
totalDurationMillis: 0,
25+
agent: "built-in",
26+
url: "?selected-node=0",
27+
};
2228

23-
const makeStage = (
24-
id: number,
25-
name: string,
26-
children: Array<StageInfo> = [],
27-
): StageInfo => {
28-
return { ...baseStage, id, name, children };
29-
};
29+
const makeStage = (
30+
id: number,
31+
name: string,
32+
children: Array<StageInfo> = [],
33+
): StageInfo => {
34+
return { ...baseStage, id, name, children };
35+
};
3036

31-
const makeParallel = (
32-
id: number,
33-
name: string,
34-
children: Array<StageInfo> = [],
35-
): StageInfo => {
36-
return {
37-
...baseStage,
38-
id,
39-
name,
40-
children,
41-
type: "PARALLEL" as StageType,
42-
};
37+
const makeParallel = (
38+
id: number,
39+
name: string,
40+
children: Array<StageInfo> = [],
41+
): StageInfo => {
42+
return {
43+
...baseStage,
44+
id,
45+
name,
46+
children,
47+
type: "PARALLEL" as StageType,
4348
};
49+
};
4450

51+
describe("createNodeColumns", () => {
4552
const makeNode = (
4653
id: number,
4754
name: string,
@@ -346,4 +353,64 @@ describe("PipelineGraphLayout", () => {
346353
]);
347354
});
348355
});
356+
357+
describe("layoutGraph", () => {
358+
const layout: LayoutInfo = {
359+
nodeSpacingH: 140,
360+
parallelSpacingH: 140,
361+
nodeSpacingV: 70,
362+
nodeRadius: 12,
363+
terminalRadius: 10,
364+
curveRadius: 15,
365+
connectorStrokeWidth: 2,
366+
labelOffsetV: 22,
367+
smallLabelOffsetV: 15,
368+
ypStart: 55,
369+
};
370+
371+
const makeSmallLabel = (stageName: string) => {
372+
return {
373+
text: stageName,
374+
};
375+
};
376+
377+
it("should not generate small labels for top stage columns with no children", () => {
378+
const graph = layoutGraph(
379+
[
380+
makeStage(6, "Non-Parallel Stage"),
381+
makeStage(11, "Parallel Stage", [
382+
makeParallel(15, "Branch A - P1"),
383+
makeParallel(16, "Branch B - P1"),
384+
makeParallel(17, "Branch C - P1", [
385+
makeStage(25, "Nested 1 - P1"),
386+
makeStage(38, "Nested 2 - P1"),
387+
]),
388+
]),
389+
makeStage(49, "Skipped stage"),
390+
makeStage(53, "Parallel Stage 2", [
391+
makeParallel(57, "Branch A - P2"),
392+
makeParallel(58, "Branch B - P2"),
393+
makeParallel(59, "Branch C - P2", [
394+
makeStage(67, "Nested 1 - P2"),
395+
makeStage(80, "Nested 2 - P2"),
396+
]),
397+
]),
398+
],
399+
layout,
400+
false,
401+
defaultMessages(DEFAULT_LOCALE),
402+
);
403+
404+
expect(graph.smallLabels).toMatchObject([
405+
makeSmallLabel("Branch A - P1"),
406+
makeSmallLabel("Branch B - P1"),
407+
makeSmallLabel("Nested 1 - P1"),
408+
makeSmallLabel("Nested 2 - P1"),
409+
makeSmallLabel("Branch A - P2"),
410+
makeSmallLabel("Branch B - P2"),
411+
makeSmallLabel("Nested 1 - P2"),
412+
makeSmallLabel("Nested 2 - P2"),
413+
]);
414+
});
415+
});
349416
});

src/main/frontend/pipeline-graph-view/pipeline-graph/main/PipelineGraphLayout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function createSmallLabels(
384384
for (const row of column.rows) {
385385
for (const node of row) {
386386
// We add small labels to parallel nodes only so skip others
387-
if (node.isPlaceholder || node.stage === column.topStage) {
387+
if (node.isPlaceholder || node.stage.id === column.topStage?.id) {
388388
continue;
389389
}
390390
const label: NodeLabelInfo = {

0 commit comments

Comments
 (0)