diff --git a/src/app/item-page/versions/notice/item-versions-notice.component.spec.ts b/src/app/item-page/versions/notice/item-versions-notice.component.spec.ts index ea5f1881a59..2b3270442d8 100644 --- a/src/app/item-page/versions/notice/item-versions-notice.component.spec.ts +++ b/src/app/item-page/versions/notice/item-versions-notice.component.spec.ts @@ -12,8 +12,6 @@ import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.u import { createPaginatedList } from '../../../shared/testing/utils.test'; import { of } from 'rxjs'; import { take } from 'rxjs/operators'; -import { ActivatedRoute, Router } from '@angular/router'; -import { MockActivatedRoute } from '../../../shared/mocks/active-router.mock'; describe('ItemVersionsNoticeComponent', () => { let component: ItemVersionsNoticeComponent; @@ -58,19 +56,12 @@ describe('ItemVersionsNoticeComponent', () => { ['getVersions', 'getLatestVersionFromHistory$', 'isLatest$', ] ); - let router: Router; - let activatedRoute: ActivatedRoute; - beforeEach(waitForAsync(() => { - router = jasmine.createSpyObj('router', ['createUrlTree']); - TestBed.configureTestingModule({ declarations: [ItemVersionsNoticeComponent], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], providers: [ - { provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy }, - { provide: Router, useValue: router }, - { provide: ActivatedRoute, useValue: new MockActivatedRoute() }, + { provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/item-page/versions/notice/item-versions-notice.component.ts b/src/app/item-page/versions/notice/item-versions-notice.component.ts index 6a127f73b53..37f81976132 100644 --- a/src/app/item-page/versions/notice/item-versions-notice.component.ts +++ b/src/app/item-page/versions/notice/item-versions-notice.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Inject, Input, OnInit } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { Observable, of } from 'rxjs'; import { RemoteData } from '../../../core/data/remote-data'; @@ -13,8 +13,7 @@ import { import { map, startWith, switchMap } from 'rxjs/operators'; import { VersionHistoryDataService } from '../../../core/data/version-history-data.service'; import { AlertType } from '../../../shared/alert/alert-type'; -import { getItemPageRoute } from '../../item-page-routing-paths'; -import { ActivatedRoute, Router } from '@angular/router'; +import { DOCUMENT } from '@angular/common'; @Component({ selector: 'ds-item-versions-notice', @@ -51,10 +50,6 @@ export class ItemVersionsNoticeComponent implements OnInit { */ showLatestVersionNotice$: Observable; - /** - * Pagination options to fetch a single version on the first page (this is the latest version in the history) - */ - /** * The AlertType enumeration * @type {AlertType} @@ -67,8 +62,7 @@ export class ItemVersionsNoticeComponent implements OnInit { destinationUrl$: Observable; constructor(private versionHistoryService: VersionHistoryDataService, - private router: Router, - private activatedRoute: ActivatedRoute) { + @Inject(DOCUMENT) private document: Document ) { } /** @@ -96,27 +90,27 @@ export class ItemVersionsNoticeComponent implements OnInit { startWith(false), ); } + // Compute the destination URL from latestVersion$ with the namespace this.destinationUrl$ = this.latestVersion$.pipe( switchMap(latestVersion => latestVersion?.item || of(null)), map(item => { - const routeCommands = [this.getItemPage(item?.payload)]; // e.g., ['/items/xyz'] + const itemId = item?.payload?.uuid; + + if (!itemId) { + console.error('No valid UUID found in payload'); + return this.document.location.pathname; // Fallback to the current path if extraction fails + } - // Use the current ActivatedRoute to make it work like [routerLink] - const urlTree = this.router.createUrlTree(routeCommands, { relativeTo: this.activatedRoute }); + // Get the base URL dynamically - with the namespace. Remove the last part of the path (the item UUID). + const baseUrl = this.document.location.pathname.split('/').slice(0, -1).join('/'); - return this.router.serializeUrl(urlTree); // Get the final URL string + // Construct the final URL dynamically + const finalUrl = `${baseUrl}/${itemId}`; + + return finalUrl; }) ); } - /** - * Get the item page url - * @param item The item for which the url is requested - */ - getItemPage(item: Item): string { - if (hasValue(item)) { - return getItemPageRoute(item); - } - } }