This commit is contained in:
Alex Holliday committed 2026-01-29 22:47:29 +00:00
1 parent 84e4ea7b64
commit 841d25ce3e
3 files changed
+132 -38

No files matched your search

+101 -33
View File
@@ -8,6 +8,7 @@ import Stack from "@mui/material/Stack";
import RadioGroup from "@mui/material/RadioGroup"; import RadioGroup from "@mui/material/RadioGroup";
import FormControl from "@mui/material/FormControl"; import FormControl from "@mui/material/FormControl";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import MenuItem from "@mui/material/MenuItem";
import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; import { BasePage, ConfigBox } from "@/Components/v2/design-elements";
import { RadioWithDescription, Button, TextField, Select } from "@/Components/v2/inputs"; import { RadioWithDescription, Button, TextField, Select } from "@/Components/v2/inputs";
@@ -15,14 +16,15 @@ import { useGet } from "@/Hooks/UseApi";
import { useMonitorForm } from "@/Hooks/useMonitorForm"; import { useMonitorForm } from "@/Hooks/useMonitorForm";
import type { Monitor, MonitorType } from "@/Types/Monitor"; import type { Monitor, MonitorType } from "@/Types/Monitor";
import type { MonitorFormData } from "@/Validation/monitor"; import type { MonitorFormData } from "@/Validation/monitor";
import MenuItem from "@mui/material/MenuItem";
interface GeneralSettingsConfig { interface GeneralSettingsConfig {
urlLabel: string; urlLabel: string;
urlPlaceholder: string; urlPlaceholder: string;
namePlaceholder: string; namePlaceholder: string;
showUrl: boolean;
showPort: boolean; showPort: boolean;
showGameSelect: boolean; showGameSelect: boolean;
showSecret: boolean;
} }
const getGeneralSettingsConfig = ( const getGeneralSettingsConfig = (
@@ -31,39 +33,67 @@ const getGeneralSettingsConfig = (
): GeneralSettingsConfig => { ): GeneralSettingsConfig => {
const configs: Record<string, GeneralSettingsConfig> = { const configs: Record<string, GeneralSettingsConfig> = {
http: { http: {
urlLabel: t("monitorType.http.label"), urlLabel: t("pages.createMonitor.form.general.option.url.label"),
urlPlaceholder: t("monitorType.http.placeholder"), urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
namePlaceholder: t("monitorType.http.namePlaceholder"), namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: false, showPort: false,
showGameSelect: false, showGameSelect: false,
showSecret: false,
}, },
ping: { ping: {
urlLabel: t("monitorType.ping.label"), urlLabel: t("pages.createMonitor.form.general.option.host.label"),
urlPlaceholder: t("monitorType.ping.placeholder"), urlPlaceholder: t("pages.createMonitor.form.general.option.host.placeholder"),
namePlaceholder: t("monitorType.ping.namePlaceholder"), namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: false, showPort: false,
showGameSelect: false, showGameSelect: false,
showSecret: false,
}, },
docker: { docker: {
urlLabel: t("monitorType.docker.label"), urlLabel: t("pages.createMonitor.form.general.option.container.label"),
urlPlaceholder: t("monitorType.docker.placeholder"), urlPlaceholder: t("pages.createMonitor.form.general.option.container.placeholder"),
namePlaceholder: t("monitorType.docker.namePlaceholder"), namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: false, showPort: false,
showGameSelect: false, showGameSelect: false,
showSecret: false,
}, },
port: { port: {
urlLabel: t("monitorType.port.label"), urlLabel: t("pages.createMonitor.form.general.option.url.label"),
urlPlaceholder: t("monitorType.port.placeholder"), urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
namePlaceholder: t("monitorType.port.namePlaceholder"), namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: true, showPort: true,
showGameSelect: false, showGameSelect: false,
showSecret: false,
}, },
game: { game: {
urlLabel: t("monitorType.game.label"), urlLabel: t("pages.createMonitor.form.general.option.url.label"),
urlPlaceholder: t("monitorType.game.placeholder"), urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
namePlaceholder: t("monitorType.game.namePlaceholder"), namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: true, showPort: true,
showGameSelect: true, showGameSelect: true,
showSecret: false,
},
pagespeed: {
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: false,
showGameSelect: false,
showSecret: false,
},
hardware: {
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
showUrl: true,
showPort: false,
showGameSelect: false,
showSecret: true,
}, },
}; };
return configs[type] || configs.http; return configs[type] || configs.http;
@@ -156,6 +186,20 @@ const CreateMonitorPage = () => {
label={t("pages.createMonitor.form.type.optionGame")} label={t("pages.createMonitor.form.type.optionGame")}
description={t("pages.createMonitor.form.type.optionGameDescription")} description={t("pages.createMonitor.form.type.optionGameDescription")}
/> />
<RadioWithDescription
value="pagespeed"
label={t("pages.createMonitor.form.type.optionPagespeed")}
description={t(
"pages.createMonitor.form.type.optionPagespeedDescription"
)}
/>
<RadioWithDescription
value="hardware"
label={t("pages.createMonitor.form.type.optionHardware")}
description={t(
"pages.createMonitor.form.type.optionHardwareDescription"
)}
/>
</RadioGroup> </RadioGroup>
</FormControl> </FormControl>
)} )}
@@ -169,22 +213,24 @@ const CreateMonitorPage = () => {
subtitle={t(`pages.createMonitor.form.general.description.${watchedType}`)} subtitle={t(`pages.createMonitor.form.general.description.${watchedType}`)}
rightContent={ rightContent={
<Stack spacing={theme.spacing(8)}> <Stack spacing={theme.spacing(8)}>
{/* URL/Host/Container field */} {/* URL/Host/Container field - not shown for hardware */}
<Controller {generalSettingsConfig.showUrl && (
name="url" <Controller
control={control} name="url"
render={({ field, fieldState }) => ( control={control}
<TextField render={({ field, fieldState }) => (
{...field} <TextField
type="text" {...field}
fieldLabel={generalSettingsConfig.urlLabel} type="text"
placeholder={generalSettingsConfig.urlPlaceholder} fieldLabel={generalSettingsConfig.urlLabel}
fullWidth placeholder={generalSettingsConfig.urlPlaceholder}
error={!!fieldState.error} fullWidth
helperText={fieldState.error?.message ?? ""} error={!!fieldState.error}
/> helperText={fieldState.error?.message ?? ""}
)} />
/> )}
/>
)}
{/* Port field - only for port and game types */} {/* Port field - only for port and game types */}
{generalSettingsConfig.showPort && ( {generalSettingsConfig.showPort && (
@@ -225,6 +271,28 @@ const CreateMonitorPage = () => {
/> />
)} )}
{/* Secret field - only for hardware type */}
{generalSettingsConfig.showSecret && (
<Controller
name="secret"
control={control}
render={({ field, fieldState }) => (
<TextField
{...field}
value={field.value ?? ""}
type="text"
fieldLabel={t("pages.createMonitor.form.general.option.secret.label")}
placeholder={t(
"pages.createMonitor.form.general.option.secret.placeholder"
)}
fullWidth
error={!!fieldState.error}
helperText={fieldState.error?.message ?? ""}
/>
)}
/>
)}
{/* Display name field - common to all types */} {/* Display name field - common to all types */}
<Controller <Controller
name="name" name="name"
@@ -233,7 +301,7 @@ const CreateMonitorPage = () => {
<TextField <TextField
{...field} {...field}
type="text" type="text"
fieldLabel={t("displayName")} fieldLabel={t("pages.createMonitor.form.general.option.name.label")}
placeholder={generalSettingsConfig.namePlaceholder} placeholder={generalSettingsConfig.namePlaceholder}
fullWidth fullWidth
error={!!fieldState.error} error={!!fieldState.error}
+2 -2
View File
@@ -76,8 +76,8 @@ const pagespeedSchema = baseSchema.extend({
// Hardware/Infrastructure monitor schema // Hardware/Infrastructure monitor schema
const hardwareSchema = baseSchema.extend({ const hardwareSchema = baseSchema.extend({
type: z.literal("hardware"), type: z.literal("hardware"),
url: z.string().optional(), url: z.string({ message: "URL is required" }).min(1, "URL is required"),
secret: z.string().optional(), secret: z.string({ message: "Secret is required" }).min(1, "Secret is required"),
cpuAlertThreshold: z cpuAlertThreshold: z
.number() .number()
.min(0, "CPU threshold must be at least 0") .min(0, "CPU threshold must be at least 0")
+29 -3
View File
@@ -235,7 +235,11 @@
"optionPort": "Port", "optionPort": "Port",
"optionPortDescription": "Monitor if a specific port on a server is open.", "optionPortDescription": "Monitor if a specific port on a server is open.",
"optionGame": "Game", "optionGame": "Game",
"optionGameDescription": "Monitor if a specific game server is online." "optionGameDescription": "Monitor if a specific game server is online.",
"optionPagespeed": "PageSpeed",
"optionPagespeedDescription": "Analyze page performance using Google PageSpeed Insights.",
"optionHardware": "Hardware",
"optionHardwareDescription": "Monitor server hardware metrics like CPU, memory, and disk."
}, },
"general": { "general": {
"title": "General settings", "title": "General settings",
@@ -245,8 +249,30 @@
"docker": "Enter the Docker container name or ID. You can use either the container name (e.g., my-app) or the container ID (full 64-char ID or short ID).", "docker": "Enter the Docker container name or ID. You can use either the container name (e.g., my-app) or the container ID (full 64-char ID or short ID).",
"port": "Enter the URL or IP of the server, the port number and a clear display name that appears on the dashboard.", "port": "Enter the URL or IP of the server, the port number and a clear display name that appears on the dashboard.",
"game": "Enter the IP address or hostname and the port number to ping (e.g., 192.168.1.100 or example.com) and choose game type.", "game": "Enter the IP address or hostname and the port number to ping (e.g., 192.168.1.100 or example.com) and choose game type.",
"pagespeed": "Here you can select the URL of the host, together with the type of monitor.", "pagespeed": "Enter the URL of the page to analyze with Google PageSpeed and add a clear display name that appears on the dashboard.",
"infrastructure": "Here you can select the URL of the host, together with the friendly name and authorization secret to connect to the server agent." "hardware": "Enter the URL of your infrastructure agent, the authorization secret, and a clear display name that appears on the dashboard."
},
"option": {
"url": {
"label": "URL",
"placeholder": "https://www.google.com"
},
"name": {
"label": "Display name",
"placeholder": "e.g. My Website"
},
"host": {
"label": "Host",
"placeholder": "192.168.1.100 or example.com"
},
"container": {
"label": "Container name/ID",
"placeholder": "my-app or abcd1234"
},
"secret": {
"label": "Authorization secret",
"placeholder": "Enter your secret key"
}
} }
} }
} }