Skip to content

Commit b6ef06b

Browse files
authored
fix(ui): workflow/workflowrun view, do not listen on full workflow state (#5086)
1 parent f92cfbb commit b6ef06b

39 files changed

+798
-674
lines changed

engine/api/workflow_run.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,6 @@ func (api *API) getWorkflowCommitsHandler() service.Handler {
610610
}
611611
}
612612

613-
if wfRun == nil {
614-
wfRun = &sdk.WorkflowRun{Number: number, Workflow: *wf}
615-
}
616613
wfNodeRun := &sdk.WorkflowNodeRun{}
617614
if branch != "" {
618615
wfNodeRun.VCSBranch = branch
@@ -626,20 +623,26 @@ func (api *API) getWorkflowCommitsHandler() service.Handler {
626623
// Find hash and branch of ancestor node run
627624
var nodeIDsAncestors []int64
628625
if node != nil {
629-
nodeIDsAncestors = node.Ancestors(wfRun.Workflow.WorkflowData)
626+
nodeIDsAncestors = node.Ancestors(wf.WorkflowData)
630627
}
631628

632-
for _, ancestorID := range nodeIDsAncestors {
633-
if wfRun.WorkflowNodeRuns != nil && wfRun.WorkflowNodeRuns[ancestorID][0].VCSRepository == app.RepositoryFullname {
634-
wfNodeRun.VCSHash = wfRun.WorkflowNodeRuns[ancestorID][0].VCSHash
635-
wfNodeRun.VCSBranch = wfRun.WorkflowNodeRuns[ancestorID][0].VCSBranch
636-
break
629+
if wfRun != nil && wfRun.WorkflowNodeRuns != nil {
630+
for _, ancestorID := range nodeIDsAncestors {
631+
nodeRuns, ok := wfRun.WorkflowNodeRuns[ancestorID]
632+
if !ok || len(nodeRuns) == 0 {
633+
continue
634+
}
635+
if nodeRuns[0].VCSRepository == app.RepositoryFullname {
636+
wfNodeRun.VCSHash = nodeRuns[0].VCSHash
637+
wfNodeRun.VCSBranch = nodeRuns[0].VCSBranch
638+
break
639+
}
637640
}
638641
}
639642
}
640643

641644
log.Debug("getWorkflowCommitsHandler> VCSHash: %s VCSBranch: %s", wfNodeRun.VCSHash, wfNodeRun.VCSBranch)
642-
commits, _, err := workflow.GetNodeRunBuildCommits(ctx, api.mustDB(), api.Cache, *proj, wf, nodeName, wfRun.Number, wfNodeRun, &app, &env)
645+
commits, _, err := workflow.GetNodeRunBuildCommits(ctx, api.mustDB(), api.Cache, *proj, wf, nodeName, number, wfNodeRun, &app, &env)
643646
if err != nil {
644647
return sdk.WrapError(err, "unable to load commits")
645648
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,7 @@ 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-
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);
332-
}
323+
ancestors.push(n.id);
333324
break loop;
334325
}
335326
}
@@ -668,6 +659,7 @@ export class WNodeHook {
668659
ref: string;
669660
node_id: number;
670661
hook_model_id: number;
662+
hoomodel_name: string;
671663
config: Map<string, WorkflowNodeHookConfigValue>;
672664
conditions: WorkflowNodeConditions;
673665

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ 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 } from 'app/store/workflow.state';
18-
import { Subscription } from 'rxjs';
17+
import { ProjectState } from 'app/store/project.state';
18+
import { WorkflowState, WorkflowStateModel } from 'app/store/workflow.state';
1919

