99053: Save queryParams in init to prevent them being overwritten

This commit is contained in:
Alexandre Vryghem
2023-02-10 16:39:27 +01:00
parent 356962a571
commit dce84dbe70
11 changed files with 41 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Location } from '@angular/common';
import {
AdvancedWorkflowActionRatingComponent,
ADVANCED_WORKFLOW_TASK_OPTION_RATING
@@ -28,6 +29,7 @@ import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-res
import { RatingAdvancedWorkflowInfo } from '../../../core/tasks/models/rating-advanced-workflow-info.model';
import { RequestService } from '../../../core/data/request.service';
import { RequestServiceStub } from '../../../shared/testing/request-service.stub';
import { LocationStub } from '../../../shared/testing/location.stub';
const claimedTaskId = '2';
const workflowId = '1';
@@ -77,6 +79,7 @@ describe('AdvancedWorkflowActionRatingComponent', () => {
},
},
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
{ provide: Location, useValue: new LocationStub() },
{ provide: NotificationsService, useValue: notificationService },
{ provide: RouteService, useValue: routeServiceStub },
{ provide: Router, useValue: new RouterStub() },

View File

@@ -108,6 +108,7 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
},
});
component.ngOnInit();
component.previousPage();
expect(router.navigate).toHaveBeenCalledWith(['/mydspace'], {

View File

@@ -65,7 +65,7 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
protected requestService: RequestService,
protected location: Location,
) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, workflowActionService, claimedTaskDataService, requestService);
super(route, workflowItemService, router, routeService, notificationsService, translationService, workflowActionService, claimedTaskDataService, requestService, location);
}
ngOnDestroy(): void {
@@ -140,7 +140,7 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
* switching between the different pages
*/
previousPage(): void {
let queryParams: Params = (this.location.getState() as { [key: string]: any }).previousQueryParams;
let queryParams: Params = this.previousQueryParameters;
if (!hasValue(queryParams)) {
queryParams = {
configuration: 'workflow',

View File

@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Location } from '@angular/common';
import { AdvancedWorkflowActionComponent } from './advanced-workflow-action.component';
import { Component } from '@angular/core';
import { MockComponent } from 'ng-mocks';
@@ -20,6 +21,7 @@ import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-res
import { WorkflowItemDataServiceStub } from '../../../shared/testing/workflow-item-data-service.stub';
import { RequestService } from '../../../core/data/request.service';
import { RequestServiceStub } from '../../../shared/testing/request-service.stub';
import { LocationStub } from '../../../shared/testing/location.stub';
const workflowId = '1';
@@ -28,17 +30,18 @@ describe('AdvancedWorkflowActionComponent', () => {
let fixture: ComponentFixture<AdvancedWorkflowActionComponent>;
let claimedTaskDataService: ClaimedTaskDataServiceStub;
let location: LocationStub;
let notificationService: NotificationsServiceStub;
let workflowActionDataService: WorkflowActionDataServiceStub;
let workflowItemDataService: WorkflowItemDataServiceStub;
beforeEach(async () => {
claimedTaskDataService = new ClaimedTaskDataServiceStub();
location = new LocationStub();
notificationService = new NotificationsServiceStub();
workflowActionDataService = new WorkflowActionDataServiceStub();
workflowItemDataService = new WorkflowItemDataServiceStub();
await TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
@@ -63,6 +66,7 @@ describe('AdvancedWorkflowActionComponent', () => {
},
},
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
{ provide: Location, useValue: location },
{ provide: NotificationsService, useValue: notificationService },
{ provide: RouteService, useValue: routeServiceStub },
{ provide: WorkflowActionDataService, useValue: workflowActionDataService },

View File

@@ -13,6 +13,7 @@ import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.se
import { map } from 'rxjs/operators';
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
import { RequestService } from '../../../core/data/request.service';
import { Location } from '@angular/common';
/**
* Abstract component for rendering an advanced claimed task's workflow page
@@ -38,8 +39,9 @@ export abstract class AdvancedWorkflowActionComponent extends WorkflowItemAction
protected workflowActionService: WorkflowActionDataService,
protected claimedTaskDataService: ClaimedTaskDataService,
protected requestService: RequestService,
protected location: Location,
) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService);
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService, location);
}
ngOnInit(): void {

View File

@@ -18,6 +18,8 @@ import { RouterStub } from '../shared/testing/router.stub';
import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub';
import { RequestService } from '../core/data/request.service';
import { RequestServiceStub } from '../shared/testing/request-service.stub';
import { Location } from '@angular/common';
import { LocationStub } from '../shared/testing/location.stub';
const type = 'testType';
describe('WorkflowItemActionPageComponent', () => {
@@ -52,6 +54,7 @@ describe('WorkflowItemActionPageComponent', () => {
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: Location, useValue: new LocationStub() },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
{ provide: RequestService, useClass: RequestServiceStub },
@@ -115,8 +118,9 @@ class TestComponent extends WorkflowItemActionPageComponent {
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService,
protected location: Location,
) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService);
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService, location);
}
getType(): string {

View File

@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Observable, forkJoin } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
@@ -24,6 +25,7 @@ export abstract class WorkflowItemActionPageComponent implements OnInit {
public type;
public wfi$: Observable<WorkflowItem>;
public item$: Observable<Item>;
protected previousQueryParameters?: Params;
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
@@ -32,6 +34,7 @@ export abstract class WorkflowItemActionPageComponent implements OnInit {
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService,
protected location: Location,
) {
}
@@ -42,6 +45,7 @@ export abstract class WorkflowItemActionPageComponent implements OnInit {
this.type = this.getType();
this.wfi$ = this.route.data.pipe(map((data: Data) => data.wfi as RemoteData<WorkflowItem>), getRemoteDataPayload());
this.item$ = this.wfi$.pipe(switchMap((wfi: WorkflowItem) => (wfi.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
this.previousQueryParameters = (this.location.getState() as { [key: string]: any }).previousQueryParams;
}
/**
@@ -72,10 +76,11 @@ export abstract class WorkflowItemActionPageComponent implements OnInit {
previousPage() {
this.routeService.getPreviousUrl().pipe(take(1))
.subscribe((url) => {
let params: Params = {};
if (isEmpty(url)) {
url = '/mydspace';
params = this.previousQueryParameters;
}
const params: Params = {};
if (url.split('?').length > 1) {
for (const param of url.split('?')[1].split('&')) {
params[param.split('=')[0]] = decodeURIComponent(param.split('=')[1]);

View File

@@ -1,5 +1,5 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { Location } from '@angular/common';
import { WorkflowItemDeleteComponent } from './workflow-item-delete.component';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
@@ -17,6 +17,7 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import { RouterStub } from '../../shared/testing/router.stub';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { LocationStub } from '../../shared/testing/location.stub';
describe('WorkflowItemDeleteComponent', () => {
let component: WorkflowItemDeleteComponent;
@@ -50,6 +51,7 @@ describe('WorkflowItemDeleteComponent', () => {
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: Location, useValue: new LocationStub() },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
{ provide: RequestService, useValue: getMockRequestService() },

View File

@@ -11,6 +11,7 @@ import { map } from 'rxjs/operators';
import { RemoteData } from '../../core/data/remote-data';
import { NoContent } from '../../core/shared/NoContent.model';
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { Location } from '@angular/common';
@Component({
selector: 'ds-workflow-item-delete',
@@ -26,8 +27,10 @@ export class WorkflowItemDeleteComponent extends WorkflowItemActionPageComponent
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService);
protected requestService: RequestService,
protected location: Location,
) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService, location);
}
/**

View File

@@ -1,5 +1,5 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { Location } from '@angular/common';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouteService } from '../../core/services/route.service';
@@ -17,6 +17,7 @@ import { RouterStub } from '../../shared/testing/router.stub';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { LocationStub } from '../../shared/testing/location.stub';
describe('WorkflowItemSendBackComponent', () => {
let component: WorkflowItemSendBackComponent;
@@ -50,6 +51,7 @@ describe('WorkflowItemSendBackComponent', () => {
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: Location, useValue: new LocationStub() },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
{ provide: RequestService, useValue: getMockRequestService() },

View File

@@ -7,6 +7,7 @@ import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { RequestService } from '../../core/data/request.service';
import { Location } from '@angular/common';
@Component({
selector: 'ds-workflow-item-send-back',
@@ -22,8 +23,10 @@ export class WorkflowItemSendBackComponent extends WorkflowItemActionPageCompone
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService);
protected requestService: RequestService,
protected location: Location,
) {
super(route, workflowItemService, router, routeService, notificationsService, translationService, requestService, location);
}
/**