Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove quotation marks from url #345

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 65 additions & 14 deletions src/app/core/services/filters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,53 @@ export class FiltersService {
) {}

private pushFiltersToUrl(): void {
const queryParams = {};
const queryParams = { ...this.route.snapshot.queryParams };

for (const filterName of Object.keys(this.filter$.value)) {
if (this.filter$.value[filterName] instanceof Set) {
queryParams[filterName] = JSON.stringify([...this.filter$.value[filterName]]);
} else {
queryParams[filterName] = JSON.stringify(this.filter$.value[filterName]);
const filterValue = this.filter$.value[filterName];

// Don't include empty or null filters
// Intended behaviour to reset to default if 0 of a certain filter are selected
switch (filterName) {
// Strings
case 'title':
case 'type':
if (!filterValue) {
delete queryParams[filterName];
continue;
}
queryParams[filterName] = filterValue;
break;
// Arrays
case 'status':
case 'labels':
case 'milestones':
if (filterValue.length === 0) {
delete queryParams[filterName];
continue;
}
queryParams[filterName] = filterValue;
break;
// Sets
case 'selectedLabels':
case 'deselectedLabels':
if (filterValue.size === 0) {
delete queryParams[filterName];
}
queryParams[filterName] = [...filterValue];
break;
// Objects
case 'sort':
queryParams[filterName] = JSON.stringify(filterValue);
break;
default:
}
}
queryParams[FiltersService.PRESET_VIEW_QUERY_PARAM_KEY] = this.presetView$.value;

this.router.navigate([], {
relativeTo: this.route,
queryParams,
queryParamsHandling: 'merge',
replaceUrl: true
});
}
Expand All @@ -100,7 +133,6 @@ export class FiltersService {
const queryParams = this.route.snapshot.queryParamMap;
try {
const presetView = queryParams.get(FiltersService.PRESET_VIEW_QUERY_PARAM_KEY);

// Use preset view if set in url
if (presetView && this.presetViews.hasOwnProperty(presetView) && presetView !== 'custom') {
this.updatePresetView(presetView);
Expand All @@ -114,16 +146,35 @@ export class FiltersService {
}

for (const filterName of Object.keys(nextFilter)) {
const stringifiedFilterData = queryParams.get(filterName);
if (!stringifiedFilterData) {
// Check if there is no such param in url
if (queryParams.get(filterName) === null) {
continue;
}
const filterData = JSON.parse(stringifiedFilterData);

if (nextFilter[filterName] instanceof Set) {
nextFilter[filterName] = new Set(filterData);
} else {
nextFilter[filterName] = filterData;
const filterData = queryParams.getAll(filterName);

switch (filterName) {
// Strings
case 'title':
case 'type':
nextFilter[filterName] = filterData[0];
break;
// Arrays
case 'status':
case 'labels':
case 'milestones':
nextFilter[filterName] = filterData;
break;
// Sets
case 'selectedLabels':
case 'deselectedLabels':
nextFilter[filterName] = new Set(filterData);
break;
// Objects
case 'sort':
nextFilter[filterName] = JSON.parse(filterData[0]);
break;
default:
}
}
this.updateFilters(nextFilter);
Expand Down
Loading