Skip to content

Commit 79c36e5

Browse files
authored
fix(ui): add subscription on workflowRun event (#5213)
1 parent 2c5b0eb commit 79c36e5

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
OnInit,
88
Output
99
} from '@angular/core';
10-
import { Store } from '@ngxs/store';
10+
import { Select, Store } from '@ngxs/store';
1111
import { IPopup } from '@richardlt/ng2-semantic-ui';
1212
import { PipelineStatus } from 'app/model/pipeline.model';
1313
import { Project } from 'app/model/project.model';
@@ -16,6 +16,8 @@ import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
1616
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
1717
import { ProjectState } from 'app/store/project.state';
1818
import { WorkflowState, WorkflowStateModel } from 'app/store/workflow.state';
19+
import { Observable, Subscription } from 'rxjs';
20+
import { map } from 'rxjs/operators';
1921

2022
@Component({
2123
selector: 'app-workflow-menu-wnode-edit',
@@ -32,9 +34,16 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
3234

3335
project: Project;
3436
workflow: Workflow;
37+
node: WNode;
38+
39+
3540
workflowrun: WorkflowRun;
41+
@Select(WorkflowState.getSelectedWorkflowRun()) workflowRun$: Observable<WorkflowRun>;
42+
workflowRunSub: Subscription;
43+
3644
noderun: WorkflowNodeRun;
37-
node: WNode;
45+
nodeRunSub: Subscription;
46+
3847
runnable: boolean;
3948
readonly = true;
4049

@@ -48,11 +57,36 @@ export class WorkflowWNodeMenuEditComponent implements OnInit {
4857

4958
let state: WorkflowStateModel = this._store.selectSnapshot(WorkflowState);
5059
this.workflow = state.workflow;
51-
this.workflowrun = state.workflowRun;
52-
this.noderun = state.workflowNodeRun;
5360
this.node = state.node;
54-
this.readonly = !state.canEdit || (!!this.workflow.from_template && !!this.workflow.from_repository);
5561

62+
63+
this.workflowRunSub = this.workflowRun$.subscribe(wr => {
64+
if (!wr) {
65+
return;
66+
}
67+
if (this.workflow.id !== wr.workflow_id) {
68+
return;
69+
}
70+
this.workflowrun = wr;
71+
this.runnable = this.getCanBeRun();
72+
this._cd.markForCheck();
73+
});
74+
75+
this.nodeRunSub = this._store.select(WorkflowState.nodeRunByNodeID)
76+
.pipe(map(filterFn => filterFn(this.node.id))).subscribe( nodeRun => {
77+
if (!nodeRun) {
78+
return;
79+
}
80+
if (this.noderun && this.noderun.status === nodeRun.status) {
81+
return;
82+
}
83+
this.noderun = nodeRun;
84+
this.runnable = this.getCanBeRun();
85+
this._cd.markForCheck();
86+
});
87+
88+
89+
this.readonly = !state.canEdit || (!!this.workflow.from_template && !!this.workflow.from_repository);
5690
this.runnable = this.getCanBeRun();
5791
this._cd.markForCheck();
5892
}

ui/src/app/shared/workflow/sidebar/run-node/workflow.sidebar.run.node.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class WorkflowSidebarRunNodeComponent implements OnDestroy, OnInit {
3434

3535
project: Project;
3636
workflow: Workflow;
37+
38+
@Select(WorkflowState.getSelectedWorkflowRun()) worklowRun$: Observable<WorkflowRun>;
39+
wrSubs: Subscription;
3740
workflowRun: WorkflowRun;
3841

3942
@Select(WorkflowState.getSelectedNode()) node$: Observable<WNode>;
@@ -93,7 +96,15 @@ export class WorkflowSidebarRunNodeComponent implements OnDestroy, OnInit {
9396
ngOnInit(): void {
9497
this.project = this._store.selectSnapshot(ProjectState.projectSnapshot);
9598
this.workflow = this._store.selectSnapshot(WorkflowState.workflowSnapshot);
96-
this.workflowRun = this._store.selectSnapshot(WorkflowState.workflowRunSnapshot);
99+
100+
this.wrSubs = this.worklowRun$.subscribe(wr => {
101+
if (!wr) {
102+
return;
103+
}
104+
this.workflowRun = wr;
105+
this.canBeRun = this.getCanBeRun();
106+
this._cd.markForCheck();
107+
});
97108

98109
this.nodeSubs = this.node$.subscribe(n => {
99110
if (!n && !this.node) {

ui/src/app/views/workflow/workflow.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class WorkflowComponent implements OnInit {
5151
workflowSubscription: Subscription;
5252

5353
projectSubscription: Subscription;
54-
dataRouteSubscription: Subscription;
5554
qpRouteSubscription: Subscription;
5655
paramsRouteSubscription: Subscription;
5756
eventsRouteSubscription: Subscription;
@@ -80,9 +79,6 @@ export class WorkflowComponent implements OnInit {
8079
selectedNodeRef: string;
8180
selectecHookRef: string;
8281

83-
showButtons = false;
84-
loadingPopupButton = false;
85-
8682
constructor(
8783
private _activatedRoute: ActivatedRoute,
8884
private _router: Router,

0 commit comments

Comments
 (0)