Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance search by filtering by URL, hostname and dns resolve server #5438

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
24 changes: 19 additions & 5 deletions src/components/MonitorList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,25 @@ export default {
// finds monitor name, tag name or tag value
let searchTextMatch = true;
if (this.searchText !== "") {
const loweredSearchText = this.searchText.toLowerCase();
searchTextMatch =
monitor.name.toLowerCase().includes(loweredSearchText)
|| monitor.tags.find(tag => tag.name.toLowerCase().includes(loweredSearchText)
|| tag.value?.toLowerCase().includes(loweredSearchText));
try {
// Escape special characters for use in the regular expression
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

const escapedSearchText = escapeRegExp(this.searchText);
const regex = new RegExp(escapedSearchText, "i");

const safeRegexTest = (str) => str && regex.test(str);

searchTextMatch =
regex.test(monitor.name) ||
safeRegexTest(monitor.url) ||
safeRegexTest(monitor.hostname) ||
safeRegexTest(monitor.dns_resolve_server) ||
monitor.tags.some(tag => regex.test(tag.name) || safeRegexTest(tag.value));
} catch (e) {
console.error("Invalid regex pattern:", e);
searchTextMatch = false;
}
}

// filter by status
Expand Down
Loading