feat: Set default friendly name using hostname or the URL host (#5795)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
happy-game
2025-05-08 17:06:14 +08:00
committed by GitHub
parent eb18677e4f
commit 86b3ef9c86
3 changed files with 108 additions and 1 deletions

View File

@@ -64,6 +64,7 @@
"Expected Value": "Expected Value",
"Json Query Expression": "Json Query Expression",
"Friendly Name": "Friendly Name",
"defaultFriendlyName": "New Monitor",
"URL": "URL",
"Hostname": "Hostname",
"Host URL": "Host URL",

View File

@@ -109,7 +109,7 @@
<!-- Friendly Name -->
<div class="my-3">
<label for="name" class="form-label">{{ $t("Friendly Name") }}</label>
<input id="name" v-model="monitor.name" type="text" class="form-control" required data-testid="friendly-name-input">
<input id="name" v-model="monitor.name" type="text" class="form-control" data-testid="friendly-name-input" :placeholder="defaultFriendlyName">
</div>
<!-- URL -->
@@ -1157,6 +1157,25 @@ export default {
},
computed: {
defaultFriendlyName() {
if (this.monitor.hostname) {
return this.monitor.hostname;
}
if (this.monitor.url) {
if (this.monitor.url !== "http://" && this.monitor.url !== "https://") {
// Ensure monitor without a URL is not affected by invisible URL.
try {
const url = new URL(this.monitor.url);
return url.hostname;
} catch (e) {
return this.monitor.url.replace(/https?:\/\//, "");
}
}
}
// Default placeholder if neither hostname nor URL is available
return this.$t("defaultFriendlyName");
},
ipRegex() {
// Allow to test with simple dns server with port (127.0.0.1:5300)
@@ -1700,6 +1719,10 @@ message HealthCheckResponse {
this.processing = true;
if (!this.monitor.name) {
this.monitor.name = this.defaultFriendlyName;
}
if (!this.isInputValid()) {
this.processing = false;
return;