add form UI

This commit is contained in:
Alex Holliday committed 2026-06-22 11:24:35 -07:00
1 parent dead97169f
commit ba943e90c2
3 files changed
+83 -24

No files matched your search

+73 -23
View File
@@ -42,8 +42,11 @@ import {
type Monitor, type Monitor,
type MonitorType, type MonitorType,
type GamesMap, type GamesMap,
type HttpMethod,
supportsGeoCheck, supportsGeoCheck,
DefaultPageSpeedStrategy, DefaultPageSpeedStrategy,
DefaultHttpMethod,
HttpMethods,
} from "@/Types/Monitor"; } from "@/Types/Monitor";
import type { Notification } from "@/Types/Notification"; import type { Notification } from "@/Types/Notification";
import type { Tag } from "@/Types/Tag"; import type { Tag } from "@/Types/Tag";
@@ -259,7 +262,7 @@ const CreateMonitorPage = () => {
resolver: zodResolver(schema), resolver: zodResolver(schema),
defaultValues: defaults, defaultValues: defaults,
}); });
const { control, watch, handleSubmit, clearErrors, trigger, reset } = form; const { control, watch, handleSubmit, clearErrors, trigger, reset, setValue } = form;
useEffect(() => { useEffect(() => {
reset(defaults); reset(defaults);
@@ -271,6 +274,7 @@ const CreateMonitorPage = () => {
const showStep = (step: number) => isEditMode || currentStep === step; const showStep = (step: number) => isEditMode || currentStep === step;
const watchedType = watch("type") as MonitorType; const watchedType = watch("type") as MonitorType;
const watchedMethod = watch("method") as HttpMethod | undefined;
const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean; const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean;
const watchGeoCheckEnabled = watch("geoCheckEnabled") as boolean; const watchGeoCheckEnabled = watch("geoCheckEnabled") as boolean;
@@ -1091,6 +1095,50 @@ const CreateMonitorPage = () => {
subtitle={t("pages.createMonitor.form.advanced.description")} subtitle={t("pages.createMonitor.form.advanced.description")}
rightContent={ rightContent={
<Stack spacing={theme.spacing(LAYOUT.MD)}> <Stack spacing={theme.spacing(LAYOUT.MD)}>
<Controller
name="method"
control={control}
render={({ field }) => (
<Stack spacing={theme.spacing(LAYOUT.MD)}>
<Select
{...field}
value={field.value ?? DefaultHttpMethod}
onChange={(e) => {
const value = e.target.value as HttpMethod;
field.onChange(value);
// HEAD has no response body, reset advanced matching fields if selected
if (value === "HEAD") {
setValue("useAdvancedMatching", false);
setValue("matchMethod", "");
setValue("expectedValue", "");
setValue("jsonPath", "");
}
}}
fieldLabel={t(
"pages.createMonitor.form.advanced.option.method.label"
)}
>
{HttpMethods.map((method) => (
<MenuItem
key={method}
value={method}
>
{method}
</MenuItem>
))}
</Select>
<Typography
component="span"
color={theme.palette.text.secondary}
sx={{ opacity: 0.8 }}
>
{t(
`pages.createMonitor.form.advanced.option.method.description.${field.value ?? DefaultHttpMethod}`
)}
</Typography>
</Stack>
)}
/>
<Controller <Controller
name="customUpCodes" name="customUpCodes"
control={control} control={control}
@@ -1162,28 +1210,30 @@ const CreateMonitorPage = () => {
); );
}} }}
/> />
<Controller {watchedMethod !== "HEAD" && (
name="useAdvancedMatching" <Controller
control={control} name="useAdvancedMatching"
render={({ field }) => ( control={control}
<Stack render={({ field }) => (
direction="row" <Stack
alignItems="center" direction="row"
spacing={theme.spacing(SPACING.LG)} alignItems="center"
> spacing={theme.spacing(SPACING.LG)}
<Switch >
checked={field.value ?? false} <Switch
onChange={(e) => field.onChange(e.target.checked)} checked={field.value ?? false}
/> onChange={(e) => field.onChange(e.target.checked)}
<Typography> />
{t( <Typography>
"pages.createMonitor.form.advanced.option.advancedMatching.label" {t(
)} "pages.createMonitor.form.advanced.option.advancedMatching.label"
</Typography> )}
</Stack> </Typography>
)} </Stack>
/> )}
{watchedUseAdvancedMatching && ( />
)}
{watchedUseAdvancedMatching && watchedMethod !== "HEAD" && (
<Stack spacing={theme.spacing(LAYOUT.MD)}> <Stack spacing={theme.spacing(LAYOUT.MD)}>
<Controller <Controller
name="matchMethod" name="matchMethod"
@@ -324,7 +324,9 @@ export const MonitorTable = ({
</Stack> </Stack>
), ),
render: (row) => { render: (row) => {
return row.type; return row.type === "http" && row.method
? `${row.type} (${row.method})`
: row.type;
}, },
}, },
{ {
+7
View File
@@ -490,6 +490,13 @@
"advanced": { "advanced": {
"description": "Optional settings for advanced use cases", "description": "Optional settings for advanced use cases",
"option": { "option": {
"method": {
"label": "Request method",
"description": {
"GET": "GET fetches the full response including the body. Advanced matching fully supported",
"HEAD": "HEAD fetches only response headers for reducing load on the target. Supports status code matching but not advanced matching as there is no body."
}
},
"advancedMatching": { "advancedMatching": {
"label": "Use advanced matching" "label": "Use advanced matching"
}, },