replace textfields with sliders

This commit is contained in:
Alex Holliday committed 2026-02-26 19:07:43 +00:00
1 parent 0442c8dd0f
commit 85edea713a
3 files changed
+55 -97

No files matched your search

+16 -4
View File
@@ -22,10 +22,22 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) =>
systemEmailTLSServername: data?.systemEmailTLSServername || "", systemEmailTLSServername: data?.systemEmailTLSServername || "",
systemEmailPort: data?.systemEmailPort, systemEmailPort: data?.systemEmailPort,
globalThresholds: { globalThresholds: {
cpu: data?.globalThresholds?.cpu ?? 0, cpu:
memory: data?.globalThresholds?.memory ?? 0, data?.globalThresholds?.cpu && data.globalThresholds.cpu >= 1
disk: data?.globalThresholds?.disk ?? 0, ? data.globalThresholds.cpu
temperature: data?.globalThresholds?.temperature ?? 0, : 80,
memory:
data?.globalThresholds?.memory && data.globalThresholds.memory >= 1
? data.globalThresholds.memory
: 80,
disk:
data?.globalThresholds?.disk && data.globalThresholds.disk >= 1
? data.globalThresholds.disk
: 80,
temperature:
data?.globalThresholds?.temperature && data.globalThresholds.temperature >= 1
? data.globalThresholds.temperature
: 80,
}, },
checkTTL: data?.checkTTL ?? 30, checkTTL: data?.checkTTL ?? 30,
pagespeedApiKey: "", pagespeedApiKey: "",
+33 -65
View File
@@ -14,7 +14,7 @@ import { useIsAdmin } from "@/Hooks/useIsAdmin.js";
import type { SettingsFormData } from "@/Validation/settings"; import type { SettingsFormData } from "@/Validation/settings";
import { useState } from "react"; import { useState } from "react";
import { Controller } from "react-hook-form"; import { Controller } from "react-hook-form";
import { TextField, Button, FieldLabel } from "@/Components/inputs"; import { TextField, Button, FieldLabel, SliderWithLabel } from "@/Components/inputs";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import { useDelete } from "@/Hooks/UseApi"; import { useDelete } from "@/Hooks/UseApi";
@@ -465,24 +465,16 @@ export const SettingsPage = () => {
name="globalThresholds.cpu" name="globalThresholds.cpu"
control={form.control} control={form.control}
defaultValue={defaults.globalThresholds?.cpu} defaultValue={defaults.globalThresholds?.cpu}
render={({ field, fieldState }) => ( render={({ field }) => (
<TextField <SliderWithLabel
{...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" min={1}
inputProps={{ min: 0 }} max={100}
placeholder={t( sliderMaxWidth={{ xs: "100%", md: "50%" }}
"pages.settings.form.thresholds.option.cpu.placeholder" value={field.value || 1}
)} onChange={(_, value) => field.onChange(value)}
error={!!fieldState.error} valueLabelDisplay="auto"
helperText={fieldState.error?.message}
/> />
)} )}
/> />
@@ -490,24 +482,16 @@ export const SettingsPage = () => {
name="globalThresholds.memory" name="globalThresholds.memory"
control={form.control} control={form.control}
defaultValue={defaults.globalThresholds?.memory} defaultValue={defaults.globalThresholds?.memory}
render={({ field, fieldState }) => ( render={({ field }) => (
<TextField <SliderWithLabel
{...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" min={1}
inputProps={{ min: 0 }} max={100}
placeholder={t( sliderMaxWidth={{ xs: "100%", md: "50%" }}
"pages.settings.form.thresholds.option.memory.placeholder" value={field.value || 1}
)} onChange={(_, value) => field.onChange(value)}
error={!!fieldState.error} valueLabelDisplay="auto"
helperText={fieldState.error?.message}
/> />
)} )}
/> />
@@ -515,24 +499,16 @@ export const SettingsPage = () => {
name="globalThresholds.disk" name="globalThresholds.disk"
control={form.control} control={form.control}
defaultValue={defaults.globalThresholds?.disk} defaultValue={defaults.globalThresholds?.disk}
render={({ field, fieldState }) => ( render={({ field }) => (
<TextField <SliderWithLabel
{...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" min={1}
inputProps={{ min: 0 }} max={100}
placeholder={t( sliderMaxWidth={{ xs: "100%", md: "50%" }}
"pages.settings.form.thresholds.option.disk.placeholder" value={field.value || 1}
)} onChange={(_, value) => field.onChange(value)}
error={!!fieldState.error} valueLabelDisplay="auto"
helperText={fieldState.error?.message}
/> />
)} )}
/> />
@@ -540,26 +516,18 @@ export const SettingsPage = () => {
name="globalThresholds.temperature" name="globalThresholds.temperature"
control={form.control} control={form.control}
defaultValue={defaults.globalThresholds?.temperature} defaultValue={defaults.globalThresholds?.temperature}
render={({ field, fieldState }) => ( render={({ field }) => (
<TextField <SliderWithLabel
{...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"
)} )}
type="number" min={1}
inputProps={{ min: 0 }} max={100}
placeholder={t( sliderMaxWidth={{ xs: "100%", md: "50%" }}
"pages.settings.form.thresholds.option.temperature.placeholder" value={field.value || 1}
)} onChange={(_, value) => field.onChange(value)}
error={!!fieldState.error} valueLabelDisplay="auto"
helperText={fieldState.error?.message}
/> />
)} )}
/> />
+6 -28
View File
@@ -40,34 +40,12 @@ export const settingsSchema = z.object({
.string() .string()
.transform((val) => (val.trim() === "" ? undefined : val.trim())) .transform((val) => (val.trim() === "" ? undefined : val.trim()))
.optional(), .optional(),
globalThresholds: z globalThresholds: z.object({
.object({ cpu: z.number().int().min(1).max(100),
cpu: z memory: z.number().int().min(1).max(100),
.number() disk: z.number().int().min(1).max(100),
.int() temperature: z.number().int().min(1).max(100),
.min(1, "Please enter a valid value") }),
.max(100, "Maximum value is 100")
.optional(),
memory: z
.number()
.int()
.min(1, "Please enter a valid value")
.max(100, "Maximum value is 100")
.optional(),
disk: z
.number()
.int()
.min(1, "Please enter a valid value")
.max(100, "Maximum value is 100")
.optional(),
temperature: z
.number()
.int()
.min(1, "Please enter a valid value")
.max(150, "Maximum value is 150")
.optional(),
})
.optional(),
}); });
export type SettingsFormData = z.infer<typeof settingsSchema>; export type SettingsFormData = z.infer<typeof settingsSchema>;