Compare commits

...

4 commits

Author SHA1 Message Date
Suven-p
d552975d6c Display toast on invalid query params 2024-10-28 07:21:28 +05:45
Suven-p
baf0a1bdb9 Refactor 2024-10-28 06:05:35 +05:45
Suven-p
dfb1b97780 Use default value to remove unused filters from query params 2024-10-28 06:01:35 +05:45
Suven-p
177363ac60 Revert "Delete query params if empty"
This reverts commit 2e18a19a9e.
2024-10-28 05:50:50 +05:45
3 changed files with 61 additions and 45 deletions

View file

@ -160,32 +160,34 @@ export default {
/**
* Returns applied filters based on query params.
* @returns {{ status: number[], active: bool, tags: number[] }} The current filter state.
* @returns {{ status: number[], active: any[], tags: number[] }} The current filter state.
*/
filterState() {
// Since query params are always strings, convert them to the correct type
let status = this.$route.query["status"] || null;
if (status) {
if (!Array.isArray(status)) {
status = [ status ];
}
status = status.map(Number);
let status = this.$route.query["status"] || [];
if (!Array.isArray(status)) {
status = [ status ];
}
status = status.map(Number);
// Casting to boolean does not work here as Boolean("false") === true
let active = this.$route.query["active"] || null;
if (active) {
if (!Array.isArray(active)) {
active = [ active ];
}
active = active.map(val => val === "true");
let active = this.$route.query["active"] || [];
if (!Array.isArray(active)) {
active = [ active ];
}
let tags = this.$route.query["tags"] || null;
if (tags) {
if (!Array.isArray(tags)) {
tags = [ tags ];
active = active.map(val => {
if (val === "true") {
return true;
}
tags = tags.map(Number);
if (val === "false") {
return false;
}
return val;
});
let tags = this.$route.query["tags"] || [];
if (!Array.isArray(tags)) {
tags = [ tags ];
}
tags = tags.map(Number);
return {
status,
active,
@ -198,12 +200,11 @@ export default {
return this.$route.query.searchText || "";
},
set(value) {
const newQuery = {
...this.$route.query,
searchText: value,
};
if (!value) {
let newQuery = { ...this.$route.query };
if (value === "") {
delete newQuery.searchText;
} else {
newQuery.searchText = value;
}
this.$router.replace({
query: newQuery,
@ -286,26 +287,17 @@ export default {
},
/**
* Update the MonitorList Filter
* @param {{ status: number[], active: bool, tags: number[] }} newFilter Object with new filter
* @param {{ status: number[], active: any[], tags: number[] }} newFilter Object with new filter
* @returns {void}
*/
updateFilter(newFilter) {
let newQuery = {
...this.$route.query,
...newFilter,
};
if (!newFilter.status || newFilter.status.length === 0) {
delete newQuery.status;
}
if (!newFilter.active || newFilter.active.length === 0) {
delete newQuery.active;
}
if (!newFilter.tags || newFilter.tags.length === 0) {
delete newQuery.tags;
}
this.$router.replace({
query: newQuery,
query: {
...this.$route.query,
status: newFilter.status,
active: newFilter.active,
tags: newFilter.tags,
},
});
},
/**

View file

@ -80,8 +80,9 @@
<MonitorListFilterDropdown :filterActive="filterState.active?.length > 0">
<template #status>
<span v-if="filterState.active?.length === 1">
<span v-if="filterState.active[0]">{{ $t("Running") }}</span>
<span v-else>{{ $t("filterActivePaused") }}</span>
<span v-if="filterState.active[0] === true">{{ $t("Running") }}</span>
<span v-else-if="filterState.active[0] === false">{{ $t("filterActivePaused") }}</span>
<span v-else>{{ $t("Unknown") }}</span>
</span>
<span v-else>
{{ $t("filterActive") }}
@ -186,10 +187,31 @@ export default {
});
return num;
},
/**
* Returns an array of invalid filters assuming tagsList has been fetched
* @returns {Array} Array of invalid filters
*/
invalidFilters() {
const filters = [];
if (!this.filterState.status.every((val) => val >= 0 && val <= 3)) {
filters.push(this.$t("Status"));
}
if (!this.filterState.active.every((val) => val === true || val === false)) {
filters.push(this.$t("Active"));
}
if (!this.filterState.tags.every((val) => this.tagsList.find(tag => tag.id === val))) {
filters.push(this.$t("Tags"));
}
return filters;
}
},
mounted() {
this.getExistingTags();
this.getExistingTags(() => {
if (this.invalidFilters.length > 0) {
this.$root.toastError(this.$t("InvalidFilters", [ this.invalidFilters.join(", ") ]));
}
});
},
methods: {
toggleStatusFilter(status) {
@ -242,14 +264,15 @@ export default {
},
clearFilters() {
this.$emit("updateFilter", {
status: null,
status: [],
});
},
getExistingTags() {
getExistingTags(callback) {
this.$root.getSocket().emit("getTags", (res) => {
if (res.ok) {
this.tagsList = res.tags;
}
callback();
});
},
getTaggedMonitorCount(tag) {

View file

@ -1060,5 +1060,6 @@
"RabbitMQ Password": "RabbitMQ Password",
"rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.",
"SendGrid API Key": "SendGrid API Key",
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas",
"InvalidFilters": "The following filters are invalid: {0}"
}