Skip to content

Commit

Permalink
111731: Remove empty arrays from query Params, since they can cause t…
Browse files Browse the repository at this point in the history
…he labels to temporarily display undefined for a few milliseconds
  • Loading branch information
alexandrevryghem committed Feb 15, 2024
1 parent 47f89a6 commit a6675b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app/core/services/route.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/services/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
Expand Down

0 comments on commit a6675b8

Please sign in to comment.