feat(client): split uptime monitor creation into a 3-step wizard
This commit is contained in:
1 parent
9ffe0caed9
commit
c98ec7d047
2 files changed
+110
-13
No files matched your search
@@ -3,6 +3,7 @@ import { useEffect } from "react";
|
|||||||
import { logger } from "@/Utils/logger";
|
import { logger } from "@/Utils/logger";
|
||||||
import { useParams, useLocation, useNavigate } from "react-router";
|
import { useParams, useLocation, useNavigate } from "react-router";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
import type { FieldPath } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
@@ -18,7 +19,12 @@ import { Trash2 } from "lucide-react";
|
|||||||
import { HeaderDeleteControls } from "@/Components/monitors";
|
import { HeaderDeleteControls } from "@/Components/monitors";
|
||||||
import { GeoContinents } from "@/Types/GeoCheck";
|
import { GeoContinents } from "@/Types/GeoCheck";
|
||||||
|
|
||||||
import { BasePage, ColoredLabel, ConfigBox } from "@/Components/design-elements";
|
import {
|
||||||
|
BasePage,
|
||||||
|
ColoredLabel,
|
||||||
|
ConfigBox,
|
||||||
|
StepProgress,
|
||||||
|
} from "@/Components/design-elements";
|
||||||
import {
|
import {
|
||||||
RadioWithDescription,
|
RadioWithDescription,
|
||||||
Button,
|
Button,
|
||||||
@@ -207,6 +213,33 @@ const getGeneralSettingsConfig = (
|
|||||||
return configs[type] || configs.http;
|
return configs[type] || configs.http;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TOTAL_STEPS = 3;
|
||||||
|
|
||||||
|
// Fields validated before advancing past each wizard step (uptime create only).
|
||||||
|
const STEP_FIELDS: FieldPath<MonitorFormData>[][] = [
|
||||||
|
[
|
||||||
|
"type",
|
||||||
|
"url",
|
||||||
|
"name",
|
||||||
|
"port",
|
||||||
|
"gameId",
|
||||||
|
"grpcServiceName",
|
||||||
|
"dnsServer",
|
||||||
|
"dnsRecordType",
|
||||||
|
],
|
||||||
|
["interval", "statusWindowSize", "statusWindowThreshold", "notifications", "tags"],
|
||||||
|
[
|
||||||
|
"ignoreTlsErrors",
|
||||||
|
"useAdvancedMatching",
|
||||||
|
"matchMethod",
|
||||||
|
"expectedValue",
|
||||||
|
"jsonPath",
|
||||||
|
"geoCheckEnabled",
|
||||||
|
"geoCheckLocations",
|
||||||
|
"geoCheckInterval",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
const CreateMonitorPage = () => {
|
const CreateMonitorPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -249,12 +282,25 @@ const CreateMonitorPage = () => {
|
|||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
const { control, watch, handleSubmit, clearErrors } = form;
|
const { control, watch, handleSubmit, clearErrors, trigger } = form;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
form.reset(defaults);
|
form.reset(defaults);
|
||||||
}, [defaults, form]);
|
}, [defaults, form]);
|
||||||
|
|
||||||
|
// Multi-step wizard (uptime create only). Other flows keep the flat form.
|
||||||
|
const isWizard = showTypeSelector;
|
||||||
|
const [currentStep, setCurrentStep] = useState(0);
|
||||||
|
const showStep = (step: number) => !isWizard || currentStep === step;
|
||||||
|
|
||||||
|
const handleNext = async () => {
|
||||||
|
const isValid = await trigger(STEP_FIELDS[currentStep]);
|
||||||
|
if (isValid) {
|
||||||
|
setCurrentStep((step) => Math.min(step + 1, TOTAL_STEPS - 1));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleBack = () => setCurrentStep((step) => Math.max(step - 1, 0));
|
||||||
|
|
||||||
const watchedType = watch("type") as MonitorType;
|
const watchedType = watch("type") as MonitorType;
|
||||||
|
|
||||||
const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean;
|
const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean;
|
||||||
@@ -332,8 +378,14 @@ const CreateMonitorPage = () => {
|
|||||||
refetch={refetchMonitor}
|
refetch={refetchMonitor}
|
||||||
onDelete={handleDeleteClick}
|
onDelete={handleDeleteClick}
|
||||||
/>
|
/>
|
||||||
|
{isWizard && (
|
||||||
|
<StepProgress
|
||||||
|
steps={TOTAL_STEPS}
|
||||||
|
current={currentStep}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{/* Monitor Type Selection - only shown for uptime monitors */}
|
{/* Monitor Type Selection - only shown for uptime monitors */}
|
||||||
{showTypeSelector && (
|
{showTypeSelector && showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.type.title")}
|
title={t("pages.createMonitor.form.type.title")}
|
||||||
subtitle={t("pages.createMonitor.form.type.description")}
|
subtitle={t("pages.createMonitor.form.type.description")}
|
||||||
@@ -411,6 +463,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.general.title")}
|
title={t("pages.createMonitor.form.general.title")}
|
||||||
subtitle={
|
subtitle={
|
||||||
@@ -513,7 +566,9 @@ const CreateMonitorPage = () => {
|
|||||||
error={!!fieldState.error}
|
error={!!fieldState.error}
|
||||||
>
|
>
|
||||||
<MenuItem value="">
|
<MenuItem value="">
|
||||||
{t("pages.createMonitor.form.general.option.game.placeholder")}{" "}
|
{t(
|
||||||
|
"pages.createMonitor.form.general.option.game.placeholder"
|
||||||
|
)}{" "}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{games &&
|
{games &&
|
||||||
Object.entries(games).map(([key, game]) => (
|
Object.entries(games).map(([key, game]) => (
|
||||||
@@ -563,7 +618,9 @@ const CreateMonitorPage = () => {
|
|||||||
{...field}
|
{...field}
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
type="text"
|
type="text"
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.secret.label")}
|
fieldLabel={t(
|
||||||
|
"pages.createMonitor.form.general.option.secret.label"
|
||||||
|
)}
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"pages.createMonitor.form.general.option.secret.placeholder"
|
"pages.createMonitor.form.general.option.secret.placeholder"
|
||||||
)}
|
)}
|
||||||
@@ -611,7 +668,9 @@ const CreateMonitorPage = () => {
|
|||||||
error={!!fieldState.error}
|
error={!!fieldState.error}
|
||||||
>
|
>
|
||||||
<MenuItem value={"A"}>
|
<MenuItem value={"A"}>
|
||||||
{t("pages.createMonitor.form.general.option.dnsRecordType.value.A")}
|
{t(
|
||||||
|
"pages.createMonitor.form.general.option.dnsRecordType.value.A"
|
||||||
|
)}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem value={"AAAA"}>
|
<MenuItem value={"AAAA"}>
|
||||||
{t(
|
{t(
|
||||||
@@ -661,7 +720,9 @@ const CreateMonitorPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.frequency.title")}
|
title={t("pages.createMonitor.form.frequency.title")}
|
||||||
subtitle={t("pages.createMonitor.form.frequency.description")}
|
subtitle={t("pages.createMonitor.form.frequency.description")}
|
||||||
@@ -733,9 +794,10 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Alert Thresholds - only for hardware type */}
|
{/* Alert Thresholds - only for hardware type */}
|
||||||
{generalSettingsConfig.showSecret && (
|
{generalSettingsConfig.showSecret && showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.thresholds.title")}
|
title={t("pages.createMonitor.form.thresholds.title")}
|
||||||
subtitle={t("pages.createMonitor.form.thresholds.description")}
|
subtitle={t("pages.createMonitor.form.thresholds.description")}
|
||||||
@@ -818,6 +880,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.incidents.title")}
|
title={t("pages.createMonitor.form.incidents.title")}
|
||||||
subtitle={t("pages.createMonitor.form.incidents.description")}
|
subtitle={t("pages.createMonitor.form.incidents.description")}
|
||||||
@@ -830,7 +893,9 @@ const CreateMonitorPage = () => {
|
|||||||
<SliderWithLabel
|
<SliderWithLabel
|
||||||
{...field}
|
{...field}
|
||||||
sliderMaxWidth={{ xs: "100%", md: "50%" }}
|
sliderMaxWidth={{ xs: "100%", md: "50%" }}
|
||||||
fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")}
|
fieldLabel={t(
|
||||||
|
"pages.createMonitor.form.incidents.option.checks.label"
|
||||||
|
)}
|
||||||
min={1}
|
min={1}
|
||||||
max={25}
|
max={25}
|
||||||
valueLabelDisplay="auto"
|
valueLabelDisplay="auto"
|
||||||
@@ -856,7 +921,9 @@ const CreateMonitorPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.notifications.title")}
|
title={t("pages.createMonitor.form.notifications.title")}
|
||||||
subtitle={t("pages.createMonitor.form.notifications.description")}
|
subtitle={t("pages.createMonitor.form.notifications.description")}
|
||||||
@@ -924,7 +991,9 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.tags.title")}
|
title={t("pages.createMonitor.form.tags.title")}
|
||||||
subtitle={t("pages.createMonitor.form.tags.description")}
|
subtitle={t("pages.createMonitor.form.tags.description")}
|
||||||
@@ -978,7 +1047,9 @@ const CreateMonitorPage = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
field.onChange(
|
field.onChange(
|
||||||
(field.value ?? []).filter((id: string) => id !== tag.id)
|
(field.value ?? []).filter(
|
||||||
|
(id: string) => id !== tag.id
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
aria-label="Remove tag"
|
aria-label="Remove tag"
|
||||||
@@ -996,8 +1067,10 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{(watchedType === "http" ||
|
{showStep(2) &&
|
||||||
|
(watchedType === "http" ||
|
||||||
watchedType === "grpc" ||
|
watchedType === "grpc" ||
|
||||||
watchedType === "websocket") && (
|
watchedType === "websocket") && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
@@ -1027,7 +1100,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{watchedType === "http" && (
|
{showStep(2) && watchedType === "http" && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.advanced.title")}
|
title={t("pages.createMonitor.form.advanced.title")}
|
||||||
subtitle={t("pages.createMonitor.form.advanced.description")}
|
subtitle={t("pages.createMonitor.form.advanced.description")}
|
||||||
@@ -1142,7 +1215,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{supportsGeoCheck(watchedType) && (
|
{showStep(2) && supportsGeoCheck(watchedType) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.geoChecks.title")}
|
title={t("pages.createMonitor.form.geoChecks.title")}
|
||||||
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
||||||
@@ -1278,8 +1351,29 @@ const CreateMonitorPage = () => {
|
|||||||
|
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
justifyContent="flex-end"
|
justifyContent={isWizard ? "space-between" : "flex-end"}
|
||||||
>
|
>
|
||||||
|
{isWizard && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outlined"
|
||||||
|
color="secondary"
|
||||||
|
disabled={currentStep === 0}
|
||||||
|
onClick={handleBack}
|
||||||
|
>
|
||||||
|
{t("common.buttons.back")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isWizard && currentStep < TOTAL_STEPS - 1 ? (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleNext}
|
||||||
|
>
|
||||||
|
{t("common.buttons.next")}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
type="submit"
|
type="submit"
|
||||||
@@ -1288,6 +1382,7 @@ const CreateMonitorPage = () => {
|
|||||||
>
|
>
|
||||||
{t("common.buttons.save")}
|
{t("common.buttons.save")}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isDeleteDialogOpen}
|
open={isDeleteDialogOpen}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@
|
|||||||
"pause": "Pause",
|
"pause": "Pause",
|
||||||
"resume": "Resume",
|
"resume": "Resume",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
|
"next": "Next",
|
||||||
|
"back": "Back",
|
||||||
"sendInvite": "Send invite",
|
"sendInvite": "Send invite",
|
||||||
"test": "Test",
|
"test": "Test",
|
||||||
"testNotifications": "Test notifications",
|
"testNotifications": "Test notifications",
|
||||||
|
|||||||
Reference in new issue
Block a user