Merge pull request #3868 from bluewave-labs/feat/proxy-frontend
add global proxy setting config and translation keys
This commit is contained in:
4 files changed
+150
-58
No files matched your search
@@ -43,6 +43,8 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) =>
|
|||||||
checkTTL: data?.checkTTL ?? 30,
|
checkTTL: data?.checkTTL ?? 30,
|
||||||
pagespeedApiKey: "",
|
pagespeedApiKey: "",
|
||||||
systemEmailPassword: "",
|
systemEmailPassword: "",
|
||||||
|
globalProxyEnabled: data?.globalProxyEnabled ?? false,
|
||||||
|
globalProxyId: data?.globalProxyId ?? null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { schema: settingsSchema, defaults };
|
return { schema: settingsSchema, defaults };
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
type SelectChangeEvent,
|
type SelectChangeEvent,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { FormProvider, useForm, type FieldPath } from "react-hook-form";
|
import { FormProvider, useForm, type FieldPath } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -43,6 +43,8 @@ import { FormTextField } from "@/Components/inputs/forms/FormTextField";
|
|||||||
import { FormSliderField } from "@/Components/inputs/forms/FormSliderField";
|
import { FormSliderField } from "@/Components/inputs/forms/FormSliderField";
|
||||||
import { FormSwitchField } from "@/Components/inputs/forms/FormSwitchField";
|
import { FormSwitchField } from "@/Components/inputs/forms/FormSwitchField";
|
||||||
import { FormNumberField } from "@/Components/inputs/forms/FormNumberField";
|
import { FormNumberField } from "@/Components/inputs/forms/FormNumberField";
|
||||||
|
import { FormSelectField } from "@/Components/inputs/forms/FormSelectField";
|
||||||
|
import type { ProxyResponse } from "@/Types/Proxy";
|
||||||
|
|
||||||
interface SettingsResponse {
|
interface SettingsResponse {
|
||||||
settings: any;
|
settings: any;
|
||||||
@@ -65,6 +67,17 @@ export const SettingsPage = () => {
|
|||||||
|
|
||||||
// Fetch settings data from API
|
// Fetch settings data from API
|
||||||
const { data: fetchedSettings } = useGet<SettingsResponse>("/settings");
|
const { data: fetchedSettings } = useGet<SettingsResponse>("/settings");
|
||||||
|
// Get proxies
|
||||||
|
const { data: proxies } = useGet<ProxyResponse[]>("/proxies/team");
|
||||||
|
const proxyOptions = useMemo(
|
||||||
|
() =>
|
||||||
|
(proxies ?? []).map((proxy) => ({
|
||||||
|
value: proxy.id,
|
||||||
|
label: `${proxy.name} (${proxy.host}:${proxy.port})`,
|
||||||
|
})),
|
||||||
|
[proxies]
|
||||||
|
);
|
||||||
|
|
||||||
// Form submission
|
// Form submission
|
||||||
const { patch, loading: isSaving } = usePatch<SettingsFormData, SettingsResponse>();
|
const { patch, loading: isSaving } = usePatch<SettingsFormData, SettingsResponse>();
|
||||||
|
|
||||||
@@ -115,6 +128,8 @@ export const SettingsPage = () => {
|
|||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { watch } = form;
|
||||||
|
|
||||||
// Reset form when defaults change
|
// Reset form when defaults change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
form.reset(defaults);
|
form.reset(defaults);
|
||||||
@@ -292,6 +307,21 @@ export const SettingsPage = () => {
|
|||||||
|
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
const languages = Object.keys(i18n.options.resources || {});
|
||||||
|
|
||||||
|
const globalProxyEnabled = watch("globalProxyEnabled");
|
||||||
|
|
||||||
|
// Enabling the proxy with nothing selected preselects the first proxy
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
globalProxyEnabled &&
|
||||||
|
!form.getValues("globalProxyId") &&
|
||||||
|
proxyOptions.length > 0
|
||||||
|
) {
|
||||||
|
form.setValue("globalProxyId", proxyOptions[0].value, {
|
||||||
|
shouldValidate: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [globalProxyEnabled, proxyOptions, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...form}>
|
<FormProvider {...form}>
|
||||||
<BasePage
|
<BasePage
|
||||||
@@ -365,6 +395,38 @@ export const SettingsPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
{isAdmin && (
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.settings.form.globalProxy.title")}
|
||||||
|
subtitle={t("pages.settings.form.globalProxy.description")}
|
||||||
|
rightContent={
|
||||||
|
proxyOptions.length > 0 ? (
|
||||||
|
<Stack>
|
||||||
|
<FormSwitchField
|
||||||
|
name="globalProxyEnabled"
|
||||||
|
labelPlacement="start"
|
||||||
|
label={t("pages.settings.form.globalProxy.option.enabled.label")}
|
||||||
|
/>
|
||||||
|
{globalProxyEnabled && (
|
||||||
|
<FormSelectField
|
||||||
|
fieldLabel={t(
|
||||||
|
"pages.settings.form.globalProxy.option.proxy.label"
|
||||||
|
)}
|
||||||
|
name="globalProxyId"
|
||||||
|
options={proxyOptions}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
) : (
|
||||||
|
<TextLink
|
||||||
|
text={t("pages.settings.form.globalProxy.option.empty.text")}
|
||||||
|
linkText={t("pages.settings.form.globalProxy.option.empty.link")}
|
||||||
|
href="/proxies"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.settings.form.pagespeed.title")}
|
title={t("pages.settings.form.pagespeed.title")}
|
||||||
|
|||||||
@@ -1,61 +1,73 @@
|
|||||||
import { CHECK_TTL_SENTINEL } from "@/Types/Check";
|
import { CHECK_TTL_SENTINEL } from "@/Types/Check";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const settingsSchema = z.object({
|
export const settingsSchema = z
|
||||||
systemEmailIgnoreTLS: z.boolean(),
|
.object({
|
||||||
systemEmailRequireTLS: z.boolean(),
|
systemEmailIgnoreTLS: z.boolean(),
|
||||||
systemEmailRejectUnauthorized: z.boolean(),
|
systemEmailRequireTLS: z.boolean(),
|
||||||
systemEmailConnectionHost: z
|
systemEmailRejectUnauthorized: z.boolean(),
|
||||||
.string()
|
systemEmailConnectionHost: z
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.string()
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailSecure: z.boolean().optional(),
|
.optional(),
|
||||||
systemEmailPool: z.boolean().optional(),
|
systemEmailSecure: z.boolean().optional(),
|
||||||
showURL: z.boolean().optional(),
|
systemEmailPool: z.boolean().optional(),
|
||||||
checkTTL: z
|
showURL: z.boolean().optional(),
|
||||||
.number()
|
checkTTL: z
|
||||||
.int()
|
.number()
|
||||||
.min(1, "Please enter a value")
|
.int()
|
||||||
.max(CHECK_TTL_SENTINEL, `Maximum ${CHECK_TTL_SENTINEL}`),
|
.min(1, "Please enter a value")
|
||||||
pagespeedApiKey: z
|
.max(CHECK_TTL_SENTINEL, `Maximum ${CHECK_TTL_SENTINEL}`),
|
||||||
.string()
|
pagespeedApiKey: z
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.string()
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailHost: z
|
.optional(),
|
||||||
.string()
|
systemEmailHost: z
|
||||||
.regex(/^[a-zA-Z0-9.-]*$/, "Invalid hostname or IP address")
|
.string()
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.regex(/^[a-zA-Z0-9.-]*$/, "Invalid hostname or IP address")
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailPort: z.number().int().min(1).max(65535).optional(),
|
.optional(),
|
||||||
systemEmailAddress: z
|
systemEmailPort: z.number().int().min(1).max(65535).optional(),
|
||||||
.email("Please enter a valid email address")
|
systemEmailAddress: z
|
||||||
.or(z.literal(""))
|
.email("Please enter a valid email address")
|
||||||
.transform((val) => (val === "" ? null : val.toLowerCase().trim()))
|
.or(z.literal(""))
|
||||||
.optional(),
|
.transform((val) => (val === "" ? null : val.toLowerCase().trim()))
|
||||||
systemEmailDisplayName: z
|
.optional(),
|
||||||
.string()
|
systemEmailDisplayName: z
|
||||||
.max(100, "Display name must be 100 characters or fewer")
|
.string()
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.max(100, "Display name must be 100 characters or fewer")
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailUser: z
|
.optional(),
|
||||||
.string()
|
systemEmailUser: z
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.string()
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailPassword: z
|
.optional(),
|
||||||
.string()
|
systemEmailPassword: z
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.string()
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
systemEmailTLSServername: z
|
.optional(),
|
||||||
.string()
|
systemEmailTLSServername: z
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.string()
|
||||||
.optional(),
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
globalThresholds: z.object({
|
.optional(),
|
||||||
cpu: z.number().int().min(1).max(100),
|
globalThresholds: z.object({
|
||||||
memory: z.number().int().min(1).max(100),
|
cpu: z.number().int().min(1).max(100),
|
||||||
disk: z.number().int().min(1).max(100),
|
memory: z.number().int().min(1).max(100),
|
||||||
temperature: z.number().int().min(1).max(150),
|
disk: z.number().int().min(1).max(100),
|
||||||
}),
|
temperature: z.number().int().min(1).max(150),
|
||||||
});
|
}),
|
||||||
|
globalProxyEnabled: z.boolean(),
|
||||||
|
globalProxyId: z.string().nullable().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((body, ctx) => {
|
||||||
|
if (body.globalProxyEnabled === true && !body.globalProxyId) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: "custom",
|
||||||
|
path: ["globalProxyId"],
|
||||||
|
message: "A proxy must be selected to enable the global proxy",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export type SettingsFormInput = z.input<typeof settingsSchema>;
|
export type SettingsFormInput = z.input<typeof settingsSchema>;
|
||||||
export type SettingsFormData = z.infer<typeof settingsSchema>;
|
export type SettingsFormData = z.infer<typeof settingsSchema>;
|
||||||
@@ -643,13 +643,13 @@
|
|||||||
"label": "Proxy",
|
"label": "Proxy",
|
||||||
"value": {
|
"value": {
|
||||||
"inheritDirect": "Default (direct connection)",
|
"inheritDirect": "Default (direct connection)",
|
||||||
"inheritGlobal": "Default (global proxy: {{name}})",
|
"inheritGlobal": "Default ({{name}})",
|
||||||
"none": "Never use a proxy",
|
"none": "Never use a proxy",
|
||||||
"custom": "Custom proxy"
|
"custom": "Custom proxy"
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"inheritDirect": "No global proxy is configured, connect directly. If a global proxy is later configured, this monitor will use it.",
|
"inheritDirect": "No global proxy is configured, connect directly. If a global proxy is later configured, this monitor will use it.",
|
||||||
"inheritGlobal": "Follows the global proxy setting — changing it in Settings also changes this monitor's connection.",
|
"inheritGlobal": "Use the global proxy setting",
|
||||||
"none": "Always connects directly even if a global proxy is enabled later.",
|
"none": "Always connects directly even if a global proxy is enabled later.",
|
||||||
"custom": "Route this monitor's checks through a specific proxy. Overrides global proxy"
|
"custom": "Route this monitor's checks through a specific proxy. Overrides global proxy"
|
||||||
}
|
}
|
||||||
@@ -1362,6 +1362,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"globalProxy": {
|
||||||
|
"title": "Global proxy",
|
||||||
|
"description": "Route monitoring checks through a proxy by default. Applies to all HTTP monitors whose proxy setting is \"Default\"; monitors set to \"Never use a proxy\" or a custom proxy are unaffected.",
|
||||||
|
"option": {
|
||||||
|
"enabled": {
|
||||||
|
"label": "Use global proxy"
|
||||||
|
},
|
||||||
|
"proxy": {
|
||||||
|
"label": "Choose a global proxy"
|
||||||
|
},
|
||||||
|
"empty": {
|
||||||
|
"text": "No proxies configured yet.",
|
||||||
|
"link": "Create one first"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"pagespeed": {
|
"pagespeed": {
|
||||||
"title": "Google PageSpeed API key",
|
"title": "Google PageSpeed API key",
|
||||||
"description": "Enter your Google PageSpeed API key to enable Google PageSpeed monitoring. Click Reset to update the key.",
|
"description": "Enter your Google PageSpeed API key to enable Google PageSpeed monitoring. Click Reset to update the key.",
|
||||||
|
|||||||
Reference in new issue
Block a user