Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Split the SSO auth settings pages into card sections (#81750)

Andrei Chernykh8a7375b368fe
diff --git a/e2e/test/scenarios/data-model/data-model-shared-2.cy.spec.ts b/e2e/test/scenarios/data-model/data-model-shared-2.cy.spec.ts
index 4238aeb4ad0..b7c7d92602a 100644
--- a/e2e/test/scenarios/data-model/data-model-shared-2.cy.spec.ts
+++ b/e2e/test/scenarios/data-model/data-model-shared-2.cy.spec.ts
@@ -198,7 +198,9 @@ areas.forEach((area) => {
cy.button("Discard cached field values").should("be.visible");
});
- cy.realPress("Escape");
+ // synthetic escape: realPress depends on real browser focus, which
+ // the app may not hold in CI, so the keystroke can miss the modal
+ cy.get("body").type("{esc}");
H.modal().should("not.exist");
});
diff --git a/e2e/test/scenarios/data-model/data-model-shared-4.cy.spec.ts b/e2e/test/scenarios/data-model/data-model-shared-4.cy.spec.ts
index 56aa2125633..c55b479820c 100644
--- a/e2e/test/scenarios/data-model/data-model-shared-4.cy.spec.ts
+++ b/e2e/test/scenarios/data-model/data-model-shared-4.cy.spec.ts
@@ -148,7 +148,10 @@ areas.forEach((area) => {
verifyAndCloseToast("Failed to discard values");
if (area === "admin") {
- cy.realPress("Escape");
+ // synthetic escape: realPress depends on real browser focus, which
+ // the app may not hold in CI, so the keystroke can miss the modal
+ cy.get("body").type("{esc}");
+ H.modal().should("not.exist");
}
if (area === "data studio") {
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
index 3e62ae36d04..c10cdd83307 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
@@ -2,6 +2,7 @@ import { t } from "ttag";
import { SettingsSection } from "metabase/admin/components/SettingsSection";
import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
+import { getExtraFormFieldProps } from "metabase/admin/settings/utils";
import { FormTextInput } from "metabase/forms";
import { useAdminSetting } from "metabase/settings";
import { provisioningOptions } from "metabase-enterprise/auth/utils";
@@ -26,8 +27,8 @@ export function LdapGroupMembershipFilter() {
<FormTextInput
name="ldap-group-membership-filter"
label={t`Group membership filter`}
- description={settingDetails?.description}
nullable
+ {...getExtraFormFieldProps(settingDetails)}
/>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
index 48bdb1d61d5..baf63acc273 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
@@ -2,6 +2,10 @@ import { t } from "ttag";
import _ from "underscore";
import {
+ CollapsibleSettingsSection,
+ SETTINGS_CARD_DESCRIPTION_PROPS,
+ SETTINGS_CARD_STACK_PROPS,
+ SETTINGS_CARD_TITLE_PROPS,
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
@@ -15,21 +19,35 @@ import {
FormErrorMessage,
FormProvider,
FormSecretKey,
- FormSection,
FormSubmitButton,
FormTextInput,
} from "metabase/forms";
+import { useSelector } from "metabase/redux";
+import { getApplicationName } from "metabase/selectors/whitelabel";
import {
useAdminSetting,
useGetAdminSettingsDetailsQuery,
} from "metabase/settings";
-import { Flex, Stack } from "metabase/ui";
+import { Box, Flex, Stack } from "metabase/ui";
import { provisioningOptions } from "metabase-enterprise/auth/utils";
import type {
EnterpriseSettings,
+ SettingDefinition,
SettingDefinitionMap,
} from "metabase-types/api";
+// Attribute-key fields show only a placeholder, no helper text. Env-locked
+// fields swap the placeholder for the readOnly "Using MB_..." notice.
+const getAttributeFieldProps = (
+ setting: SettingDefinition | undefined,
+ placeholder?: string,
+) => {
+ if (setting?.is_env_setting) {
+ return getExtraFormFieldProps(setting);
+ }
+ return { placeholder };
+};
+
export type JWTFormValues = Pick<
EnterpriseSettings,
| "jwt-identity-provider-uri"
@@ -46,6 +64,7 @@ export const SettingsJWTForm = () => {
refetch: refetchSettingDetails,
} = useGetAdminSettingsDetailsQuery();
const { value: jwtEnabled, updateSettings } = useAdminSetting("jwt-enabled");
+ const applicationName = useSelector(getApplicationName);
const [sendToast] = useToast();
const handleSubmit = async (values: Partial<JWTFormValues>) => {
@@ -84,6 +103,17 @@ export const SettingsJWTForm = () => {
}
const usingTenants = settingDetails["use-tenants"]?.value;
+ const hasUserAttributes = [
+ settingDetails["jwt-attribute-email"],
+ settingDetails["jwt-attribute-firstname"],
+ settingDetails["jwt-attribute-lastname"],
+ settingDetails["jwt-attribute-groups"],
+ ...(usingTenants ? [settingDetails["jwt-attribute-tenant"]] : []),
+ ].some(
+ // env-configured attributes come back with a nil value and only the
+ // is_env_setting flag, so value alone can't detect them
+ (setting) => Boolean(setting?.value) || (setting?.is_env_setting ?? false),
+ );
return (
<SettingsPageWrapper title={t`JWT`}>
@@ -97,15 +127,19 @@ export const SettingsJWTForm = () => {
/>
</SettingsSection>
)}
- <SettingsSection>
- <FormProvider
- initialValues={getFormValues(settingDetails)}
- onSubmit={handleSubmit}
- enableReinitialize
- >
- {({ dirty }) => (
- <Form>
- <FormSection title={"Server Settings"}>
+ <FormProvider
+ initialValues={getFormValues(settingDetails)}
+ onSubmit={handleSubmit}
+ enableReinitialize
+ >
+ {({ dirty }) => (
+ <Form>
+ <Stack gap="xl">
+ <SettingsSection
+ title={t`Server settings`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="xl">
<FormTextInput
name="jwt-identity-provider-uri"
@@ -126,60 +160,73 @@ export const SettingsJWTForm = () => {
)}
/>
</Stack>
- </FormSection>
- <FormSection
- title={"User attribute configuration (optional)"}
- collapsible
+ </SettingsSection>
+ <CollapsibleSettingsSection
+ title={t`User attribute configuration`}
+ description={t`You can send additional user attributes to ${applicationName} by adding the attributes as key/value pairs to your JWT`}
+ defaultOpened={hasUserAttributes}
>
<Stack gap="lg">
<FormTextInput
name="jwt-attribute-email"
- label={t`Email attribute`}
- {...getExtraFormFieldProps(
+ label={t`Email attribute key`}
+ {...getAttributeFieldProps(
settingDetails?.["jwt-attribute-email"],
+ "email-key",
)}
/>
<FormTextInput
name="jwt-attribute-firstname"
- label={t`First name attribute`}
- {...getExtraFormFieldProps(
+ label={t`First name attribute key`}
+ {...getAttributeFieldProps(
settingDetails?.["jwt-attribute-firstname"],
+ "first-name-key",
)}
/>
<FormTextInput
name="jwt-attribute-lastname"
- label={t`Last name attribute`}
- {...getExtraFormFieldProps(
+ label={t`Last name attribute key`}
+ {...getAttributeFieldProps(
settingDetails?.["jwt-attribute-lastname"],
+ "last-name-key",
)}
/>
<FormTextInput
name="jwt-attribute-groups"
- label={t`Group assignment attribute`}
- {...getExtraFormFieldProps(
+ label={t`Group assignment attribute key`}
+ {...getAttributeFieldProps(
settingDetails?.["jwt-attribute-groups"],
+ "group-assignment-key",
)}
/>
{usingTenants && (
<FormTextInput
name="jwt-attribute-tenant"
- label={t`Tenant assignment attribute`}
- {...getExtraFormFieldProps(
+ label={t`Tenant assignment attribute key`}
+ {...getAttributeFieldProps(
settingDetails?.["jwt-attribute-tenant"],
)}
/>
)}
</Stack>
- </FormSection>
- <FormSection title={"Group Sync"} data-testid="jwt-group-schema">
- <GroupMappingsWidget
- setting={{ key: "jwt-group-sync" }}
- onChange={handleSubmit}
- mappingSetting="jwt-group-mappings"
- groupHeading={t`Group Name`}
- groupPlaceholder={t`Group Name`}
- />
- </FormSection>
+ </CollapsibleSettingsSection>
+ <SettingsSection
+ title={t`Group mapping`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ description={t`Lets you assign users to custom ${applicationName} groups based on their JWT attributes`}
+ descriptionProps={SETTINGS_CARD_DESCRIPTION_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
+ <Box data-testid="jwt-group-schema">
+ <GroupMappingsWidget
+ setting={{ key: "jwt-group-sync" }}
+ onChange={handleSubmit}
+ mappingSetting="jwt-group-mappings"
+ groupHeading={t`Group Name`}
+ groupPlaceholder={t`Group Name`}
+ />
+ </Box>
+ </SettingsSection>
<FormErrorMessage />
<Flex justify="end">
<FormSubmitButton
@@ -188,10 +235,10 @@ export const SettingsJWTForm = () => {
variant="filled"
/>
</Flex>
- </Form>
- )}
- </FormProvider>
- </SettingsSection>
+ </Stack>
+ </Form>
+ )}
+ </FormProvider>
</SettingsPageWrapper>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
index 59474aa3cfd..05262a21fa8 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
@@ -26,10 +26,16 @@ const setup = async ({
jwtEnabled,
useTenants,
configured,
+ attributesConfigured,
+ attributesEnvConfigured,
+ tenantAttributeConfigured,
}: {
jwtEnabled?: boolean;
useTenants?: boolean;
configured?: boolean;
+ attributesConfigured?: boolean;
+ attributesEnvConfigured?: boolean;
+ tenantAttributeConfigured?: boolean;
} = {}) => {
setupSettingsEndpoints([
{ key: "use-tenants", value: useTenants ?? false },
@@ -40,6 +46,21 @@ const setup = async ({
{ key: "jwt-shared-secret", value: "590ab155f412d477b8ab9c8b0e7b" },
] as const)
: []),
+ ...(attributesConfigured
+ ? ([{ key: "jwt-attribute-email", value: "email-key" }] as const)
+ : []),
+ ...(attributesEnvConfigured
+ ? ([
+ {
+ key: "jwt-attribute-email",
+ is_env_setting: true,
+ env_name: "MB_JWT_ATTRIBUTE_EMAIL",
+ },
+ ] as const)
+ : []),
+ ...(tenantAttributeConfigured
+ ? ([{ key: "jwt-attribute-tenant", value: "tenant-key" }] as const)
+ : []),
]);
setupPropertiesEndpoints(
createMockSettings({
@@ -55,7 +76,13 @@ const setup = async ({
renderWithProviders(<SettingsJWTForm />, { withUndos: true });
- await screen.findByText("Server Settings");
+ await screen.findByText("Server settings");
+};
+
+const expandUserAttributeSection = async () => {
+ await userEvent.click(
+ await screen.findByRole("button", { name: /User attribute configuration/ }),
+ );
};
describe("SettingsJWTForm", () => {
@@ -87,6 +114,7 @@ describe("SettingsJWTForm", () => {
ATTRS["jwt-shared-secret"],
);
await userEvent.click(await screen.findByRole("button", { name: /Done/ }));
+ await expandUserAttributeSection();
await userEvent.type(
await screen.findByRole("textbox", { name: /Email attribute/ }),
ATTRS["jwt-attribute-email"],
@@ -151,6 +179,49 @@ describe("SettingsJWTForm", () => {
expect(await screen.findByText("Changes saved")).toBeInTheDocument();
});
+ it("collapses the user attribute section when no attribute is set", async () => {
+ await setup();
+
+ expect(
+ await screen.findByRole("button", {
+ name: /User attribute configuration/,
+ }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("expands the user attribute section when an attribute is set", async () => {
+ await setup({ attributesConfigured: true });
+
+ expect(
+ await screen.findByRole("button", {
+ name: /User attribute configuration/,
+ }),
+ ).toHaveAttribute("aria-expanded", "true");
+ expect(
+ screen.getByRole("textbox", { name: /Email attribute/ }),
+ ).toBeVisible();
+ });
+
+ it("expands the user attribute section when attributes are set via env vars", async () => {
+ await setup({ attributesEnvConfigured: true });
+
+ expect(
+ await screen.findByRole("button", {
+ name: /User attribute configuration/,
+ }),
+ ).toHaveAttribute("aria-expanded", "true");
+ });
+
+ it("ignores a tenant attribute for the default-open check when tenants are off", async () => {
+ await setup({ tenantAttributeConfigured: true });
+
+ expect(
+ await screen.findByRole("button", {
+ name: /User attribute configuration/,
+ }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+
it("should not show tenant attribute unless tenanting is on", async () => {
await setup();
@@ -167,6 +238,7 @@ describe("SettingsJWTForm", () => {
ATTRS["jwt-identity-provider-uri"],
);
+ await expandUserAttributeSection();
await userEvent.type(
await screen.findByRole("textbox", {
name: /Tenant assignment attribute/,
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
index ffb450c0041..44b71188d60 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
@@ -4,11 +4,16 @@ import { t } from "ttag";
import * as Yup from "yup";
import {
+ CollapsibleSettingsSection,
+ SETTINGS_CARD_DESCRIPTION_PROPS,
+ SETTINGS_CARD_STACK_PROPS,
+ SETTINGS_CARD_TITLE_PROPS,
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { GroupMappingsWidgetView } from "metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupMappingsWidgetView";
+import { SETTINGS_FIELD_DESCRIPTION_PROPS } from "metabase/admin/settings/utils";
import {
useClearGroupMembershipMutation,
useDeletePermissionsGroupMutation,
@@ -22,14 +27,13 @@ import {
Form,
FormErrorMessage,
FormProvider,
- FormSection,
FormSubmitButton,
FormTextInput,
} from "metabase/forms";
import { useSelector } from "metabase/redux";
import { getApplicationName } from "metabase/selectors/whitelabel";
import { useSetting } from "metabase/settings";
-import { Button, Flex, Stack, Text } from "metabase/ui";
+import { Button, Flex, Stack } from "metabase/ui";
import {
type CustomOidcConfig,
type OidcCheckRequest,
@@ -42,6 +46,11 @@ import {
import { provisioningOptions } from "metabase-enterprise/auth/utils";
import type { Group, GroupId } from "metabase-types/api";
+const DEFAULT_SCOPES = ["openid", "email", "profile"];
+const DEFAULT_EMAIL_ATTRIBUTE = "email";
+const DEFAULT_FIRST_NAME_ATTRIBUTE = "given_name";
+const DEFAULT_LAST_NAME_ATTRIBUTE = "family_name";
+
function getOidcFormSchema() {
return Yup.object({
"login-prompt": Yup.string().required(t`Login prompt is required`),
@@ -54,10 +63,14 @@ function getOidcFormSchema() {
"issuer-uri": Yup.string().required(t`Issuer URI is required`),
"client-id": Yup.string().required(t`Client ID is required`),
"client-secret": Yup.string().nullable().default(null),
- scopes: Yup.string().nullable().default("openid, email, profile"),
- "attribute-email": Yup.string().nullable().default("email"),
- "attribute-firstname": Yup.string().nullable().default("given_name"),
- "attribute-lastname": Yup.string().nullable().default("family_name"),
+ scopes: Yup.string().nullable().default(DEFAULT_SCOPES.join(", ")),
+ "attribute-email": Yup.string().nullable().default(DEFAULT_EMAIL_ATTRIBUTE),
+ "attribute-firstname": Yup.string()
+ .nullable()
+ .default(DEFAULT_FIRST_NAME_ATTRIBUTE),
+ "attribute-lastname": Yup.string()
+ .nullable()
+ .default(DEFAULT_LAST_NAME_ATTRIBUTE),
"group-sync-enabled": Yup.boolean().default(false),
"group-attribute": Yup.string().nullable().default("groups"),
});
@@ -87,10 +100,10 @@ function providerToFormValues(
"issuer-uri": "",
"client-id": "",
"client-secret": null,
- scopes: "openid, email, profile",
- "attribute-email": "email",
- "attribute-firstname": "given_name",
- "attribute-lastname": "family_name",
+ scopes: DEFAULT_SCOPES.join(", "),
+ "attribute-email": DEFAULT_EMAIL_ATTRIBUTE,
+ "attribute-firstname": DEFAULT_FIRST_NAME_ATTRIBUTE,
+ "attribute-lastname": DEFAULT_LAST_NAME_ATTRIBUTE,
"group-sync-enabled": false,
"group-attribute": "groups",
};
@@ -105,10 +118,12 @@ function providerToFormValues(
"issuer-uri": provider["issuer-uri"] ?? "",
"client-id": provider["client-id"] ?? "",
"client-secret": null,
- scopes: (provider.scopes ?? ["openid", "email", "profile"]).join(", "),
- "attribute-email": attributeMap["email"] ?? "email",
- "attribute-firstname": attributeMap["first_name"] ?? "given_name",
- "attribute-lastname": attributeMap["last_name"] ?? "family_name",
+ scopes: (provider.scopes ?? DEFAULT_SCOPES).join(", "),
+ "attribute-email": attributeMap["email"] ?? DEFAULT_EMAIL_ATTRIBUTE,
+ "attribute-firstname":
+ attributeMap["first_name"] ?? DEFAULT_FIRST_NAME_ATTRIBUTE,
+ "attribute-lastname":
+ attributeMap["last_name"] ?? DEFAULT_LAST_NAME_ATTRIBUTE,
"group-sync-enabled": groupSync.enabled ?? false,
"group-attribute": groupSync["group-attribute"] ?? "groups",
};
@@ -123,7 +138,7 @@ function formValuesToProvider(
.split(",")
.map((s) => s.trim())
.filter(Boolean)
- : ["openid", "email", "profile"];
+ : DEFAULT_SCOPES;
const attributeMap: Record<string, string> = {};
if (values["attribute-email"]) {
@@ -188,7 +203,6 @@ export function SettingsOIDCForm() {
() => providerToFormValues(existingProvider),
[existingProvider],
);
-
const runCheck = useCallback(
async (values: OIDCFormValues) => {
const req: OidcCheckRequest = {
@@ -353,186 +367,193 @@ export function SettingsOIDCForm() {
return (
<SettingsPageWrapper title={t`OpenID Connect`}>
- <Stack gap="xl">
- <SettingsSection>
- <AdminSettingInput
- name="oidc-user-provisioning-enabled?"
- title={t`User provisioning`}
- inputType="radio"
- options={provisioningOptions("OIDC")}
- />
- </SettingsSection>
-
- <FormProvider
- initialValues={initialValues}
- onSubmit={handleSubmit}
- validationSchema={getOidcFormSchema()}
- enableReinitialize
- >
- {({ dirty, values }) => (
- <Form>
- <SettingsSection>
- <FormSection title={t`Server settings`}>
- <Stack gap="lg">
- <FormTextInput
- name="key"
- label={t`Key`}
- description={t`Provider identifier. Your OIDC redirect URI will be "${siteUrl}/auth/sso/${values.key || "{key}"}/callback"`}
- placeholder={t`e.g. okta`}
- required
- disabled={isExisting}
- />
- <FormTextInput
- name="login-prompt"
- label={t`Login prompt`}
- description={t`Button text on the ${applicationName} sign-in screen`}
- placeholder={t`e.g. Sign in with Okta`}
- required
- />
- <FormTextInput
- name="issuer-uri"
- label={t`Issuer URI`}
- description={t`The OIDC issuer URI. The discovery endpoint "${(values["issuer-uri"] || "{url}").replace(/\/+$/, "")}/.well-known/openid-configuration" should be accessible.`}
- placeholder="https://your-idp.example.com"
- required
- />
- <FormTextInput
- name="client-id"
- label={t`Client ID`}
- description={t`The Client ID configured for ${applicationName} in your OIDC provider.`}
- required
- />
- <FormTextInput
- name="client-secret"
- label={t`Client Secret`}
- description={t`The Client secret configured in your OIDC provider.`}
- type="password"
- placeholder={
- isExisting ? t`Leave blank to keep current value` : ""
- }
- />
- </Stack>
- </FormSection>
-
- {isExisting && (
- <FormSection
- title={t`Synchronize group membership with your SSO`}
- >
- <Text c="text-secondary" mb="xl">
- {t`To enable this, you'll need to create mappings to tell ${applicationName} which group(s) your users should be added to based on the SSO group they're in.`}
- </Text>
- <Stack gap="lg">
- <GroupMappingsWidgetView
- setting={{ key: "group-sync-enabled" }}
- mappings={
- existingProvider?.["group-sync"]?.[
- "group-mappings"
- ] ?? {}
- }
- updateSetting={handleUpdateGroupMappings}
- allGroups={allGroups}
- deleteGroup={handleDeleteGroup}
- clearGroupMember={handleClearGroupMember}
- mappingSetting="oidc-group-mappings"
- groupHeading={t`Group name`}
- groupPlaceholder={t`Group name`}
- />
- <FormTextInput
- name="group-attribute"
- label={t`Group attribute name`}
- description={t`The OIDC claim that contains group membership information.`}
- nullable
- />
- </Stack>
- </FormSection>
- )}
-
- <FormSection title={t`Optional settings`} collapsible>
- <Stack gap="lg">
- <FormTextInput
- name="scopes"
- label={t`Scopes`}
- description={t`Comma-separated list of OIDC scopes to request.`}
- nullable
- />
- </Stack>
- </FormSection>
+ <SettingsSection>
+ <AdminSettingInput
+ name="oidc-user-provisioning-enabled?"
+ title={t`User provisioning`}
+ inputType="radio"
+ options={provisioningOptions("OIDC")}
+ />
+ </SettingsSection>
+
+ <FormProvider
+ initialValues={initialValues}
+ onSubmit={handleSubmit}
+ validationSchema={getOidcFormSchema()}
+ enableReinitialize
+ >
+ {({ dirty, values }) => (
+ <Form>
+ <Stack gap="xl">
+ <SettingsSection
+ title={t`Server settings`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
+ <Stack gap="lg">
+ <FormTextInput
+ name="key"
+ label={t`Key`}
+ description={t`Provider identifier. Your OIDC redirect URI will be "${siteUrl}/auth/sso/${values.key || "{key}"}/callback"`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ placeholder={t`e.g. okta`}
+ required
+ disabled={isExisting}
+ />
+ <FormTextInput
+ name="login-prompt"
+ label={t`Login prompt`}
+ description={t`Button text on the ${applicationName} sign-in screen`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ placeholder={t`e.g. Sign in with Okta`}
+ required
+ />
+ <FormTextInput
+ name="issuer-uri"
+ label={t`Issuer URI`}
+ description={t`The OIDC issuer URI. The discovery endpoint "${(values["issuer-uri"] || "{url}").replace(/\/+$/, "")}/.well-known/openid-configuration" should be accessible.`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ placeholder="https://your-idp.example.com"
+ required
+ />
+ <FormTextInput
+ name="client-id"
+ label={t`Client ID`}
+ description={t`The Client ID configured for ${applicationName} in your OIDC provider.`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ required
+ />
+ <FormTextInput
+ name="client-secret"
+ label={t`Client Secret`}
+ description={t`The Client secret configured in your OIDC provider.`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ type="password"
+ placeholder={
+ isExisting ? t`Leave blank to keep current value` : ""
+ }
+ />
+ </Stack>
+ </SettingsSection>
- <FormSection title={t`Attribute mapping`} collapsible>
- <Text c="text-secondary" mb="lg">
- {t`Map OIDC claims to user attributes. Use standard OIDC claim names or your provider's custom claims.`}
- </Text>
+ {isExisting && (
+ <SettingsSection
+ title={t`Group mapping`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ description={t`To enable this, you'll need to create mappings to tell ${applicationName} which group(s) your users should be added to based on the SSO group they're in.`}
+ descriptionProps={SETTINGS_CARD_DESCRIPTION_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="lg">
- <FormTextInput
- name="attribute-email"
- label={t`Email attribute`}
- nullable
- />
- <FormTextInput
- name="attribute-firstname"
- label={t`First name attribute`}
- nullable
+ <GroupMappingsWidgetView
+ setting={{ key: "group-sync-enabled" }}
+ mappings={
+ existingProvider?.["group-sync"]?.["group-mappings"] ??
+ {}
+ }
+ updateSetting={handleUpdateGroupMappings}
+ allGroups={allGroups}
+ deleteGroup={handleDeleteGroup}
+ clearGroupMember={handleClearGroupMember}
+ mappingSetting="oidc-group-mappings"
+ groupHeading={t`Group name`}
+ groupPlaceholder={t`Group name`}
/>
<FormTextInput
- name="attribute-lastname"
- label={t`Last name attribute`}
+ name="group-attribute"
+ label={t`Group attribute name`}
+ description={t`The OIDC claim that contains group membership information.`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
nullable
/>
</Stack>
- </FormSection>
-
- <FormErrorMessage />
- <Flex justify="space-between">
- {isExisting ? (
- <>
- <Flex gap="lg">
- <Button variant="outline" onClick={handleToggleEnabled}>
- {isEnabled ? t`Disable` : t`Enable`}
- </Button>
- <Button
- variant="filled"
- color="feedback-negative"
- onClick={deleteModal.open}
- >
- {t`Delete configuration`}
- </Button>
- </Flex>
- <ConfirmModal
- opened={isDeleteModalOpen}
- title={t`Delete this OIDC provider?`}
- message={t`Users will no longer be able to sign in with this provider. This can't be undone.`}
- onClose={deleteModal.close}
- onConfirm={handleDelete}
- />
- </>
- ) : (
- <span />
- )}
- <Flex gap="lg">
- <Button
- variant="outline"
- loading={isChecking}
- disabled={!values["issuer-uri"] || !values["client-id"]}
- onClick={() => handleCheckConnection(values)}
- >
- {t`Check connection`}
- </Button>
- <FormSubmitButton
- disabled={!dirty}
- label={
- isExisting && isEnabled
- ? t`Save changes`
- : t`Save and enable`
- }
- variant="filled"
+ </SettingsSection>
+ )}
+
+ <CollapsibleSettingsSection title={t`Optional settings`}>
+ <Stack gap="lg">
+ <FormTextInput
+ name="scopes"
+ label={t`Scopes`}
+ description={t`Comma-separated list of OIDC scopes to request.`}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
+ nullable
+ />
+ </Stack>
+ </CollapsibleSettingsSection>
+
+ <CollapsibleSettingsSection
+ title={t`Attribute mapping`}
+ description={t`Map OIDC claims to user attributes. Use standard OIDC claim names or your provider's custom claims.`}
+ >
+ <Stack gap="lg">
+ <FormTextInput
+ name="attribute-email"
+ label={t`Email attribute`}
+ nullable
+ />
+ <FormTextInput
+ name="attribute-firstname"
+ label={t`First name attribute`}
+ nullable
+ />
+ <FormTextInput
+ name="attribute-lastname"
+ label={t`Last name attribute`}
+ nullable
+ />
+ </Stack>
+ </CollapsibleSettingsSection>
+
+ <FormErrorMessage />
+ <Flex gap="lg" wrap="wrap" justify="space-between">
+ {isExisting && (
+ <>
+ <Flex gap="lg" wrap="wrap">
+ <Button variant="outline" onClick={handleToggleEnabled}>
+ {isEnabled ? t`Disable` : t`Enable`}
+ </Button>
+ <Button
+ variant="filled"
+ color="feedback-negative"
+ onClick={deleteModal.open}
+ >
+ {t`Delete configuration`}
+ </Button>
+ </Flex>
+ <ConfirmModal
+ opened={isDeleteModalOpen}
+ title={t`Delete this OIDC provider?`}
+ message={t`Users will no longer be able to sign in with this provider. This can't be undone.`}
+ onClose={deleteModal.close}
+ onConfirm={handleDelete}
/>
- </Flex>
+ </>
+ )}
+ <Flex gap="lg" wrap="wrap" ml={isExisting ? undefined : "auto"}>
+ <Button
+ variant="outline"
+ loading={isChecking}
+ disabled={!values["issuer-uri"] || !values["client-id"]}
+ onClick={() => handleCheckConnection(values)}
+ >
+ {t`Check connection`}
+ </Button>
+ <FormSubmitButton
+ disabled={!dirty}
+ label={
+ isExisting && isEnabled
+ ? t`Save changes`
+ : t`Save and enable`
+ }
+ variant="filled"
+ />
</Flex>
- </SettingsSection>
- </Form>
- )}
- </FormProvider>
- </Stack>
+ </Flex>
+ </Stack>
+ </Form>
+ )}
+ </FormProvider>
</SettingsPageWrapper>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
index ca41bab878e..2f89546cea7 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
@@ -76,21 +76,63 @@ const setup = async (options?: { providers?: CustomOidcConfig[] }) => {
await screen.findByText("OpenID Connect");
};
+describe("SettingsOIDCForm - collapsible sections", () => {
+ it("starts both optional sections collapsed for a new provider", async () => {
+ await setup({ providers: [] });
+
+ expect(
+ screen.getByRole("button", { name: "Optional settings" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ expect(
+ screen.getByRole("button", { name: "Attribute mapping" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("starts both optional sections collapsed when the provider only has default values", async () => {
+ await setup({ providers: [EXISTING_PROVIDER] });
+
+ expect(
+ screen.getByRole("button", { name: "Optional settings" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ expect(
+ screen.getByRole("button", { name: "Attribute mapping" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("starts both optional sections collapsed even when the provider has custom values", async () => {
+ await setup({
+ providers: [
+ {
+ ...EXISTING_PROVIDER,
+ scopes: ["openid", "email"],
+ "attribute-map": {
+ ...EXISTING_PROVIDER["attribute-map"],
+ email: "mail",
+ },
+ },
+ ],
+ });
+
+ expect(
+ screen.getByRole("button", { name: "Optional settings" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ expect(
+ screen.getByRole("button", { name: "Attribute mapping" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+});
+
describe("SettingsOIDCForm - Group Sync", () => {
it("does not show group sync section for new providers", async () => {
await setup({ providers: [] });
- expect(
- screen.queryByText("Synchronize group membership with your SSO"),
- ).not.toBeInTheDocument();
+ expect(screen.queryByText("Group mapping")).not.toBeInTheDocument();
});
it("shows the group sync UI for existing providers", async () => {
await setup({ providers: [EXISTING_PROVIDER] });
- expect(
- screen.getByText("Synchronize group membership with your SSO"),
- ).toBeInTheDocument();
+ expect(screen.getByText("Group mapping")).toBeInTheDocument();
expect(screen.getByTestId("group-sync-switch")).toBeInTheDocument();
expect(screen.getByLabelText("Group attribute name")).toBeInTheDocument();
expect(
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
index 8fcac2c0e64..f1bbb0c221a 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
@@ -4,13 +4,20 @@ import _ from "underscore";
import * as Yup from "yup";
import {
+ CollapsibleSettingsSection,
+ SETTINGS_CARD_DESCRIPTION_PROPS,
+ SETTINGS_CARD_STACK_PROPS,
+ SETTINGS_CARD_TITLE_PROPS,
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
import { SettingHeader } from "metabase/admin/settings/components/SettingHeader";
import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { GroupMappingsWidget } from "metabase/admin/settings/components/widgets/GroupMappingsWidget";
-import { getExtraFormFieldProps } from "metabase/admin/settings/utils";
+import {
+ SETTINGS_FIELD_DESCRIPTION_PROPS,
+ getExtraFormFieldProps,
+} from "metabase/admin/settings/utils";
import { CopyTextInput } from "metabase/common/components/CopyTextInput";
import { ExternalLink } from "metabase/common/components/ExternalLink";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
@@ -20,11 +27,12 @@ import {
Form,
FormErrorMessage,
FormProvider,
- FormSection,
FormSubmitButton,
FormTextInput,
FormTextarea,
} from "metabase/forms";
+import { useSelector } from "metabase/redux";
+import { getApplicationName } from "metabase/selectors/whitelabel";
import {
useGetAdminSettingsDetailsQuery,
useGetSettingsQuery,
@@ -63,6 +71,7 @@ export function SettingsSAMLForm() {
const { data: settingValues, isLoading: isLoadingValues } =
useGetSettingsQuery();
const [updateSamlSettings] = useUpdateSamlMutation();
+ const applicationName = useSelector(getApplicationName);
const isEnabled = Boolean(settingValues?.["saml-enabled"]);
@@ -90,41 +99,48 @@ export function SettingsSAMLForm() {
);
}
+ // saml-keystore-password is sensitive, so session properties never
+ // include it; path and alias are the detectable signals
+ const hasKeystoreSettings = Boolean(
+ settingValues["saml-keystore-path"] || settingValues["saml-keystore-alias"],
+ );
+
return (
- <SettingsPageWrapper title={t`SAML`}>
+ <SettingsPageWrapper
+ title={t`SAML`}
+ description={jt`Use the settings below to configure your SSO via SAML. If you have any questions, check out our ${(
+ <ExternalLink
+ key="link"
+ href={docsUrl}
+ >{t`documentation`}</ExternalLink>
+ )}.`}
+ >
{isEnabled && <SamlUserProvisioning />}
- <SettingsSection>
- <FormProvider
- initialValues={getFormValues(settingValues ?? {})}
- onSubmit={handleSubmit}
- validationSchema={SAML_FORM_SCHEMA}
- enableReinitialize
- >
- {({ dirty }) => (
- <Form>
- <Title order={2}>{t`Set up SAML-based SSO`}</Title>
- <Text c="text-secondary" mb="xxl">
- {jt`Use the settings below to configure your SSO via SAML. If you have any questions, check out our ${(
- <ExternalLink
- key="link"
- href={docsUrl}
- >{t`documentation`}</ExternalLink>
- )}.`}
- </Text>
- <FormSection title={t`Configure your identity provider (IdP)`}>
- <Text c="text-secondary" mb="xxl">
- {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings */}
- {t`Your identity provider will need the following info about Metabase.`}
- </Text>
-
+ <FormProvider
+ initialValues={getFormValues(settingValues ?? {})}
+ onSubmit={handleSubmit}
+ validationSchema={SAML_FORM_SCHEMA}
+ enableReinitialize
+ >
+ {({ dirty }) => (
+ <Form>
+ <Stack gap="lg">
+ <SettingsSection
+ title={t`Configure your identity provider (IdP)`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ description={t`Your identity provider will need the following info about ${applicationName}.`}
+ descriptionProps={SETTINGS_CARD_DESCRIPTION_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<CopyTextInput
value={`${siteUrl}/auth/sso`}
label={t`URL the IdP should redirect back to`}
description={t`This is called the Single Sign On URL in Okta, the Application Callback URL in Auth0, and the ACS (Consumer) URL in OneLogin. `}
+ descriptionProps={SETTINGS_FIELD_DESCRIPTION_PROPS}
readOnly
/>
- <Title order={4} mt="xxl">{t`SAML attributes`}</Title>
+ <Title order={3} size="h5" mt="xxl">{t`SAML attributes`}</Title>
<Text c="text-secondary" mb="lg">
{t`In most IdPs, you'll need to put each of these in an input box labeled "Name" in the attribute statements section.`}
</Text>
@@ -165,16 +181,15 @@ export function SettingsSAMLForm() {
/>
)}
</Stack>
- </FormSection>
+ </SettingsSection>
- <FormSection
- // eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings
- title={t`Tell Metabase about your identity provider`}
+ <SettingsSection
+ title={t`Tell ${applicationName} about your identity provider`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ description={t`${applicationName} will need the following info about your provider.`}
+ descriptionProps={SETTINGS_CARD_DESCRIPTION_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
>
- <Text mb="xxl" mt="sm" c="text-secondary">
- {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings */}
- {t`Metabase will need the following info about your provider.`}
- </Text>
<Stack gap="lg">
<FormTextInput
name="saml-identity-provider-uri"
@@ -210,9 +225,12 @@ export function SettingsSAMLForm() {
)}
/>
</Stack>
- </FormSection>
+ </SettingsSection>
- <FormSection title={t`Sign SSO requests (optional)`} collapsible>
+ <CollapsibleSettingsSection
+ title={t`Sign SSO requests (optional)`}
+ defaultOpened={hasKeystoreSettings}
+ >
<Stack gap="lg">
<FormTextInput
name="saml-keystore-path"
@@ -241,16 +259,15 @@ export function SettingsSAMLForm() {
)}
/>
</Stack>
- </FormSection>
+ </CollapsibleSettingsSection>
- <FormSection
- title={t`Synchronize group membership with your SSO`}
+ <SettingsSection
+ title={t`Group mapping`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ description={t`To enable this, you'll need to create mappings to tell ${applicationName} which group(s) your users should be added to based on the SSO group they're in.`}
+ descriptionProps={SETTINGS_CARD_DESCRIPTION_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
>
- <Text c="text-secondary" mb="xl">
- {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings */}
- {t`To enable this, you'll need to create mappings to tell Metabase which group(s) your users should
- be added to based on the SSO group they're in.`}
- </Text>
<Stack gap="lg">
<GroupMappingsWidget
isFormik
@@ -272,7 +289,7 @@ export function SettingsSAMLForm() {
)}
/>
</Stack>
- </FormSection>
+ </SettingsSection>
<FormErrorMessage />
<Flex justify="end">
@@ -282,10 +299,10 @@ export function SettingsSAMLForm() {
variant="filled"
/>
</Flex>
- </Form>
- )}
- </FormProvider>
- </SettingsSection>
+ </Stack>
+ </Form>
+ )}
+ </FormProvider>
</SettingsPageWrapper>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
index 593722d26f4..48f879b9d68 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
@@ -35,7 +35,7 @@ const setup = async (
</>,
);
- await screen.findByText("Set up SAML-based SSO");
+ await screen.findByText("Configure your identity provider (IdP)");
await waitFor(async () => {
const gets = await findRequests("GET");
expect(gets).toHaveLength(3);
diff --git a/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.module.css b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.module.css
index 40b0cce1f4f..c30919c19d3 100644
--- a/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.module.css
+++ b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.module.css
@@ -1,6 +1,88 @@
+.PageTitle {
+ align-items: center;
+}
+
.SettingsSection {
background-color: var(--mb-color-background_page-primary);
border: 1px solid var(--mb-color-border-neutral);
border-radius: var(--mantine-radius-sm);
padding: var(--mantine-spacing-xxl);
}
+
+/* Accordion-backed collapsible card: neutralizes the app-wide Accordion
+ theme (brand label, circled chevron, item chrome) and applies the
+ settings-card look. Selectors are scoped under the root class, with
+ state variants repeated, to out-rank the theme classNames regardless
+ of stylesheet order. */
+.CollapsibleAccordion .CollapsibleItem,
+.CollapsibleAccordion .CollapsibleItem[data-active] {
+ background-color: var(--mb-color-background_page-primary);
+ border: 1px solid var(--mb-color-border-neutral);
+ border-radius: var(--mantine-radius-sm);
+ padding: var(--mantine-spacing-xl) var(--mantine-spacing-xxl);
+}
+
+.CollapsibleHeader {
+ position: relative;
+
+ /* keep text clear of the absolutely-positioned chevron */
+ padding-right: var(--mantine-spacing-xxl);
+}
+
+.CollapsibleAccordion .CollapsibleControl,
+.CollapsibleAccordion .CollapsibleControl:hover {
+ padding: 0;
+ background-color: transparent;
+}
+
+/* the theme's Accordion styles remove the focus outline; restore it */
+.CollapsibleAccordion .CollapsibleControl.CollapsibleControl:focus-visible {
+ outline: 2px solid var(--mb-color-focus);
+}
+
+/* stretch the hit area over the whole header row, description included */
+.CollapsibleAccordion .CollapsibleControl::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ cursor: pointer;
+}
+
+.CollapsibleAccordion .CollapsibleLabel {
+ padding: 0;
+ color: var(--mb-color-text-primary);
+ font-size: var(--mantine-h4-font-size);
+ line-height: var(--mantine-h4-line-height);
+ font-weight: 700;
+}
+
+.CollapsibleAccordion .CollapsibleChevron,
+.CollapsibleAccordion .CollapsibleChevron[data-rotate] {
+ position: absolute;
+ top: 50%;
+ right: 0;
+ width: auto;
+ height: auto;
+ margin: 0;
+ border: 0;
+ border-radius: 0;
+ color: var(--mb-color-text-primary);
+}
+
+.CollapsibleAccordion .CollapsibleChevron {
+ transform: translateY(-50%);
+}
+
+.CollapsibleAccordion .CollapsibleChevron[data-rotate] {
+ transform: translateY(-50%) rotate(180deg);
+}
+
+.CollapsibleAccordion .CollapsibleContent {
+ padding: var(--mantine-spacing-xl) 0 0;
+ border-top: 0;
+}
+
+.CollapsibleAccordion .CollapsiblePanel {
+ line-height: inherit;
+ word-break: normal;
+}
diff --git a/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.tsx b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.tsx
index 910d408c592..1bb0096cdf3 100644
--- a/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.tsx
+++ b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.tsx
@@ -1,9 +1,11 @@
+import cx from "classnames";
import type React from "react";
-import CS from "metabase/css/core/index.css";
import {
+ Accordion,
Box,
type BoxProps,
+ Icon,
Stack,
type StackProps,
Text,
@@ -14,10 +16,20 @@ import {
import S from "./SettingsSection.module.css";
+// Card titles render h4-sized but stay h2 so the page outline doesn't jump
+// from the h1 page title to h4.
+export const SETTINGS_CARD_TITLE_PROPS: TitleProps = { order: 2, size: "h4" };
+export const SETTINGS_CARD_DESCRIPTION_PROPS: TextProps = {
+ lh: "sm",
+ mt: "xxs",
+};
+export const SETTINGS_CARD_STACK_PROPS: StackProps = { gap: "lg" };
+
export function SettingsSection({
title,
titleProps,
description,
+ descriptionProps,
children,
id,
stackProps,
@@ -26,14 +38,20 @@ export function SettingsSection({
title?: React.ReactNode;
titleProps?: TitleProps;
description?: React.ReactNode;
+ descriptionProps?: TextProps;
children?: React.ReactNode;
id?: string;
stackProps?: StackProps;
} & BoxProps) {
+ const { className: stackClassName, ...restStackProps } = stackProps ?? {};
return (
<Box id={id} {...boxProps}>
{children && (
- <Stack gap="xl" className={S.SettingsSection} {...stackProps}>
+ <Stack
+ gap="xl"
+ className={cx(S.SettingsSection, stackClassName)}
+ {...restStackProps}
+ >
{(title || description) && (
<Box mb="sm">
{title && (
@@ -41,7 +59,11 @@ export function SettingsSection({
{title}
</Title>
)}
- {description && <Text c="text-secondary">{description}</Text>}
+ {description && (
+ <Text c="text-secondary" {...descriptionProps}>
+ {description}
+ </Text>
+ )}
</Box>
)}
{children}
@@ -51,6 +73,55 @@ export function SettingsSection({
);
}
+const COLLAPSIBLE_SECTION_VALUE = "section";
+
+export function CollapsibleSettingsSection({
+ title,
+ description,
+ defaultOpened = false,
+ children,
+ className,
+ ...boxProps
+}: {
+ title: React.ReactNode;
+ description?: React.ReactNode;
+ defaultOpened?: boolean;
+ children?: React.ReactNode;
+} & BoxProps) {
+ return (
+ <Accordion
+ className={cx(S.CollapsibleAccordion, className)}
+ classNames={{
+ item: S.CollapsibleItem,
+ control: S.CollapsibleControl,
+ label: S.CollapsibleLabel,
+ chevron: S.CollapsibleChevron,
+ content: S.CollapsibleContent,
+ panel: S.CollapsiblePanel,
+ }}
+ chevron={<Icon aria-hidden name="chevrondown" />}
+ order={2}
+ defaultValue={defaultOpened ? COLLAPSIBLE_SECTION_VALUE : null}
+ {...boxProps}
+ >
+ <Accordion.Item value={COLLAPSIBLE_SECTION_VALUE}>
+ {/* the header wrapper anchors the control's stretched hit area, so
+ the whole header row toggles while the description stays outside
+ the control button and out of its accessible name */}
+ <Box className={S.CollapsibleHeader}>
+ <Accordion.Control>{title}</Accordion.Control>
+ {description && (
+ <Text c="text-secondary" {...SETTINGS_CARD_DESCRIPTION_PROPS}>
+ {description}
+ </Text>
+ )}
+ </Box>
+ <Accordion.Panel>{children}</Accordion.Panel>
+ </Accordion.Item>
+ </Accordion>
+ );
+}
+
export function SettingsPageWrapper({
title,
description,
@@ -68,7 +139,7 @@ export function SettingsPageWrapper({
{(title || description) && (
<Stack gap="sm">
{title && (
- <Title order={1} display="flex" className={CS.alignCenter}>
+ <Title order={1} display="flex" className={S.PageTitle}>
{title}
</Title>
)}
diff --git a/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.unit.spec.tsx b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.unit.spec.tsx
new file mode 100644
index 00000000000..073cfe82e52
--- /dev/null
+++ b/frontend/src/metabase/admin/components/SettingsSection/SettingsSection.unit.spec.tsx
@@ -0,0 +1,63 @@
+import userEvent from "@testing-library/user-event";
+
+import { renderWithProviders, screen, waitFor } from "__support__/ui";
+
+import { CollapsibleSettingsSection } from "./SettingsSection";
+
+const setup = ({ defaultOpened }: { defaultOpened?: boolean } = {}) => {
+ renderWithProviders(
+ <CollapsibleSettingsSection
+ title="Section title"
+ description="Section description"
+ defaultOpened={defaultOpened}
+ >
+ <div>Section content</div>
+ </CollapsibleSettingsSection>,
+ );
+};
+
+describe("CollapsibleSettingsSection", () => {
+ it("shows the title and description while collapsed", () => {
+ setup();
+
+ expect(screen.getByText("Section title")).toBeInTheDocument();
+ expect(screen.getByText("Section description")).toBeInTheDocument();
+ expect(screen.getByText("Section content")).not.toBeVisible();
+ expect(
+ screen.getByRole("button", { name: /Section title/ }),
+ ).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("exposes the title as a heading and keeps the chevron out of the accessible name", () => {
+ setup();
+
+ expect(
+ screen.getByRole("heading", { name: "Section title" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: "Section title" }),
+ ).toBeInTheDocument();
+ expect(screen.queryByRole("img")).not.toBeInTheDocument();
+ });
+
+ it("expands and collapses on header click", async () => {
+ setup();
+ const header = screen.getByRole("button", { name: /Section title/ });
+
+ await userEvent.click(header);
+ await waitFor(() =>
+ expect(screen.getByText("Section content")).toBeVisible(),
+ );
+ expect(header).toHaveAttribute("aria-expanded", "true");
+
+ // jsdom never completes the closing transition, so assert state via aria
+ await userEvent.click(header);
+ expect(header).toHaveAttribute("aria-expanded", "false");
+ });
+
+ it("can start expanded via defaultOpened", () => {
+ setup({ defaultOpened: true });
+
+ expect(screen.getByText("Section content")).toBeVisible();
+ });
+});
diff --git a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
index 2a6b5d79852..375b3c6dd67 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
@@ -5,6 +5,8 @@ import type { TestConfig } from "yup";
import * as Yup from "yup";
import {
+ SETTINGS_CARD_STACK_PROPS,
+ SETTINGS_CARD_TITLE_PROPS,
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
@@ -16,7 +18,6 @@ import {
FormErrorMessage,
FormProvider,
FormRadioGroup,
- FormSection,
FormSubmitButton,
FormTextInput,
} from "metabase/forms";
@@ -25,7 +26,7 @@ import {
useGetAdminSettingsDetailsQuery,
useGetSettingsQuery,
} from "metabase/settings";
-import { Box, Divider, Flex, Group, Radio, Stack } from "metabase/ui";
+import { Box, Flex, Group, Radio, Stack } from "metabase/ui";
import type { EnterpriseSettings, Settings } from "metabase-types/api";
import { useUpdateLdapMutation } from "../api/ldap";
@@ -92,8 +93,12 @@ export const SettingsLdapForm = () => {
>
{({ dirty }) => (
<Form>
- <SettingsSection>
- <FormSection title={"Server settings"}>
+ <Stack gap="xl">
+ <SettingsSection
+ title={t`Server settings`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="lg">
<FormTextInput
name="ldap-host"
@@ -146,9 +151,12 @@ export const SettingsLdapForm = () => {
)}
/>
</Stack>
- </FormSection>
- <Divider />
- <FormSection title={"User schema"}>
+ </SettingsSection>
+ <SettingsSection
+ title={t`User schema`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="lg">
<FormTextInput
name="ldap-user-base"
@@ -168,9 +176,12 @@ export const SettingsLdapForm = () => {
)}
/>
</Stack>
- </FormSection>
- <Divider />
- <FormSection title={"Attributes"}>
+ </SettingsSection>
+ <SettingsSection
+ title={t`Attributes`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="lg">
<FormTextInput
name="ldap-attribute-email"
@@ -197,9 +208,12 @@ export const SettingsLdapForm = () => {
)}
/>
</Stack>
- </FormSection>
- <Divider />
- <FormSection title={"Group schema"}>
+ </SettingsSection>
+ <SettingsSection
+ title={t`Group mapping`}
+ titleProps={SETTINGS_CARD_TITLE_PROPS}
+ stackProps={SETTINGS_CARD_STACK_PROPS}
+ >
<Stack gap="lg">
<GroupMappingsWidget
isFormik
@@ -221,7 +235,7 @@ export const SettingsLdapForm = () => {
/>
<PLUGIN_LDAP_FORM_FIELDS.LdapGroupMembershipFilter />
</Stack>
- </FormSection>
+ </SettingsSection>
<Flex justify="end" gap="1rem">
<Box>
<FormErrorMessage />
@@ -232,7 +246,7 @@ export const SettingsLdapForm = () => {
variant="filled"
/>
</Flex>
- </SettingsSection>
+ </Stack>
</Form>
)}
</FormProvider>
diff --git a/frontend/src/metabase/admin/settings/tests/setup.tsx b/frontend/src/metabase/admin/settings/tests/setup.tsx
index 52af8fc9bff..9eeb268481e 100644
--- a/frontend/src/metabase/admin/settings/tests/setup.tsx
+++ b/frontend/src/metabase/admin/settings/tests/setup.tsx
@@ -87,7 +87,10 @@ export const enterpriseRoutes: RouteMap = {
};
export const premiumRoutes: RouteMap = {
- saml: { path: "/authentication/saml", testPattern: /Set up SAML-based SSO/i },
+ saml: {
+ path: "/authentication/saml",
+ testPattern: /Configure your identity provider/i,
+ },
jwt: { path: "/authentication/jwt", testPattern: /Server Settings/i },
};
diff --git a/frontend/src/metabase/admin/settings/utils.ts b/frontend/src/metabase/admin/settings/utils.ts
index adf8ed5af36..e77980b4a9d 100644
--- a/frontend/src/metabase/admin/settings/utils.ts
+++ b/frontend/src/metabase/admin/settings/utils.ts
@@ -9,14 +9,25 @@ export const useGetEnvVarDocsUrl = (envName: string | undefined) => {
});
};
+// Matches SettingHeader's description styling; the metabase/ui Input theme
+// default renders field descriptions smaller and darker.
+export const SETTINGS_FIELD_DESCRIPTION_PROPS = {
+ c: "text-secondary",
+ fz: "md",
+ lh: "xl",
+ maw: "38rem",
+} as const;
+
export const getExtraFormFieldProps = (setting?: SettingDefinition) => {
if (setting?.is_env_setting) {
return {
description: t`Using ${setting.env_name}`,
+ descriptionProps: SETTINGS_FIELD_DESCRIPTION_PROPS,
readOnly: true,
};
}
return {
description: setting?.description ?? "",
+ descriptionProps: SETTINGS_FIELD_DESCRIPTION_PROPS,
};
};
diff --git a/frontend/src/metabase/common/components/DisclosureTriangle/DisclosureTriangle.tsx b/frontend/src/metabase/common/components/DisclosureTriangle/DisclosureTriangle.tsx
deleted file mode 100644
index 56c215814da..00000000000
--- a/frontend/src/metabase/common/components/DisclosureTriangle/DisclosureTriangle.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { Icon } from "metabase/ui";
-
-interface DisclosureTriangleProps {
- open: boolean;
- className?: string;
-}
-
-export const DisclosureTriangle = ({
- open,
- className,
-}: DisclosureTriangleProps) => (
- <Icon
- className={className}
- name="expand_arrow"
- style={{
- transition: "transform 300ms ease-out",
- transform: `rotate(${open ? 0 : -90}deg)`,
- }}
- />
-);
diff --git a/frontend/src/metabase/common/components/DisclosureTriangle/index.tsx b/frontend/src/metabase/common/components/DisclosureTriangle/index.tsx
deleted file mode 100644
index 92f3d65532a..00000000000
--- a/frontend/src/metabase/common/components/DisclosureTriangle/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { DisclosureTriangle } from "./DisclosureTriangle";
diff --git a/frontend/src/metabase/forms/components/FormSecretKey/FormSecretKey.module.css b/frontend/src/metabase/forms/components/FormSecretKey/FormSecretKey.module.css
index 608d5ad9206..72ea914c894 100644
--- a/frontend/src/metabase/forms/components/FormSecretKey/FormSecretKey.module.css
+++ b/frontend/src/metabase/forms/components/FormSecretKey/FormSecretKey.module.css
@@ -1,16 +1,18 @@
.inputWrapper {
display: flex;
+
+ /* on narrow widths the button wraps below the input instead of squeezing it */
+ flex-wrap: wrap;
gap: 0.5rem;
.input {
- flex-grow: 1;
+ /* explicit basis: the input's own width: 100% would otherwise claim the
+ whole line and force the button to wrap at every width */
+ flex: 1 1 10rem;
+ min-width: 10rem;
&.unset {
display: none;
-
- & ~ .generateButton {
- min-width: 10rem;
- }
}
}
@@ -24,5 +26,9 @@
.rightSection {
justify-content: flex-start;
position: relative;
+
+ /* Mantine's absolute-section top compensates the input border; as a
+ relative flex child it would shift the button 1px down */
+ top: 0;
width: auto;
}
diff --git a/frontend/src/metabase/forms/components/FormSecretKey/SetupKeyModal.tsx b/frontend/src/metabase/forms/components/FormSecretKey/SetupKeyModal.tsx
index d50aeda8d31..5dc41760e36 100644
--- a/frontend/src/metabase/forms/components/FormSecretKey/SetupKeyModal.tsx
+++ b/frontend/src/metabase/forms/components/FormSecretKey/SetupKeyModal.tsx
@@ -3,10 +3,9 @@ import { useMount } from "react-use";
import { t } from "ttag";
import { useLazyGenerateRandomTokenQuery } from "metabase/api/util";
-import { IconButtonWrapper } from "metabase/common/components/IconButtonWrapper";
import { useMetadataToasts } from "metabase/common/hooks";
-import CS from "metabase/css/core/index.css";
import {
+ ActionIcon,
Alert,
Button,
Flex,
@@ -61,8 +60,8 @@ export const SetupKeyModal = (props: SetupKeyDialogProps) => {
<Loader size="xs" />
) : (
<Tooltip label={t`Copy to clipboard`}>
- <IconButtonWrapper
- aria-label={t`Preview the query`}
+ <ActionIcon
+ aria-label={t`Copy to clipboard`}
onClick={async () => {
try {
await navigator.clipboard.writeText(secretValue);
@@ -75,26 +74,21 @@ export const SetupKeyModal = (props: SetupKeyDialogProps) => {
}}
>
<Icon name="copy" />
- </IconButtonWrapper>
+ </ActionIcon>
</Tooltip>
)
}
flex="1 0 auto"
aria-label={t`New secret key`}
/>
- <Button
- className={CS.flexNoShrink}
- variant="filled"
- onClick={generateToken}
- >
+ <Button flex="0 0 auto" variant="filled" onClick={generateToken}>
{t`Regenerate key`}
</Button>
</Flex>
<Stack gap="sm">
<Alert size="compact" color="warning">
{t`Make sure you copy this key now and save it in a safe place.`}
- <br />
- <Text fw="bold" component="strong">
+ <Text fw="bold" component="strong" display="block">
{t`You won't be able to see it again.`}
</Text>
</Alert>
diff --git a/frontend/src/metabase/forms/components/FormSection/FormSection.styled.tsx b/frontend/src/metabase/forms/components/FormSection/FormSection.styled.tsx
deleted file mode 100644
index 985eb50a76b..00000000000
--- a/frontend/src/metabase/forms/components/FormSection/FormSection.styled.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const CollapsibleSectionContent = styled.div`
- display: flex;
- align-items: center;
- cursor: pointer;
- margin-bottom: 1rem;
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
-`;
diff --git a/frontend/src/metabase/forms/components/FormSection/FormSection.tsx b/frontend/src/metabase/forms/components/FormSection/FormSection.tsx
deleted file mode 100644
index 0fca7db5bd7..00000000000
--- a/frontend/src/metabase/forms/components/FormSection/FormSection.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import { DisclosureTriangle } from "metabase/common/components/DisclosureTriangle";
-import { useToggle } from "metabase/common/hooks/use-toggle";
-import CS from "metabase/css/core/index.css";
-
-import { CollapsibleSectionContent } from "./FormSection.styled";
-
-interface SectionProps {
- title?: string;
- children: React.ReactNode;
-}
-
-function StandardSection({ title, children, ...props }: SectionProps) {
- return (
- <section className={CS.mb4} {...props}>
- {title && <h2 className={CS.mb2}>{title}</h2>}
- {children}
- </section>
- );
-}
-
-function CollapsibleSection({ title, children, ...props }: SectionProps) {
- const [isExpanded, { toggle: handleToggle }] = useToggle(false);
- return (
- <section className={CS.mb4} {...props}>
- <CollapsibleSectionContent onClick={handleToggle}>
- <DisclosureTriangle className={CS.mr1} open={isExpanded} />
- <h3>{title}</h3>
- </CollapsibleSectionContent>
- <div className={isExpanded ? undefined : CS.hide}>{children}</div>
- </section>
- );
-}
-
-interface CustomFormSectionProps extends SectionProps {
- collapsible?: boolean;
-}
-
-export function FormSection({ collapsible, ...props }: CustomFormSectionProps) {
- const Section = collapsible ? CollapsibleSection : StandardSection;
- return <Section {...props} />;
-}
diff --git a/frontend/src/metabase/forms/components/FormSection/index.ts b/frontend/src/metabase/forms/components/FormSection/index.ts
deleted file mode 100644
index b022861335e..00000000000
--- a/frontend/src/metabase/forms/components/FormSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./FormSection";
diff --git a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.styled.tsx b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.module.css
similarity index 52%
rename from frontend/src/metabase/forms/components/FormTextInput/FormTextInput.styled.tsx
rename to frontend/src/metabase/forms/components/FormTextInput/FormTextInput.module.css
index c64c0c9d448..4f473445207 100644
--- a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.styled.tsx
+++ b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.module.css
@@ -1,19 +1,14 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-
-export const CopyWidgetButton = styled(CopyButton)`
+.copyButton {
position: absolute;
top: 0;
bottom: 0;
right: 0;
display: flex;
align-items: center;
- padding: 0.5rem;
+ padding: var(--mantine-spacing-sm);
border-left: 1px solid var(--mb-color-border-neutral);
- border-top-right-radius: 4px;
- border-bottom-right-radius: 4px;
+ border-top-right-radius: var(--mantine-radius-xxs);
+ border-bottom-right-radius: var(--mantine-radius-xxs);
color: var(--mb-color-core-brand);
outline: none;
@@ -21,4 +16,4 @@ export const CopyWidgetButton = styled(CopyButton)`
color: var(--mb-color-text-primary-inverse);
background-color: var(--mb-color-core-brand);
}
-`;
+}
diff --git a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx
index 32af0a8ca79..79eb30eb113 100644
--- a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx
+++ b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx
@@ -2,10 +2,11 @@ import { useField, useFormikContext } from "formik";
import type { ChangeEvent, FocusEvent, Ref } from "react";
import { forwardRef, useCallback } from "react";
+import { CopyButton } from "metabase/common/components/CopyButton";
import type { TextInputProps } from "metabase/ui";
import { TextInput } from "metabase/ui";
-import { CopyWidgetButton } from "./FormTextInput.styled";
+import S from "./FormTextInput.module.css";
export interface FormTextInputProps extends Omit<
TextInputProps,
@@ -54,7 +55,7 @@ export const FormTextInput = forwardRef(function FormTextInput(
);
const rightSection = hasCopyButton ? (
- <CopyWidgetButton value={value} />
+ <CopyButton className={S.copyButton} value={value} />
) : (
props.rightSection
);
diff --git a/frontend/src/metabase/forms/components/index.ts b/frontend/src/metabase/forms/components/index.ts
index cd0167f69f0..57207ca137a 100644
--- a/frontend/src/metabase/forms/components/index.ts
+++ b/frontend/src/metabase/forms/components/index.ts
@@ -15,7 +15,6 @@ export * from "./FormObserver";
export * from "./FormProvider";
export * from "./FormRadioGroup";
export * from "./FormSecretKey";
-export * from "./FormSection";
export * from "./FormSegmentedControl";
export * from "./FormSelect";
export * from "./FormSubmitButton";
diff --git a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx b/frontend/src/metabase/palette/components/Palette.unit.spec.tsx
index 9c960dd86ba..9ff92efabc2 100644
--- a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx
+++ b/frontend/src/metabase/palette/components/Palette.unit.spec.tsx
@@ -88,10 +88,14 @@ describe("command palette", () => {
const calls = () =>
fetchMock.callHistory.calls(/\/api\/setting\/color-scheme/);
+ // wait for the call to be recorded: reading at(-1) too early re-reads the
+ // previous request, whose body is already consumed
+ await waitFor(() => expect(calls()).toHaveLength(1));
expect(await calls().at(-1)?.request?.json()).toEqual({ value: "dark" });
await userEvent.click(await screen.findByText("Toggle dark/light mode"));
+ await waitFor(() => expect(calls()).toHaveLength(2));
expect(await calls().at(-1)?.request?.json()).toEqual({
value: "auto",
});