Skip to content

Commit

Permalink
fix(api,ui): run event when people delete a run from UI (#5482)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Oct 8, 2020
1 parent 96ca232 commit bbbdcd3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions engine/api/event/publish_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func PublishWorkflowRun(ctx context.Context, wr sdk.WorkflowRun, projectKey stri
LastModified: wr.LastModified.Unix(),
LastModifiedNano: wr.LastModified.UnixNano(),
Tags: wr.Tags,
ToDelete: wr.ToDelete,
}
data := publishWorkflowRunData{
projectKey: projectKey,
Expand Down
2 changes: 2 additions & 0 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ func (api *API) deleteWorkflowRunHandler() service.Handler {
if err := workflow.MarkWorkflowRunsAsDelete(api.mustDB(), []int64{run.ID}); err != nil {
return sdk.WrapError(err, "cannot mark workflow run %d as delete", run.ID)
}
run.ToDelete = true

workflow.CountWorkflowRunsMarkToDelete(ctx, api.mustDB(), api.Metrics.WorkflowRunsMarkToDelete)
event.PublishWorkflowRun(ctx, *run, key)

return service.WriteJSON(w, nil, http.StatusAccepted)
}
Expand Down
1 change: 1 addition & 0 deletions sdk/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type EventRunWorkflow struct {
LastModified int64 `json:"last_modified"`
LastModifiedNano int64 `json:"last_modified_nano"`
Tags []WorkflowRunTag `json:"tags"`
ToDelete bool `json:"to_delete"`
}

// EventNotif contains event data for a job
Expand Down
22 changes: 21 additions & 1 deletion ui/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ import { DeleteFromCachePipeline, ExternalChangePipeline, ResyncPipeline } from
import { PipelinesState, PipelinesStateModel } from './store/pipelines.state';
import * as projectActions from './store/project.action';
import { ProjectState, ProjectStateModel } from './store/project.state';
import { ExternalChangeWorkflow, GetWorkflow, GetWorkflowNodeRun, GetWorkflowRun, UpdateWorkflowRunList } from './store/workflow.action';
import {
ExternalChangeWorkflow,
GetWorkflow,
GetWorkflowNodeRun,
GetWorkflowRun,
RemoveWorkflowRunFromList,
UpdateWorkflowRunList
} from './store/workflow.action';
import { WorkflowState } from './store/workflow.state';

@Injectable()
Expand Down Expand Up @@ -328,6 +335,19 @@ export class AppService {
}
switch (event.type_event) {
case EventType.RUN_WORKFLOW_PREFIX:
if (event.payload['to_delete']) {
this._store.dispatch(new RemoveWorkflowRunFromList({
projectKey: event.project_key,
workflowName: event.workflow_name,
num: event.workflow_run_num
}));

if (this.routeParams['number'] === event.workflow_run_num.toString()) {
this._toast.info('', 'This run has just been deleted')
this._router.navigate(['/project', this.routeParams['key'], 'workflow', event.workflow_name]);
}
return;
}
if (this.routeParams['number'] === event.workflow_run_num.toString()) {
// if same run number , then update store
this._store.dispatch(
Expand Down
5 changes: 5 additions & 0 deletions ui/src/app/store/workflow.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class GetWorkflowRun {
constructor(public payload: { projectKey: string, workflowName: string, num: number }) { }
}

export class RemoveWorkflowRunFromList {
static readonly type = '[Workflow] Remove Workflow Run From List';
constructor(public payload: { projectKey: string, workflowName: string, num: number }) { }
}

export class GetWorkflowRuns {
static readonly type = '[Workflow] Get Workflow Runs';
constructor(public payload: { projectKey: string, workflowName: string, limit: string, offset: string, filters?: {}}) { }
Expand Down
11 changes: 11 additions & 0 deletions ui/src/app/store/workflow.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,17 @@ export class WorkflowState {
}));
}

@Action(actionWorkflow.RemoveWorkflowRunFromList)
removeWorkflowRunFromList(ctx: StateContext<WorkflowStateModel>, action: actionWorkflow.RemoveWorkflowRunFromList) {
const state = ctx.getState();
ctx.setState({
...state,
listRuns: state.listRuns.filter(r => r.num !== action.payload.num ||
r.workflow.name !== action.payload.workflowName ||
r.workflow.project_key !== action.payload.projectKey)
});
}

@Action(actionWorkflow.GetWorkflowRuns)
getWorkflowRuns(ctx: StateContext<WorkflowStateModel>, action: actionWorkflow.GetWorkflowRuns) {
const state = ctx.getState();
Expand Down

0 comments on commit bbbdcd3

Please sign in to comment.