From 75eeaf233cd2141975fe06eed6f1f637d2205c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sun, 3 May 2020 12:28:35 +0100 Subject: [PATCH] fix(ui): don't remove ?q= from query args when filter list is empty --- ui/src/Stores/AlertStore.js | 16 ++++++---------- ui/src/Stores/AlertStore.test.js | 7 ++++++- 2 files changed, 12 insertions(+), 11 deletions(-) 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", () => {