Skip to content

Commit 454d726

Browse files
authored
fix(ui): do not rerender sidebar when non changes + update children instead of destroy/recreate (#5061)
1 parent 53fb4a2 commit 454d726

29 files changed

+827
-463
lines changed

engine/api/workflow_event.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
2222
}
2323
for _, wnr := range report.Nodes() {
2424
wr, errWR := workflow.LoadRunByID(db, wnr.WorkflowRunID, workflow.LoadRunOptions{
25-
WithLightTests: true,
25+
DisableDetailledNodeRun: true,
2626
})
2727
if errWR != nil {
28-
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow run %d: %s", wnr.WorkflowRunID, errWR)
28+
log.Warning(ctx, "workflowSendEvent> Cannot load workflow run %d: %s", wnr.WorkflowRunID, errWR)
2929
continue
3030
}
3131

@@ -36,11 +36,19 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
3636
var errN error
3737
previousNodeRun, errN = workflow.PreviousNodeRun(db, wnr, wnr.WorkflowNodeName, wr.WorkflowID)
3838
if errN != nil {
39-
log.Warning(ctx, "WorkflowSendEvent> Cannot load previous node run: %s", errN)
39+
log.Warning(ctx, "workflowSendEvent> Cannot load previous node run: %v", errN)
4040
}
4141
}
4242

