Skip to content

Commit

Permalink
feat(website): end URL with & sign
Browse files Browse the repository at this point in the history
Resolves: #454
  • Loading branch information
Jonas Zarzalis (TNG) committed Jan 9, 2025
1 parent bc22289 commit 6107db1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions website/src/util/formatUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function formatUrl(pathname: string, searchParams: URLSearchParams) {
const searchParamsString = searchParams.toString();
return `${pathname}${searchParamsString === '' ? '' : `?${searchParamsString}&`}`;
}
6 changes: 4 additions & 2 deletions website/src/views/covid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { organismConfig, Organisms } from '../types/Organism.ts';
import { type DataOrigin, dataOrigins } from '../types/dataOrigins.ts';
import { SequencingEffortsStateHandler } from './pageStateHandlers/SequencingEffortsPageStateHandler.ts';
import { SingleVariantPageStateHandler } from './pageStateHandlers/SingleVariantPageStateHandler.ts';
import { formatUrl } from '../util/formatUrl.ts';

const earliestDate = '2020-01-06';

Expand Down Expand Up @@ -164,7 +165,7 @@ class CovidSingleVariantStateHandler
if (pageState.collectionId !== undefined) {
search.set('collectionId', pageState.collectionId.toString());
}
return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public override toLapisFilter(pageState: CovidVariantData) {
Expand Down Expand Up @@ -350,7 +351,8 @@ class CovidSequencingEffortsStateHandler
if (pageState.collectionId !== undefined) {
search.set('collectionId', pageState.collectionId.toString());
}
return `${this.pathname}?${search}`;

return formatUrl(this.pathname, search);
}

public override toLapisFilter(pageState: CovidVariantData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
searchParamsFromFilterMap,
toLapisFilterWithoutVariant,
} from './PageStateHandler.ts';
import { formatUrl } from '../../util/formatUrl.ts';

export abstract class CompareSideBySideStateHandler<ColumnData extends DatasetAndVariantData = DatasetAndVariantData>
implements PageStateHandler<CompareSideBySideData<ColumnData>>
Expand Down Expand Up @@ -54,7 +55,7 @@ export abstract class CompareSideBySideStateHandler<ColumnData extends DatasetAn
this.writeColumnDataToSearchParams(search, variant),
);

return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public setFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
toLapisFilterWithoutVariant,
} from './PageStateHandler.ts';
import type { VariantFilterConfig } from '../../components/pageStateSelectors/VariantFilterConfig.ts';
import { formatUrl } from '../../util/formatUrl.ts';

export class CompareToBaselineStateHandler implements PageStateHandler<CompareToBaselineData> {
protected readonly pathname;
Expand Down Expand Up @@ -84,7 +85,7 @@ export class CompareToBaselineStateHandler implements PageStateHandler<CompareTo
getLineageFilterFields(this.constants.lineageFilters),
);

return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public datasetFilterToLapisFilter(baselineFilter: DatasetFilter): LapisFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
toLapisFilterWithoutVariant,
} from './PageStateHandler.ts';
import type { VariantFilterConfig } from '../../components/pageStateSelectors/VariantFilterConfig.ts';
import { formatUrl } from '../../util/formatUrl.ts';

export class CompareVariantsPageStateHandler implements PageStateHandler<CompareVariantsData> {
protected readonly pathname;
Expand Down Expand Up @@ -75,7 +76,7 @@ export class CompareVariantsPageStateHandler implements PageStateHandler<Compare
setSearchFromDateRange(search, this.constants.mainDateField, pageState.datasetFilter.dateRange);
}

return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public datasetFilterToLapisFilter(datasetFilter: DatasetFilter): LapisFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
setSearchFromLocation,
} from '../helpers.ts';
import { type PageStateHandler, toLapisFilterWithoutVariant } from './PageStateHandler.ts';
import { formatUrl } from '../../util/formatUrl.ts';

export class SequencingEffortsStateHandler<PageState extends DatasetAndVariantData = DatasetAndVariantData>
implements PageStateHandler<DatasetAndVariantData>
Expand Down Expand Up @@ -48,7 +49,7 @@ export class SequencingEffortsStateHandler<PageState extends DatasetAndVariantDa
pageState.variantFilter,
getLineageFilterFields(this.constants.lineageFilters),
);
return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public toLapisFilter(pageState: DatasetAndVariantData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
setSearchFromLocation,
} from '../helpers.ts';
import { type PageStateHandler, toLapisFilterWithoutVariant } from './PageStateHandler.ts';
import { formatUrl } from '../../util/formatUrl.ts';

export class SingleVariantPageStateHandler<PageState extends DatasetAndVariantData = DatasetAndVariantData>
implements PageStateHandler<DatasetAndVariantData>
Expand Down Expand Up @@ -51,7 +52,7 @@ export class SingleVariantPageStateHandler<PageState extends DatasetAndVariantDa
pageState.variantFilter,
getLineageFilterFields(this.constants.lineageFilters),
);
return `${this.pathname}?${search}`;
return formatUrl(this.pathname, search);
}

public toLapisFilter(pageState: DatasetAndVariantData) {
Expand Down

0 comments on commit 6107db1

Please sign in to comment.