Use default value to remove unused filters from query params

This commit is contained in:
Suven-p 2024-10-28 06:01:35 +05:45
parent 177363ac60
commit dfb1b97780
2 changed files with 11 additions and 8 deletions

View file

@ -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) {
let newQuery = { ...this.$route.query };
if (value === "") {
delete newQuery.searchText;
} else {
newQuery.searchText = value;
}
this.$router.replace({ this.$router.replace({
query: { query: newQuery,
...this.$route.query,
searchText: value,
}
}); });
} }
}, },

View file

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