diff --git a/ui/src/Stores/AlertStore.js b/ui/src/Stores/AlertStore.js index 3fe084904..a911bd39e 100644 --- a/ui/src/Stores/AlertStore.js +++ b/ui/src/Stores/AlertStore.js @@ -66,16 +66,12 @@ function DecodeLocationSearch(searchString) { function UpdateLocationSearch(newParams) { const baseURLWithoutSearch = window.location.href.split("?")[0]; - const newSearch = FormatAPIFilterQuery(newParams.q || []); - if (newSearch !== "") { - window.history.pushState( - null, - null, - `${baseURLWithoutSearch}?${newSearch}` - ); - } else { - window.history.pushState(null, null, baseURLWithoutSearch); - } + const newSearch = FormatAPIFilterQuery(newParams.q); + window.history.pushState( + null, + null, + `${baseURLWithoutSearch}?${newSearch || "q="}` + ); } const AlertStoreStatuses = Object.freeze({ diff --git a/ui/src/Stores/AlertStore.test.js b/ui/src/Stores/AlertStore.test.js index 1a951fb1a..13f6658d3 100644 --- a/ui/src/Stores/AlertStore.test.js +++ b/ui/src/Stores/AlertStore.test.js @@ -383,13 +383,18 @@ describe("UpdateLocationSearch", () => { it("{a: foo} is not pushed to location.search", () => { UpdateLocationSearch({ a: "foo" }); - expect(window.location.search).toBe(""); + expect(window.location.search).toBe("?q="); }); it("{a: foo, q: bar} is pushed to location.search", () => { UpdateLocationSearch({ a: "foo", q: "bar" }); expect(window.location.search).toBe("?q=bar"); }); + + it("{q: [1, 2]} is pushed to location.search", () => { + UpdateLocationSearch({ q: ["1", "2"] }); + expect(window.location.search).toBe("?q=1&q=2"); + }); }); describe("AlertStore.fetch", () => {