fix(ui): don't remove ?q= from query args when filter list is empty

This commit is contained in:
Łukasz Mierzwa
2020-05-03 12:28:35 +01:00
committed by Łukasz Mierzwa
parent eef3d675d6
commit 75eeaf233c
2 changed files with 12 additions and 11 deletions

View File

@@ -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({

View File

@@ -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", () => {