111731: Remove empty arrays from query Params, since they can cause the labels to temporarily display undefined for a few milliseconds

This commit is contained in:
Alexandre Vryghem
2024-02-15 00:41:13 +01:00
parent 47f89a6f9d
commit a6675b8983
2 changed files with 15 additions and 0 deletions

View File

@@ -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) => {

View File

@@ -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;
}),