From a6675b89838aed13d112e93797d74e68835be548 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 15 Feb 2024 00:41:13 +0100 Subject: [PATCH] 111731: Remove empty arrays from query Params, since they can cause the labels to temporarily display undefined for a few milliseconds --- src/app/core/services/route.service.spec.ts | 12 ++++++++++++ src/app/core/services/route.service.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/app/core/services/route.service.spec.ts b/src/app/core/services/route.service.spec.ts index 802368f38df..93525ac8183 100644 --- a/src/app/core/services/route.service.spec.ts +++ b/src/app/core/services/route.service.spec.ts @@ -201,6 +201,18 @@ describe('RouteService', () => { }); }); + it('should remove the parameter completely if only one value is defined in an array', (done: DoneFn) => { + route.testParams['f.author'] = ['1282121b-5394-4689-ab93-78d537764052,authority']; + service.getParamsExceptValue('f.author', '1282121b-5394-4689-ab93-78d537764052,authority').pipe(take(1)).subscribe((params: Params) => { + expect(params).toEqual({ + 'query': '', + 'spc.page': '1', + 'f.has_content_in_original_bundle': 'true,equals', + }); + done(); + }); + }); + it('should return all params except the applied filter even when multiple filters of the same type are selected', (done: DoneFn) => { route.testParams['f.author'] = ['1282121b-5394-4689-ab93-78d537764052,authority', '71b91a28-c280-4352-a199-bd7fc3312501,authority']; service.getParamsExceptValue('f.author', '1282121b-5394-4689-ab93-78d537764052,authority').pipe(take(1)).subscribe((params: Params) => { diff --git a/src/app/core/services/route.service.ts b/src/app/core/services/route.service.ts index 6c5b73f7558..5c28d3f5fd2 100644 --- a/src/app/core/services/route.service.ts +++ b/src/app/core/services/route.service.ts @@ -242,6 +242,9 @@ export class RouteService { delete newParams[name]; } else if (Array.isArray(queryParamValues) && queryParamValues.includes(value)) { newParams[name] = (queryParamValues as string[]).filter((paramValue: string) => paramValue !== value); + if (newParams[name].length === 0) { + delete newParams[name]; + } } return newParams; }),