fix(client): render settings tab panels conditionally
Code review caught that the tab panels never hid.
Each panel was a `<Stack hidden={activeTab !== key}>`. The `hidden`
attribute reaches the DOM, but the only rule acting on it is the user
agent's `[hidden] { display: none }`, and MUI's Stack sets
`display: flex` in an author-level emotion class
(@mui/system/Stack/createStack.js:70). Author origin beats user agent
regardless of specificity, so every panel stayed visible: all five tabs
rendered stacked down the page and clicking a tab changed nothing.
Panels are now conditionally rendered, matching Pages/Account. This also
fixes a second defect: BasePage wraps children in `Stack spacing`, whose
sibling selector keys on DOM position rather than visibility, so the four
empty panels a non-admin never sees still collected a margin-top each and
left four blank gaps below "About".
My commit message for the previous commit argued panels had to stay
mounted or a partial tree would compute a stale `isValid` and lock
saving. That was wrong. No Form*Field passes `shouldUnregister`, and
react-hook-form defaults it to false, so unmounting a panel preserves its
values and validation state.
Also moves the tab-reveal off `onError`, which was unreachable: the save
button is `disabled={!isValid}` under `mode: "onChange"`, so
handleSubmit's error branch never fires. The validation Alert renders
straight from `formState.errors`, so a field on a hidden tab could be
named with no way to reach it. Each field in the Alert is now a button
that switches to its own tab.
Claude-Session: https://claude.ai/code/session_01AbYLvwpEaZFXktHVcqrFRd
This commit is contained in:
1 parent
9d0f0116f3
commit
d59bdf6c0c
1 file changed
+43
-31
@@ -347,15 +347,17 @@ export const SettingsPage = () => {
|
||||
|
||||
const onError = (errors: unknown) => {
|
||||
logger.debug("Form validation errors", errors);
|
||||
// The save bar lists errors by field name, so reveal the tab owning the
|
||||
// first one rather than naming a field the user cannot see.
|
||||
const firstField = Object.keys(errors ?? {})[0];
|
||||
if (firstField) {
|
||||
const target = tabForField(firstField);
|
||||
};
|
||||
|
||||
// The save bar lists errors by field name, and the offending field may sit on
|
||||
// a tab that is not open. Submitting cannot reveal it -- the button is
|
||||
// disabled while the form is invalid -- so each listed field switches to its
|
||||
// own tab instead.
|
||||
const revealField = (field: string) => {
|
||||
const target = tabForField(field);
|
||||
if (visibleTabs.some((tab) => tab.key === target)) {
|
||||
handleTabChange(target);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const languages = Object.keys(i18n.options.resources || {});
|
||||
@@ -398,10 +400,8 @@ export const SettingsPage = () => {
|
||||
)}
|
||||
|
||||
{/* general tab */}
|
||||
<Stack
|
||||
gap={theme.spacing(LAYOUT.MD)}
|
||||
hidden={activeTab !== "general"}
|
||||
>
|
||||
{activeTab === "general" && (
|
||||
<Stack gap={theme.spacing(LAYOUT.MD)}>
|
||||
<ConfigBox
|
||||
title={t("pages.settings.form.timezone.title")}
|
||||
subtitle={t("pages.settings.form.timezone.description")}
|
||||
@@ -505,12 +505,11 @@ export const SettingsPage = () => {
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* monitoring tab */}
|
||||
<Stack
|
||||
gap={theme.spacing(LAYOUT.MD)}
|
||||
hidden={activeTab !== "monitoring"}
|
||||
>
|
||||
{activeTab === "monitoring" && (
|
||||
<Stack gap={theme.spacing(LAYOUT.MD)}>
|
||||
{/* Global Thresholds */}
|
||||
{isAdmin && (
|
||||
<ConfigBox
|
||||
@@ -601,12 +600,11 @@ export const SettingsPage = () => {
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* email tab */}
|
||||
<Stack
|
||||
gap={theme.spacing(LAYOUT.MD)}
|
||||
hidden={activeTab !== "email"}
|
||||
>
|
||||
{activeTab === "email" && (
|
||||
<Stack gap={theme.spacing(LAYOUT.MD)}>
|
||||
{/* Email Settings - Admin Only */}
|
||||
{isAdmin && (
|
||||
<ConfigBox
|
||||
@@ -646,12 +644,14 @@ export const SettingsPage = () => {
|
||||
pass: "<your_password>",
|
||||
},
|
||||
name:
|
||||
form.watch("systemEmailConnectionHost") || "localhost",
|
||||
form.watch("systemEmailConnectionHost") ||
|
||||
"localhost",
|
||||
pool: form.watch("systemEmailPool") ?? false,
|
||||
tls: {
|
||||
rejectUnauthorized:
|
||||
form.watch("systemEmailRejectUnauthorized") ?? true,
|
||||
ignoreTLS: form.watch("systemEmailIgnoreTLS") ?? false,
|
||||
ignoreTLS:
|
||||
form.watch("systemEmailIgnoreTLS") ?? false,
|
||||
requireTLS:
|
||||
form.watch("systemEmailRequireTLS") ?? false,
|
||||
servername:
|
||||
@@ -761,7 +761,9 @@ export const SettingsPage = () => {
|
||||
{/* TLS Servername (Optional) */}
|
||||
<FormTextField
|
||||
name="systemEmailTLSServername"
|
||||
fieldLabel={t("pages.settings.form.email.option.tlsServername.label")}
|
||||
fieldLabel={t(
|
||||
"pages.settings.form.email.option.tlsServername.label"
|
||||
)}
|
||||
placeholder={t(
|
||||
"pages.settings.form.email.option.tlsServername.placeholder"
|
||||
)}
|
||||
@@ -815,12 +817,11 @@ export const SettingsPage = () => {
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* integrations tab */}
|
||||
<Stack
|
||||
gap={theme.spacing(LAYOUT.MD)}
|
||||
hidden={activeTab !== "integrations"}
|
||||
>
|
||||
{activeTab === "integrations" && (
|
||||
<Stack gap={theme.spacing(LAYOUT.MD)}>
|
||||
{isAdmin && (
|
||||
<ConfigBox
|
||||
title={t("pages.settings.form.globalProxy.title")}
|
||||
@@ -863,7 +864,9 @@ export const SettingsPage = () => {
|
||||
<FormTextField
|
||||
name="pagespeedApiKey"
|
||||
type="password"
|
||||
fieldLabel={t("pages.settings.form.pagespeed.option.apiKey.label")}
|
||||
fieldLabel={t(
|
||||
"pages.settings.form.pagespeed.option.apiKey.label"
|
||||
)}
|
||||
placeholder={t(
|
||||
"pages.settings.form.pagespeed.option.apiKey.placeholder"
|
||||
)}
|
||||
@@ -889,12 +892,11 @@ export const SettingsPage = () => {
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* data tab */}
|
||||
<Stack
|
||||
gap={theme.spacing(LAYOUT.MD)}
|
||||
hidden={activeTab !== "data"}
|
||||
>
|
||||
{activeTab === "data" && (
|
||||
<Stack gap={theme.spacing(LAYOUT.MD)}>
|
||||
{/* Export Monitors - Admin Only */}
|
||||
{isAdmin && (
|
||||
<ConfigBox
|
||||
@@ -968,6 +970,7 @@ export const SettingsPage = () => {
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* Clear Stats Confirmation Dialog */}
|
||||
<Dialog
|
||||
@@ -1032,7 +1035,16 @@ export const SettingsPage = () => {
|
||||
return (
|
||||
<li key={field}>
|
||||
<Typography variant="body2">
|
||||
<strong>{field}:</strong> {message}
|
||||
<Link
|
||||
component="button"
|
||||
type="button"
|
||||
variant="body2"
|
||||
color={theme.palette.error.main}
|
||||
onClick={() => revealField(field)}
|
||||
>
|
||||
<strong>{field}</strong>
|
||||
</Link>
|
||||
: {message}
|
||||
</Typography>
|
||||
</li>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user