Skip to content

Commit 1dc41d9

Browse files
authored
Expand tree view to a reasonable step by default (#177)
1 parent 1ebe312 commit 1dc41d9

File tree

1 file changed

+64
-17
lines changed

1 file changed

+64
-17
lines changed

src/main/frontend/pipeline-console-view/pipeline-console/main/PipelineConsole.tsx

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import React from "react";
22

33
import { SplitPane } from "react-collapse-pane";
44
import { makeReactChildren, tokenizeANSIString } from "./Ansi";
5-
import { StageInfo } from "../../../pipeline-graph-view/pipeline-graph/main/";
5+
import {
6+
StageInfo,
7+
Result,
8+
} from "../../../pipeline-graph-view/pipeline-graph/main/";
69
import { DataTreeView, StepInfo } from "./DataTreeView";
710

811
import Typography from "@mui/material/Typography";
@@ -160,12 +163,8 @@ export class PipelineConsole extends React.Component<
160163

161164
// State update methods
162165
async updateState() {
163-
let stagesPromse = this.setStages();
164-
let stepsPromise = this.setSteps();
165-
// Try waiting for
166-
await stagesPromse;
167-
await stepsPromise;
168-
this.handleUrlParams();
166+
this.setStages();
167+
this.setSteps();
169168
}
170169

171170
setStages() {
@@ -174,9 +173,14 @@ export class PipelineConsole extends React.Component<
174173
.then((res) => res.json())
175174
.then((result) => {
176175
console.debug("Updating stages");
177-
this.setState({
178-
stages: result.data.stages,
179-
});
176+
this.setState(
177+
{
178+
stages: result.data.stages,
179+
},
180+
() => {
181+
this.selectNode();
182+
}
183+
);
180184
});
181185
// returns Promise
182186
}
@@ -186,10 +190,14 @@ export class PipelineConsole extends React.Component<
186190
.then((step_res) => step_res.json())
187191
.then((step_result) => {
188192
console.debug("Updating steps");
189-
console.debug(JSON.stringify(step_result.data));
190-
this.setState({
191-
steps: step_result.data.steps,
192-
});
193+
this.setState(
194+
{
195+
steps: step_result.data.steps,
196+
},
197+
() => {
198+
this.selectNode();
199+
}
200+
);
193201
})
194202
.catch(console.log);
195203
}
@@ -211,8 +219,8 @@ export class PipelineConsole extends React.Component<
211219
}
212220
}
213221

214-
handleUrlParams() {
215-
console.debug(`In handleUrlParams.`);
222+
selectNode() {
223+
console.debug(`In selectNode.`);
216224
let params = new URLSearchParams(document.location.search.substring(1));
217225
let selected = params.get("selected-node") || "";
218226
if (selected) {
@@ -235,7 +243,22 @@ export class PipelineConsole extends React.Component<
235243
expanded: expanded,
236244
});
237245
} else {
238-
console.debug("No node selected.");
246+
let step = this.getDefaultSelectedStep(this.state.steps);
247+
if (step) {
248+
console.debug(`Selecting step with id '${selected}`);
249+
this.setConsoleText(String(step.id));
250+
selected = String(step.id);
251+
let expanded = this.getStageNodeHierarchy(
252+
step.stageId,
253+
this.state.stages
254+
);
255+
this.setState({
256+
selected: selected,
257+
expanded: expanded,
258+
});
259+
} else {
260+
console.debug("No node selected.");
261+
}
239262
}
240263
}
241264

@@ -300,6 +323,30 @@ export class PipelineConsole extends React.Component<
300323
return [];
301324
}
302325

326+
// Determines the default selected step in the tree view based
327+
getDefaultSelectedStep(steps: StepInfo[]) {
328+
let selectedStep = steps.find(step => step !== undefined)
329+
for (let i = 0; i < steps.length; i++) {
330+
let step = steps[i];
331+
let stepResult = step.state.toLowerCase() as Result;
332+
switch (stepResult) {
333+
case Result.running:
334+
case Result.queued:
335+
case Result.paused:
336+
return step;
337+
case Result.unstable:
338+
case Result.failure:
339+
case Result.aborted:
340+
let selectedStepResult = selectedStep?.state.toLowerCase() as Result;
341+
if (!selectedStepResult || stepResult > selectedStepResult) {
342+
selectedStep = step;
343+
}
344+
break;
345+
}
346+
}
347+
return selectedStep;
348+
}
349+
303350
renderStageDetails() {
304351
let focusedStage = null;
305352
for (let i = 0; i < this.state.stages.length; i++) {

0 commit comments

Comments
 (0)