Skip to content

Commit a64cb2f

Browse files
authored
fix(ui): workflow node run state management (#5103)
1 parent 46f44ca commit a64cb2f

30 files changed

+893
-638
lines changed

engine/api/workflow/execute_node_job_run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) {
6161
case *sdk.WorkflowNodeJobRun:
6262
r.jobs = append(r.jobs, *x)
6363
case sdk.WorkflowNodeRun:
64-
r.addWorkflowNodeRun(ctx, x)
64+
r.addWorkflowNodeRun(x)
6565
case *sdk.WorkflowNodeRun:
66-
r.addWorkflowNodeRun(ctx, *x)
66+
r.addWorkflowNodeRun(*x)
6767
case sdk.WorkflowRun:
6868
r.workflows = append(r.workflows, x)
6969
case *sdk.WorkflowRun:
@@ -74,7 +74,7 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) {
7474
}
7575
}
7676

77-
func (r *ProcessorReport) addWorkflowNodeRun(ctx context.Context, nr sdk.WorkflowNodeRun) {
77+
func (r *ProcessorReport) addWorkflowNodeRun(nr sdk.WorkflowNodeRun) {
7878
for i := range r.nodes {
7979
if nr.ID == r.nodes[i].ID {
8080
r.nodes[i] = nr

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"angular2-prettyjson": "3.0.1",
5959
"angular2-toaster": "7.0.0",
6060
"animate.css": "3.7.2",
61-
"ansi_up": "3.0.0",
61+
"ansi_up": "4.0.4",
6262
"codemirror": "5.51.0",
6363
"core-js": "2.6.3",
6464
"d3": "5.7.0",

ui/src/app/app.component.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Title } from '@angular/platform-browser';
66
import { ActivatedRoute, NavigationEnd, NavigationStart, ResolveEnd, ResolveStart, Router } from '@angular/router';
77
import { TranslateService } from '@ngx-translate/core';
88
import { Store } from '@ngxs/store';
9+
import { WorkflowNodeRun } from 'app/model/workflow.run.model';
910
import { GetCDSStatus } from 'app/store/cds.action';
1011
import { CDSState } from 'app/store/cds.state';
1112
import { Observable } from 'rxjs';
@@ -229,8 +230,21 @@ export class AppComponent implements OnInit {
229230
if (!e.type_event || e.type_event.indexOf(EventType.RUN_WORKFLOW_PREFIX) !== 0) {
230231
results.push(e);
231232
} else {
232-
let wr = results.find(re => re.project_key === e.project_key
233-
&& re.workflow_name === e.workflow_name && re.type_event === e.type_event);
233+
let wr = results.find(re => {
234+
if (re.project_key === e.project_key && re.workflow_name === e.workflow_name
235+
&& re.type_event === e.type_event) {
236+
switch (e.type_event) {
237+
case EventType.RUN_WORKFLOW_NODE:
238+
let wnrEvent = <WorkflowNodeRun>e.payload;
239+
let otherEvent = <WorkflowNodeRun>re.payload;
240+
return wnrEvent.id === otherEvent.id;
241+
case EventType.RUN_WORKFLOW_PREFIX:
242+
return e.workflow_run_num === re.workflow_run_num;
243+
default: return true
244+
}
245+
}
246+
return false;
247+
});
234248
if (!wr) {
235249
results.push(e);
236250
}

ui/src/app/shared/commit/commit.list.component.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
2+
import { Select } from '@ngxs/store';
23
import { Commit } from 'app/model/repositories.model';
4+
import { WorkflowNodeRun } from 'app/model/workflow.run.model';
5+
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
6+
import { WorkflowState } from 'app/store/workflow.state';
7+
import { Observable, Subscription } from 'rxjs';
38
import { Column, ColumnType } from '../table/data-table.component';
49

510
@Component({
@@ -8,11 +13,16 @@ import { Column, ColumnType } from '../table/data-table.component';
813
styleUrls: ['./commit.list.scss'],
914
changeDetection: ChangeDetectionStrategy.OnPush
1015
})
11-
export class CommitListComponent {
12-
@Input() commits: Array<Commit>;
16+
@AutoUnsubscribe()
17+
export class CommitListComponent implements OnInit {
18+
19+
@Select(WorkflowState.getSelectedNodeRun()) nodeRun$: Observable<WorkflowNodeRun>;
20+
nodeRunSubs: Subscription;
21+
22+
commits: Array<Commit>;
1323
columns: Column<Commit>[];
1424

15-
constructor() {
25+
constructor(private _cd: ChangeDetectorRef) {
1626
this.columns = [
1727
<Column<Commit>>{
1828
type: ColumnType.IMG_TEXT,
@@ -52,4 +62,17 @@ export class CommitListComponent {
5262
},
5363
];
5464
}
65+
66+
ngOnInit(): void {
67+
this.nodeRunSubs = this.nodeRun$.subscribe(nr => {
68+
if (!nr) {
69+
return;
70+
}
71+
if (this.commits && nr.commits && this.commits.length === nr.commits.length) {
72+
return;
73+
}
74+
this.commits = nr.commits;
75+
this._cd.markForCheck();
76+
});
77+
}
5578
}

ui/src/app/shared/diff/diff.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
4141
}
4242
];
4343

44-
let pipelinesLength = Math.max(before && before.pipelines ?
45-
before.pipelines.length : 0, after && after.pipelines ? after.pipelines.length : 0);
44+
let pipelinesLength = Math.max(before && before.pipelines ? before.pipelines.length : 0,
45+
after && after.pipelines ? after.pipelines.length : 0);
4646
for (let i = 0; i < pipelinesLength; i++) {
4747
diffItems.push(
4848
<Item>{
@@ -65,7 +65,8 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
6565
translateData: { number: applicationsLength > 1 ? i : '' },
6666
before: before && before.applications && before.applications[i] ?
6767
Base64.b64DecodeUnicode(before.applications[i].value) : null,
68-
after: after && after.applications && after.applications[i] ? Base64.b64DecodeUnicode(after.applications[i].value) : null,
68+
after: after && after.applications && after.applications[i] ?
69+
Base64.b64DecodeUnicode(after.applications[i].value) : null,
6970
type: 'text/x-yaml'
7071
})
7172
}
@@ -81,7 +82,8 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
8182
translateData: { number: environmentsLength > 1 ? i : '' },
8283
before: before && before.environments && before.environments[i] ?
8384
Base64.b64DecodeUnicode(before.environments[i].value) : null,
84-
after: after && after.environments && after.environments[i] ? Base64.b64DecodeUnicode(after.environments[i].value) : null,
85+
after: after && after.environments && after.environments[i] ?
86+
Base64.b64DecodeUnicode(after.environments[i].value) : null,
8587
type: 'text/x-yaml'
8688
})
8789
}

ui/src/app/shared/vulnerability/list/vulnerability.list.component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
22
import { TranslateService } from '@ngx-translate/core';
3+
import { Store } from '@ngxs/store';
34
import { Application, Vulnerability } from 'app/model/application.model';
45
import { Project } from 'app/model/project.model';
56
import { ApplicationService } from 'app/service/application/application.service';
67
import { ToastService } from 'app/shared/toast/ToastService';
8+
import { ApplicationsState, ApplicationStateModel } from 'app/store/applications.state';
9+
import { ProjectState } from 'app/store/project.state';
710
import cloneDeep from 'lodash-es/cloneDeep';
811
import { finalize } from 'rxjs/operators';
912

@@ -32,19 +35,21 @@ export class VulnerabilitiesListComponent {
3235
}
3336
};
3437
@Input() edit = false;
35-
@Input() project: Project;
36-
@Input() application: Application;
3738

39+
application: Application;
40+
project: Project;
3841
allVulnerabilities: Array<Vulnerability>;
3942
filteredVulnerabilities: Array<Vulnerability>;
4043

4144
constructor(
4245
private _applicationService: ApplicationService,
4346
private _translate: TranslateService,
4447
private _toast: ToastService,
45-
private _cd: ChangeDetectorRef
48+
private _cd: ChangeDetectorRef,
49+
private _store: Store
4650
) {
47-
51+
this.project = this._store.selectSnapshot(ProjectState.projectSnapshot);
52+
this.application = (<ApplicationStateModel>this._store.selectSnapshot(ApplicationsState)).application;
4853
}
4954

5055
updateVulns(): void {

ui/src/app/shared/vulnerability/vulnerabilities.component.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
2-
import { Application, Severity, Vulnerability } from 'app/model/application.model';
3-
import { Project } from 'app/model/project.model';
4-
import { WorkflowNodeRunVulnerabilityReport } from 'app/model/workflow.run.model';
2+
import { Store } from '@ngxs/store';
3+
import { Severity, Vulnerability } from 'app/model/application.model';
4+
import { ApplicationsState, ApplicationStateModel } from 'app/store/applications.state';
5+
import { WorkflowState, WorkflowStateModel } from 'app/store/workflow.state';
56

67
@Component({
78
selector: 'app-vulnerabilities',
@@ -11,7 +12,8 @@ import { WorkflowNodeRunVulnerabilityReport } from 'app/model/workflow.run.model
1112
})
1213
export class VulnerabilitiesComponent {
1314

14-
_vulnerabilities: Vulnerability[];
15+
@Input() edit = false;
16+
1517
orderedVulnerabilities: Vulnerability[];
1618
summary = {
1719
total: 0,
@@ -30,33 +32,24 @@ export class VulnerabilitiesComponent {
3032
unknown: 0,
3133
deltaUnknown: 0,
3234
};
35+
filter = '';
3336

34-
@Input('vulnerabilities')
35-
set vulnerabilities(data: Vulnerability[]) {
36-
this._vulnerabilities = data;
37-
this.initVulnerabilities(data);
38-
}
39-
get vulnerabilities() {
40-
return this._vulnerabilities;
41-
}
42-
43-
@Input('report')
44-
set report(data: WorkflowNodeRunVulnerabilityReport) {
45-
if (data) {
46-
this.vulnerabilities = data.report.vulnerabilities;
47-
if (data.report.previous_run_summary) {
48-
this.calculateDelta(data.report.previous_run_summary);
49-
} else if (data.report.default_branch_summary) {
50-
this.calculateDelta(data.report.default_branch_summary);
37+
constructor(private _store: Store) {
38+
let nr = (<WorkflowStateModel>this._store.selectSnapshot(WorkflowState)).workflowNodeRun;
39+
if (nr) {
40+
this.initVulnerabilities(nr.vulnerabilities_report.report.vulnerabilities);
41+
if (nr.vulnerabilities_report.report.previous_run_summary) {
42+
this.calculateDelta(nr.vulnerabilities_report.report.previous_run_summary);
43+
} else {
44+
this.calculateDelta(nr.vulnerabilities_report.report.default_branch_summary);
5145
}
46+
this.edit = false;
47+
} else {
48+
let app = (<ApplicationStateModel>this._store.selectSnapshot(ApplicationsState)).application;
49+
this.initVulnerabilities(app.vulnerabilities);
5250
}
53-
}
54-
55-
@Input() edit = false;
56-
@Input() project: Project;
57-
@Input() application: Application;
5851

59-
filter = '';
52+
}
6053

6154
updateFilter(v: Vulnerability): void {
6255
this.filter = v.component + ' ' + v.version;

ui/src/app/shared/vulnerability/vulnerabilities.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
</div>
6969

7070
<div class="list">
71-
<app-vulnerabilities-list [filter]="filter" [vulnerabilities]="orderedVulnerabilities" [edit]="edit"
72-
[project]="project" [application]="application"></app-vulnerabilities-list>
71+
<app-vulnerabilities-list [filter]="filter" [vulnerabilities]="orderedVulnerabilities" [edit]="edit"></app-vulnerabilities-list>
7372
</div>
7473

7574
</div>

ui/src/app/shared/workflow/sidebar/run-node/stage/job/job.summary.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[pipelineActionId]="job.pipeline_action_id"
1818
[stepName]="job.action.actions[stepOrder].name"
1919
[stepOptionnal]="job.action.actions[stepOrder].optional"
20-
[stepOrder]="stepIds"
20+
[stepOrder]="stepOrder"
2121
[workflowNodeRunId]="workflowRunNodeId"
2222
[stageId]="stageId"
2323
[jobId]="jobId">

ui/src/app/store/cds.state.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ export class CDSState {
4141
@Action(GetCDSStatus)
4242
getCDSStatus(ctx: StateContext<CDSStateModel>, _: GetCDSStatus) {
4343
this._monitoringService.getStatus().subscribe(s => {
44-
let maintenance = s.lines.find(m => {
44+
let maintenance = 'false';
45+
let line = s.lines.find(m => {
4546
if (m.component === 'Global/Maintenance') {
4647
return m
4748
}
48-
}).value;
49+
});
50+
if (line) {
51+
maintenance = line.value;
52+
}
4953
ctx.dispatch(new UpdateMaintenance(maintenance === 'true'));
5054
});
5155
}

0 commit comments

Comments
 (0)