Skip to content

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

Use database select in workspace database form (#74791)

Alexander Polyankina734e25ebc9c
diff --git a/e2e/support/helpers/e2e-workspace-helpers.ts b/e2e/support/helpers/e2e-workspace-helpers.ts
index 64f77d18908..3fb819e530c 100644
--- a/e2e/support/helpers/e2e-workspace-helpers.ts
+++ b/e2e/support/helpers/e2e-workspace-helpers.ts
@@ -91,8 +91,8 @@ export const WorkspaceDatabaseSection = {
export const NewWorkspaceDatabaseModal = {
get: () => modal(),
- databaseRadio: (name: string) =>
- NewWorkspaceDatabaseModal.get().findByRole("radio", { name }),
+ databaseSelect: () =>
+ NewWorkspaceDatabaseModal.get().findByRole("textbox", { name: "Database" }),
schemasGroup: () =>
NewWorkspaceDatabaseModal.get().findByText("Schemas to include"),
schemaCheckbox: (name: string) =>
diff --git a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/DatabaseSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/DatabaseSection.unit.spec.tsx
index e6e4ab346dc..4913172799a 100644
--- a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/DatabaseSection.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/DatabaseSection.unit.spec.tsx
@@ -48,16 +48,19 @@ function setup({
}
describe("DatabaseSection", () => {
- it("can open the add modal and shows both databases as radio options", async () => {
+ it("can open the add modal and shows both databases as select options", async () => {
setup();
await userEvent.click(screen.getByRole("button", { name: /Add database/ }));
+ await userEvent.click(
+ await screen.findByRole("textbox", { name: "Database" }),
+ );
expect(
- await screen.findByRole("radio", { name: "Postgres" }),
+ await screen.findByRole("option", { name: "Postgres" }),
).toBeInTheDocument();
expect(
- screen.getByRole("radio", { name: "Snowflake" }),
+ screen.getByRole("option", { name: "Snowflake" }),
).toBeInTheDocument();
});
diff --git a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.tsx b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.tsx
index e21936d6b02..643ca5dc3bd 100644
--- a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.tsx
@@ -11,15 +11,13 @@ import {
} from "metabase/forms";
import {
Button,
- FixedSizeIcon,
FocusTrap,
Group,
Input,
Modal,
- Radio,
+ Select,
Stack,
Text,
- Tooltip,
} from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import { useCreateWorkspaceDatabaseMutation } from "metabase-enterprise/api";
@@ -143,7 +141,7 @@ function NewDatabaseForm({
<Text>
{t`This will create a temporary schema and user in this database, grant that user read access to the schemas you select, and write access to the temporary schema.`}
</Text>
- <DatabaseInput
+ <DatabaseSelect
databases={availableDatabases}
value={values.database_id}
onChange={(databaseId) => {
@@ -173,13 +171,13 @@ function NewDatabaseForm({
);
}
-type DatabaseInputProps = {
+type DatabaseSelectProps = {
databases: Database[];
value: DatabaseId | null;
onChange: (databaseId: DatabaseId | null) => void;
};
-function DatabaseInput({ databases, value, onChange }: DatabaseInputProps) {
+function DatabaseSelect({ databases, value, onChange }: DatabaseSelectProps) {
if (databases.length === 1) {
return (
<Input.Wrapper label={t`Database`}>
@@ -188,42 +186,20 @@ function DatabaseInput({ databases, value, onChange }: DatabaseInputProps) {
);
}
+ const data = databases.map((database) => ({
+ value: String(database.id),
+ label: database.name,
+ disabled: !supportsWorkspaces(database),
+ }));
+
return (
- <Radio.Group
+ <Select
label={t`Database`}
+ data={data}
value={value != null ? String(value) : null}
onChange={(newValue) =>
onChange(newValue != null ? Number(newValue) : null)
}
- >
- <Stack gap="sm">
- {databases.map((database) => (
- <Radio
- key={database.id}
- value={String(database.id)}
- label={<DatabaseLabel database={database} />}
- disabled={!supportsWorkspaces(database)}
- />
- ))}
- </Stack>
- </Radio.Group>
- );
-}
-
-type DatabaseLabelProps = {
- database: Database;
-};
-
-function DatabaseLabel({ database }: DatabaseLabelProps) {
- if (supportsWorkspaces(database)) {
- return <>{database.name}</>;
- }
- return (
- <Group gap="xs" wrap="nowrap" component="span">
- <span>{database.name}</span>
- <Tooltip label={t`This database does not support workspaces.`}>
- <FixedSizeIcon name="info" c="text-secondary" aria-hidden />
- </Tooltip>
- </Group>
+ />
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.unit.spec.tsx
index 947101807fe..db05bec860c 100644
--- a/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/workspaces/pages/WorkspacePage/DatabaseSection/NewDatabaseModal/NewDatabaseModal.unit.spec.tsx
@@ -89,18 +89,24 @@ describe("NewDatabaseModal", () => {
);
});
- it("renders a single database as text without a radio group", () => {
+ it("renders a single database as text without a select", () => {
setup({ availableDatabases: [POSTGRES_DATABASE] });
expect(screen.getByText("Postgres")).toBeInTheDocument();
- expect(screen.queryByRole("radio")).not.toBeInTheDocument();
+ expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
});
- it("disables radios for databases that do not support workspaces", () => {
+ it("disables options for databases that do not support workspaces", async () => {
setup({ availableDatabases: [POSTGRES_DATABASE, UNSUPPORTED_DATABASE] });
- expect(screen.getByRole("radio", { name: "Postgres" })).toBeEnabled();
- expect(screen.getByRole("radio", { name: /Unsupported/ })).toBeDisabled();
+ await userEvent.click(screen.getByRole("textbox", { name: "Database" }));
+
+ expect(
+ screen.getByRole("option", { name: "Postgres" }),
+ ).not.toHaveAttribute("data-combobox-disabled");
+ expect(screen.getByRole("option", { name: "Unsupported" })).toHaveAttribute(
+ "data-combobox-disabled",
+ );
});
it("requires at least one schema when the database supports schemas", async () => {