Merge branch 'w2p-98211_advanced-workflow-actions-7.2' into w2p-98211_advanced-workflow-actions-main

This commit is contained in:
Alexandre Vryghem
2023-02-10 15:55:09 +01:00
8 changed files with 62 additions and 42 deletions

View File

@@ -1,9 +1,13 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Injector } from '@angular/core';
import { ClaimedTaskActionsAbstractComponent } from './claimed-task-actions-abstract.component'; import { ClaimedTaskActionsAbstractComponent } from './claimed-task-actions-abstract.component';
import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators'; import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { getAdvancedWorkflowRoute } from '../../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths'; import { getAdvancedWorkflowRoute } from '../../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths';
import { Params } from '@angular/router'; import { Params, Router, ActivatedRoute, NavigationExtras } from '@angular/router';
import { NotificationsService } from '../../../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { SearchService } from '../../../../core/shared/search/search.service';
import { RequestService } from '../../../../core/data/request.service';
/** /**
* Abstract component for rendering an advanced claimed task's action * Abstract component for rendering an advanced claimed task's action
@@ -27,6 +31,18 @@ export abstract class AdvancedClaimedTaskActionsAbstractComponent extends Claime
*/ */
workflowTaskPageRoute: string; workflowTaskPageRoute: string;
constructor(
protected injector: Injector,
protected router: Router,
protected notificationsService: NotificationsService,
protected translate: TranslateService,
protected searchService: SearchService,
protected requestService: RequestService,
protected route: ActivatedRoute,
) {
super(injector, router, notificationsService, translate, searchService, requestService);
}
ngOnInit(): void { ngOnInit(): void {
super.ngOnInit(); super.ngOnInit();
this.initPageRoute(); this.initPageRoute();
@@ -47,9 +63,14 @@ export abstract class AdvancedClaimedTaskActionsAbstractComponent extends Claime
* Navigates to the advanced workflow page based on the {@link workflow}. * Navigates to the advanced workflow page based on the {@link workflow}.
*/ */
openAdvancedClaimedTaskTab(): void { openAdvancedClaimedTaskTab(): void {
void this.router.navigate([this.workflowTaskPageRoute], { const navigationExtras: NavigationExtras = {
queryParams: this.getQueryParams(), queryParams: this.getQueryParams(),
}); };
if (Object.keys(this.route.snapshot.queryParams).length > 0) {
navigationExtras.state = {};
navigationExtras.state.previousQueryParams = this.route.snapshot.queryParams;
}
void this.router.navigate([this.workflowTaskPageRoute], navigationExtras);
} }
/** /**

View File

@@ -9,7 +9,7 @@ import { SearchServiceStub } from '../../../testing/search-service.stub';
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service'; import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
import { NotificationsService } from '../../../notifications/notifications.service'; import { NotificationsService } from '../../../notifications/notifications.service';
import { RequestService } from '../../../../core/data/request.service'; import { RequestService } from '../../../../core/data/request.service';
import { Router } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchService } from '../../../../core/shared/search/search.service';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
@@ -19,6 +19,7 @@ import {
} from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-rating/advanced-workflow-action-rating.component'; } from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-rating/advanced-workflow-action-rating.component';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
const taskId = 'claimed-task-1'; const taskId = 'claimed-task-1';
const workflowId = 'workflow-1'; const workflowId = 'workflow-1';
@@ -35,12 +36,14 @@ describe('AdvancedClaimedTaskActionRatingComponent', () => {
let claimedTaskDataService: ClaimedTaskDataServiceStub; let claimedTaskDataService: ClaimedTaskDataServiceStub;
let notificationService: NotificationsServiceStub; let notificationService: NotificationsServiceStub;
let route: ActivatedRouteStub;
let router: RouterStub; let router: RouterStub;
let searchService: SearchServiceStub; let searchService: SearchServiceStub;
beforeEach(async () => { beforeEach(async () => {
claimedTaskDataService = new ClaimedTaskDataServiceStub(); claimedTaskDataService = new ClaimedTaskDataServiceStub();
notificationService = new NotificationsServiceStub(); notificationService = new NotificationsServiceStub();
route = new ActivatedRouteStub();
router = new RouterStub(); router = new RouterStub();
searchService = new SearchServiceStub(); searchService = new SearchServiceStub();
@@ -52,6 +55,7 @@ describe('AdvancedClaimedTaskActionRatingComponent', () => {
AdvancedClaimedTaskActionRatingComponent, AdvancedClaimedTaskActionRatingComponent,
], ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: route },
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService }, { provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
{ provide: NotificationsService, useValue: notificationService }, { provide: NotificationsService, useValue: notificationService },
{ provide: RequestService, useValue: {} }, { provide: RequestService, useValue: {} },

View File

@@ -1,5 +1,5 @@
import { Component, Injector } from '@angular/core'; import { Component, Injector } from '@angular/core';
import { Router } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { NotificationsService } from '../../../notifications/notifications.service'; import { NotificationsService } from '../../../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchService } from '../../../../core/shared/search/search.service';
@@ -38,8 +38,9 @@ export class AdvancedClaimedTaskActionRatingComponent extends AdvancedClaimedTas
protected translate: TranslateService, protected translate: TranslateService,
protected searchService: SearchService, protected searchService: SearchService,
protected requestService: RequestService, protected requestService: RequestService,
protected route: ActivatedRoute,
) { ) {
super(injector, router, notificationsService, translate, searchService, requestService); super(injector, router, notificationsService, translate, searchService, requestService, route);
} }
} }

View File

@@ -99,22 +99,4 @@ describe('AdvancedClaimedTaskActionSelectReviewerComponent', () => {
}, },
}); });
}); });
it('should navigate to the advanced workflow page with a previousSearchQuery when clicked anq a query is defined', () => {
spyOnProperty(route, 'snapshot').and.returnValue({
queryParams: {
query: 'Thor%20Love%20and%20Thunder',
}
});
component.workflowTaskPageRoute = `/workflowitems/${workflowId}/advanced`;
fixture.debugElement.query(By.css('.selectReviewerAction')).nativeElement.click();
expect(router.navigate).toHaveBeenCalledWith([`/workflowitems/${workflowId}/advanced`], {
queryParams: {
workflow: ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER,
claimedTask: taskId,
previousSearchQuery: 'Thor%20Love%20and%20Thunder',
},
});
});
}); });

View File

@@ -3,7 +3,7 @@ import { rendersWorkflowTaskOption } from '../switcher/claimed-task-actions-deco
import { import {
AdvancedClaimedTaskActionsAbstractComponent AdvancedClaimedTaskActionsAbstractComponent
} from '../abstract/advanced-claimed-task-actions-abstract.component'; } from '../abstract/advanced-claimed-task-actions-abstract.component';
import { Router, Params, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { NotificationsService } from '../../../notifications/notifications.service'; import { NotificationsService } from '../../../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchService } from '../../../../core/shared/search/search.service';
@@ -12,7 +12,6 @@ import {
ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER, ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER,
ADVANCED_WORKFLOW_TASK_OPTION_SELECT_REVIEWER ADVANCED_WORKFLOW_TASK_OPTION_SELECT_REVIEWER
} from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-select-reviewer/advanced-workflow-action-select-reviewer.component'; } from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-select-reviewer/advanced-workflow-action-select-reviewer.component';
import { hasValue } from '../../../empty.util';
/** /**
* Advanced Workflow button that redirect to the {@link AdvancedWorkflowActionSelectReviewerComponent} * Advanced Workflow button that redirect to the {@link AdvancedWorkflowActionSelectReviewerComponent}
@@ -41,15 +40,7 @@ export class AdvancedClaimedTaskActionSelectReviewerComponent extends AdvancedCl
protected requestService: RequestService, protected requestService: RequestService,
protected route: ActivatedRoute, protected route: ActivatedRoute,
) { ) {
super(injector, router, notificationsService, translate, searchService, requestService); super(injector, router, notificationsService, translate, searchService, requestService, route);
}
getQueryParams(): Params {
const params: Params = super.getQueryParams();
if (hasValue(this.route.snapshot.queryParams.query)) {
params.previousSearchQuery = this.route.snapshot.queryParams.query;
}
return params;
} }
} }

View File

@@ -0,0 +1,7 @@
export class LocationStub {
getState(): unknown {
return {};
}
}

View File

@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Location } from '@angular/common';
import { import {
AdvancedWorkflowActionSelectReviewerComponent, AdvancedWorkflowActionSelectReviewerComponent,
ADVANCED_WORKFLOW_TASK_OPTION_SELECT_REVIEWER, ADVANCED_WORKFLOW_TASK_OPTION_SELECT_REVIEWER,
@@ -25,6 +26,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RequestService } from '../../../core/data/request.service'; import { RequestService } from '../../../core/data/request.service';
import { RequestServiceStub } from '../../../shared/testing/request-service.stub'; import { RequestServiceStub } from '../../../shared/testing/request-service.stub';
import { RouterStub } from '../../../shared/testing/router.stub'; import { RouterStub } from '../../../shared/testing/router.stub';
import { LocationStub } from '../../../shared/testing/location.stub';
const claimedTaskId = '2'; const claimedTaskId = '2';
const workflowId = '1'; const workflowId = '1';
@@ -36,6 +38,7 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
let fixture: ComponentFixture<AdvancedWorkflowActionSelectReviewerComponent>; let fixture: ComponentFixture<AdvancedWorkflowActionSelectReviewerComponent>;
let claimedTaskDataService: ClaimedTaskDataServiceStub; let claimedTaskDataService: ClaimedTaskDataServiceStub;
let location: LocationStub;
let notificationService: NotificationsServiceStub; let notificationService: NotificationsServiceStub;
let router: RouterStub; let router: RouterStub;
let workflowActionDataService: WorkflowItemDataServiceStub; let workflowActionDataService: WorkflowItemDataServiceStub;
@@ -43,6 +46,7 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
beforeEach(async () => { beforeEach(async () => {
claimedTaskDataService = new ClaimedTaskDataServiceStub(); claimedTaskDataService = new ClaimedTaskDataServiceStub();
location = new LocationStub();
notificationService = new NotificationsServiceStub(); notificationService = new NotificationsServiceStub();
router = new RouterStub(); router = new RouterStub();
workflowActionDataService = new WorkflowActionDataServiceStub(); workflowActionDataService = new WorkflowActionDataServiceStub();
@@ -72,9 +76,10 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
}, },
}, },
}, },
{ provide: Router, useValue: router },
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService }, { provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
{ provide: Location, useValue: location },
{ provide: NotificationsService, useValue: notificationService }, { provide: NotificationsService, useValue: notificationService },
{ provide: Router, useValue: router },
{ provide: RouteService, useValue: routeServiceStub }, { provide: RouteService, useValue: routeServiceStub },
{ provide: WorkflowActionDataService, useValue: workflowActionDataService }, { provide: WorkflowActionDataService, useValue: workflowActionDataService },
{ provide: WorkflowItemDataService, useValue: workflowItemDataService }, { provide: WorkflowItemDataService, useValue: workflowItemDataService },
@@ -96,6 +101,13 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
describe('previousPage', () => { describe('previousPage', () => {
it('should navigate back to the Workflow tasks page with the previous query', () => { it('should navigate back to the Workflow tasks page with the previous query', () => {
spyOn(location, 'getState').and.returnValue({
previousQueryParams: {
configuration: 'workflow',
query: 'Thor Love and Thunder',
},
});
component.previousPage(); component.previousPage();
expect(router.navigate).toHaveBeenCalledWith(['/mydspace'], { expect(router.navigate).toHaveBeenCalledWith(['/mydspace'], {

View File

@@ -1,4 +1,5 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { Location } from '@angular/common';
import { import {
rendersAdvancedWorkflowTaskOption rendersAdvancedWorkflowTaskOption
} from '../../../shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-decorator'; } from '../../../shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-decorator';
@@ -62,6 +63,7 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
protected workflowActionService: WorkflowActionDataService, protected workflowActionService: WorkflowActionDataService,
protected claimedTaskDataService: ClaimedTaskDataService, protected claimedTaskDataService: ClaimedTaskDataService,
protected requestService: RequestService, 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);
} }
@@ -138,11 +140,11 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
* switching between the different pages * switching between the different pages
*/ */
previousPage(): void { previousPage(): void {
const queryParams: Params = { let queryParams: Params = (this.location.getState() as { [key: string]: any }).previousQueryParams;
if (!hasValue(queryParams)) {
queryParams = {
configuration: 'workflow', configuration: 'workflow',
}; };
if (hasValue(this.route.snapshot.queryParams.previousSearchQuery)) {
queryParams.query = decodeURIComponent(this.route.snapshot.queryParams.previousSearchQuery);
} }
void this.router.navigate(['/mydspace'], { queryParams: queryParams }); void this.router.navigate(['/mydspace'], { queryParams: queryParams });
} }