43-
event.PublishWorkflowNodeRun(ctx, db, store, wnr, wr.Workflow, &previousNodeRun)
43+
nr, err := workflow.LoadNodeRunByID(db, wnr.ID, workflow.LoadRunOptions{
44+
DisableDetailledNodeRun: true,
45+
})
46+
if err != nil {
47+
log.Warning(ctx, "workflowSendEvent > Cannot load workflow node run: %v", err)
48+
continue
49+
}
50+
51+
event.PublishWorkflowNodeRun(ctx, db, store, *nr, wr.Workflow, &previousNodeRun)
4452
e := &workflow.VCSEventMessenger{}
4553
if err := e.SendVCSEvent(ctx, db, store, proj, *wr, wnr); err != nil {
4654
log.Warning(ctx, "WorkflowSendEvent> Cannot send vcs notification")
@@ -50,14 +58,14 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
5058
for _, jobrun := range report.Jobs() {
5159
noderun, err := workflow.LoadNodeRunByID(db, jobrun.WorkflowNodeRunID, workflow.LoadRunOptions{})
5260
if err != nil {
53-
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow node run %d: %s", jobrun.WorkflowNodeRunID, err)
61+
log.Warning(ctx, "workflowSendEvent> Cannot load workflow node run %d: %s", jobrun.WorkflowNodeRunID, err)
5462
continue
5563
}
5664
wr, errWR := workflow.LoadRunByID(db, noderun.WorkflowRunID, workflow.LoadRunOptions{
5765
WithLightTests: true,
5866
})
5967
if errWR != nil {
60-
log.Warning(ctx, "WorkflowSendEvent> Cannot load workflow run %d: %s", noderun.WorkflowRunID, errWR)
68+
log.Warning(ctx, "workflowSendEvent> Cannot load workflow run %d: %s", noderun.WorkflowRunID, errWR)
6169
continue
6270
}
6371
event.PublishWorkflowNodeJobRun(ctx, db, proj.Key, *wr, jobrun)

engine/api/workflow_queue.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,12 @@ func postJobResult(ctx context.Context, dbFunc func(context.Context) *gorp.DbMap
492492

493493
for i := range report.WorkflowRuns() {
494494
run := &report.WorkflowRuns()[i]
495-
report, err := updateParentWorkflowRun(ctx, newDBFunc, store, run)
495+
reportParent, err := updateParentWorkflowRun(ctx, newDBFunc, store, run)
496496
if err != nil {
497497
return nil, sdk.WithStack(err)
498498
}
499499

500-
go WorkflowSendEvent(context.Background(), tx, store, *proj, report)
500+
go WorkflowSendEvent(context.Background(), tx, store, *proj, reportParent)
501501

502502
if sdk.StatusIsTerminated(run.Status) {
503503
//Start a goroutine to update commit statuses in repositories manager
@@ -675,9 +675,7 @@ func (api *API) postWorkflowJobStepStatusHandler() service.Handler {
675675
}
676676

677677
if nodeRun.ID == 0 {
678-
nodeRunP, err := workflow.LoadNodeRunByID(api.mustDB(), nodeJobRun.WorkflowNodeRunID, workflow.LoadRunOptions{
679-
DisableDetailledNodeRun: true,
680-
})
678+
nodeRunP, err := workflow.LoadNodeRunByID(api.mustDB(), nodeJobRun.WorkflowNodeRunID, workflow.LoadRunOptions{DisableDetailledNodeRun: true})
681679
if err != nil {
682680
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load node run for event: %v", err)
683681
return nil

sdk/event.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import (
55
"time"
66
)
77

8-
// These are constant for events about workflow runs
9-
const (
10-
EventSubsWorkflowRuns = "event:workflow:runs"
11-
EventSubWorkflowRun = "event:workflow:run"
12-
)
13-
148
// Event represents a event from API
159
// Event is "create", "update", "delete"
1610
// Status is "Waiting" "Building" "Success" "Fail" "Unknown", optional

ui/src/app/app.service.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22
import { ActivatedRoute, Router } from '@angular/router';
33
import { TranslateService } from '@ngx-translate/core';
44
import { Store } from '@ngxs/store';
5-
import { WorkflowNodeRun } from 'app/model/workflow.run.model';
5+
import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
66
import { AsCodeEvent } from 'app/store/ascode.action';
77
import { UpdateMaintenance } from 'app/store/cds.action';
88
import cloneDeep from 'lodash-es/cloneDeep';
@@ -333,26 +333,34 @@ export class AppService {
333333
this._workflowRunService
334334
.getWorkflowRun(event.project_key, event.workflow_name, event.workflow_run_num)
335335
.pipe(first())
336-
.subscribe(wr => this._store.dispatch(new UpdateWorkflowRunList({ workflowRun: wr })));
336+
.subscribe(wrkRun => this._store.dispatch(new UpdateWorkflowRunList({ workflowRun: wrkRun })));
337337
}
338338
break;
339339
case EventType.RUN_WORKFLOW_NODE:
340-
if (this.routeParams['number'] === event.workflow_run_num.toString()) {
340+
// Refresh node run if user is listening on it
341+
const wnr = this._store.selectSnapshot<WorkflowNodeRun>((state) => {
342+
return state.workflow.workflowNodeRun;
343+
});
344+
let wnrEvent = <WorkflowNodeRun>event.payload;
345+
if (wnr && wnr.id === wnrEvent.id) {
346+
this._store.dispatch(
347+
new GetWorkflowNodeRun({
348+
projectKey: event.project_key,
349+
workflowName: event.workflow_name,
350+
num: event.workflow_run_num,
351+
nodeRunID: wnr.id
352+
}));
353+
}
354+
355+
// Refresh workflow run if user is listening on it
356+
const wr = this._store.selectSnapshot<WorkflowRun>((state) => state.workflow.workflowRun);
357+
if (wr && wr.num === event.workflow_run_num) {
341358
this._store.dispatch(new GetWorkflowRun(
342359
{
343-
projectKey: event.project_key, workflowName: event.workflow_name,
360+
projectKey: event.project_key,
361+
workflowName: event.workflow_name,
344362
num: event.workflow_run_num
345363
}));
346-
let wnr = <WorkflowNodeRun>event.payload;
347-
if (this.routeParams['nodeId'] && this.routeParams['nodeId'].toString() === wnr.id) {
348-
this._store.dispatch(
349-
new GetWorkflowNodeRun({
350-
projectKey: event.project_key,
351-
workflowName: event.workflow_name,
352-
num: event.workflow_run_num,
353-
nodeRunID: this.routeParams['nodeId']
354-
}));
355-
}
356364
}
357365
break;
358366
}

ui/src/app/model/workflow.model.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,16 @@ export class Workflow {
320320
for (let j = 0; j < n.triggers.length; j++) {
321321
let t = n.triggers[j];
322322
if (t.child_node.id === currentNodeID) {
323-
if (workflowRun.version < 2) {
324-
switch (n.type) {
325-
case WNodeType.JOIN:
326-
ancestors.push(...n.parents.map(p => p.parent_id));
327-
break;
328-
case WNodeType.FORK:
329-
ancestors.push(...Workflow.getParentNodeIds(workflowRun, n.id));
330-
break;
331-
default:
332-
ancestors.push(n.id);
323+
switch (n.type) {
324+
case WNodeType.JOIN:
325+
ancestors.push(...n.parents.map(p => p.parent_id));
326+
break;
327+
case WNodeType.FORK:
328+
ancestors.push(...Workflow.getParentNodeIds(workflowRun, n.id));
329+
break;
330+
default:
331+
ancestors.push(n.id);
333332
}
334-
} else {
335-
ancestors.push(n.id);
336-
}
337333
break loop;
338334
}
339335
}

ui/src/app/model/workflow.run.model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class WorkflowRun {
4040
tags: Array<WorkflowRunTags>;
4141
commits: Array<Commit>;
4242
infos: Array<SpawnInfo>;
43-
version: number;
4443

4544
// Useful for UI
4645
duration: string;

ui/src/app/shared/workflow/menu/edit-node/menu.edit.node.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Project } from 'app/model/project.model';
1414
import { WNode, Workflow } from 'app/model/workflow.model';
1515
import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
1616
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
17-
import { WorkflowState, WorkflowStateModel } from 'app/store/workflow.state';
17+
import { WorkflowState } from 'app/store/workflow.state';
1818
import { Subscription } from 'rxjs';
1919

2020
@Component({
@@ -28,7 +28,6 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
2828

2929
// Project that contains the workflow
3030
@Input() project: Project;
31-
3231
@Input() node: WNode;
3332
_noderun: WorkflowNodeRun;
3433
@Input('noderun') set noderun(data: WorkflowNodeRun) {
@@ -57,9 +56,8 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
5756
) { }
5857

5958
ngOnInit(): void {
60-
this.storeSubscription = this._store.select(WorkflowState.getCurrent())
61-
.subscribe((s: WorkflowStateModel) => {
62-
this.workflow = s.workflow;
59+
this.storeSubscription = this._store.select(WorkflowState.getWorkflow()).subscribe((w: Workflow) => {
60+
this.workflow = w;
6361
this.runnable = this.getCanBeRun();
6462
this._cd.markForCheck();
6563
});

0 commit comments

Comments
 (0)