diff --git a/website/src/util/formatUrl.ts b/website/src/util/formatUrl.ts new file mode 100644 index 00000000..f01ad61c --- /dev/null +++ b/website/src/util/formatUrl.ts @@ -0,0 +1,4 @@ +export function formatUrl(pathname: string, searchParams: URLSearchParams) { + const searchParamsString = searchParams.toString(); + return `${pathname}${searchParamsString === '' ? '' : `?${searchParamsString}&`}`; +} diff --git a/website/src/views/covid.ts b/website/src/views/covid.ts index dc26d81a..23b77b80 100644 --- a/website/src/views/covid.ts +++ b/website/src/views/covid.ts @@ -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'; @@ -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) { @@ -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) { diff --git a/website/src/views/pageStateHandlers/CompareSideBySidePageStateHandler.ts b/website/src/views/pageStateHandlers/CompareSideBySidePageStateHandler.ts index 4f4b42e1..a6ddd0a7 100644 --- a/website/src/views/pageStateHandlers/CompareSideBySidePageStateHandler.ts +++ b/website/src/views/pageStateHandlers/CompareSideBySidePageStateHandler.ts @@ -18,6 +18,7 @@ import { searchParamsFromFilterMap, toLapisFilterWithoutVariant, } from './PageStateHandler.ts'; +import { formatUrl } from '../../util/formatUrl.ts'; export abstract class CompareSideBySideStateHandler implements PageStateHandler> @@ -54,7 +55,7 @@ export abstract class CompareSideBySideStateHandler { protected readonly pathname; @@ -84,7 +85,7 @@ export class CompareToBaselineStateHandler implements PageStateHandler { protected readonly pathname; @@ -75,7 +76,7 @@ export class CompareVariantsPageStateHandler implements PageStateHandler implements PageStateHandler @@ -48,7 +49,7 @@ export class SequencingEffortsStateHandler implements PageStateHandler @@ -51,7 +52,7 @@ export class SingleVariantPageStateHandler