Clear url parameters for entity search tabs (#2734)

* 110878: Entity search - clear params on tab switch

* 110878: Properly clear browse-by values when navigating

* 132230: Related entity tab switching: only keep query & scope, reset page to 1

---------

Co-authored-by: Nona Luypaert <nona.luypaert@atmire.com>
This commit is contained in:
Atmire-Kristof
2025-09-05 23:46:44 +02:00
committed by GitHub
parent c48c4ad6c7
commit bf24baf630
7 changed files with 22 additions and 11 deletions

View File

@@ -248,6 +248,8 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
if (typeof params.startsWith === 'string') { if (typeof params.startsWith === 'string') {
this.startsWith = params.startsWith.trim(); this.startsWith = params.startsWith.trim();
} else {
this.startsWith = '';
} }
if (isNotEmpty(this.value)) { if (isNotEmpty(this.value)) {

View File

@@ -44,6 +44,12 @@ describe('TabbedRelatedEntitiesSearchComponent', () => {
provide: ActivatedRoute, provide: ActivatedRoute,
useValue: { useValue: {
queryParams: of({ tab: mockRelationType }), queryParams: of({ tab: mockRelationType }),
snapshot: {
queryParams: {
scope: 'collection-uuid',
query: 'test',
},
},
}, },
}, },
{ provide: Router, useValue: router }, { provide: Router, useValue: router },
@@ -89,8 +95,10 @@ describe('TabbedRelatedEntitiesSearchComponent', () => {
relativeTo: (comp as any).route, relativeTo: (comp as any).route,
queryParams: { queryParams: {
tab: event.nextId, tab: event.nextId,
query: 'test',
scope: 'collection-uuid',
'spc.page': 1,
}, },
queryParamsHandling: 'merge',
}); });
}); });
}); });

View File

@@ -89,8 +89,10 @@ export class TabbedRelatedEntitiesSearchComponent implements OnInit {
relativeTo: this.route, relativeTo: this.route,
queryParams: { queryParams: {
tab: event.nextId, tab: event.nextId,
query: this.route.snapshot.queryParams.query,
scope: this.route.snapshot.queryParams.scope,
'spc.page': 1,
}, },
queryParamsHandling: 'merge',
}); });
} }

View File

@@ -1,6 +1,6 @@
<div class="d-flex flex-row"> <div class="d-flex flex-row">
@if (linkType !== linkTypes.None) { @if (linkType !== linkTypes.None) {
<a [target]="(linkType === linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType === linkTypes.ExternalLink) ? 'noopener noreferrer' : null" [routerLink]="[]" [queryParams]="queryParams$ | async" [queryParamsHandling]="'merge'" class="lead" role="link" tabindex="0"> <a [target]="(linkType === linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType === linkTypes.ExternalLink) ? 'noopener noreferrer' : null" [routerLink]="[]" [queryParams]="queryParams$ | async" class="lead" role="link" tabindex="0">
{{object.value}} {{object.value}}
</a> </a>
} }

View File

@@ -100,7 +100,7 @@ describe('StartsWithDateComponent', () => {
}); });
it('should add a startsWith query parameter', () => { it('should add a startsWith query parameter', () => {
expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }); expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }, undefined, { queryParamsHandling: '' });
}); });
it('should automatically fill in the input field', () => { it('should automatically fill in the input field', () => {
@@ -122,7 +122,7 @@ describe('StartsWithDateComponent', () => {
}); });
it('should add a startsWith query parameter', () => { it('should add a startsWith query parameter', () => {
expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }); expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }, undefined, { queryParamsHandling: '' });
}); });
it('should automatically fill in the input field', () => { it('should automatically fill in the input field', () => {
@@ -146,7 +146,7 @@ describe('StartsWithDateComponent', () => {
}); });
it('should add a startsWith query parameter', () => { it('should add a startsWith query parameter', () => {
expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }); expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }, undefined, { queryParamsHandling: '' });
}); });
it('should automatically fill in the input field', () => { it('should automatically fill in the input field', () => {
@@ -171,7 +171,7 @@ describe('StartsWithDateComponent', () => {
}); });
it('should add a startsWith query parameter', () => { it('should add a startsWith query parameter', () => {
expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }); expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }, undefined, { queryParamsHandling: '' });
}); });
}); });

View File

@@ -92,11 +92,10 @@ export abstract class StartsWithAbstractComponent implements OnInit, OnDestroy {
this.startsWith = undefined; this.startsWith = undefined;
} }
if (resetPage) { if (resetPage) {
this.paginationService.updateRoute(this.paginationId, { page: 1 }, { startsWith: this.startsWith }); this.paginationService.updateRoute(this.paginationId, { page: 1 }, { startsWith: this.startsWith }, undefined, { queryParamsHandling: '' });
} else { } else {
void this.router.navigate([], { void this.router.navigate([], {
queryParams: Object.assign({ startsWith: this.startsWith }), queryParams: Object.assign({ startsWith: this.startsWith }),
queryParamsHandling: 'merge',
}); });
} }
} }

View File

@@ -74,8 +74,8 @@ describe('StartsWithTextComponent', () => {
expect(comp.startsWith).toEqual(expectedValue); expect(comp.startsWith).toEqual(expectedValue);
}); });
it('should add a startsWith query parameter', () => { it('should add a startsWith query parameter and clear all others', () => {
expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }); expect(paginationService.updateRoute).toHaveBeenCalledWith('page-id', { page: 1 }, { startsWith: expectedValue }, undefined, { queryParamsHandling: '' });
}); });
}); });