Use default value to remove unused filters from query params

pull/5248/head
Suven-p 2 months ago
parent 177363ac60
commit dfb1b97780

@ -164,7 +164,7 @@ export default {
*/ */
filterState() { filterState() {
// Since query params are always strings, convert them to the correct type // Since query params are always strings, convert them to the correct type
let status = this.$route.query["status"] || null; let status = this.$route.query["status"] || [];
if (status) { if (status) {
if (!Array.isArray(status)) { if (!Array.isArray(status)) {
status = [ status ]; status = [ status ];
@ -172,14 +172,14 @@ export default {
status = status.map(Number); status = status.map(Number);
} }
// Casting to boolean does not work here as Boolean("false") === true // Casting to boolean does not work here as Boolean("false") === true
let active = this.$route.query["active"] || null; let active = this.$route.query["active"] || [];
if (active) { if (active) {
if (!Array.isArray(active)) { if (!Array.isArray(active)) {
active = [ active ]; active = [ active ];
} }
active = active.map(val => val === "true"); active = active.map(val => val === "true");
} }
let tags = this.$route.query["tags"] || null; let tags = this.$route.query["tags"] || [];
if (tags) { if (tags) {
if (!Array.isArray(tags)) { if (!Array.isArray(tags)) {
tags = [ tags ]; tags = [ tags ];
@ -198,11 +198,14 @@ export default {
return this.$route.query.searchText || ""; return this.$route.query.searchText || "";
}, },
set(value) { set(value) {
this.$router.replace({ let newQuery = { ...this.$route.query };
query: { if (value === "") {
...this.$route.query, delete newQuery.searchText;
searchText: value, } else {
newQuery.searchText = value;
} }
this.$router.replace({
query: newQuery,
}); });
} }
}, },

@ -242,7 +242,7 @@ export default {
}, },
clearFilters() { clearFilters() {
this.$emit("updateFilter", { this.$emit("updateFilter", {
status: null, status: [],
}); });
}, },
getExistingTags() { getExistingTags() {

Loading…
Cancel
Save