mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 05:53:03 +00:00
99053: Pass all queryParameters to advanced workflow pages by default
This commit is contained in:
@@ -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 { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
|
||||
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
|
||||
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
|
||||
@@ -27,6 +31,18 @@ export abstract class AdvancedClaimedTaskActionsAbstractComponent extends Claime
|
||||
*/
|
||||
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 {
|
||||
super.ngOnInit();
|
||||
this.initPageRoute();
|
||||
@@ -47,9 +63,14 @@ export abstract class AdvancedClaimedTaskActionsAbstractComponent extends Claime
|
||||
* Navigates to the advanced workflow page based on the {@link workflow}.
|
||||
*/
|
||||
openAdvancedClaimedTaskTab(): void {
|
||||
void this.router.navigate([this.workflowTaskPageRoute], {
|
||||
const navigationExtras: NavigationExtras = {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,7 +16,6 @@ import { RequestService } from '../../../core/data/request.service';
|
||||
import { SearchService } from '../../../core/shared/search/search.service';
|
||||
import { WorkflowAction } from '../../../core/tasks/models/workflow-action-object.model';
|
||||
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
|
||||
import { WORKFLOW_TASK_OPTION_RETURN_TO_POOL } from './return-to-pool/claimed-task-actions-return-to-pool.component';
|
||||
import { getWorkflowItemViewRoute } from '../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths';
|
||||
|
||||
/**
|
||||
|
@@ -9,7 +9,7 @@ import { SearchServiceStub } from '../../../testing/search-service.stub';
|
||||
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||
import { NotificationsService } from '../../../notifications/notifications.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 { Location } from '@angular/common';
|
||||
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';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
|
||||
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
|
||||
|
||||
const taskId = 'claimed-task-1';
|
||||
const workflowId = 'workflow-1';
|
||||
@@ -35,12 +36,14 @@ describe('AdvancedClaimedTaskActionRatingComponent', () => {
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let route: ActivatedRouteStub;
|
||||
let router: RouterStub;
|
||||
let searchService: SearchServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
route = new ActivatedRouteStub();
|
||||
router = new RouterStub();
|
||||
searchService = new SearchServiceStub();
|
||||
|
||||
@@ -52,6 +55,7 @@ describe('AdvancedClaimedTaskActionRatingComponent', () => {
|
||||
AdvancedClaimedTaskActionRatingComponent,
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Component, Injector } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { NotificationsService } from '../../../notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
@@ -38,8 +38,9 @@ export class AdvancedClaimedTaskActionRatingComponent extends AdvancedClaimedTas
|
||||
protected translate: TranslateService,
|
||||
protected searchService: SearchService,
|
||||
protected requestService: RequestService,
|
||||
protected route: ActivatedRoute,
|
||||
) {
|
||||
super(injector, router, notificationsService, translate, searchService, requestService);
|
||||
super(injector, router, notificationsService, translate, searchService, requestService, route);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -3,7 +3,7 @@ import { rendersWorkflowTaskOption } from '../switcher/claimed-task-actions-deco
|
||||
import {
|
||||
AdvancedClaimedTaskActionsAbstractComponent
|
||||
} 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 { TranslateService } from '@ngx-translate/core';
|
||||
import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
ADVANCED_WORKFLOW_ACTION_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';
|
||||
import { hasValue } from '../../../empty.util';
|
||||
|
||||
/**
|
||||
* Advanced Workflow button that redirect to the {@link AdvancedWorkflowActionSelectReviewerComponent}
|
||||
@@ -41,15 +40,7 @@ export class AdvancedClaimedTaskActionSelectReviewerComponent extends AdvancedCl
|
||||
protected requestService: RequestService,
|
||||
protected route: ActivatedRoute,
|
||||
) {
|
||||
super(injector, router, notificationsService, translate, searchService, requestService);
|
||||
}
|
||||
|
||||
getQueryParams(): Params {
|
||||
const params: Params = super.getQueryParams();
|
||||
if (hasValue(this.route.snapshot.queryParams.query)) {
|
||||
params.previousSearchQuery = this.route.snapshot.queryParams.query;
|
||||
}
|
||||
return params;
|
||||
super(injector, router, notificationsService, translate, searchService, requestService, route);
|
||||
}
|
||||
|
||||
}
|
||||
|
7
src/app/shared/testing/location.stub.ts
Normal file
7
src/app/shared/testing/location.stub.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export class LocationStub {
|
||||
|
||||
getState(): unknown {
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Location } from '@angular/common';
|
||||
import {
|
||||
AdvancedWorkflowActionSelectReviewerComponent,
|
||||
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 { RequestServiceStub } from '../../../shared/testing/request-service.stub';
|
||||
import { RouterStub } from '../../../shared/testing/router.stub';
|
||||
import { LocationStub } from '../../../shared/testing/location.stub';
|
||||
|
||||
const claimedTaskId = '2';
|
||||
const workflowId = '1';
|
||||
@@ -36,6 +38,7 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
|
||||
let fixture: ComponentFixture<AdvancedWorkflowActionSelectReviewerComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let location: LocationStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let router: RouterStub;
|
||||
let workflowActionDataService: WorkflowItemDataServiceStub;
|
||||
@@ -43,6 +46,7 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
location = new LocationStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
router = new RouterStub();
|
||||
workflowActionDataService = new WorkflowActionDataServiceStub();
|
||||
@@ -72,9 +76,10 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: Location, useValue: location },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: WorkflowActionDataService, useValue: workflowActionDataService },
|
||||
{ provide: WorkflowItemDataService, useValue: workflowItemDataService },
|
||||
@@ -96,6 +101,13 @@ describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
|
||||
|
||||
describe('previousPage', () => {
|
||||
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();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/mydspace'], {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import {
|
||||
rendersAdvancedWorkflowTaskOption
|
||||
} from '../../../shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-decorator';
|
||||
@@ -62,6 +63,7 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
|
||||
protected workflowActionService: WorkflowActionDataService,
|
||||
protected claimedTaskDataService: ClaimedTaskDataService,
|
||||
protected requestService: RequestService,
|
||||
protected location: Location,
|
||||
) {
|
||||
super(route, workflowItemService, router, routeService, notificationsService, translationService, workflowActionService, claimedTaskDataService, requestService);
|
||||
}
|
||||
@@ -138,11 +140,11 @@ export class AdvancedWorkflowActionSelectReviewerComponent extends AdvancedWorkf
|
||||
* switching between the different pages
|
||||
*/
|
||||
previousPage(): void {
|
||||
const queryParams: Params = {
|
||||
configuration: 'workflow',
|
||||
};
|
||||
if (hasValue(this.route.snapshot.queryParams.previousSearchQuery)) {
|
||||
queryParams.query = decodeURIComponent(this.route.snapshot.queryParams.previousSearchQuery);
|
||||
let queryParams: Params = (this.location.getState() as { [key: string]: any }).previousQueryParams;
|
||||
if (!hasValue(queryParams)) {
|
||||
queryParams = {
|
||||
configuration: 'workflow',
|
||||
};
|
||||
}
|
||||
void this.router.navigate(['/mydspace'], { queryParams: queryParams });
|
||||
}
|
||||
|
Reference in New Issue
Block a user