Skip to content

Commit

Permalink
Merge pull request #222 from Vafilor/fix/back.link
Browse files Browse the repository at this point in the history
fix: issue where back link sometimes didn't work in workflows
  • Loading branch information
rushtehrani authored Dec 18, 2020
2 parents 956bf59 + e9ab3f0 commit 3ab48a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/app/router/app-router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ export class AppRouter {
* pushRoute appends a route to the route history and keeps track of bookkeeping like max items allowed.
*/
private pushRoute(route: string) {
const lastRoute = this.getLastRoute();
// format route so we don't store query parameters
// this way we don't have a back link that takes you to the same page but different query parameters
const indexOfParam = route.indexOf('?');
if ( indexOfParam > 0 ) {
route = route.substring(0, indexOfParam);
}

const lastRoute = this.getLastRoute();
if (route === lastRoute) {
return;
}
Expand All @@ -59,12 +65,21 @@ export class AppRouter {
}
}

/**
* returns false if there is no where to go back to.
*/
goBack() {
if (this.routerHistory.length > 0) {
this.routerHistory.splice(this.routerHistory.length - 1, 1);
}

if (this.routerHistory.length === 0) {
return false;
}

this.location.back();

return true;
}

getBackLink(namespace: string, defaultLink: BackLink): BackLink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ export class WorkflowTemplateViewComponent implements OnInit {
e.preventDefault();
}

this.appRouter.goBack();
if (!this.appRouter.goBack()) {
this.appRouter.navigateToWorkflowTemplates(this.namespace);
}
}
}
9 changes: 5 additions & 4 deletions src/app/workflow/workflow-view/workflow-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SimpleWorkflowDetail, WorkflowPhase, WorkflowService } from '../workflow.service';
import { NodeRenderer, NodeStatus } from '../../node/node.service';
import { DagClickEvent, DagComponent } from '../../dag/dag.component';
import { DagComponent } from '../../dag/dag.component';
import { NodeInfoComponent } from '../../node-info/node-info.component';
import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
import { AceEditorComponent } from 'ng2-ace-editor';
Expand Down Expand Up @@ -31,7 +31,6 @@ import { Alert } from '../../alert/alert';
import { AlertService } from '../../alert/alert.service';
import { PermissionService } from '../../permissions/permission.service';
import { MetricsEditDialogComponent } from '../../metrics/metrics-edit-dialog/metrics-edit-dialog.component';
import { environment } from '../../../environments/environment';

const aceRange = ace.acequire('ace/range').Range;

Expand Down Expand Up @@ -608,7 +607,9 @@ export class WorkflowViewComponent implements OnInit, OnDestroy {
e.preventDefault();
}

this.appRouter.goBack();
if (!this.appRouter.goBack()) {
this.appRouter.navigateToWorkflowsExecutions(this.namespace);
}
}

onPhaseUpdate(oldPhase: WorkflowPhase, newPhase: WorkflowPhase) {
Expand Down

0 comments on commit 3ab48a7

Please sign in to comment.