Skip to content

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

[PRG-114] Show help & more specific error message when a database connection fails (#62956)

Andersond998df052e3f
diff --git a/e2e/test/scenarios/admin/databases.cy.spec.js b/e2e/test/scenarios/admin/databases.cy.spec.js
index 641ec0ad404..947816649a9 100644
--- a/e2e/test/scenarios/admin/databases.cy.spec.js
+++ b/e2e/test/scenarios/admin/databases.cy.spec.js
@@ -492,8 +492,44 @@ describe("scenarios > admin > databases > exceptions", () => {
cy.button("Save").click();
cy.wait("@createDatabase");
- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
- cy.findByText("DATABASE CONNECTION ERROR").should("exist");
+ cy.findByTestId("database-form")
+ .parent()
+ .within(() => {
+ cy.findByText("DATABASE CONNECTION ERROR").should("be.visible");
+ });
+ });
+
+ it("should show specific error message when error is on host or port", () => {
+ cy.intercept("POST", "/api/database", (req) => {
+ req.reply({
+ statusCode: 400,
+ body: {
+ message: "DATABASE CONNECTION ERROR",
+ errors: {
+ host: "Check your host",
+ port: "Check your port",
+ },
+ },
+ });
+ }).as("createDatabase");
+
+ cy.visit("/admin/databases/create");
+
+ H.typeAndBlurUsingLabel("Display name", "Test");
+ H.typeAndBlurUsingLabel("Database name", "db");
+ H.typeAndBlurUsingLabel("Username", "admin");
+
+ cy.button("Save").click();
+ cy.wait("@createDatabase");
+
+ cy.findByTestId("database-form")
+ .parent()
+ .within(() => {
+ cy.findByText("DATABASE CONNECTION ERROR").should("not.exist");
+ cy.findByText(
+ /Make sure your Host and Port settings are correct/,
+ ).should("be.visible");
+ });
});
it("should handle non-existing databases (metabase#11037)", () => {
diff --git a/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.tsx b/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.tsx
index 8b197bf77ad..21cf0cdb56d 100644
--- a/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.tsx
+++ b/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.tsx
@@ -10,11 +10,11 @@ import { GenericError } from "metabase/common/components/ErrorPages";
import { LeaveRouteConfirmModal } from "metabase/common/components/LeaveConfirmModal";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { useCallbackEffect } from "metabase/common/hooks/use-callback-effect";
-import {
- DatabaseForm,
- type DatabaseFormConfig,
-} from "metabase/databases/components/DatabaseForm";
-import type { FormLocation } from "metabase/databases/types";
+import { DatabaseForm } from "metabase/databases/components/DatabaseForm";
+import type {
+ DatabaseFormConfig,
+ FormLocation,
+} from "metabase/databases/types";
import { useDispatch } from "metabase/lib/redux";
import { Text } from "metabase/ui";
import type {
diff --git a/frontend/src/metabase/css/core/colors.module.css b/frontend/src/metabase/css/core/colors.module.css
index 6d27e31462b..55872d7349b 100644
--- a/frontend/src/metabase/css/core/colors.module.css
+++ b/frontend/src/metabase/css/core/colors.module.css
@@ -208,10 +208,10 @@
--mb-base-color-orion-alpha-60: hsla(204, 66%, 8%, 0.62);
--mb-base-color-orion-alpha-50: hsla(204, 66%, 8%, 0.51);
--mb-base-color-orion-alpha-40: hsla(204, 66%, 8%, 0.44);
- --mb-base-color-orion-alpha-30: hsla(204, 66%, 8%, 0.44);
- --mb-base-color-orion-alpha-20: hsla(204, 66%, 8%, 0.44);
- --mb-base-color-orion-alpha-10: hsla(204, 66%, 8%, 0.44);
- --mb-base-color-orion-alpha-5: hsla(204, 66%, 8%, 0.44);
+ --mb-base-color-orion-alpha-30: hsla(204, 66%, 8%, 0.29);
+ --mb-base-color-orion-alpha-20: hsla(204, 66%, 8%, 0.14);
+ --mb-base-color-orion-alpha-10: hsla(204, 66%, 8%, 0.05);
+ --mb-base-color-orion-alpha-5: hsla(204, 66%, 8%, 0.02);
/* Lobster */
--mb-base-color-lobster-100: hsla(0, 81%, 11%, 1);
diff --git a/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx b/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
index 8026b1f8467..2e35fd34a84 100644
--- a/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
@@ -148,7 +148,7 @@ function ConnectionStringDescription({
exitDelay={0}
>
{(styles) => (
- <Group style={styles} top={0} pos="absolute" h="lg">
+ <Group style={styles} top={0} pos="absolute" h="lg" component="span">
{t`You can use a connection string to pre-fill the details below.`}
</Group>
)}
@@ -170,8 +170,9 @@ function ConnectionStringDescription({
c="danger"
fw="bold"
fz="sm"
+ component="span"
>
- <Group gap="xs">
+ <Group gap="xs" component="span">
<Icon name="warning_round_filled" c="var(--mb-color-danger)" />
{t`Couldn’t use this connection string.`}
</Group>
@@ -195,8 +196,9 @@ function ConnectionStringDescription({
c="success"
fw="bold"
fz="sm"
+ component="span"
>
- <Group gap="xs">
+ <Group gap="xs" component="span">
<Icon
name="check_filled"
style={{ color: "var(--mb-color-success)" }}
@@ -208,7 +210,7 @@ function ConnectionStringDescription({
</Transition>
);
return (
- <Group h="lg" pos="relative">
+ <Group h="lg" pos="relative" component="span">
{failureMessage}
{defaultDescription}
{successMessage}
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
index 8105f2320cc..635acdb4769 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
@@ -1,31 +1,16 @@
-import { useFormikContext } from "formik";
-import { useCallback, useEffect, useMemo, useState } from "react";
-import { match } from "ts-pattern";
-import { c, t } from "ttag";
+import { useCallback, useMemo, useState } from "react";
-import ExternalLink from "metabase/common/components/ExternalLink";
-import { FormFooter } from "metabase/common/components/FormFooter";
-import { useDocsUrl, useSetting } from "metabase/common/hooks";
import { Form, FormProvider } from "metabase/forms";
-import { FormErrorMessage } from "metabase/forms/components/FormErrorMessage";
-import { FormSubmitButton } from "metabase/forms/components/FormSubmitButton";
import { useSelector } from "metabase/lib/redux";
-import { Box, Button, Flex, Text } from "metabase/ui";
-import type { DatabaseData, Engine, EngineKey } from "metabase-types/api";
+import type { DatabaseData, EngineKey } from "metabase-types/api";
import { getEngines } from "../../selectors";
import type { FormLocation } from "../../types";
-import { getDefaultEngineKey } from "../../utils/engine";
-import {
- getSubmitValues,
- getValidationSchema,
- getVisibleFields,
-} from "../../utils/schema";
-import { DatabaseConnectionStringField } from "../DatabaseConnectionUri";
-import DatabaseDetailField from "../DatabaseDetailField";
-import { DatabaseEngineField } from "../DatabaseEngineField";
-import DatabaseEngineWarning from "../DatabaseEngineWarning";
-import { DatabaseNameField } from "../DatabaseNameField";
+import { getSubmitValues, getValidationSchema } from "../../utils/schema";
+
+import { DatabaseFormBody } from "./DatabaseFormBody";
+import { DatabaseFormFooter } from "./DatabaseFormFooter";
+import { getEngine, getEngineKey } from "./utils";
export type EngineFieldState = "default" | "hidden" | "disabled";
@@ -116,244 +101,32 @@ export const DatabaseForm = ({
enableReinitialize
onSubmit={handleSubmit}
>
- <DatabaseFormBody
- engine={engine}
- // casting won't be needed after migrating all usages of engineKey
- engineKey={engineKey as EngineKey}
- engines={engines}
- engineFieldState={engineFieldState}
- autofocusFieldName={autofocusFieldName}
- isAdvanced={isAdvanced}
- onEngineChange={handleEngineChange}
- onCancel={onCancel}
- setIsDirty={setIsDirty}
- config={config}
- showSampleDatabase={showSampleDatabase}
- ContinueWithoutDataSlot={ContinueWithoutDataSlot}
- location={location}
- />
- </FormProvider>
- );
-};
-
-interface DatabaseFormBodyProps {
- engine: Engine | undefined;
- engineKey: EngineKey | undefined;
- engines: Record<string, Engine>;
- engineFieldState?: "default" | "hidden" | "disabled";
- autofocusFieldName?: string;
- isAdvanced: boolean;
- onEngineChange: (engineKey: string | undefined) => void;
- onCancel?: () => void;
- setIsDirty?: (isDirty: boolean) => void;
- config: DatabaseFormConfig;
- showSampleDatabase?: boolean;
- ContinueWithoutDataSlot?: ContinueWithoutDataComponent;
- location: FormLocation;
-}
-
-const DatabaseFormBody = ({
- engine,
- engineKey,
- engines,
- engineFieldState = "default",
- autofocusFieldName,
- isAdvanced,
- onEngineChange,
- onCancel,
- setIsDirty,
- config,
- showSampleDatabase = false,
- ContinueWithoutDataSlot,
- location,
-}: DatabaseFormBodyProps): JSX.Element => {
- const { values, dirty, setValues } = useFormikContext<DatabaseData>();
-
- useEffect(() => {
- setIsDirty?.(dirty);
- }, [dirty, setIsDirty]);
-
- const fields = useMemo(() => {
- return engine ? getVisibleFields(engine, values, isAdvanced) : [];
- }, [engine, values, isAdvanced]);
-
- const px = match(location)
- .with("setup", () => "sm")
- .with("embedding_setup", () => "xl")
- .with("admin", () => "xl")
- .with("full-page", () => undefined)
- .exhaustive();
- const mah = location === "full-page" ? "100%" : "calc(100vh - 20rem)";
-
- return (
- <Form
- data-testid="database-form"
- pt={location === "full-page" ? undefined : "md"}
- >
- <Box mah={mah} style={{ overflowY: "auto" }} px={px} mb="md">
- {engineFieldState !== "hidden" && (
- <>
- <DatabaseEngineField
- engineKey={engineKey}
- engines={engines}
- isAdvanced={isAdvanced}
- onChange={onEngineChange}
- disabled={engineFieldState === "disabled"}
- showSampleDatabase={showSampleDatabase}
- />
- <DatabaseEngineWarning
- engineKey={engineKey}
- engines={engines}
- onChange={onEngineChange}
- />
- </>
- )}
- <DatabaseConnectionStringField
- engineKey={engineKey}
+ <Form
+ data-testid="database-form"
+ pt={location === "full-page" ? undefined : "md"}
+ >
+ <DatabaseFormBody
+ engine={engine}
+ // casting won't be needed after migrating all usages of engineKey
+ engineKey={engineKey as EngineKey}
+ engines={engines}
+ engineFieldState={engineFieldState}
+ autofocusFieldName={autofocusFieldName}
+ isAdvanced={isAdvanced}
+ onEngineChange={handleEngineChange}
+ setIsDirty={setIsDirty}
+ config={config}
+ showSampleDatabase={showSampleDatabase}
location={location}
- setValues={setValues}
/>
- {engine && (
- <DatabaseNameField
- engine={engine}
- config={config}
- autoFocus={autofocusFieldName === "name"}
- />
- )}
- {fields.map((field) => (
- <DatabaseDetailField
- key={field.name}
- field={field}
- autoFocus={autofocusFieldName === field.name}
- data-kek={field.name}
- engineKey={engineKey}
- engine={engine}
- />
- ))}
- </Box>
- <DatabaseFormFooter
- isDirty={dirty}
- isAdvanced={isAdvanced}
- onCancel={onCancel}
- showSampleDatabase={showSampleDatabase}
- ContinueWithoutDataSlot={ContinueWithoutDataSlot}
- location={location}
- />
- </Form>
- );
-};
-
-interface DatabaseFormFooterProps {
- isAdvanced: boolean;
- isDirty: boolean;
- onCancel?: () => void;
- showSampleDatabase?: boolean;
- ContinueWithoutDataSlot?: ContinueWithoutDataComponent;
- location: FormLocation;
-}
-
-const DatabaseFormFooter = ({
- isAdvanced,
- isDirty,
- onCancel,
- showSampleDatabase,
- ContinueWithoutDataSlot,
- location,
-}: DatabaseFormFooterProps) => {
- const { values } = useFormikContext<DatabaseData>();
- const isNew = values.id == null;
-
- // eslint-disable-next-line no-unconditional-metabase-links-render -- Metabase setup + admin pages only
- const { url: docsUrl } = useDocsUrl("databases/connecting");
-
- const hasSampleDatabase = useSetting("has-sample-database?");
-
- if (isAdvanced) {
- return (
- <FormFooter
- data-testid="form-footer"
- px={location === "full-page" ? undefined : "xl"}
- >
- <FormErrorMessage />
- <Flex justify="space-between" align="center" w="100%">
- {isNew ? (
- <ExternalLink
- key="link"
- href={docsUrl}
- style={{ fontWeight: 500, fontSize: ".875rem" }}
- >
- {t`Need help connecting?`}
- </ExternalLink>
- ) : (
- <div />
- )}
-
- <Flex gap="sm">
- <Button onClick={onCancel}>{t`Cancel`}</Button>
- <FormSubmitButton
- disabled={!isDirty}
- variant="filled"
- label={isNew ? t`Save` : t`Save changes`}
- />
- </Flex>
- </Flex>
- </FormFooter>
- );
- }
-
- if (values.engine) {
- return (
- <FormFooter>
- <FormErrorMessage inline />
- <Button onClick={onCancel}>{t`Skip`}</Button>
- <FormSubmitButton variant="filled" label={t`Connect database`} />
- </FormFooter>
- );
- }
-
- if (ContinueWithoutDataSlot) {
- return <ContinueWithoutDataSlot onCancel={onCancel} />;
- }
-
- // This check happens only during setup where we cannot fetch databases.
- // Unless someone explicitly set the environment variable MB_LOAD_SAMPLE_CONTENT
- // to false, we can assume that the instance loads with the Sample Database.
- // https://www.metabase.com/docs/latest/configuring-metabase/environment-variables#mb_load_sample_content
- if (hasSampleDatabase !== false && showSampleDatabase) {
- return (
- <>
- <Button variant="filled" mb="md" mt="lg" onClick={onCancel}>
- {t`Continue with sample data`}
- </Button>
- <Text fz="sm">
- {c("{0} is 'Sample Database'").jt`Use our ${(
- <strong key="sample">{t`Sample Database`}</strong>
- )} to explore and test the app.`}
- </Text>
- <Text fz="sm">{t`Add your own data at any time.`}</Text>
- </>
- );
- }
-
- return (
- <Button variant="filled" mt="lg" onClick={onCancel}>
- {t`I'll add my data later`}
- </Button>
+ <DatabaseFormFooter
+ ContinueWithoutDataSlot={ContinueWithoutDataSlot}
+ isAdvanced={isAdvanced}
+ location={location}
+ onCancel={onCancel}
+ showSampleDatabase={showSampleDatabase}
+ />
+ </Form>
+ </FormProvider>
);
};
-
-const getEngine = (engines: Record<string, Engine>, engineKey?: string) => {
- return engineKey ? engines[engineKey] : undefined;
-};
-
-const getEngineKey = (
- engines: Record<string, Engine>,
- values?: Partial<DatabaseData>,
- isAdvanced?: boolean,
-) => {
- if (values?.engine && Object.keys(engines).includes(values.engine)) {
- return values.engine;
- } else if (isAdvanced) {
- return getDefaultEngineKey(engines);
- }
-};
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormBody.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormBody.tsx
new file mode 100644
index 00000000000..9f445e570a4
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormBody.tsx
@@ -0,0 +1,112 @@
+import { useFormikContext } from "formik";
+import { type JSX, useEffect, useMemo } from "react";
+import { match } from "ts-pattern";
+
+import type {
+ DatabaseFormConfig,
+ FormLocation,
+} from "metabase/databases/types";
+import { getVisibleFields } from "metabase/databases/utils/schema";
+import { Box } from "metabase/ui";
+import type { DatabaseData, Engine, EngineKey } from "metabase-types/api";
+
+import { DatabaseConnectionStringField } from "../DatabaseConnectionUri";
+import DatabaseDetailField from "../DatabaseDetailField";
+import { DatabaseEngineField } from "../DatabaseEngineField";
+import DatabaseEngineWarning from "../DatabaseEngineWarning";
+import { DatabaseFormError } from "../DatabaseFormError";
+import { DatabaseNameField } from "../DatabaseNameField";
+
+import { useHasConnectionError } from "./utils";
+
+interface DatabaseFormBodyProps {
+ engine: Engine | undefined;
+ engineKey: EngineKey | undefined;
+ engines: Record<string, Engine>;
+ engineFieldState?: "default" | "hidden" | "disabled";
+ autofocusFieldName?: string;
+ isAdvanced: boolean;
+ onEngineChange: (engineKey: string | undefined) => void;
+ setIsDirty?: (isDirty: boolean) => void;
+ config: DatabaseFormConfig;
+ showSampleDatabase?: boolean;
+ location: FormLocation;
+}
+
+export const DatabaseFormBody = ({
+ engine,
+ engineKey,
+ engines,
+ engineFieldState = "default",
+ autofocusFieldName,
+ isAdvanced,
+ onEngineChange,
+ setIsDirty,
+ config,
+ showSampleDatabase = false,
+ location,
+}: DatabaseFormBodyProps): JSX.Element => {
+ const { values, dirty, setValues } = useFormikContext<DatabaseData>();
+ const hasConnectionError = useHasConnectionError();
+
+ useEffect(() => {
+ setIsDirty?.(dirty);
+ }, [dirty, setIsDirty]);
+
+ const fields = useMemo(() => {
+ return engine ? getVisibleFields(engine, values, isAdvanced) : [];
+ }, [engine, values, isAdvanced]);
+
+ const px = match(location)
+ .with("setup", () => "sm")
+ .with("embedding_setup", () => "xl")
+ .with("admin", () => "xl")
+ .with("full-page", () => undefined)
+ .exhaustive();
+ const mah = location === "full-page" ? "100%" : "calc(100vh - 20rem)";
+
+ return (
+ <Box mah={mah} mb="md" px={px} style={{ overflowY: "auto" }}>
+ {engineFieldState !== "hidden" && (
+ <>
+ <DatabaseEngineField
+ engineKey={engineKey}
+ engines={engines}
+ isAdvanced={isAdvanced}
+ onChange={onEngineChange}
+ disabled={engineFieldState === "disabled"}
+ showSampleDatabase={showSampleDatabase}
+ />
+ <DatabaseEngineWarning
+ engineKey={engineKey}
+ engines={engines}
+ onChange={onEngineChange}
+ />
+ </>
+ )}
+ <DatabaseConnectionStringField
+ engineKey={engineKey}
+ location={location}
+ setValues={setValues}
+ />
+ {engine && (
+ <DatabaseNameField
+ engine={engine}
+ config={config}
+ autoFocus={autofocusFieldName === "name"}
+ />
+ )}
+ {fields.map((field) => (
+ <DatabaseDetailField
+ key={field.name}
+ field={field}
+ autoFocus={autofocusFieldName === field.name}
+ data-kek={field.name}
+ engineKey={engineKey}
+ engine={engine}
+ />
+ ))}
+ {isAdvanced && hasConnectionError && <DatabaseFormError />}
+ </Box>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormFooter.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormFooter.tsx
new file mode 100644
index 00000000000..e230e0a4f91
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseFormFooter.tsx
@@ -0,0 +1,114 @@
+import { useFormikContext } from "formik";
+import { c, t } from "ttag";
+
+import ExternalLink from "metabase/common/components/ExternalLink";
+import { FormFooter } from "metabase/common/components/FormFooter";
+import { useDocsUrl, useSetting } from "metabase/common/hooks";
+import type {
+ ContinueWithoutDataComponent,
+ FormLocation,
+} from "metabase/databases/types";
+import { FormSubmitButton } from "metabase/forms/components/FormSubmitButton";
+import { Button, Flex, Text } from "metabase/ui";
+import type { DatabaseData } from "metabase-types/api";
+
+import { DatabaseFormError } from "../DatabaseFormError";
+
+import { useHasConnectionError } from "./utils";
+
+interface DatabaseFormFooterProps {
+ isAdvanced: boolean;
+ onCancel?: () => void;
+ showSampleDatabase?: boolean;
+ ContinueWithoutDataSlot?: ContinueWithoutDataComponent;
+ location: FormLocation;
+}
+
+export const DatabaseFormFooter = ({
+ isAdvanced,
+ onCancel,
+ showSampleDatabase,
+ ContinueWithoutDataSlot,
+ location,
+}: DatabaseFormFooterProps) => {
+ const { values, dirty } = useFormikContext<DatabaseData>();
+ const isNew = values.id == null;
+ const hasConnectionError = useHasConnectionError();
+
+ // eslint-disable-next-line no-unconditional-metabase-links-render -- Metabase setup + admin pages only
+ const { url: docsUrl } = useDocsUrl("databases/connecting");
+
+ const hasSampleDatabase = useSetting("has-sample-database?");
+
+ if (isAdvanced) {
+ return (
+ <FormFooter
+ data-testid="form-footer"
+ px={location === "full-page" ? undefined : "xl"}
+ >
+ <Flex justify="space-between" align="center" w="100%">
+ {isNew ? (
+ <ExternalLink
+ key="link"
+ href={docsUrl}
+ style={{ fontWeight: 500, fontSize: ".875rem" }}
+ >
+ {t`Need help connecting?`}
+ </ExternalLink>
+ ) : (
+ <div />
+ )}
+
+ <Flex gap="sm">
+ <Button onClick={onCancel}>{t`Cancel`}</Button>
+ <FormSubmitButton
+ disabled={!dirty}
+ label={isNew ? t`Save` : t`Save changes`}
+ variant="filled"
+ />
+ </Flex>
+ </Flex>
+ </FormFooter>
+ );
+ }
+
+ if (values.engine) {
+ return (
+ <FormFooter data-testid="form-footer">
+ {hasConnectionError && <DatabaseFormError />}
+ <Button onClick={onCancel}>{t`Skip`}</Button>
+ <FormSubmitButton variant="filled" label={t`Connect database`} />
+ </FormFooter>
+ );
+ }
+
+ if (ContinueWithoutDataSlot) {
+ return <ContinueWithoutDataSlot onCancel={onCancel} />;
+ }
+
+ // This check happens only during setup where we cannot fetch databases.
+ // Unless someone explicitly set the environment variable MB_LOAD_SAMPLE_CONTENT
+ // to false, we can assume that the instance loads with the Sample Database.
+ // https://www.metabase.com/docs/latest/configuring-metabase/environment-variables#mb_load_sample_content
+ if (hasSampleDatabase !== false && showSampleDatabase) {
+ return (
+ <>
+ <Button variant="filled" mb="md" mt="lg" onClick={onCancel}>
+ {t`Continue with sample data`}
+ </Button>
+ <Text fz="sm">
+ {c("{0} is 'Sample Database'").jt`Use our ${(
+ <strong key="sample">{t`Sample Database`}</strong>
+ )} to explore and test the app.`}
+ </Text>
+ <Text fz="sm">{t`Add your own data at any time.`}</Text>
+ </>
+ );
+ }
+
+ return (
+ <Button variant="filled" mt="lg" onClick={onCancel}>
+ {t`I'll add my data later`}
+ </Button>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/common.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/common.unit.spec.tsx
index 72e5cedb0c1..b7cf14e3a40 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/common.unit.spec.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/common.unit.spec.tsx
@@ -1,14 +1,16 @@
+import { within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { screen, waitFor } from "__support__/ui";
import type { Engine } from "metabase-types/api";
+import * as utils from "../utils";
+
import { TEST_ENGINES, setup } from "./setup";
describe("DatabaseForm", () => {
it("should submit default values", async () => {
const { onSubmit } = setup();
-
const expectedDatabaseName = "My H2 Database";
const expectedConnectionString = "file:/somewhere";
await userEvent.type(
@@ -157,6 +159,38 @@ describe("DatabaseForm with provider name", () => {
);
});
});
+
+ describe("Connection error handling", () => {
+ const errorHandlingSetup = ({ isAdvanced }: { isAdvanced?: boolean }) => {
+ setup({
+ engines: TEST_ENGINES,
+ isAdvanced,
+ });
+ };
+ const errorMessage = /Metabase tried, but couldn't connect/;
+
+ beforeEach(() => {
+ jest.spyOn(utils, "useHasConnectionError").mockImplementation(() => true);
+ });
+
+ it("shows error message in the footer if isAdvanced is false (setup page)", () => {
+ errorHandlingSetup({ isAdvanced: false });
+ // Check error is rendered in the footer
+ expect(
+ within(screen.getByTestId("form-footer")).getByText(errorMessage),
+ ).toBeInTheDocument();
+ });
+
+ it("shows error message outside the footer if isAdvanced is true (admin page)", () => {
+ errorHandlingSetup({ isAdvanced: true });
+ // Check error is rendered
+ expect(screen.getByText(errorMessage)).toBeInTheDocument();
+ // But not in the footer
+ expect(
+ within(screen.getByTestId("form-footer")).queryByText(errorMessage),
+ ).not.toBeInTheDocument();
+ });
+ });
});
const EXPECTED_DEFAULT_SCHEMA = {
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
index e44dce03a4f..b15b4d250c6 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
@@ -102,6 +102,7 @@ export interface SetupOpts {
hasEnterprisePlugins?: boolean;
engines?: Record<string, Engine>;
initialValues?: Partial<DatabaseData> & { engine?: EngineKey };
+ isAdvanced?: boolean;
}
export const setup = ({
@@ -109,6 +110,7 @@ export const setup = ({
hasEnterprisePlugins,
engines = TEST_ENGINES,
initialValues = {},
+ isAdvanced = true,
}: SetupOpts = {}) => {
const state = createMockState({
settings: mockSettings({ ...settings, engines }),
@@ -119,13 +121,14 @@ export const setup = ({
}
const onSubmit = jest.fn();
+
renderWithProviders(
<DatabaseForm
initialValues={{
engine: "h2",
...initialValues,
}}
- config={{ isAdvanced: true }}
+ config={{ isAdvanced }}
onSubmit={onSubmit}
location="admin"
/>,
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/utils.ts b/frontend/src/metabase/databases/components/DatabaseForm/utils.ts
new file mode 100644
index 00000000000..7e357e181a5
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseForm/utils.ts
@@ -0,0 +1,27 @@
+import { getDefaultEngineKey } from "metabase/databases/utils/engine";
+import { useFormErrorMessage } from "metabase/forms";
+import type { DatabaseData, Engine } from "metabase-types/api";
+
+export const useHasConnectionError = () => {
+ const errorMessage = useFormErrorMessage();
+ return !!errorMessage;
+};
+
+export const getEngine = (
+ engines: Record<string, Engine>,
+ engineKey?: string,
+) => {
+ return engineKey ? engines[engineKey] : undefined;
+};
+
+export const getEngineKey = (
+ engines: Record<string, Engine>,
+ values?: Partial<DatabaseData>,
+ isAdvanced?: boolean,
+) => {
+ if (values?.engine && Object.keys(engines).includes(values.engine)) {
+ return values.engine;
+ } else if (isAdvanced) {
+ return getDefaultEngineKey(engines);
+ }
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.tsx
new file mode 100644
index 00000000000..4f8427380fd
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.tsx
@@ -0,0 +1,54 @@
+import { Link } from "react-router";
+import { t } from "ttag";
+
+import CS from "metabase/css/core/index.css";
+import { useSelector } from "metabase/lib/redux";
+import * as Urls from "metabase/lib/urls";
+import { getDocsUrl } from "metabase/selectors/settings";
+import { getUserIsAdmin } from "metabase/selectors/user";
+import { getShowMetabaseLinks } from "metabase/selectors/whitelabel";
+import { Button, Divider, Icon } from "metabase/ui";
+
+import { ContactSupportButtonSection } from "./ContactSupportButtonSection";
+
+export const AdditionalHelpButtonGroup = () => {
+ const showMetabaseLinks = useSelector(getShowMetabaseLinks);
+ const docsUrl = useSelector((state) => getDocsUrl(state, { page: "" }));
+ const isAdmin = useSelector(getUserIsAdmin);
+
+ return (
+ <>
+ {showMetabaseLinks && (
+ <>
+ <Divider variant="dashed" mb="lg" />
+ <Button
+ className={CS.link}
+ component={Link}
+ leftSection={<Icon name="reference" />}
+ target="_blank"
+ to={docsUrl}
+ variant="subtle"
+ >
+ {t`Read the docs`}
+ </Button>
+ </>
+ )}
+ {isAdmin && (
+ <>
+ <Divider variant="dashed" />
+ <Button
+ className={CS.link}
+ component={Link}
+ leftSection={<Icon name="mail" />}
+ to={Urls.newUser()}
+ variant="subtle"
+ >
+ {t`Invite a teammate to help you`}
+ </Button>
+ </>
+ )}
+ <Divider variant="dashed" />
+ <ContactSupportButtonSection />
+ </>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.unit.spec.tsx
new file mode 100644
index 00000000000..b01bcdbf333
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/AdditionalHelpButtonGroup.unit.spec.tsx
@@ -0,0 +1,78 @@
+import { Route } from "react-router";
+
+import { setupEnterprisePlugins } from "__support__/enterprise";
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen } from "__support__/ui";
+import {
+ createMockTokenFeatures,
+ createMockUser,
+} from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
+
+import { AdditionalHelpButtonGroup } from "./AdditionalHelpButtonGroup";
+
+interface SetupParams {
+ showMetabaseLinks?: boolean;
+ whitelabel?: boolean;
+ isAdmin?: boolean;
+}
+
+const setup = (params?: SetupParams) => {
+ const {
+ showMetabaseLinks = true,
+ isAdmin = true,
+ whitelabel = false,
+ } = params || {};
+ const storeInitialState = createMockState({
+ currentUser: createMockUser({ is_superuser: isAdmin }),
+ settings: mockSettings({
+ "show-metabase-links": showMetabaseLinks,
+ "token-features": createMockTokenFeatures({ whitelabel }),
+ }),
+ });
+
+ if (whitelabel) {
+ setupEnterprisePlugins();
+ }
+
+ renderWithProviders(
+ <Route path="*" component={AdditionalHelpButtonGroup} />,
+ {
+ storeInitialState,
+ withRouter: true,
+ },
+ );
+};
+
+describe("AdditionalHelpButtonGroup", () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it("should render expected help links", () => {
+ setup({ isAdmin: true, showMetabaseLinks: true });
+ expect(
+ screen.getByRole("link", { name: /Read the docs/ }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("link", { name: /Invite a teammate to help you/ }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("link", { name: "Contact Support" }),
+ ).toBeInTheDocument();
+ });
+
+ it("hide 'Read the docs' link when showMetabaseLinks is false & whitelabel feature is enabled", () => {
+ setup({ showMetabaseLinks: false, whitelabel: true });
+ expect(
+ screen.queryByRole("link", { name: /Read the docs/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("hide 'Invite a teammate to help you' link when user is not an admin", () => {
+ setup({ isAdmin: false });
+ expect(
+ screen.queryByRole("link", { name: /Invite a teammate to help you/ }),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.tsx
new file mode 100644
index 00000000000..564db5f6c97
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.tsx
@@ -0,0 +1,24 @@
+import { t } from "ttag";
+
+import { Button, Icon } from "metabase/ui";
+
+export const CheckHostAndPortButton = () => {
+ const onCheckHostAndPortClick = () => {
+ // Scroll to the area with errors
+ document
+ .querySelector<HTMLDivElement>("div[data-error]")
+ ?.scrollIntoView({ behavior: "smooth" });
+ };
+
+ return (
+ <Button
+ fw={700}
+ fz="md"
+ leftSection={<Icon name="gear" size={12} />}
+ onClick={onCheckHostAndPortClick}
+ variant="subtle"
+ >
+ {t`Check Host and Port settings`}
+ </Button>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.unit.spec.tsx
new file mode 100644
index 00000000000..c4a204b9f3c
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/CheckHostAndPortButton.unit.spec.tsx
@@ -0,0 +1,43 @@
+import userEvent from "@testing-library/user-event";
+
+import { render, screen, within } from "__support__/ui";
+
+import { CheckHostAndPortButton } from "./CheckHostAndPortButton";
+
+const setup = () => {
+ return render(
+ <div>
+ <div data-error="Check your host settings" data-testid="data-error">
+ <input />
+ </div>
+ <CheckHostAndPortButton />
+ </div>,
+ );
+};
+
+describe("CheckHostAndPortButton", () => {
+ it("should render a 'Check Host and Port settings' button with a gear icon", () => {
+ setup();
+ const button = screen.getByRole("button", {
+ name: /Check Host and Port settings/,
+ });
+ expect(button).toBeInTheDocument();
+ expect(
+ within(button).getByRole("img", { name: "gear icon" }),
+ ).toBeInTheDocument();
+ });
+
+ it("scrolls to element with data-error when clicked", async () => {
+ setup();
+ const { click } = userEvent.setup();
+ const button = screen.getByRole("button", {
+ name: /Check Host and Port settings/,
+ });
+ const targetEl = screen.getByTestId("data-error");
+ jest.spyOn(targetEl, "scrollIntoView");
+ await click(button);
+ expect(targetEl.scrollIntoView).toHaveBeenCalledWith({
+ behavior: "smooth",
+ });
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.tsx
new file mode 100644
index 00000000000..c182db94bee
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.tsx
@@ -0,0 +1,42 @@
+import { Link } from "react-router";
+import { t } from "ttag";
+
+import { useSetting } from "metabase/common/hooks";
+import { useSelector } from "metabase/lib/redux";
+import { getIsPaidPlan } from "metabase/selectors/settings";
+import { Button, Flex } from "metabase/ui";
+
+import { TroubleshootingTip } from "./TroubleshootingTip";
+
+export const ContactSupportButtonSection = () => {
+ const isPaidPlan = useSelector(getIsPaidPlan);
+ const { tag } = useSetting("version");
+
+ const helpUrl = isPaidPlan
+ ? `https://www.metabase.com/help-premium?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=${tag}`
+ : `https://www.metabase.com/help?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=${tag}`;
+
+ return (
+ <TroubleshootingTip
+ body={
+ <Flex direction="column" gap="md" align="flex-start">
+ {/* eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins */}
+ {t`Reach out to Metabase engineers who can help with technical troubleshooting. Not your typical support agents.`}
+ <Button
+ component={Link}
+ radius="md"
+ size="md"
+ target="_blank"
+ to={helpUrl}
+ variant="default"
+ >
+ {t`Contact Support`}
+ </Button>
+ </Flex>
+ }
+ noIcon
+ pb="xl"
+ title={t`Still stuck? We’re here to help`}
+ />
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.unit.spec.tsx
new file mode 100644
index 00000000000..8c583a78f0d
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/ContactSupportButtonSection.unit.spec.tsx
@@ -0,0 +1,81 @@
+import { Route } from "react-router";
+
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen, within } from "__support__/ui";
+import { createMockTokenStatus } from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
+
+import { ContactSupportButtonSection } from "./ContactSupportButtonSection";
+
+interface SetupParams {
+ tag?: string;
+ isPaidPlan?: boolean;
+}
+
+const setup = (params?: SetupParams) => {
+ const storeInitialState = createMockState({
+ settings: mockSettings({
+ version: { tag: params?.tag || "v1.2.3" },
+ "token-status": params?.isPaidPlan
+ ? createMockTokenStatus({ valid: true })
+ : undefined,
+ }),
+ });
+
+ renderWithProviders(
+ <Route path="*" component={ContactSupportButtonSection} />,
+ {
+ storeInitialState,
+ withRouter: true,
+ },
+ );
+};
+
+describe("ContactSupportButtonSection", () => {
+ it("should render a troubleshooting tip with correct title and link", () => {
+ setup();
+ const troubleshootingTip = screen.getByTestId("troubleshooting-tip");
+ expect(troubleshootingTip).toBeInTheDocument();
+ expect(
+ within(troubleshootingTip).getByText("Still stuck? We’re here to help"),
+ ).toBeInTheDocument();
+ expect(
+ within(troubleshootingTip).getByRole("link", { name: "Contact Support" }),
+ ).toBeInTheDocument();
+ });
+
+ describe("Help URL generation", () => {
+ it("should generate free plan help URL when not on paid plan", () => {
+ setup({ isPaidPlan: false });
+ const contactButton = screen.getByRole("link", {
+ name: "Contact Support",
+ });
+ expect(contactButton).toHaveAttribute(
+ "href",
+ "https://www.metabase.com/help?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1.2.3",
+ );
+ });
+
+ it("should generate premium help URL when on paid plan", () => {
+ setup({ isPaidPlan: true });
+ const contactButton = screen.getByRole("link", {
+ name: "Contact Support",
+ });
+ expect(contactButton).toHaveAttribute(
+ "href",
+ "https://www.metabase.com/help-premium?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1.2.3",
+ );
+ });
+
+ it("should handle different version tags in URL", () => {
+ setup({ tag: "v0.50.0-beta" });
+ const contactButton = screen.getByRole("link", {
+ name: "Contact Support",
+ });
+ expect(contactButton).toHaveAttribute(
+ "href",
+ "https://www.metabase.com/help?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v0.50.0-beta",
+ );
+ });
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.module.css b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.module.css
new file mode 100644
index 00000000000..8903de9ae78
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.module.css
@@ -0,0 +1,7 @@
+.paper {
+ border: 1px solid var(--mb-color-border);
+ display: block;
+ margin-bottom: 1rem;
+ margin-top: 1rem;
+ width: 100%;
+}
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.tsx
new file mode 100644
index 00000000000..4671305b46a
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.tsx
@@ -0,0 +1,68 @@
+import { useDisclosure } from "@mantine/hooks";
+import { Fragment, useRef } from "react";
+import { useMount } from "react-use";
+import { t } from "ttag";
+
+import { Alert, Box, Button, Divider, Icon, Paper, Text } from "metabase/ui";
+
+import { AdditionalHelpButtonGroup } from "./AdditionalHelpButtonGroup";
+import { CheckHostAndPortButton } from "./CheckHostAndPortButton";
+import S from "./DatabaseFormError.module.css";
+import { TroubleshootingTip } from "./TroubleshootingTip";
+import { useTroubleshootingTips } from "./useTroubleshootingTips";
+import { useDatabaseErrorDetails } from "./utils";
+
+export const DatabaseFormError = () => {
+ const [showAllTips, { toggle: toggleShowAllTips }] = useDisclosure(false);
+ const { isHostAndPortError, errorMessage } = useDatabaseErrorDetails();
+ const troubleshootingTips = useTroubleshootingTips(
+ isHostAndPortError,
+ showAllTips,
+ );
+ const ref = useRef<HTMLDivElement>(null);
+ const title = isHostAndPortError
+ ? t`Hmm, we couldn't connect to the database`
+ : // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ t`Metabase tried, but couldn't connect`;
+
+ useMount(() => {
+ if (ref.current) {
+ ref.current.scrollIntoView({ behavior: "smooth" });
+ }
+ });
+
+ return (
+ <Paper className={S.paper} ref={ref}>
+ <Box p="md" pb={0}>
+ <Alert color="warning" icon={<Icon name="warning" />} title={title}>
+ <Text>{errorMessage}</Text>
+ </Alert>
+ {troubleshootingTips.map((tipProps, index) => (
+ <Fragment key={tipProps.key}>
+ {!!index && <Divider variant="dashed" />}
+ <TroubleshootingTip {...tipProps} />
+ </Fragment>
+ ))}
+ {showAllTips && <AdditionalHelpButtonGroup />}
+ </Box>
+ {isHostAndPortError && (
+ <>
+ <Divider mt="md" />
+ <CheckHostAndPortButton />
+ </>
+ )}
+ <Divider />
+ <Button
+ fw={700}
+ fz="md"
+ leftSection={
+ <Icon name={showAllTips ? "chevronup" : "chevrondown"} size={12} />
+ }
+ onClick={toggleShowAllTips}
+ variant="subtle"
+ >
+ {showAllTips ? t`Hide` : t`More troubleshooting tips`}
+ </Button>
+ </Paper>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.unit.spec.tsx
new file mode 100644
index 00000000000..10b3ac8048c
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/DatabaseFormError.unit.spec.tsx
@@ -0,0 +1,110 @@
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen, within } from "__support__/ui";
+import { createMockState } from "metabase-types/store/mocks";
+
+import { DatabaseFormError } from "./DatabaseFormError";
+import {
+ type ErrorVariant,
+ TestFormErrorProvider,
+} from "./test-utils/TestFormErrorProvider";
+
+interface SetupOptions {
+ errorVariant?: ErrorVariant;
+ errorMessage?: string;
+}
+
+const setup = (opts?: SetupOptions) => {
+ const { errorVariant, errorMessage } = opts || {};
+ const defaultState = createMockState({
+ settings: mockSettings({
+ "show-metabase-links": true,
+ version: { tag: "v1.0.0" },
+ }),
+ });
+
+ return renderWithProviders(
+ <TestFormErrorProvider
+ errorMessage={errorMessage}
+ errorVariant={errorVariant}
+ >
+ <DatabaseFormError />
+ </TestFormErrorProvider>,
+ {
+ storeInitialState: defaultState,
+ },
+ );
+};
+
+describe("DatabaseFormError", () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe("Generic error", () => {
+ const setupOptions: SetupOptions = {
+ errorMessage: "Generic error message",
+ errorVariant: "generic",
+ };
+
+ it("should render the error alert with generic message", () => {
+ setup(setupOptions);
+ expect(
+ within(screen.getByRole("alert")).getByText(
+ "Metabase tried, but couldn't connect",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ within(screen.getByRole("alert")).getByText("Generic error message"),
+ ).toBeInTheDocument();
+ });
+
+ it("should not render the 'Check Host and Port settings' button", () => {
+ setup(setupOptions);
+ expect(
+ screen.queryByRole("button", { name: /Check Host and Port settings/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("should render the 'More troubleshooting tips' button", () => {
+ setup(setupOptions);
+ expect(
+ screen.getByRole("button", { name: /More troubleshooting tips/ }),
+ ).toBeInTheDocument();
+ });
+ });
+
+ describe("Host and port error", () => {
+ const setupOptions: SetupOptions = {
+ errorMessage: "Random error message",
+ errorVariant: "hostAndPort",
+ };
+
+ it("should render the error alert with specific message", () => {
+ setup(setupOptions);
+ expect(
+ within(screen.getByRole("alert")).getByText(
+ "Hmm, we couldn't connect to the database",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ within(screen.getByRole("alert")).getByText(
+ "Make sure your Host and Port settings are correct.",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("should render the 'Check Host and Port settings' button", () => {
+ setup(setupOptions);
+ expect(
+ screen.getByRole("button", { name: /Check Host and Port settings/ }),
+ ).toBeInTheDocument();
+ });
+
+ it("should render the 'More troubleshooting tips' button", () => {
+ setup(setupOptions);
+ expect(
+ screen.getByRole("button", { name: /More troubleshooting tips/ }),
+ ).toBeInTheDocument();
+ });
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.module.css b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.module.css
new file mode 100644
index 00000000000..105192b0485
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.module.css
@@ -0,0 +1,13 @@
+.container {
+ .title {
+ font-size: var(--mantine-font-size-md);
+ font-weight: 700;
+ line-height: calc(8 / 7);
+ }
+
+ .body {
+ font-size: var(--mantine-font-size-sm);
+ font-weight: 400;
+ line-height: calc(4 / 3);
+ }
+}
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.tsx
new file mode 100644
index 00000000000..67779adbd1c
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.tsx
@@ -0,0 +1,38 @@
+import type { ReactNode } from "react";
+
+import {
+ Box,
+ Flex,
+ type FlexProps,
+ FixedSizeIcon as Icon,
+ Text,
+} from "metabase/ui";
+
+import S from "./TroubleshootingTip.module.css";
+
+export type TipProps = {
+ body: ReactNode;
+ noIcon?: boolean;
+ title: string;
+} & Pick<FlexProps, "pb">;
+
+export const TroubleshootingTip = (props: TipProps) => {
+ const { title, body, noIcon, ...flexProps } = props;
+
+ return (
+ <Flex
+ className={S.container}
+ gap="md"
+ px="md"
+ py="lg"
+ {...flexProps}
+ data-testid="troubleshooting-tip"
+ >
+ {!noIcon && <Icon name="info" mt={2} />}
+ <Flex direction="column" gap="xs">
+ <Text className={S.title}>{title}</Text>
+ <Box className={S.body}>{body}</Box>
+ </Flex>
+ </Flex>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.unit.spec.tsx
new file mode 100644
index 00000000000..623837c9287
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/TroubleshootingTip.unit.spec.tsx
@@ -0,0 +1,69 @@
+import { render, screen } from "__support__/ui";
+
+import { TroubleshootingTip } from "./TroubleshootingTip";
+
+const defaultProps = {
+ title: "Test Title",
+ body: "Test body content",
+};
+
+describe("TroubleshootingTip", () => {
+ describe("Basic rendering", () => {
+ it("should render title and body", () => {
+ render(<TroubleshootingTip {...defaultProps} />);
+
+ expect(screen.getByText("Test Title")).toBeInTheDocument();
+ expect(screen.getByText("Test body content")).toBeInTheDocument();
+ });
+
+ it("should render with icon by default", () => {
+ render(<TroubleshootingTip {...defaultProps} />);
+ expect(
+ screen.getByRole("img", { name: "info icon" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should render without icon when noIcon is true", () => {
+ render(<TroubleshootingTip {...defaultProps} noIcon />);
+ expect(
+ screen.queryByRole("img", { name: "info icon" }),
+ ).not.toBeInTheDocument();
+ });
+ });
+
+ describe("Content handling", () => {
+ it("should render ReactNode as body", () => {
+ const bodyContent = (
+ <div>
+ <span>Complex content</span>
+ <button>Click me</button>
+ </div>
+ );
+
+ render(<TroubleshootingTip title="Complex Title" body={bodyContent} />);
+
+ expect(screen.getByText("Complex Title")).toBeInTheDocument();
+ expect(screen.getByText("Complex content")).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: "Click me" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should handle JSX elements in body", () => {
+ const bodyWithLink = (
+ <>
+ Check out our <a href="/docs">documentation</a> for more info.
+ </>
+ );
+
+ render(<TroubleshootingTip title="With Link" body={bodyWithLink} />);
+
+ expect(screen.getByText("With Link")).toBeInTheDocument();
+ expect(screen.getByText(/Check out our/)).toBeInTheDocument();
+ expect(screen.getByText(/for more info/)).toBeInTheDocument();
+ expect(
+ screen.getByRole("link", { name: "documentation" }),
+ ).toBeInTheDocument();
+ });
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/index.ts b/frontend/src/metabase/databases/components/DatabaseFormError/index.ts
new file mode 100644
index 00000000000..4e67e9ee91f
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/index.ts
@@ -0,0 +1 @@
+export { DatabaseFormError } from "./DatabaseFormError";
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/test-utils/TestFormErrorProvider.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/test-utils/TestFormErrorProvider.tsx
new file mode 100644
index 00000000000..ad318741ca3
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/test-utils/TestFormErrorProvider.tsx
@@ -0,0 +1,46 @@
+import { Formik } from "formik";
+import type { PropsWithChildren } from "react";
+
+import { FormContext, type IFormContext } from "metabase/forms";
+
+export type ErrorVariant = "hostAndPort" | "generic";
+
+export interface FormProvidersOptions {
+ errorVariant?: ErrorVariant;
+ errorMessage?: string;
+}
+
+type Props = PropsWithChildren<FormProvidersOptions>;
+
+/**
+ * Used in tests to mock form errors
+ */
+export const TestFormErrorProvider = (props: Props) => {
+ const { children, errorVariant, errorMessage } = props;
+ const formState: IFormContext = {
+ status: errorVariant ? "rejected" : "idle",
+ setStatus: () => {},
+ message: errorVariant ? errorMessage : undefined,
+ };
+
+ return (
+ <Formik
+ initialValues={{ value: {} }}
+ onSubmit={() => {}}
+ initialErrors={{
+ details: {
+ host:
+ errorVariant === "hostAndPort"
+ ? "Check your host settings"
+ : undefined,
+ port:
+ errorVariant === "hostAndPort"
+ ? "Check your port settings"
+ : undefined,
+ },
+ }}
+ >
+ <FormContext.Provider value={formState}>{children}</FormContext.Provider>
+ </Formik>
+ );
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.tsx
new file mode 100644
index 00000000000..ad2a9bdcfd2
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.tsx
@@ -0,0 +1,125 @@
+import { createSelector } from "@reduxjs/toolkit";
+import { useMemo } from "react";
+import { c, t } from "ttag";
+import { identity } from "underscore";
+
+import { useSelector } from "metabase/lib/redux";
+import { getDocsUrl } from "metabase/selectors/settings";
+import { getShowMetabaseLinks } from "metabase/selectors/whitelabel";
+import { getIsHosted } from "metabase/setup";
+import { Code } from "metabase/ui";
+import type { State } from "metabase-types/store";
+
+import type { TipProps as _TipProps } from "./TroubleshootingTip";
+import { getDocsLinkConditionally, useCloudGatewayIPs } from "./utils";
+
+type TipKey =
+ | "ip-addresses"
+ | "ssl"
+ | "permissions"
+ | "connection-settings"
+ | "credentials";
+type TipProps = _TipProps & { key: TipKey };
+
+export const useTroubleshootingTips = (
+ isHostAndPortError: boolean,
+ expanded: boolean,
+): TipProps[] => {
+ const showMetabaseLinks = useSelector(getShowMetabaseLinks);
+ const isHosted = useSelector(getIsHosted);
+ const getDocPageUrl = useSelector(docPageUrlGetter);
+ const metabaseIPAddresses = useCloudGatewayIPs();
+
+ return useMemo(() => {
+ if (isHostAndPortError && !expanded) {
+ return [];
+ }
+
+ const cloudIPLinkContent = getDocsLinkConditionally(
+ // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ t`Metabase Cloud IP addresses`,
+ getDocPageUrl("cloud/ip-addresses-to-whitelist"),
+ showMetabaseLinks,
+ );
+ const sslCertLinkContent = getDocsLinkConditionally(
+ t`SSL certificate`,
+ getDocPageUrl("databases/ssl-certificates"),
+ showMetabaseLinks,
+ );
+ const permissionsLinkContent = getDocsLinkConditionally(
+ t`correct permissions`,
+ getDocPageUrl("databases/users-roles-privileges"),
+ showMetabaseLinks,
+ );
+
+ return [
+ {
+ key: "ip-addresses" as const,
+ // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ title: t`Try allowing Metabase IP addresses`,
+ body: (
+ <>
+ {
+ // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ c("{0} refers to 'Metabase Cloud IP addresses'")
+ .jt`If the database is behind a firewall or VPN, you may need to allow connections from the ${cloudIPLinkContent}.`
+ }
+ <Code display="block" p="0.75rem" mt="sm" component="ul" lh="1rem">
+ {metabaseIPAddresses.map((ip) => (
+ <li key={ip}>{ip}</li>
+ ))}
+ </Code>
+ </>
+ ),
+ },
+ {
+ key: "ssl" as const,
+ title: t`Try using a secure connection (SSL)`,
+ body: c("{0} refers to 'SSL certificate'")
+ .jt`You’ll need an ${sslCertLinkContent} to do this.`,
+ },
+ {
+ key: "permissions" as const,
+ // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ title: t`Check Metabase user permissions`,
+ body: (() => {
+ // unchained `c` -> `jt` call to avoid prettier moving no-literal-metabase-strings comment up
+ const ctx = c("{0} refers to 'correct permissions'");
+ // eslint-disable-next-line no-literal-metabase-strings -- Only visible to admins
+ return ctx.jt`Check that Metabase has the ${permissionsLinkContent} or user role for your database.`;
+ })(),
+ },
+ {
+ key: "connection-settings" as const,
+ title: t`Double-check connection settings`,
+ body: t`Make sure the host name, port or database name don’t contain typos.`,
+ },
+ {
+ key: "credentials" as const,
+ title: t`Double-check access credentials`,
+ body: t`Is the username and password correct? If possible, copy-paste the values to the form.`,
+ },
+ ].filter((tip) => {
+ if (tip.key === "ip-addresses" && !isHosted) {
+ // Only show this tip if the user is using Metabase Cloud
+ return false;
+ }
+
+ const initialTips: TipKey[] = isHosted
+ ? ["ip-addresses", "ssl"]
+ : ["ssl", "permissions"];
+ return expanded || initialTips.includes(tip.key);
+ });
+ }, [
+ expanded,
+ getDocPageUrl,
+ isHostAndPortError,
+ isHosted,
+ metabaseIPAddresses,
+ showMetabaseLinks,
+ ]);
+};
+
+const docPageUrlGetter = createSelector([identity], (state: State) => {
+ return (page: string): string => getDocsUrl(state, { page });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.unit.spec.tsx
new file mode 100644
index 00000000000..9db2a1d4b53
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/useTroubleshootingTips.unit.spec.tsx
@@ -0,0 +1,130 @@
+import { Fragment } from "react";
+import { Route } from "react-router";
+
+import { setupEnterprisePlugins } from "__support__/enterprise";
+import { mockSettings } from "__support__/settings";
+import {
+ renderHookWithProviders,
+ renderWithProviders,
+ screen,
+} from "__support__/ui";
+import type { TokenFeatures } from "metabase-types/api";
+import { createMockTokenFeatures } from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
+
+import { useTroubleshootingTips } from "./useTroubleshootingTips";
+
+interface SetupOptions {
+ isHostAndPortError: boolean;
+ expanded: boolean;
+ isHosted?: boolean;
+ showMetabaseLinks?: boolean;
+ tokenFeatures?: Partial<TokenFeatures>;
+}
+
+const setup = (opts: SetupOptions) => {
+ const {
+ expanded,
+ isHostAndPortError,
+ isHosted = true,
+ showMetabaseLinks,
+ tokenFeatures = {},
+ } = opts;
+ return renderHookWithProviders(
+ () => useTroubleshootingTips(isHostAndPortError, expanded),
+ {
+ withRouter: true,
+ storeInitialState: createMockState({
+ settings: mockSettings({
+ "show-metabase-links": showMetabaseLinks,
+ "token-features": createMockTokenFeatures(tokenFeatures),
+ "is-hosted?": isHosted,
+ }),
+ }),
+ },
+ );
+};
+
+describe("useTroubleshootingTips", () => {
+ describe("returns correct tips when", () => {
+ it.each`
+ isHostAndPortError | expanded | isHosted | tipsReturned
+ ${false} | ${false} | ${true} | ${["ip-addresses", "ssl"]}
+ ${false} | ${false} | ${false} | ${["ssl", "permissions"]}
+ ${false} | ${true} | ${true} | ${["ip-addresses", "ssl", "permissions", "connection-settings", "credentials"]}
+ ${false} | ${true} | ${false} | ${["ssl", "permissions", "connection-settings", "credentials"]}
+ ${true} | ${false} | ${true} | ${[]}
+ ${true} | ${true} | ${true} | ${["ip-addresses", "ssl", "permissions", "connection-settings", "credentials"]}
+ ${true} | ${true} | ${false} | ${["ssl", "permissions", "connection-settings", "credentials"]}
+ `(
+ `isHostAndPortError is $isHostAndPortError & expanded is $expanded & isHosted is $isHosted`,
+ ({ isHostAndPortError, expanded, isHosted, tipsReturned }) => {
+ const { result } = setup({
+ isHostAndPortError,
+ expanded,
+ isHosted,
+ });
+ expect(result.current.map((tip) => tip.key)).toEqual(tipsReturned);
+ },
+ );
+ });
+
+ describe("showMetabaseLinks handling", () => {
+ const linksSetup = (showMetabaseLinks: boolean) => {
+ const storeInitialState = createMockState({
+ settings: mockSettings({
+ "show-metabase-links": showMetabaseLinks,
+ "token-features": createMockTokenFeatures({ whitelabel: true }),
+ "is-hosted?": true,
+ }),
+ });
+
+ setupEnterprisePlugins();
+
+ // This time we render inside a Route component to more easily assert links presence
+ renderWithProviders(
+ <Route
+ path="*"
+ component={() => {
+ const tips = useTroubleshootingTips(false, true);
+
+ return (
+ <>
+ {tips.map(({ body, key }) => (
+ <Fragment key={key}>{body}</Fragment>
+ ))}
+ </>
+ );
+ }}
+ />,
+ {
+ withRouter: true,
+ storeInitialState,
+ },
+ );
+ };
+ const expectedLinks = [
+ /Metabase Cloud IP addresses/,
+ /SSL certificate/,
+ /correct permissions/,
+ ];
+
+ it("should render external doc links when showMetabaseLinks is true", () => {
+ linksSetup(true);
+
+ for (const name of expectedLinks) {
+ const linkEl = screen.getByRole("link", { name });
+ expect(linkEl).toBeInTheDocument();
+ expect(linkEl).toHaveAttribute("target", "_blank");
+ }
+ });
+
+ it("should not render links when showMetabaseLinks is false", () => {
+ linksSetup(false);
+
+ for (const name of expectedLinks) {
+ expect(screen.queryByRole("link", { name })).not.toBeInTheDocument();
+ }
+ });
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/utils.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/utils.tsx
new file mode 100644
index 00000000000..1bd78945a1a
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/utils.tsx
@@ -0,0 +1,65 @@
+import { useFormikContext } from "formik";
+import type { ReactNode } from "react";
+import { Link } from "react-router";
+import { t } from "ttag";
+
+import { useSetting } from "metabase/common/hooks";
+import CS from "metabase/css/core/index.css";
+import { useFormErrorMessage } from "metabase/forms";
+import { Box } from "metabase/ui";
+import type { DatabaseData } from "metabase-types/api";
+
+const defaultCloudGatewayIPs = [
+ "18.207.81.126",
+ "3.211.20.157",
+ "50.17.234.169",
+];
+
+export const useCloudGatewayIPs = () => {
+ const ipAddresses = useSetting("cloud-gateway-ips");
+ return ipAddresses || defaultCloudGatewayIPs;
+};
+
+/**
+ * Renders a link to the specified docsUrl if showMetabaseLinks is true. Otherwise, returns the title raw string.
+ */
+export const getDocsLinkConditionally = (
+ title: string,
+ docsUrl: string,
+ showMetabaseLinks: boolean,
+): ReactNode => {
+ let linkContent: ReactNode = title;
+
+ if (showMetabaseLinks) {
+ linkContent = (
+ <Box
+ className={CS.link}
+ component={Link}
+ fw={600}
+ key={docsUrl}
+ target="_blank"
+ to={docsUrl}
+ >
+ {linkContent}
+ </Box>
+ );
+ }
+
+ return linkContent;
+};
+
+export const useDatabaseErrorDetails = () => {
+ const { errors } = useFormikContext<DatabaseData>();
+ const originalErrorMessage = useFormErrorMessage();
+ const isHostAndPortError =
+ typeof errors?.details === "object" &&
+ !!(errors?.details?.["host"] || errors?.details?.["port"]);
+ const errorMessage = isHostAndPortError
+ ? t`Make sure your Host and Port settings are correct.`
+ : originalErrorMessage;
+
+ return {
+ errorMessage,
+ isHostAndPortError,
+ };
+};
diff --git a/frontend/src/metabase/databases/components/DatabaseFormError/utils.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseFormError/utils.unit.spec.tsx
new file mode 100644
index 00000000000..878ccc409d7
--- /dev/null
+++ b/frontend/src/metabase/databases/components/DatabaseFormError/utils.unit.spec.tsx
@@ -0,0 +1,133 @@
+import { renderHook } from "@testing-library/react";
+import type { PropsWithChildren } from "react";
+import { Route } from "react-router";
+
+import { mockSettings } from "__support__/settings";
+import {
+ renderHookWithProviders,
+ renderWithProviders,
+ screen,
+} from "__support__/ui";
+import { createMockState } from "metabase-types/store/mocks";
+
+import {
+ type FormProvidersOptions,
+ TestFormErrorProvider,
+} from "./test-utils/TestFormErrorProvider";
+import {
+ getDocsLinkConditionally,
+ useCloudGatewayIPs,
+ useDatabaseErrorDetails,
+} from "./utils";
+
+describe("getDocsLinkConditionally", () => {
+ const setup = (showMetabaseLinks: boolean) => {
+ return renderWithProviders(
+ <Route
+ path="*"
+ component={() => (
+ <>
+ {getDocsLinkConditionally(
+ "My Link Title",
+ "https://metabase.com/docs",
+ showMetabaseLinks,
+ )}
+ </>
+ )}
+ />,
+ {
+ withRouter: true,
+ initialRoute: "/",
+ },
+ );
+ };
+
+ it("does not render a link if showMetabaseLinks is false", () => {
+ setup(false);
+ expect(screen.queryByRole("link")).not.toBeInTheDocument();
+ expect(screen.getByText("My Link Title")).toBeInTheDocument();
+ });
+
+ it("renders a link if showMetabaseLinks is true", () => {
+ setup(true);
+ expect(
+ screen.getByRole("link", { name: "My Link Title" }),
+ ).toBeInTheDocument();
+ expect(screen.getByRole("link", { name: "My Link Title" })).toHaveAttribute(
+ "href",
+ "https://metabase.com/docs",
+ );
+ expect(screen.getByRole("link", { name: "My Link Title" })).toHaveAttribute(
+ "target",
+ "_blank",
+ );
+ });
+});
+
+describe("useCloudGatewayIPs", () => {
+ const setup = (cloudGatewayIPs: string[] | null) => {
+ return renderHookWithProviders(useCloudGatewayIPs, {
+ storeInitialState: createMockState({
+ settings: mockSettings({
+ "cloud-gateway-ips": cloudGatewayIPs,
+ }),
+ }),
+ });
+ };
+
+ it("returns the cloud gateway IPs from settings", () => {
+ const { result } = setup(["1.1.1.1", "2.2.2.2"]);
+ expect(result.current).toEqual(["1.1.1.1", "2.2.2.2"]);
+ });
+
+ it("returns the default IP list if none is defined in settings", () => {
+ const { result } = setup(null);
+ expect(result.current).toEqual([
+ "18.207.81.126",
+ "3.211.20.157",
+ "50.17.234.169",
+ ]);
+ });
+});
+
+describe("useDatabaseErrorDetails", () => {
+ const setup = (opts: FormProvidersOptions) => {
+ const { errorVariant, errorMessage } = opts;
+ const FormProviderWrapper = ({ children }: PropsWithChildren) => (
+ <TestFormErrorProvider
+ errorVariant={errorVariant}
+ errorMessage={errorMessage}
+ >
+ {children}
+ </TestFormErrorProvider>
+ );
+
+ return renderHook(() => useDatabaseErrorDetails(), {
+ wrapper: FormProviderWrapper,
+ initialProps: {
+ errorVariant,
+ errorMessage,
+ },
+ });
+ };
+
+ it("should return the correct error message when error variant is 'hostAndPort'", () => {
+ const { result } = setup({
+ errorVariant: "hostAndPort",
+ errorMessage: "Random error message",
+ });
+ expect(result.current.errorMessage).toBe(
+ "Make sure your Host and Port settings are correct.",
+ );
+ expect(result.current.isHostAndPortError).toBe(true);
+ });
+
+ it("should return the correct error message when error variant is 'generic'", () => {
+ const { result } = setup({
+ errorVariant: "generic",
+ errorMessage: "Generic error message",
+ });
+ expect(result.current.errorMessage).toBe("Generic error message");
+ expect(result.current.isHostAndPortError).toBe(false);
+ });
+});
diff --git a/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx b/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx
index 4cb4a14cfe5..605c5b88359 100644
--- a/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseNameField/DatabaseNameField.tsx
@@ -1,12 +1,11 @@
import { t } from "ttag";
+import type { DatabaseFormConfig } from "metabase/databases/types";
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";
-
export interface DatabaseNameFieldProps {
engine: Engine;
config: DatabaseFormConfig;
diff --git a/frontend/src/metabase/databases/types.ts b/frontend/src/metabase/databases/types.ts
index 5ba0af1f58e..2149eea87ad 100644
--- a/frontend/src/metabase/databases/types.ts
+++ b/frontend/src/metabase/databases/types.ts
@@ -1,4 +1,4 @@
-import type { ComponentType, ReactNode } from "react";
+import type { ComponentType, JSX, ReactNode } from "react";
import type { EngineFieldOption, EngineFieldType } from "metabase-types/api";
@@ -25,3 +25,22 @@ export interface EngineFieldProps {
}
export type FormLocation = "admin" | "setup" | "embedding_setup" | "full-page";
+
+export type EngineFieldState = "default" | "hidden" | "disabled";
+
+export interface DatabaseFormConfig {
+ /** present the form with advanced configuration options */
+ isAdvanced?: boolean;
+ engine?: {
+ /** present the engine field as normal, disabled, or hidden */
+ fieldState?: EngineFieldState | undefined;
+ };
+ name?: {
+ /** present the name field as a slug */
+ isSlug?: boolean;
+ };
+}
+
+export type ContinueWithoutDataComponent = (props: {
+ onCancel?: () => void;
+}) => JSX.Element;
diff --git a/frontend/src/metabase/forms/components/FormSubmitButton/FormSubmitButton.tsx b/frontend/src/metabase/forms/components/FormSubmitButton/FormSubmitButton.tsx
index 5d6de52c4ac..e9915b571a2 100644
--- a/frontend/src/metabase/forms/components/FormSubmitButton/FormSubmitButton.tsx
+++ b/frontend/src/metabase/forms/components/FormSubmitButton/FormSubmitButton.tsx
@@ -46,6 +46,7 @@ export const FormSubmitButton = forwardRef(function FormSubmitButton(
type="submit"
color={submitColor}
disabled={isDisabled}
+ loading={status === "pending"}
>
{submitLabel}
</Button>
diff --git a/frontend/src/metabase/ui/components/feedback/Alert/Alert.config.tsx b/frontend/src/metabase/ui/components/feedback/Alert/Alert.config.tsx
index 9b17c6ee9ec..9c4ed686414 100644
--- a/frontend/src/metabase/ui/components/feedback/Alert/Alert.config.tsx
+++ b/frontend/src/metabase/ui/components/feedback/Alert/Alert.config.tsx
@@ -10,6 +10,7 @@ export const alertOverrides: MantineThemeOverride["components"] = {
classNames: {
root: AlertStyles.root,
wrapper: AlertStyles.wrapper,
+ title: AlertStyles.title,
},
}),
};
diff --git a/frontend/src/metabase/ui/components/feedback/Alert/Alert.mdx b/frontend/src/metabase/ui/components/feedback/Alert/Alert.mdx
index 61321c6de0e..e55e9ce38e9 100644
--- a/frontend/src/metabase/ui/components/feedback/Alert/Alert.mdx
+++ b/frontend/src/metabase/ui/components/feedback/Alert/Alert.mdx
@@ -12,3 +12,5 @@ Show helpful alerts when things go sideways (or maybe it's a happy alert. It hap
## Examples
<Canvas of={AlertStories.Default} />
+
+<Canvas of={AlertStories.Warning} />
diff --git a/frontend/src/metabase/ui/components/feedback/Alert/Alert.module.css b/frontend/src/metabase/ui/components/feedback/Alert/Alert.module.css
index f36abcb10e1..81df18ba951 100644
--- a/frontend/src/metabase/ui/components/feedback/Alert/Alert.module.css
+++ b/frontend/src/metabase/ui/components/feedback/Alert/Alert.module.css
@@ -5,3 +5,8 @@
.root {
background-color: color-mix(in srgb, var(--alert-color), white 90%);
}
+
+.title {
+ color: var(--mb-color-text-dark);
+ line-height: 1rem;
+}
diff --git a/frontend/src/metabase/ui/components/feedback/Alert/Alert.stories.tsx b/frontend/src/metabase/ui/components/feedback/Alert/Alert.stories.tsx
index 58570f15feb..84a4cc76689 100644
--- a/frontend/src/metabase/ui/components/feedback/Alert/Alert.stories.tsx
+++ b/frontend/src/metabase/ui/components/feedback/Alert/Alert.stories.tsx
@@ -34,6 +34,19 @@ const DefaultTemplate = (args: AlertProps) => {
);
};
+const WarningColorTemplate = (args: AlertProps) => {
+ return (
+ <Alert {...args} color="warning">
+ <Text>
+ In a future release, if a group’s View data access for a database (or
+ any of its schemas or tables) is still set to No self-service
+ (deprecated), Metabase will automatically change that group’s View data
+ access for the entire database to Blocked.
+ </Text>
+ </Alert>
+ );
+};
+
export default {
title: "Components/Feedback/Alert",
component: Alert,
@@ -44,3 +57,7 @@ export default {
export const Default = {
render: DefaultTemplate,
};
+
+export const Warning = {
+ render: WarningColorTemplate,
+};