diff --git a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.html b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.html
index 67249b085ad..da69f8258f2 100644
--- a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.html
+++ b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.html
@@ -7,11 +7,10 @@
{{headerMessage | translate: {id: item.handle} }}
-
-
diff --git a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.spec.ts b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.spec.ts
index 244c0824054..ebdb8e822b4 100644
--- a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.spec.ts
+++ b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.spec.ts
@@ -83,7 +83,13 @@ describe('AbstractSimpleItemActionComponent', () => {
itemPageUrl = `fake-url/${mockItem.id}`;
routerStub = Object.assign(new RouterStub(), {
url: `${itemPageUrl}/edit`,
+ lastSuccessfulNavigation: {
+ previousNavigation: {
+ finalUrl: { toString: () => '/admin/search' },
+ },
+ },
});
+ routerStub.navigateByUrl = jasmine.createSpy('navigateByUrl');
mockItemDataService = jasmine.createSpyObj({
findById: createSuccessfulRemoteDataObject$(mockItem),
@@ -148,18 +154,28 @@ describe('AbstractSimpleItemActionComponent', () => {
expect(comp.performAction).toHaveBeenCalled();
});
- it('should process a RemoteData to navigate and display success notification', () => {
+ it('should navigate to previous URL and show success notification on success', () => {
comp.processRestResponse(successfulRemoteData);
expect(notificationsServiceStub.success).toHaveBeenCalled();
- expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditRoute(mockItem)]);
+ expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/admin/search');
});
- it('should process a RemoteData to navigate and display success notification', () => {
+ it('should navigate to previous URL and show error notification on failure', () => {
comp.processRestResponse(failedRemoteData);
expect(notificationsServiceStub.error).toHaveBeenCalled();
- expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditRoute(mockItem)]);
+ expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/admin/search');
+ });
+
+ it('should navigate to item edit route when no previous URL exists', () => {
+ routerStub.lastSuccessfulNavigation = null;
+ comp.ngOnInit();
+ fixture.detectChanges();
+
+ comp.processRestResponse(failedRemoteData);
+
+ expect(routerStub.navigateByUrl).toHaveBeenCalledWith(getItemEditRoute(mockItem));
});
});
diff --git a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.ts b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.ts
index f1608a7e6b3..f7e669d8843 100644
--- a/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.ts
+++ b/src/app/item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.ts
@@ -27,7 +27,6 @@ import {
import { getItemEditRoute } from '../../item-page-routing-paths';
import { findSuccessfulAccordingTo } from '../edit-item-operators';
import { ModifyItemOverviewComponent } from '../modify-item-overview/modify-item-overview.component';
-
/**
* Component to render and handle simple item edit actions such as withdrawal and reinstatement.
* This component is not meant to be used itself but to be extended.
@@ -57,6 +56,8 @@ export class AbstractSimpleItemActionComponent implements OnInit {
*/
itemPageRoute: string;
+ returnUrl: string;
+
protected predicate: Predicate>;
constructor(protected route: ActivatedRoute,
@@ -67,22 +68,28 @@ export class AbstractSimpleItemActionComponent implements OnInit {
}
ngOnInit(): void {
+ const previousUrl = this.router.lastSuccessfulNavigation?.previousNavigation?.finalUrl?.toString();
+ this.returnUrl = previousUrl ?? null;
+
this.itemRD$ = this.route.data.pipe(
map((data) => data.dso),
getFirstSucceededRemoteData(),
- )as Observable>;
+ ) as Observable>;
this.itemRD$.pipe(first()).subscribe((rd) => {
this.item = rd.payload;
this.itemPageRoute = getItemPageRoute(this.item);
- },
- );
+ if (!this.returnUrl) {
+ this.returnUrl = getItemEditRoute(this.item);
+ }
+ });
this.confirmMessage = 'item.edit.' + this.messageKey + '.confirm';
this.cancelMessage = 'item.edit.' + this.messageKey + '.cancel';
this.headerMessage = 'item.edit.' + this.messageKey + '.header';
this.descriptionMessage = 'item.edit.' + this.messageKey + '.description';
}
+
/**
* Perform the operation linked to this action
*/
@@ -100,11 +107,11 @@ export class AbstractSimpleItemActionComponent implements OnInit {
findSuccessfulAccordingTo((itemRd: RemoteData- ) => this.predicate(itemRd)),
).subscribe(() => {
this.notificationsService.success(this.translateService.get('item.edit.' + this.messageKey + '.success'));
- this.router.navigate([getItemEditRoute(this.item)]);
+ this.router.navigateByUrl(this.returnUrl);
});
} else {
this.notificationsService.error(this.translateService.get('item.edit.' + this.messageKey + '.error'));
- this.router.navigate([getItemEditRoute(this.item)]);
+ this.router.navigateByUrl(this.returnUrl);
}
}