From f8fa8070ecabd1abf7540600dfc9802c99a95140 Mon Sep 17 00:00:00 2001 From: "Jonas Zarzalis (TNG)" Date: Thu, 9 Jan 2025 10:08:26 +0100 Subject: [PATCH] feat(website): end URL with & sign Resolves: #454 --- website/src/util/formatUrl.ts | 4 ++++ website/src/views/covid.ts | 6 ++++-- .../CompareSideBySidePageStateHandler.ts | 3 ++- .../CompareToBaselinePageStateHandler.spec.ts | 8 +++++--- .../CompareToBaselinePageStateHandler.ts | 3 ++- .../CompareVariantsPageStateHandler.spec.ts | 8 +++++--- .../pageStateHandlers/CompareVariantsPageStateHandler.ts | 3 ++- .../SequencingEffortsPageStateHandler.ts | 3 ++- .../pageStateHandlers/SingleVariantPageStateHandler.ts | 3 ++- 9 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 website/src/util/formatUrl.ts 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 { it('should return the default page URL', () => { const url = handler.getDefaultPageUrl(); - expect(url).toBe('/testPath/compare-to-baseline?date=Last+7+Days'); + expect(url).toBe('/testPath/compare-to-baseline?date=Last+7+Days&'); }); it('should parse page state from URL, including variants', () => { @@ -51,7 +51,8 @@ describe('CompareToBaselinePageStateHandler', () => { 'country=US&date=Last 7 Days' + '&lineage=B.2.3.4&nucleotideMutations=C234G' + '&lineage$1=B.1.1.7&nucleotideMutations$1=D614G' + - '&lineage$2=A.1.2.3&aminoAcidMutations$2=S:A123T', + '&lineage$2=A.1.2.3&aminoAcidMutations$2=S:A123T' + + '&', ); const pageState = handler.parsePageStateFromUrl(url); @@ -114,7 +115,8 @@ describe('CompareToBaselinePageStateHandler', () => { 'nucleotideMutations%241=D614G&lineage%241=B.1.1.7' + '&aminoAcidMutations%242=S%3AA123T&lineage%242=A.1.2.3' + '&country=US' + - '&nucleotideMutations=C234G&lineage=B.2.3.4', + '&nucleotideMutations=C234G&lineage=B.2.3.4' + + '&', ); }); diff --git a/website/src/views/pageStateHandlers/CompareToBaselinePageStateHandler.ts b/website/src/views/pageStateHandlers/CompareToBaselinePageStateHandler.ts index 9d541dc0..bb768dbc 100644 --- a/website/src/views/pageStateHandlers/CompareToBaselinePageStateHandler.ts +++ b/website/src/views/pageStateHandlers/CompareToBaselinePageStateHandler.ts @@ -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 { protected readonly pathname; @@ -84,7 +85,7 @@ export class CompareToBaselineStateHandler implements PageStateHandler { it('should return the default page URL', () => { const url = handler.getDefaultPageUrl(); - expect(url).toBe('/testPath/compare-variants?date=Last+7+Days'); + expect(url).toBe('/testPath/compare-variants?date=Last+7+Days&'); }); it('should parse page state from URL, including variants', () => { const url = new URL( 'http://example.com/testPath/compareVariants?country=US&date=Last 7 Days' + '&lineage$1=B.1.1.7&nucleotideMutations$1=D614G' + - '&lineage$2=A.1.2.3&aminoAcidMutations$2=S:A123T', + '&lineage$2=A.1.2.3&aminoAcidMutations$2=S:A123T' + + '&', ); const pageState = handler.parsePageStateFromUrl(url); @@ -92,7 +93,8 @@ describe('CompareVariantsPageStateHandler', () => { '/testPath/compare-variants?' + 'nucleotideMutations%241=D614G&lineage%241=B.1.1.7' + '&aminoAcidMutations%242=S%3AA123T&lineage%242=A.1.2.3' + - '&country=US', + '&country=US' + + '&', ); }); diff --git a/website/src/views/pageStateHandlers/CompareVariantsPageStateHandler.ts b/website/src/views/pageStateHandlers/CompareVariantsPageStateHandler.ts index 54c10fb1..0c7fe632 100644 --- a/website/src/views/pageStateHandlers/CompareVariantsPageStateHandler.ts +++ b/website/src/views/pageStateHandlers/CompareVariantsPageStateHandler.ts @@ -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 { 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