2020
@Component({
2121
selector: 'app-workflow-menu-wnode-edit',
@@ -27,40 +27,34 @@ import { Subscription } from 'rxjs';
2727
export class WorkflowWNodeMenuEditComponent implements OnInit {
2828

2929
// Project that contains the workflow
30-
@Input() project: Project;
31-
@Input() node: WNode;
32-
_noderun: WorkflowNodeRun;
33-
@Input('noderun') set noderun(data: WorkflowNodeRun) {
34-
this._noderun = data;
35-
this.runnable = this.getCanBeRun();
36-
}
37-
get noderun() { return this._noderun }
38-
39-
_workflowrun: WorkflowRun;
40-
@Input('workflowrun') set workflowrun(data: WorkflowRun) {
41-
this._workflowrun = data;
42-
this.runnable = this.getCanBeRun();
43-
}
44-
get workflowrun() { return this._workflowrun }
45-
4630
@Input() popup: IPopup;
47-
@Input() readonly = true;
4831
@Output() event = new EventEmitter<string>();
49-
runnable: boolean;
50-
storeSubscription: Subscription;
32+
33+
project: Project;
5134
workflow: Workflow;
35+
workflowrun: WorkflowRun;
36+
noderun: WorkflowNodeRun;
37+
node: WNode;
38+
runnable: boolean;
39+
readonly = true;
5240

5341
constructor(
5442
private _store: Store,
5543
private _cd: ChangeDetectorRef
56-
) { }
44+
) {}
5745

5846
ngOnInit(): void {
59-
this.storeSubscription = this._store.select(WorkflowState.getWorkflow()).subscribe((w: Workflow) => {
60-
this.workflow = w;
61-
this.runnable = this.getCanBeRun();
62-
this._cd.markForCheck();
63-
});
47+
this.project = this._store.selectSnapshot(ProjectState.projectSnapshot);
48+
49+
let state: WorkflowStateModel = this._store.selectSnapshot(WorkflowState);
50+
this.workflow = state.workflow;
51+
this.workflowrun = state.workflowRun;
52+
this.noderun = state.workflowNodeRun;
53+
this.node = state.node;
54+
this.readonly = !state.canEdit;
55+
56+
this.runnable = this.getCanBeRun();
57+
this._cd.markForCheck();
6458
}
6559

6660
sendEvent(e: string): void {
@@ -77,7 +71,7 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
7771
return false;
7872
}
7973

80-
// If we are in a run, check if current node can be run ( compuite by cds api)
74+
// If we are in a run, check if current node can be run ( compute by cds api)
8175
if (this.noderun && this.workflowrun && this.workflowrun.nodes) {
8276
let nodesRun = this.workflowrun.nodes[this.noderun.workflow_node_id];
8377
if (nodesRun) {

ui/src/app/shared/workflow/menu/edit-node/menu.edit.node.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</a>
77
<hr>
88
</ng-container>
9-
<ng-container *ngIf="node && !noderun">
9+
<ng-container *ngIf="node && !workflowrun">
1010
<a class="item" (click)="sendEvent('pipeline')"
1111
[class.disabled]="readonly">
1212
{{ 'workflow_node_trigger_add' | translate }}
@@ -50,13 +50,13 @@
5050
{{ 'btn_delete' | translate }}
5151
</a>
5252
</ng-container>
53-
<ng-container *ngIf="node && noderun">
54-
<ng-container *ngIf="node.type === 'pipeline'">
53+
<ng-container *ngIf="node && noderun && node.type === 'pipeline'">
5554
<a class="item" (click)="sendEvent('logs')">
5655
{{'btn_logs' | translate }}
5756
</a>
5857
<hr>
59-
</ng-container>
58+
</ng-container>
59+
<ng-container *ngIf="node && workflowrun">
6060
<a class="item" (click)="sendEvent('edit')">
6161
{{ 'workflow_node_menu_edit_ro' | translate }}
6262
</a>

ui/src/app/shared/workflow/modal/hook-add/hook.modal.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
2+
import { Store } from '@ngxs/store';
23
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
34
import { Project } from 'app/model/project.model';
45
import { WNode, WNodeHook, Workflow } from 'app/model/workflow.model';
56
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
67
import { WorkflowNodeHookFormComponent } from 'app/shared/workflow/wizard/hook/hook.form.component';
8+
import { WorkflowState } from 'app/store/workflow.state';
79
@Component({
810
selector: 'app-hook-modal',
911
templateUrl: './hook.modal.html',
@@ -17,13 +19,12 @@ export class WorkflowHookModalComponent {
1719
@Input() workflow: Workflow;
1820
@Input() node: WNode;
1921
@Input() loading: boolean;
20-
@Input() editMode: boolean;
21-
22-
@Input() hook: WNodeHook;
2322

2423
@Output() hookEvent = new EventEmitter<WNodeHook>();
2524
@Output() deleteHookEvent = new EventEmitter<WNodeHook>();
2625

26+
editMode: boolean;
27+
2728
@ViewChild('hookModalComponent', {static: false})
2829
public hookModalComponent: ModalTemplate<boolean, boolean, void>;
2930
modalConfig: TemplateModalConfig<boolean, boolean, void>;
@@ -32,7 +33,9 @@ export class WorkflowHookModalComponent {
3233
@ViewChild('hookFormComponent', {static: false})
3334
hookFormComponent: WorkflowNodeHookFormComponent;
3435

35-
constructor(private _modalService: SuiModalService) {}
36+
constructor(private _modalService: SuiModalService, private _store: Store) {
37+
this.editMode = this._store.selectSnapshot(WorkflowState).editMode;
38+
}
3639

3740
show(): void {
3841
if (this.hookModalComponent) {

ui/src/app/shared/workflow/modal/hook-add/hook.modal.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<ng-template let-context let-modal="modal" #hookModalComponent>
22
<div class="header">{{ 'workflow_node_hook_modal_title' | translate }}</div>
33
<div class="content">
4-
<app-workflow-node-hook-form [project]="project" [workflow]="workflow" [node]="node" [hook]="hook"
5-
#hookFormComponent></app-workflow-node-hook-form>
4+
<app-workflow-node-hook-form [workflow]="workflow" #hookFormComponent></app-workflow-node-hook-form>
65
</div>
76
<div class="actions">
87
<button class="ui grey button" [disabled]="loading"

ui/src/app/shared/workflow/modal/node-add/workflow.trigger.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
2+
import { Store } from '@ngxs/store';
23
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
34
import { Application } from 'app/model/application.model';
45
import { Environment } from 'app/model/environment.model';
@@ -18,6 +19,7 @@ import { EnvironmentService } from 'app/service/environment/environment.service'
1819
import { PipelineService } from 'app/service/pipeline/pipeline.service';
1920
import { WorkflowNodeAddWizardComponent } from 'app/shared/workflow/wizard/node-add/node.wizard.component';
2021
import { WorkflowWizardOutgoingHookComponent } from 'app/shared/workflow/wizard/outgoinghook/wizard.outgoinghook.component';
22+
import { WorkflowState } from 'app/store/workflow.state';
2123
import cloneDeep from 'lodash-es/cloneDeep';
2224
import { forkJoin, Observable } from 'rxjs';
2325

@@ -42,14 +44,13 @@ export class WorkflowTriggerComponent {
4244
@Input() project: Project;
4345
@Input() loading: boolean;
4446
@Input() destination: string;
45-
@Input() editMode: boolean;
4647

4748
destNode: WNode;
4849
currentSection = 'pipeline';
4950
selectedType: string;
5051
isParent: boolean;
5152

52-
constructor(private _modalService: SuiModalService, private _pipService: PipelineService,
53+
constructor(private _modalService: SuiModalService, private _pipService: PipelineService, private _store: Store,
5354
private _envService: EnvironmentService, private _appService: ApplicationService) { }
5455

5556
show(t: string, isP: boolean): void {
@@ -73,7 +74,7 @@ export class WorkflowTriggerComponent {
7374
}
7475

7576
addOutgoingHook(): void {
76-
this.destNode = this.worklflowAddOutgoingHook.hook;
77+
this.destNode = this.worklflowAddOutgoingHook.outgoingHook;
7778
this.saveTrigger();
7879
}
7980

@@ -84,8 +85,9 @@ export class WorkflowTriggerComponent {
8485
c.variable = 'cds.status';
8586
c.value = PipelineStatus.SUCCESS;
8687
c.operator = 'eq';
88+
let editMode = this._store.selectSnapshot(WorkflowState).editMode
8789
this.destNode.context.conditions.plain.push(c);
88-
if (this.editMode) {
90+
if (editMode) {
8991
let allNodes = Workflow.getAllNodes(this.workflow);
9092
this.destNode.ref = new Date().getTime().toString();
9193

@@ -111,7 +113,7 @@ export class WorkflowTriggerComponent {
111113

112114
if (this.source && !this.isParent) {
113115
let sourceNode: WNode;
114-
if (!this.editMode) {
116+
if (!editMode) {
115117
sourceNode = Workflow.getNodeByID(this.source.id, clonedWorkflow);
116118
} else {
117119
sourceNode = Workflow.getNodeByRef(this.source.ref, clonedWorkflow);
@@ -136,7 +138,7 @@ export class WorkflowTriggerComponent {
136138
} else {
137139
return
138140
}
139-
if (this.editMode) {
141+
if (editMode) {
140142
forkJoin([
141143
this.getApplication(clonedWorkflow),
142144
this.getPipeline(clonedWorkflow),

ui/src/app/shared/workflow/modal/node-add/workflow.trigger.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ <h3>{{ 'workflow_node_form_title' | translate }}</h3>
1515
</ng-container>
1616
<ng-container *ngIf="selectedType === 'outgoinghook'">
1717
<app-workflow-node-outgoinghook
18-
[project]="project"
1918
[workflow]="workflow"
20-
[source]="source"
2119
(outgoinghookEvent)="destNodeChange($event)"
2220
#worklflowAddOutgoingHook></app-workflow-node-outgoinghook>
2321
</ng-container>

0 commit comments

Comments
 (0)