Skip to content

Commit e54c74c

Browse files
committed
Move URL to api
1 parent 8e0d05a commit e54c74c

File tree

6 files changed

+25
-35
lines changed

6 files changed

+25
-35
lines changed

src/main/frontend/pipeline-graph-view/pipeline-graph/main/PipelineGraph.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,7 @@ export class PipelineGraph extends React.Component {
164164
for (const column of nodeColumns) {
165165
for (const row of column.rows) {
166166
for (const node of row) {
167-
const currentPath = this.props.path;
168-
let nodeUrl = "";
169-
170-
if (currentPath) {
171-
const runId = currentPath.split("=")[1];
172-
if (currentPath.startsWith("multi-pipeline-graph/")) {
173-
nodeUrl = `${runId}/pipeline-console?selected-node=${node.id}`
174-
} else {
175-
nodeUrl = `../${runId}/pipeline-console?selected-node=${node.id}`
176-
}
177-
178-
nodes.push({...node, url: nodeUrl});
179-
continue;
180-
}
181-
182-
const newPath = this.getTreePath();
183-
if (newPath.startsWith("pipeline-graph/tree")) {
184-
nodeUrl = `pipeline-console?selected-node=${node.id}`
185-
} else {
186-
nodeUrl = `../pipeline-console?selected-node=${node.id}`
187-
}
188-
189-
nodes.push({...node, url: nodeUrl});
167+
nodes.push(node);
190168
}
191169
}
192170
}

src/main/frontend/pipeline-graph-view/pipeline-graph/main/PipelineGraphModel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface StageInfo {
6363
startTimeMillis: string;
6464
totalDurationMillis: string;
6565
agent: string;
66+
url: string;
6667
}
6768

6869
interface BaseNodeInfo {
@@ -83,7 +84,6 @@ export interface StageNodeInfo extends BaseNodeInfo {
8384
// -- Unique
8485
stage: StageInfo;
8586
seqContainerName?: string; // Used within a parallel branch to denote the name of the container of the parallel sequential stages
86-
url?: string;
8787
}
8888

8989
export interface PlaceholderNodeInfo extends BaseNodeInfo {

src/main/frontend/pipeline-graph-view/pipeline-graph/main/support/nodes.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
LayoutInfo,
77
NodeColumn,
88
NodeInfo,
9-
StageInfo,
9+
StageInfo, StageNodeInfo
1010
} from "../PipelineGraphModel";
1111

1212
type SVGChildren = Array<any>; // Fixme: Maybe refine this? Not sure what should go here, we have working code I can't make typecheck
@@ -36,7 +36,7 @@ export function Node({ node }: NodeProps) {
3636
return React.createElement("div", groupProps, ...groupChildren);
3737
}
3838

39-
const { title, state } = node.stage ?? {};
39+
const { title, state, url } = node.stage ?? {};
4040
const resultClean = decodeResultValue(state);
4141

4242
groupChildren.push(getSymbolForResult(resultClean));
@@ -50,7 +50,7 @@ export function Node({ node }: NodeProps) {
5050
// Most of the nodes are in shared code, so they're rendered at 0,0. We transform with a <g> to position them
5151
const groupProps = {
5252
key,
53-
href: clickable ? node.url : null,
53+
href: clickable ? document.head.dataset.rooturl + url : null,
5454
style: {
5555
position: "absolute",
5656
top: node.y,

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApi.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ private List<PipelineStageInternal> getPipelineNodes(PipelineGraphBuilderApi bui
7676

7777
private Function<String, PipelineStage> mapper(
7878
Map<String, PipelineStageInternal> stageMap, Map<String, List<String>> stageToChildrenMap) {
79-
79+
String runUrl = run.getUrl();
8080
return id -> {
8181
List<String> orDefault = stageToChildrenMap.getOrDefault(id, emptyList());
8282
List<PipelineStage> children =
8383
orDefault.stream().map(mapper(stageMap, stageToChildrenMap)).collect(Collectors.toList());
84-
return stageMap.get(id).toPipelineStage(children);
84+
return stageMap.get(id).toPipelineStage(children, runUrl);
8585
};
8686
}
8787

@@ -117,14 +117,15 @@ private PipelineGraph createTree(PipelineGraphBuilderApi builder) {
117117
stageToChildrenMap.put(stage.getParents().get(0), parentChildren);
118118
}
119119
});
120+
String runUrl = run.getUrl();
120121
List<PipelineStage> stageResults = stageMap.values().stream()
121122
.map(pipelineStageInternal -> {
122123
List<PipelineStage> children =
123124
stageToChildrenMap.getOrDefault(pipelineStageInternal.getId(), emptyList()).stream()
124125
.map(mapper(stageMap, stageToChildrenMap))
125126
.collect(Collectors.toList());
126127

127-
return pipelineStageInternal.toPipelineStage(children);
128+
return pipelineStageInternal.toPipelineStage(children, runUrl);
128129
})
129130
.filter(stage -> !childNodes.contains(stage.getId()))
130131
.collect(Collectors.toList());
@@ -205,14 +206,15 @@ private PipelineGraph createShallowTree(PipelineGraphBuilderApi builder) {
205206
}
206207
});
207208

209+
String runUrl = run.getUrl();
208210
List<PipelineStage> stageResults = stageMap.values().stream()
209211
.map(pipelineStageInternal -> {
210212
List<PipelineStage> children =
211213
stageToChildrenMap.getOrDefault(pipelineStageInternal.getId(), emptyList()).stream()
212214
.map(mapper(stageMap, stageToChildrenMap))
213215
.collect(Collectors.toList());
214216

215-
return pipelineStageInternal.toPipelineStage(children);
217+
return pipelineStageInternal.toPipelineStage(children, runUrl);
216218
})
217219
.filter(stage -> topLevelStageIds.contains(stage.getId()))
218220
.collect(Collectors.toList());

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class PipelineStage extends AbstractPipelineNode {
1111
private boolean sequential;
1212
private boolean synthetic;
1313
private String agent;
14+
private String url;
1415

1516
public PipelineStage(
1617
String id,
@@ -25,14 +26,16 @@ public PipelineStage(
2526
boolean sequential,
2627
boolean synthetic,
2728
TimingInfo timingInfo,
28-
String agent) {
29+
String agent,
30+
String runUrl) {
2931
super(id, name, state, completePercent, type, title, timingInfo);
3032
this.children = children;
3133
this.seqContainerName = seqContainerName;
3234
this.nextSibling = nextSibling;
3335
this.sequential = sequential;
3436
this.synthetic = synthetic;
3537
this.agent = agent;
38+
this.url = "/" + runUrl + "pipeline-console?selected-node=" + id;
3639
}
3740

3841
public PipelineStage getNextSibling() {
@@ -60,4 +63,8 @@ public boolean isSynthetic() {
6063
public String getAgent() {
6164
return agent;
6265
}
66+
67+
public String getUrl() {
68+
return url;
69+
}
6370
}

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Collections;
44
import java.util.List;
55
import java.util.Locale;
6+
7+
import hudson.model.Run;
68
import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo;
79

810
public class PipelineStageInternal {
@@ -132,7 +134,7 @@ public void setAgent(String aAgent) {
132134
this.agent = aAgent;
133135
}
134136

135-
public PipelineStage toPipelineStage(List<PipelineStage> children) {
137+
public PipelineStage toPipelineStage(List<PipelineStage> children, String runUrl) {
136138
return new PipelineStage(
137139
id,
138140
name,
@@ -142,10 +144,11 @@ public PipelineStage toPipelineStage(List<PipelineStage> children) {
142144
type,
143145
title,
144146
seqContainerName,
145-
nextSibling != null ? nextSibling.toPipelineStage(Collections.emptyList()) : null,
147+
nextSibling != null ? nextSibling.toPipelineStage(Collections.emptyList(), runUrl) : null,
146148
sequential,
147149
synthetic,
148150
timingInfo,
149-
agent);
151+
agent,
152+
runUrl);
150153
}
151154
}

0 commit comments

Comments
 (0)