create bound components for text input and radio input
This commit is contained in:
1 parent
623db938f5
commit
6e1e5dd1a5
6 files changed
+203
-176
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
useFormContext,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
|
} from "react-hook-form";
|
||||||
|
import { TextField } from "@/Components/inputs";
|
||||||
|
|
||||||
|
interface FormNumberFieldProps<T extends FieldValues> extends Omit<
|
||||||
|
React.ComponentProps<typeof TextField>,
|
||||||
|
"name" | "error" | "helperText" | "type"
|
||||||
|
> {
|
||||||
|
name: FieldPath<T>;
|
||||||
|
emptyValue?: number; // what an empty input writes to the form; 0 keeps today's sentinel
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FormNumberField = <T extends FieldValues>({
|
||||||
|
name,
|
||||||
|
emptyValue = 0,
|
||||||
|
...rest
|
||||||
|
}: FormNumberFieldProps<T>) => {
|
||||||
|
const { control } = useFormContext<T>();
|
||||||
|
return (
|
||||||
|
<Controller
|
||||||
|
name={name}
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="number"
|
||||||
|
value={
|
||||||
|
field.value === undefined || field.value === emptyValue ? "" : field.value
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
field.onChange(val === "" ? emptyValue : Number(val));
|
||||||
|
}}
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
fullWidth
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { RadioGroup, useTheme } from "@mui/material";
|
||||||
|
import FormControl from "@mui/material/FormControl";
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
useFormContext,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
|
} from "react-hook-form";
|
||||||
|
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||||
|
import { RadioWithDescription } from "@/Components/inputs/Radio";
|
||||||
|
export interface FormRadioOption {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormRadioGroupProps<T extends FieldValues> {
|
||||||
|
name: FieldPath<T>;
|
||||||
|
options: FormRadioOption[];
|
||||||
|
}
|
||||||
|
export const FormRadioGroup = <T extends FieldValues>({
|
||||||
|
name,
|
||||||
|
options,
|
||||||
|
}: FormRadioGroupProps<T>) => {
|
||||||
|
const { control } = useFormContext<T>();
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Controller
|
||||||
|
name={name}
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<FormControl error={!!fieldState.error}>
|
||||||
|
<RadioGroup
|
||||||
|
{...field}
|
||||||
|
sx={{ gap: theme.spacing(LAYOUT.MD) }}
|
||||||
|
>
|
||||||
|
{options.map((option) => (
|
||||||
|
<RadioWithDescription
|
||||||
|
key={option.value}
|
||||||
|
value={option.value}
|
||||||
|
label={option.label}
|
||||||
|
description={option.description}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
useFormContext,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
|
} from "react-hook-form";
|
||||||
|
|
||||||
|
import { TextField } from "@/Components/inputs";
|
||||||
|
|
||||||
|
interface FormTextFieldProps<T extends FieldValues> extends Omit<
|
||||||
|
React.ComponentProps<typeof TextField>,
|
||||||
|
"name" | "error" | "helperText"
|
||||||
|
> {
|
||||||
|
name: FieldPath<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FormTextField = <T extends FieldValues>({
|
||||||
|
name,
|
||||||
|
...rest
|
||||||
|
}: FormTextFieldProps<T>) => {
|
||||||
|
const { control } = useFormContext<T>();
|
||||||
|
return (
|
||||||
|
<Controller
|
||||||
|
name={name}
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="text"
|
||||||
|
value={field.value ?? ""}
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
fullWidth
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3,12 +3,10 @@ import { useEffect } from "react";
|
|||||||
import { logger } from "@/Utils/logger";
|
import { logger } from "@/Utils/logger";
|
||||||
import { ALL_HTTP_STATUS_CODES } from "@/Utils/statusCode";
|
import { ALL_HTTP_STATUS_CODES } from "@/Utils/statusCode";
|
||||||
import { useParams, useLocation, useNavigate } from "react-router";
|
import { useParams, useLocation, useNavigate } from "react-router";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller, FormProvider } 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";
|
||||||
import RadioGroup from "@mui/material/RadioGroup";
|
|
||||||
import FormControl from "@mui/material/FormControl";
|
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
@@ -28,7 +26,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
RadioWithDescription,
|
RadioWithDescription,
|
||||||
Button,
|
Button,
|
||||||
TextField,
|
|
||||||
Select,
|
Select,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
SwitchComponent as Switch,
|
SwitchComponent as Switch,
|
||||||
@@ -47,6 +44,8 @@ import {
|
|||||||
DefaultPageSpeedStrategy,
|
DefaultPageSpeedStrategy,
|
||||||
DefaultHttpMethod,
|
DefaultHttpMethod,
|
||||||
HttpMethods,
|
HttpMethods,
|
||||||
|
SelectableMonitorTypes,
|
||||||
|
monitorTypeLabelKey,
|
||||||
} 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";
|
||||||
@@ -55,6 +54,9 @@ import {
|
|||||||
monitorStepCount,
|
monitorStepCount,
|
||||||
type MonitorFormData,
|
type MonitorFormData,
|
||||||
} from "@/Validation/monitor";
|
} from "@/Validation/monitor";
|
||||||
|
import { FormNumberField } from "@/Components/inputs/forms/FormNumberField";
|
||||||
|
import { FormTextField } from "@/Components/inputs/forms/FormTextField";
|
||||||
|
import { FormRadioGroup } from "@/Components/inputs/forms/FormRadioGroup";
|
||||||
|
|
||||||
interface GeneralSettingsConfig {
|
interface GeneralSettingsConfig {
|
||||||
urlLabel: string;
|
urlLabel: string;
|
||||||
@@ -357,6 +359,7 @@ const CreateMonitorPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<FormProvider {...form}>
|
||||||
<BasePage
|
<BasePage
|
||||||
component="form"
|
component="form"
|
||||||
onSubmit={handleSubmit(onSubmit, onError)}
|
onSubmit={handleSubmit(onSubmit, onError)}
|
||||||
@@ -379,74 +382,17 @@ const CreateMonitorPage = () => {
|
|||||||
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")}
|
||||||
rightContent={
|
rightContent={
|
||||||
<Controller
|
<FormRadioGroup
|
||||||
name="type"
|
name={"type"}
|
||||||
control={control}
|
options={SelectableMonitorTypes.map((type) => ({
|
||||||
render={({ field, fieldState }) => (
|
value: type,
|
||||||
<FormControl error={!!fieldState.error}>
|
label: t(
|
||||||
<RadioGroup
|
`pages.common.monitors.monitorTypes.${monitorTypeLabelKey[type]}`
|
||||||
{...field}
|
),
|
||||||
sx={{ gap: theme.spacing(LAYOUT.MD) }}
|
description: t(
|
||||||
>
|
`pages.createMonitor.form.type.${monitorTypeLabelKey[type]}Description`
|
||||||
<RadioWithDescription
|
),
|
||||||
value="http"
|
}))}
|
||||||
label={t("pages.common.monitors.monitorTypes.optionHttp")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionHttpDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="ping"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionPing")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionPingDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="docker"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionDocker")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionDockerDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="port"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionPort")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionPortDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="game"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionGame")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionGameDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="grpc"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionGrpc")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionGrpcDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="websocket"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionWebSocket")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionWebSocketDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="dns"
|
|
||||||
label={t("pages.common.monitors.monitorTypes.optionDns")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionDnsDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</RadioGroup>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -473,21 +419,11 @@ const CreateMonitorPage = () => {
|
|||||||
<Stack spacing={theme.spacing(LAYOUT.MD)}>
|
<Stack spacing={theme.spacing(LAYOUT.MD)}>
|
||||||
{/* URL/Host/Container field - not shown for hardware */}
|
{/* URL/Host/Container field - not shown for hardware */}
|
||||||
{generalSettingsConfig.showUrl && (
|
{generalSettingsConfig.showUrl && (
|
||||||
<Controller
|
<FormTextField
|
||||||
name="url"
|
name="url"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={generalSettingsConfig.urlLabel}
|
fieldLabel={generalSettingsConfig.urlLabel}
|
||||||
placeholder={generalSettingsConfig.urlPlaceholder}
|
placeholder={generalSettingsConfig.urlPlaceholder}
|
||||||
fullWidth
|
|
||||||
disabled={isEditMode}
|
disabled={isEditMode}
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -518,27 +454,12 @@ const CreateMonitorPage = () => {
|
|||||||
|
|
||||||
{/* Port field - only for port and game types */}
|
{/* Port field - only for port and game types */}
|
||||||
{generalSettingsConfig.showPort && (
|
{generalSettingsConfig.showPort && (
|
||||||
<Controller
|
<FormNumberField
|
||||||
name="port"
|
name={"port"}
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value === 0 ? "" : field.value}
|
|
||||||
onChange={(e) => {
|
|
||||||
const val = e.target.value;
|
|
||||||
field.onChange(val === "" ? 0 : Number(val));
|
|
||||||
}}
|
|
||||||
type="number"
|
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.port.label")}
|
fieldLabel={t("pages.createMonitor.form.general.option.port.label")}
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"pages.createMonitor.form.general.option.port.placeholder"
|
"pages.createMonitor.form.general.option.port.placeholder"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -551,7 +472,9 @@ const CreateMonitorPage = () => {
|
|||||||
<Select
|
<Select
|
||||||
{...field}
|
{...field}
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.game.label")}
|
fieldLabel={t(
|
||||||
|
"pages.createMonitor.form.general.option.game.label"
|
||||||
|
)}
|
||||||
error={!!fieldState.error}
|
error={!!fieldState.error}
|
||||||
>
|
>
|
||||||
<MenuItem value="">
|
<MenuItem value="">
|
||||||
@@ -575,71 +498,36 @@ const CreateMonitorPage = () => {
|
|||||||
|
|
||||||
{/* gRPC Service Name field - only for grpc type */}
|
{/* gRPC Service Name field - only for grpc type */}
|
||||||
{generalSettingsConfig.showGrpcServiceName && (
|
{generalSettingsConfig.showGrpcServiceName && (
|
||||||
<Controller
|
<FormTextField
|
||||||
name="grpcServiceName"
|
name="grpcServiceName"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={t(
|
fieldLabel={t(
|
||||||
"pages.createMonitor.form.general.option.grpcServiceName.label"
|
"pages.createMonitor.form.general.option.grpcServiceName.label"
|
||||||
)}
|
)}
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"pages.createMonitor.form.general.option.grpcServiceName.placeholder"
|
"pages.createMonitor.form.general.option.grpcServiceName.placeholder"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Secret field - only for hardware type */}
|
{/* Secret field - only for hardware type */}
|
||||||
{generalSettingsConfig.showSecret && (
|
{generalSettingsConfig.showSecret && (
|
||||||
<Controller
|
<FormTextField
|
||||||
name="secret"
|
name="secret"
|
||||||
control={control}
|
fieldLabel={t("pages.createMonitor.form.general.option.secret.label")}
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
type="text"
|
|
||||||
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"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{generalSettingsConfig.showDnsServer && (
|
{generalSettingsConfig.showDnsServer && (
|
||||||
<Controller
|
<FormTextField
|
||||||
name="dnsServer"
|
name="dnsServer"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={t(
|
fieldLabel={t(
|
||||||
"pages.createMonitor.form.general.option.dnsServer.label"
|
"pages.createMonitor.form.general.option.dnsServer.label"
|
||||||
)}
|
)}
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"pages.createMonitor.form.general.option.dnsServer.placeholder"
|
"pages.createMonitor.form.general.option.dnsServer.placeholder"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{generalSettingsConfig.showDnsRecordType && (
|
{generalSettingsConfig.showDnsRecordType && (
|
||||||
@@ -690,21 +578,10 @@ const CreateMonitorPage = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<FormTextField
|
||||||
<Controller
|
|
||||||
name="name"
|
name="name"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.name.label")}
|
fieldLabel={t("pages.createMonitor.form.general.option.name.label")}
|
||||||
placeholder={generalSettingsConfig.namePlaceholder}
|
placeholder={generalSettingsConfig.namePlaceholder}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
@@ -1264,38 +1141,21 @@ const CreateMonitorPage = () => {
|
|||||||
</Select>
|
</Select>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Controller
|
|
||||||
|
<FormTextField
|
||||||
name="expectedValue"
|
name="expectedValue"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
fieldLabel={t(
|
fieldLabel={t(
|
||||||
"pages.createMonitor.form.advanced.option.expectedValue.label"
|
"pages.createMonitor.form.advanced.option.expectedValue.label"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
/>
|
<FormTextField
|
||||||
<Controller
|
|
||||||
name="jsonPath"
|
name="jsonPath"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
fieldLabel={t(
|
fieldLabel={t(
|
||||||
"pages.createMonitor.form.advanced.option.jsonPath.label"
|
"pages.createMonitor.form.advanced.option.jsonPath.label"
|
||||||
)}
|
)}
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
component="span"
|
component="span"
|
||||||
color={theme.palette.text.secondary}
|
color={theme.palette.text.secondary}
|
||||||
@@ -1369,7 +1229,10 @@ const CreateMonitorPage = () => {
|
|||||||
options={locationOptions}
|
options={locationOptions}
|
||||||
value={selectedLocations}
|
value={selectedLocations}
|
||||||
getOptionLabel={(option) => option.name}
|
getOptionLabel={(option) => option.name}
|
||||||
onChange={(_: unknown, newValue: typeof locationOptions) => {
|
onChange={(
|
||||||
|
_: unknown,
|
||||||
|
newValue: typeof locationOptions
|
||||||
|
) => {
|
||||||
field.onChange(newValue.map((loc) => loc.id));
|
field.onChange(newValue.map((loc) => loc.id));
|
||||||
}}
|
}}
|
||||||
isOptionEqualToValue={(option, value) =>
|
isOptionEqualToValue={(option, value) =>
|
||||||
@@ -1501,6 +1364,7 @@ const CreateMonitorPage = () => {
|
|||||||
loading={isDeleting}
|
loading={isDeleting}
|
||||||
/>
|
/>
|
||||||
</BasePage>
|
</BasePage>
|
||||||
|
</FormProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,34 @@ export const MonitorTypes = [
|
|||||||
] as const;
|
] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
|
|
||||||
|
// The subset offered by the CreateMonitor type selector, in display order.
|
||||||
|
// pagespeed/hardware are set by their own pages; unknown is never selectable.
|
||||||
|
export const SelectableMonitorTypes = [
|
||||||
|
"http",
|
||||||
|
"ping",
|
||||||
|
"docker",
|
||||||
|
"port",
|
||||||
|
"game",
|
||||||
|
"grpc",
|
||||||
|
"websocket",
|
||||||
|
"dns",
|
||||||
|
] as const;
|
||||||
|
export type SelectableMonitorType = (typeof SelectableMonitorTypes)[number];
|
||||||
|
|
||||||
|
// Irregular i18n key fragments shared by the type selector's label
|
||||||
|
// (pages.common.monitors.monitorTypes.<fragment>) and description
|
||||||
|
// (pages.createMonitor.form.type.<fragment>Description) keys.
|
||||||
|
export const monitorTypeLabelKey: Record<SelectableMonitorType, string> = {
|
||||||
|
http: "optionHttp",
|
||||||
|
ping: "optionPing",
|
||||||
|
docker: "optionDocker",
|
||||||
|
port: "optionPort",
|
||||||
|
game: "optionGame",
|
||||||
|
grpc: "optionGrpc",
|
||||||
|
websocket: "optionWebSocket",
|
||||||
|
dns: "optionDns",
|
||||||
|
};
|
||||||
|
|
||||||
export const DnsRecordTypes = ["A", "AAAA", "CNAME", "MX", "TXT", "NS"] as const;
|
export const DnsRecordTypes = ["A", "AAAA", "CNAME", "MX", "TXT", "NS"] as const;
|
||||||
export type DnsRecordType = (typeof DnsRecordTypes)[number];
|
export type DnsRecordType = (typeof DnsRecordTypes)[number];
|
||||||
|
|
||||||
|
|||||||
@@ -583,7 +583,7 @@
|
|||||||
},
|
},
|
||||||
"port": {
|
"port": {
|
||||||
"label": "Port to monitor",
|
"label": "Port to monitor",
|
||||||
"placeholder": 80
|
"placeholder": "80"
|
||||||
},
|
},
|
||||||
"grpcServiceName": {
|
"grpcServiceName": {
|
||||||
"label": "Service name",
|
"label": "Service name",
|
||||||
|
|||||||
Reference in new issue
Block a user