The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Update the Database Form to use Mantine components (#61163)
Nick Fitzpatrickad20093b7f1e
diff --git a/e2e/support/helpers/e2e-models-metadata-helpers.js b/e2e/support/helpers/e2e-models-metadata-helpers.jsindex 6f90386b86a..270ffd19912 100644--- a/e2e/support/helpers/e2e-models-metadata-helpers.js+++ b/e2e/support/helpers/e2e-models-metadata-helpers.js@@ -26,13 +26,12 @@ export function saveMetadataChanges() {export function openColumnOptions(column) {const columnNameRegex = new RegExp(`^${column}$`);- tableInteractive()- .findAllByTestId("header-cell")- .contains(columnNameRegex)- .scrollIntoView()- .should("be.visible");-// Query element again to ensure it's not unmounted+ tableInteractive().findAllByTestId("header-cell");+ tableInteractive().contains(columnNameRegex);+ tableInteractive().scrollIntoView();+ tableInteractive().should("be.visible");+tableInteractive().findAllByTestId("header-cell").contains(columnNameRegex)diff --git a/e2e/test/scenarios/admin/database-connection-strings.cy.spec.ts b/e2e/test/scenarios/admin/database-connection-strings.cy.spec.tsindex f867ea4f794..4d5ee83d6b1 100644--- a/e2e/test/scenarios/admin/database-connection-strings.cy.spec.ts+++ b/e2e/test/scenarios/admin/database-connection-strings.cy.spec.ts@@ -253,7 +253,7 @@ describe("Database connection strings", () => {);cy.findByLabelText("Port").should("have.value", "1111");- cy.findByLabelText("Database type").should("have.text", "PostgreSQL");+ cy.findByLabelText("Database type").should("have.value", "PostgreSQL");});describe("actual database connections", { tags: "@external" }, () => {diff --git a/e2e/test/scenarios/admin/databases.cy.spec.js b/e2e/test/scenarios/admin/databases.cy.spec.jsindex 94931434702..ca09f3bdb22 100644--- a/e2e/test/scenarios/admin/databases.cy.spec.js+++ b/e2e/test/scenarios/admin/databases.cy.spec.js@@ -42,7 +42,7 @@ describe(describe("admin > database > add", () => {function toggleFieldWithDisplayName(displayName) {- cy.findByLabelText(displayName).click();+ cy.findByLabelText(new RegExp(displayName)).click({ force: true });}function selectFieldOption(fieldName, option) {@@ -110,17 +110,17 @@ describe("admin > database > add", () => {cy.findByTestId("database-form").within(() => {cy.findByText("Show advanced options").click();- cy.findByLabelText("Rerun queries for simple explorations").should(+ cy.findByLabelText(/Rerun queries for simple explorations/).should("have.attr",- "aria-checked",+ "data-checked","true",);// Reproduces (metabase#14334)cy.findByText("Additional JDBC connection string options");// Reproduces (metabase#17450)- cy.findByLabelText("Choose when syncs and scans happen")- .click()- .should("have.attr", "aria-checked", "true");+ cy.findByLabelText(/Choose when syncs and scans happen/)+ .click({ force: true })+ .should("have.attr", "data-checked", "true");cy.findByLabelText("Never, I'll do this manually if I need to",@@ -154,16 +154,18 @@ describe("admin > database > add", () => {});const confirmSSLFields = (visible, hidden) => {- visible.forEach((field) => cy.findByText(field));- hidden.forEach((field) => cy.findByText(field).should("not.exist"));+ visible.forEach((field) => cy.findByText(new RegExp(field)));+ hidden.forEach((field) =>+ cy.findByText(new RegExp(field)).should("not.exist"),+ );};- const ssl = "Use a secure connection (SSL)",+ const ssl = "Use a secure connection \\(SSL\\)",sslMode = "SSL Mode",useClientCert = "Authenticate client certificate?",- clientPemCert = "SSL Client Certificate (PEM)",- clientPkcsCert = "SSL Client Key (PKCS-8/DER)",- sslRootCert = "SSL Root Certificate (PEM)";+ clientPemCert = "SSL Client Certificate \\(PEM\\)",+ clientPkcsCert = "SSL Client Key \\(PKCS-8/DER\\)",+ sslRootCert = "SSL Root Certificate \\(PEM\\)";// initially, all SSL sub-properties should be hiddenconfirmSSLFields(@@ -234,9 +236,9 @@ describe("admin > database > add", () => {"Connected",);- cy.findByLabelText("Choose when syncs and scans happen").should(+ cy.findByLabelText(/Choose when syncs and scans happen/).should("have.attr",- "aria-checked",+ "data-checked","true",);@@ -571,7 +573,7 @@ describe("scenarios > admin > databases > sample database", () => {"should not be possible to change database type for the Sample Database (metabase#16382)",);cy.findByLabelText("Database type")- .should("have.text", "H2")+ .should("have.value", "H2").and("be.disabled");cy.log("should correctly display connection settings");@@ -584,21 +586,22 @@ describe("scenarios > admin > databases > sample database", () => {// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usagecy.findByText("Show advanced options").click();// `auto_run_queries` toggle should be ON by default- cy.findByLabelText("Rerun queries for simple explorations")- .should("have.attr", "aria-checked", "true")- .click();+ cy.findByLabelText(/Rerun queries for simple explorations/)+ .should("have.attr", "data-checked", "true")+ .click({ force: true });// Reported failing in v0.36.4cy.log("should respect the settings for automatic query running (metabase#13187)",);- cy.findByLabelText("Rerun queries for simple explorations").should(- "have.attr",- "aria-checked",- "false",+ cy.findByLabelText(/Rerun queries for simple explorations/).should(+ "not.have.attr",+ "data-checked",);cy.log("change the metadata_sync period");- cy.findByLabelText("Choose when syncs and scans happen").click();+ cy.findByLabelText(/Choose when syncs and scans happen/).click({+ force: true,+ });// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usagecy.findByText("Hourly").click();H.popover().within(() => {@@ -652,7 +655,9 @@ describe("scenarios > admin > databases > sample database", () => {visitDatabase(SAMPLE_DB_ID);editDatabase();H.modal().findByText("Show advanced options").click();- cy.findByLabelText("Choose when syncs and scans happen").click();+ cy.findByLabelText(/Choose when syncs and scans happen/).click({+ force: true,+ });cy.button("Save changes").click();cy.wait("@databaseUpdate").then(({ request: { body }, response }) => {expect(body.is_full_sync).to.equal(false);diff --git a/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts b/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.tsindex 1be3b677012..a2d0a826b29 100644--- a/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts+++ b/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts@@ -210,7 +210,7 @@ describe("Add data modal", () => {H.modal().within(() => {cy.findByText("Add a database").should("be.visible");- cy.findByLabelText("Database type").should("contain", "Snowflake");+ cy.findByLabelText("Database type").should("have.value", "Snowflake");});});diff --git a/enterprise/frontend/src/metabase-enterprise/database_routing/index.tsx b/enterprise/frontend/src/metabase-enterprise/database_routing/index.tsxindex 31d83430d0e..3a7ac6b81c9 100644--- a/enterprise/frontend/src/metabase-enterprise/database_routing/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/database_routing/index.tsx@@ -19,7 +19,7 @@ if (hasPremiumFeature("database_routing")) {}return {- title: t`Slug`,+ label: t`Slug`,// eslint-disable-next-line no-literal-metabase-strings -- Admin settingsdescription: t`Metabase will route queries to this database when the user attribute value matches this slug.`, // Metabase will use this value to map to the user attribute you specify to swap queries at run time`,placeholder: t`For example, pro-users`,diff --git a/frontend/src/metabase/admin/people/forms/UserForm.tsx b/frontend/src/metabase/admin/people/forms/UserForm.tsxindex 999dd96dad1..066535f94a0 100644--- a/frontend/src/metabase/admin/people/forms/UserForm.tsx+++ b/frontend/src/metabase/admin/people/forms/UserForm.tsx@@ -51,6 +51,7 @@ export const UserForm = ({placeholder={t`Johnny`}label={t`First name`}mb="md"+ nullable/><FormTextInputname="last_name"@@ -58,6 +59,7 @@ export const UserForm = ({placeholder={t`Appleseed`}label={t`Last name`}mb="md"+ nullable/><FormTextInputname="email"diff --git a/frontend/src/metabase/common/components/SchedulePicker/SchedulePickerView.tsx b/frontend/src/metabase/common/components/SchedulePicker/SchedulePickerView.tsxindex 73476c81dd6..0ef0c68e9dc 100644--- a/frontend/src/metabase/common/components/SchedulePicker/SchedulePickerView.tsx+++ b/frontend/src/metabase/common/components/SchedulePicker/SchedulePickerView.tsx@@ -266,7 +266,7 @@ class SchedulePicker extends Component<SchedulePickerProps> {textBeforeInterval,className,style,- mt = "lg",+ mt = "md",} = this.props;const scheduleType = schedule.schedule_type;diff --git a/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.styled.tsx b/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.styled.tsxdeleted file mode 100644index 66cbda43851..00000000000--- a/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.styled.tsx+++ /dev/null@@ -1,15 +0,0 @@-// eslint-disable-next-line no-restricted-imports-import styled from "@emotion/styled";--import Button from "metabase/common/components/Button";--export const SectionButton = styled(Button)`- color: var(--mb-color-brand);- padding: 0;- border: none;- border-radius: 0;-- &:hover {- background-color: transparent;- }-`;diff --git a/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.tsx b/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.tsxindex 28ae7dd3d8b..b0617125c9d 100644--- a/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseAuthProviderSectionField/DatabaseAuthProviderSectionField.tsx@@ -2,9 +2,8 @@ import { useField } from "formik";import { useCallback } from "react";import { t } from "ttag";-import FormField from "metabase/common/components/FormField";--import { SectionButton } from "./DatabaseAuthProviderSectionField.styled";+import { FormField } from "metabase/forms";+import { Button } from "metabase/ui";export interface DatabaseAuthProviderSectionFieldProps {name: string;@@ -21,9 +20,14 @@ const DatabaseAuthProviderSectionField = ({return (<FormField>- <SectionButton type="button" onClick={handleClick}>+ <Button+ w="fit-content"+ variant="subtle"+ size="compact-sm"+ onClick={handleClick}+ >{value ? t`Use password` : t`Use an authentication provider`}- </SectionButton>+ </Button></FormField>);};diff --git a/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.styled.tsx b/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.styled.tsxindex eb5e19ad773..e0017fc74ff 100644--- a/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.styled.tsx+++ b/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.styled.tsx@@ -36,6 +36,7 @@ export const ScheduleOptionIndicator = styled.div<ScheduleOptionIndicatorProps>`border: 0.125rem solid${(props) => (props.isSelected ? color("brand") : color("text-light"))};border-radius: 50%;+ flex: 0 0 1.125rem;`;interface ScheduleOptionIndicatorBackgroundProps {diff --git a/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.tsx b/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.tsxindex 441c5770b74..09dc8788150 100644--- a/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseCacheScheduleField/DatabaseCacheScheduleField.tsx@@ -3,8 +3,8 @@ import type { ReactNode } from "react";import { useCallback } from "react";import { t } from "ttag";-import FormField from "metabase/common/components/FormField";import SchedulePicker from "metabase/common/components/SchedulePicker/SchedulePickerView";+import { FormField } from "metabase/forms";import type {DatabaseData,ScheduleSettings,diff --git a/frontend/src/metabase/databases/components/DatabaseConnectionSectionField/DatabaseConnectionSectionField.tsx b/frontend/src/metabase/databases/components/DatabaseConnectionSectionField/DatabaseConnectionSectionField.tsxindex c09e0c52616..b2909862ef2 100644--- a/frontend/src/metabase/databases/components/DatabaseConnectionSectionField/DatabaseConnectionSectionField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseConnectionSectionField/DatabaseConnectionSectionField.tsx@@ -2,7 +2,7 @@ import { useField } from "formik";import { useCallback } from "react";import { t } from "ttag";-import FormField from "metabase/common/components/FormField";+import { FormField } from "metabase/forms";import { Box, Radio } from "metabase/ui";export interface DatabaseConnectionSectionFieldProps {diff --git a/frontend/src/metabase/databases/components/DatabaseDetailField/DatabaseDetailField.tsx b/frontend/src/metabase/databases/components/DatabaseDetailField/DatabaseDetailField.tsxindex 575e6a5af4e..6e69918f8af 100644--- a/frontend/src/metabase/databases/components/DatabaseDetailField/DatabaseDetailField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseDetailField/DatabaseDetailField.tsx@@ -1,10 +1,13 @@import FormFileInput from "metabase/common/components/FormFileInput";-import FormInput from "metabase/common/components/FormInput";-import FormNumericInput from "metabase/common/components/FormNumericInput";-import FormSelect from "metabase/common/components/FormSelect";-import FormTextArea from "metabase/common/components/FormTextArea";-import FormToggle from "metabase/common/components/FormToggle";-import type { EngineField } from "metabase-types/api";+import {+ FormNumberInput,+ FormSelect,+ FormSwitch,+ FormTextInput,+ FormTextarea,+} from "metabase/forms";+import { Icon, type SwitchProps, Tooltip } from "metabase/ui";+import type { EngineField, EngineFieldOption } from "metabase-types/api";import { FIELD_OVERRIDES } from "../../constants";import type { EngineFieldOverride } from "../../types";@@ -34,13 +37,13 @@ const DatabaseDetailField = ({switch (type) {case "password":- return <FormInput {...props} {...getPasswordProps(field)} nullable />;+ return <FormTextInput {...props} {...getPasswordProps(field)} nullable />;case "text":- return <FormTextArea {...props} />;+ return <FormTextarea {...props} />;case "integer":- return <FormNumericInput {...props} {...getInputProps(field)} nullable />;+ return <FormNumberInput {...props} {...getInputProps(field)} nullable />;case "boolean":- return <FormToggle {...props} />;+ return <FormSwitch {...props} {...getSwitchProps()} />;case "select":return <FormSelect {...props} {...getSelectProps(field, override)} />;case "textFile":@@ -52,10 +55,23 @@ const DatabaseDetailField = ({case "hidden":return null;default:- return <FormInput {...props} {...getInputProps(field)} nullable />;+ return <FormTextInput {...props} {...getInputProps(field)} nullable />;}};+const getSwitchProps = (): SwitchProps => ({+ labelPosition: "left" as const,+ styles: {+ body: {+ justifyContent: "space-between",+ },+ label: {+ fontWeight: "bold",+ fontSize: "var(--mantine-font-size-md)",+ },+ },+});+const getFieldType = (field: EngineField, override?: EngineFieldOverride) => {return override?.type ?? field.type;};@@ -66,17 +82,27 @@ const getFieldProps = (field: EngineField, override?: EngineFieldOverride) => {return {name: override?.name ?? `details.${field.name}`,+ label: override?.title ?? field["display-name"],title: override?.title ?? field["display-name"],description: override?.description ?? field.description,placeholder: placeholder != null ? String(placeholder) : undefined,encoding: field["treat-before-posting"],+ mb: "md",};};const getInputProps = (field: EngineField) => {+ const icon = field["helper-text"] ? <Icon name="info" /> : undefined;++ const rightSection =+ field["helper-text"] && icon ? (+ <Tooltip label={field["helper-text"]}>{icon}</Tooltip>+ ) : (+ icon+ );+return {- rightIcon: field["helper-text"] ? ("info" as const) : undefined,- rightIconTooltip: field["helper-text"],+ rightSection,};};@@ -89,9 +115,17 @@ const getPasswordProps = (field: EngineField) => {const getSelectProps = (field: EngineField, override?: EngineFieldOverride) => {return {- options: override?.options ?? field.options ?? [],+ data: convertEnginFeildOptionsToSelectOptions(+ override?.options ?? field.options ?? [],+ ),};};+const convertEnginFeildOptionsToSelectOptions = (+ options: EngineFieldOption[],+) => {+ return options.map((option) => ({ label: option.name, value: option.value }));+};+// eslint-disable-next-line import/no-default-export -- deprecated usageexport default DatabaseDetailField;diff --git a/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineField.tsx b/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineField.tsxindex 440ce727952..c93907e1e8e 100644--- a/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineField.tsx@@ -28,7 +28,10 @@ export const DatabaseEngineField = ({const { values } = useFormikContext<DatabaseData>();const options = useMemo(() => {- return getEngineOptions(engines, engineKey, isAdvanced);+ return getEngineOptions(engines, engineKey, isAdvanced).map((option) => ({+ label: option.name,+ value: option.value,+ }));}, [engines, engineKey, isAdvanced]);if (isAdvanced) {diff --git a/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineSelect.tsx b/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineSelect.tsxindex 52e639a2844..5dba18a82b4 100644--- a/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineSelect.tsx+++ b/frontend/src/metabase/databases/components/DatabaseEngineField/DatabaseEngineSelect.tsx@@ -1,13 +1,11 @@import { useCallback } from "react";import { t } from "ttag";-import FormSelect from "metabase/common/components/FormSelect";-import type { SelectChangeEvent } from "metabase/common/components/Select";--import type { EngineOption } from "../../types";+import { FormSelect } from "metabase/forms";+import type { SelectOption } from "metabase/ui";export interface DatabaseEngineSelectProps {- options: EngineOption[];+ options: SelectOption[];disabled: boolean;onChange: (engine: string) => void;}@@ -18,8 +16,8 @@ const DatabaseEngineSelect = ({onChange,}: DatabaseEngineSelectProps): JSX.Element => {const handleChange = useCallback(- (event: SelectChangeEvent<string>) => {- onChange(event.target.value);+ (value: string) => {+ onChange(value);},[onChange],);@@ -27,11 +25,13 @@ const DatabaseEngineSelect = ({return (<FormSelectname="engine"- title={t`Database type`}+ label={t`Database type`}placeholder={t`Select a database`}- options={options}+ data={options}disabled={disabled}onChange={handleChange}+ mb="md"+ searchable/>);};diff --git a/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsxindex 66344d88777..b27236c23e2 100644--- a/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx@@ -2,9 +2,8 @@ import { useField } from "formik";import { useCallback } from "react";import { t } from "ttag";-import FormField from "metabase/common/components/FormField";--import { SectionButton } from "./DatabaseHostameSectionField.styled";+import { FormField } from "metabase/forms";+import { Button } from "metabase/ui";export interface DatabaseHostnameSectionFieldProps {name: string;@@ -21,9 +20,14 @@ const DatabaseHostnameSectionField = ({return (<FormField>- <SectionButton type="button" onClick={handleClick}>+ <Button+ w="fit-content"+ variant="subtle"+ size="compact-sm"+ onClick={handleClick}+ >{value ? t`Use account name` : t`Use hostname`}- </SectionButton>+ </Button></FormField>);};diff --git a/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx b/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsxindex 3bcbcd4e2f1..4cb4a14cfe5 100644--- a/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx@@ -1,7 +1,8 @@import { t } from "ttag";-import FormInput from "metabase/common/components/FormInput";+import { FormTextInput } from "metabase/forms";import { PLUGIN_DB_ROUTING } from "metabase/plugins";+import { Icon, Tooltip } from "metabase/ui";import type { Engine } from "metabase-types/api";import type { DatabaseFormConfig } from "../DatabaseForm";@@ -24,16 +25,20 @@ export const DatabaseNameField = ({: {};return (- <FormInput+ <FormTextInputname="name"- title={t`Display name`}+ label={t`Display name`}placeholder={t`Our ${name}`}{...PLUGIN_DB_ROUTING.getDatabaseNameFieldProps(config.name?.isSlug || false,)}- rightIcon="info"- // eslint-disable-next-line no-literal-metabase-strings -- Admin settings- rightIconTooltip={t`Choose what this data will be called in Metabase.`}+ rightSection={+ // eslint-disable-next-line no-literal-metabase-strings -- Admin settings+ <Tooltip label={t`Choose what this data will be called in Metabase.`}>+ <Icon name="info" />+ </Tooltip>+ }+ mb="md"{...autoFocusProps}{...props}/>diff --git a/frontend/src/metabase/databases/components/DatabaseScheduleToggleField/DatabaseScheduleToggleField.tsx b/frontend/src/metabase/databases/components/DatabaseScheduleToggleField/DatabaseScheduleToggleField.tsxindex c76cf33fc89..0d081169e07 100644--- a/frontend/src/metabase/databases/components/DatabaseScheduleToggleField/DatabaseScheduleToggleField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseScheduleToggleField/DatabaseScheduleToggleField.tsx@@ -1,8 +1,8 @@import { useFormikContext } from "formik";-import type { ReactNode } from "react";+import type { ChangeEvent, ReactNode } from "react";import { useCallback } from "react";-import FormToggle from "metabase/common/components/FormToggle";+import { FormSwitch } from "metabase/forms";import type { DatabaseData } from "metabase-types/api";export interface DatabaseScheduleToggleFieldProps {@@ -19,19 +19,30 @@ const DatabaseScheduleToggleField = ({const { setFieldValue } = useFormikContext<DatabaseData>();const handleChange = useCallback(- (value: boolean) => {- setFieldValue("is_full_sync", !value);+ (event: ChangeEvent<HTMLInputElement>) => {+ setFieldValue("is_full_sync", !event.target.checked);setFieldValue("is_on_demand", false);},[setFieldValue],);return (- <FormToggle+ <FormSwitchname={name}- title={title}+ label={title}description={description}onChange={handleChange}+ mb="md"+ labelPosition="left"+ styles={{+ body: {+ justifyContent: "space-between",+ },+ label: {+ fontWeight: "bold",+ fontSize: "var(--mantine-font-size-md)",+ },+ }}/>);};diff --git a/frontend/src/metabase/databases/components/DatabaseSyncScheduleField/DatabaseSyncScheduleField.tsx b/frontend/src/metabase/databases/components/DatabaseSyncScheduleField/DatabaseSyncScheduleField.tsxindex 689f1dd90e7..6bbc1469567 100644--- a/frontend/src/metabase/databases/components/DatabaseSyncScheduleField/DatabaseSyncScheduleField.tsx+++ b/frontend/src/metabase/databases/components/DatabaseSyncScheduleField/DatabaseSyncScheduleField.tsx@@ -3,8 +3,8 @@ import type { ReactNode } from "react";import { useCallback } from "react";import { t } from "ttag";-import FormField from "metabase/common/components/FormField";import SchedulePicker from "metabase/common/components/SchedulePicker/SchedulePickerView";+import { FormField } from "metabase/forms";import type { ScheduleSettings, ScheduleType } from "metabase-types/api";const DEFAULT_SCHEDULE: ScheduleSettings = {diff --git a/frontend/src/metabase/forms/components/FormField/FormField.stories.tsx b/frontend/src/metabase/forms/components/FormField/FormField.stories.tsxnew file mode 100644index 00000000000..42e36e0eb34--- /dev/null+++ b/frontend/src/metabase/forms/components/FormField/FormField.stories.tsx@@ -0,0 +1,24 @@+import { TextInput } from "metabase/ui";++import { FormField, type FormFieldProps } from "./FormField";++const FormFieldTemplate = (args: FormFieldProps) => {+ return (+ <FormField {...args}>+ <TextInput placeholder="Type something here" />+ </FormField>+ );+};++export default {+ title: "Forms/Form Field",+ component: FormField,+ args: {+ title: "Your Input",+ description: "Something Helpful",+ },+};++export const Default = {+ render: FormFieldTemplate,+};diff --git a/frontend/src/metabase/forms/components/FormField/FormField.tsx b/frontend/src/metabase/forms/components/FormField/FormField.tsxnew file mode 100644index 00000000000..5b315683944--- /dev/null+++ b/frontend/src/metabase/forms/components/FormField/FormField.tsx@@ -0,0 +1,94 @@+import type { ReactNode, Ref } from "react";+import { forwardRef } from "react";+import { t } from "ttag";++import { Box, Flex, type FlexProps, Icon, Text, Tooltip } from "metabase/ui";++export interface FormFieldProps extends FlexProps {+ title?: string;+ actions?: ReactNode;+ description?: ReactNode;+ optional?: boolean;+ error?: string;+ htmlFor?: string;+ infoLabel?: string;+ infoTooltip?: string;+}++export const FormField = forwardRef(function FormField(+ {+ title,+ actions,+ description,+ error,+ htmlFor,+ infoLabel,+ infoTooltip,+ children,+ optional,+ ...props+ }: FormFieldProps,+ ref: Ref<HTMLDivElement>,+) {+ const hasTitle = Boolean(title);+ const hasDescription = Boolean(description);+ const hasError = Boolean(error);++ return (+ <Flex {...props} ref={ref} direction="column" mb="md">+ {(hasTitle || hasDescription) && (+ <Box>+ <Flex align="center" mb={hasDescription ? "xs" : undefined}>+ {hasTitle && (+ <Text+ component="label"+ c={hasError ? "error" : "text-primary"}+ htmlFor={htmlFor}+ fw="bold"+ fz="md"+ >+ {title}+ {hasError && (+ <Text component="span" c="error" role="alert">+ : {error}+ </Text>+ )}+ </Text>+ )}+ {!!optional && !hasError && (+ <Text+ component="span"+ c={"text-medium"}+ fw="900"+ fz="sm"+ ml="xs"+ >{t`(optional)`}</Text>+ )}+ {(infoLabel || infoTooltip) && (+ <Tooltip multiline label={infoTooltip}>+ {infoLabel ? (+ <Text c="text-medium" mb="sm" fz="md" ml="auto">+ {infoLabel}+ </Text>+ ) : (+ <Icon c="bg-dark" ml="sm" name="info" />+ )}+ </Tooltip>+ )}+ {actions && (+ <Box ml="auto" fz="0.75rem" fw="900" c="text-medium">+ {actions}+ </Box>+ )}+ </Flex>+ {description && (+ <Text c="text-medium" mb="sm" fz="sm" lh="md">+ {description}+ </Text>+ )}+ </Box>+ )}+ {children}+ </Flex>+ );+});diff --git a/frontend/src/metabase/forms/components/FormField/index.ts b/frontend/src/metabase/forms/components/FormField/index.tsnew file mode 100644index 00000000000..f3f4916865f--- /dev/null+++ b/frontend/src/metabase/forms/components/FormField/index.ts@@ -0,0 +1 @@+export * from "./FormField";diff --git a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsxindex 2ac9e00e3f0..6051cc7fc6a 100644--- a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx+++ b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.tsx@@ -32,7 +32,7 @@ export const FormTextInput = forwardRef(function FormTextInput((event: ChangeEvent<HTMLInputElement>) => {const newValue = event.target.value;if (newValue === "") {- setValue(nullable ? null : undefined);+ setValue(nullable ? null : newValue);} else {setValue(newValue);}diff --git a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.unit.spec.tsx b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.unit.spec.tsxindex 4d87828884b..ae4a2b306a5 100644--- a/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.unit.spec.tsx+++ b/frontend/src/metabase/forms/components/FormTextInput/FormTextInput.unit.spec.tsx@@ -102,10 +102,7 @@ describe("FormTextInput", () => {await userEvent.click(screen.getByText("Submit"));await waitFor(() => {- expect(onSubmit).toHaveBeenCalledWith(- { name: undefined },- expect.anything(),- );+ expect(onSubmit).toHaveBeenCalledWith({ name: "" }, expect.anything());});});diff --git a/frontend/src/metabase/forms/components/index.ts b/frontend/src/metabase/forms/components/index.tsindex 5a7559bd7e9..f75d4a38f51 100644--- a/frontend/src/metabase/forms/components/index.ts+++ b/frontend/src/metabase/forms/components/index.ts@@ -4,6 +4,7 @@ export * from "./FormCheckboxGroup";export * from "./FormChipGroup";export * from "./FormDateInput";export * from "./FormErrorMessage";+export * from "./FormField";export * from "./FormGroupsWidget";export * from "./FormGroupWidget";export * from "./FormMessage";