@@ -40,6 +40,8 @@ export default class PipelineWorkflowGraphComponent extends Component {
4040
4141 showPRJobs ;
4242
43+ lastScrolledSelectedJobKey = null ;
44+
4345 constructor ( ) {
4446 super ( ...arguments ) ;
4547 this . event = this . args . event ;
@@ -61,6 +63,18 @@ export default class PipelineWorkflowGraphComponent extends Component {
6163 ) ;
6264 }
6365
66+ get selectedJobId ( ) {
67+ return this . args . selectedJobId ? `${ this . args . selectedJobId } ` : '' ;
68+ }
69+
70+ get selectedJobKey ( ) {
71+ if ( ! this . event ?. id || ! this . selectedJobId ) {
72+ return null ;
73+ }
74+
75+ return `${ this . event . id } :${ this . selectedJobId } ` ;
76+ }
77+
6478 getDecoratedGraph (
6579 workflowGraph ,
6680 builds ,
@@ -91,6 +105,43 @@ export default class PipelineWorkflowGraphComponent extends Component {
91105 } ) ;
92106 }
93107
108+ applySelectedJobLabel ( ) {
109+ if ( ! this . graphSvg ) {
110+ return ;
111+ }
112+
113+ let jobFound = false ;
114+
115+ this . graphSvg . selectAll ( '.graph-label' ) . classed ( 'selected-job' , node => {
116+ const isSelected =
117+ ! ! this . selectedJobId && `${ node ?. id } ` === this . selectedJobId ;
118+
119+ if ( isSelected ) {
120+ jobFound = true ;
121+ }
122+
123+ return isSelected ;
124+ } ) ;
125+
126+ if ( ! jobFound ) {
127+ this . lastScrolledSelectedJobKey = null ;
128+
129+ return ;
130+ }
131+
132+ if (
133+ this . selectedJobKey &&
134+ this . lastScrolledSelectedJobKey !== this . selectedJobKey
135+ ) {
136+ const selectedLabel = this . graphSvg
137+ . select ( '.graph-label.selected-job' )
138+ . node ( ) ;
139+
140+ selectedLabel ?. scrollIntoView ( { block : 'center' , inline : 'center' } ) ;
141+ this . lastScrolledSelectedJobKey = this . selectedJobKey ;
142+ }
143+ }
144+
94145 @action
95146 draw ( element ) {
96147 const isSkippedEvent = isSkipped ( this . event , this . builds ) ;
@@ -188,6 +239,8 @@ export default class PipelineWorkflowGraphComponent extends Component {
188239 verticalDisplacements ,
189240 horizontalDisplacements
190241 ) ;
242+
243+ this . applySelectedJobLabel ( ) ;
191244 }
192245
193246 @action
@@ -243,5 +296,6 @@ export default class PipelineWorkflowGraphComponent extends Component {
243296 nodeWidth
244297 ) ;
245298 updateStageStatuses ( this . graphSvg , this . decoratedGraph ) ;
299+ this . applySelectedJobLabel ( ) ;
246300 }
247301}
0 commit comments