port
This commit is contained in:
1 parent
216c7753b4
commit
f2779160a1
3 files changed
+41
-11
No files matched your search
@@ -22,10 +22,10 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) =>
|
|||||||
systemEmailTLSServername: data?.systemEmailTLSServername || "",
|
systemEmailTLSServername: data?.systemEmailTLSServername || "",
|
||||||
systemEmailPort: data?.systemEmailPort,
|
systemEmailPort: data?.systemEmailPort,
|
||||||
globalThresholds: {
|
globalThresholds: {
|
||||||
cpu: data?.globalThresholds?.cpu,
|
cpu: data?.globalThresholds?.cpu ?? 0,
|
||||||
memory: data?.globalThresholds?.memory,
|
memory: data?.globalThresholds?.memory ?? 0,
|
||||||
disk: data?.globalThresholds?.disk,
|
disk: data?.globalThresholds?.disk ?? 0,
|
||||||
temperature: data?.globalThresholds?.temperature,
|
temperature: data?.globalThresholds?.temperature ?? 0,
|
||||||
},
|
},
|
||||||
checkTTL: data?.checkTTL ?? 30,
|
checkTTL: data?.checkTTL ?? 30,
|
||||||
pagespeedApiKey: "",
|
pagespeedApiKey: "",
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export const SettingsPage = () => {
|
|||||||
const form = useForm<SettingsFormData>({
|
const form = useForm<SettingsFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset form when defaults change
|
// Reset form when defaults change
|
||||||
@@ -136,10 +137,12 @@ export const SettingsPage = () => {
|
|||||||
(acc as any)[typedKey] = "";
|
(acc as any)[typedKey] = "";
|
||||||
} else if (typeof value === "object" && value !== null) {
|
} else if (typeof value === "object" && value !== null) {
|
||||||
// Handle nested objects like globalThresholds
|
// Handle nested objects like globalThresholds
|
||||||
|
// Convert 0 to "" for unsetting thresholds
|
||||||
(acc as any)[typedKey] = Object.entries(value).reduce(
|
(acc as any)[typedKey] = Object.entries(value).reduce(
|
||||||
(nested, [nestedKey, nestedValue]) => ({
|
(nested, [nestedKey, nestedValue]) => ({
|
||||||
...nested,
|
...nested,
|
||||||
[nestedKey]: nestedValue === undefined ? "" : nestedValue,
|
[nestedKey]:
|
||||||
|
nestedValue === undefined || nestedValue === 0 ? "" : nestedValue,
|
||||||
}),
|
}),
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
@@ -327,7 +330,7 @@ export const SettingsPage = () => {
|
|||||||
color="error"
|
color="error"
|
||||||
onClick={() => setIsStatsDialogOpen(true)}
|
onClick={() => setIsStatsDialogOpen(true)}
|
||||||
>
|
>
|
||||||
{t("pages.settings.form.stats.buttonText")}
|
{t("common.buttons.clear")}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -347,6 +350,13 @@ export const SettingsPage = () => {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
|
value={
|
||||||
|
field.value === undefined || field.value === 0 ? "" : field.value
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
field.onChange(val === "" ? 0 : Number(val));
|
||||||
|
}}
|
||||||
fieldLabel={t("pages.settings.form.thresholds.option.cpu.label")}
|
fieldLabel={t("pages.settings.form.thresholds.option.cpu.label")}
|
||||||
type="number"
|
type="number"
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
@@ -364,6 +374,13 @@ export const SettingsPage = () => {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
|
value={
|
||||||
|
field.value === undefined || field.value === 0 ? "" : field.value
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
field.onChange(val === "" ? 0 : Number(val));
|
||||||
|
}}
|
||||||
fieldLabel={t("pages.settings.form.thresholds.option.memory.label")}
|
fieldLabel={t("pages.settings.form.thresholds.option.memory.label")}
|
||||||
type="number"
|
type="number"
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
@@ -381,6 +398,13 @@ export const SettingsPage = () => {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
|
value={
|
||||||
|
field.value === undefined || field.value === 0 ? "" : field.value
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
field.onChange(val === "" ? 0 : Number(val));
|
||||||
|
}}
|
||||||
fieldLabel={t("pages.settings.form.thresholds.option.disk.label")}
|
fieldLabel={t("pages.settings.form.thresholds.option.disk.label")}
|
||||||
type="number"
|
type="number"
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
@@ -398,6 +422,13 @@ export const SettingsPage = () => {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
|
value={
|
||||||
|
field.value === undefined || field.value === 0 ? "" : field.value
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
field.onChange(val === "" ? 0 : Number(val));
|
||||||
|
}}
|
||||||
fieldLabel={t(
|
fieldLabel={t(
|
||||||
"pages.settings.form.thresholds.option.temperature.label"
|
"pages.settings.form.thresholds.option.temperature.label"
|
||||||
)}
|
)}
|
||||||
@@ -452,7 +483,6 @@ export const SettingsPage = () => {
|
|||||||
{t("common.buttons.save")}
|
{t("common.buttons.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
<pre>{JSON.stringify(form.formState.isValid, null, 2)}</pre>
|
|
||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ export const settingsSchema = z.object({
|
|||||||
.optional(),
|
.optional(),
|
||||||
globalThresholds: z
|
globalThresholds: z
|
||||||
.object({
|
.object({
|
||||||
cpu: z.number().int().min(0).max(100).optional(),
|
cpu: z.number().int().min(0).max(100),
|
||||||
memory: z.number().int().min(0).max(100).optional(),
|
memory: z.number().int().min(0).max(100),
|
||||||
disk: z.number().int().min(0).max(100).optional(),
|
disk: z.number().int().min(0).max(100),
|
||||||
temperature: z.number().int().min(0).max(150).optional(),
|
temperature: z.number().int().min(0).max(150),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user