Skip to content

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

Keep engines and the timezone list out of the bulk settings payloads (#80138)

Romeo Van Snick41661db78743
diff --git a/e2e/test/scenarios/actions/model-actions.cy.spec.js b/e2e/test/scenarios/actions/model-actions.cy.spec.js
index 5543c50d37c..5544dc7896b 100644
--- a/e2e/test/scenarios/actions/model-actions.cy.spec.js
+++ b/e2e/test/scenarios/actions/model-actions.cy.spec.js
@@ -285,6 +285,9 @@ describe(
beforeEach(() => {
cy.intercept("GET", "/api/card/*").as("getModel");
+ cy.intercept("GET", "/api/card/*/query_metadata").as(
+ "getModelQueryMetadata",
+ );
cy.intercept("GET", "/api/action/*").as("getAction");
cy.intercept("PUT", "/api/action/*").as("updateAction");
@@ -318,6 +321,10 @@ describe(
cy.wait("@getModel");
});
+ // The Actions menu renders only once the source table's metadata has
+ // arrived, because it is gated on `supportsImplicitActions()`.
+ cy.wait("@getModelQueryMetadata");
+
cy.findByTestId("model-actions-header")
.findByLabelText("Actions")
.click();
diff --git a/enterprise/frontend/src/embedding-sdk-package/cli/steps/add-database-connection.ts b/enterprise/frontend/src/embedding-sdk-package/cli/steps/add-database-connection.ts
index 2aca7a575f6..d90bfb77cb9 100644
--- a/enterprise/frontend/src/embedding-sdk-package/cli/steps/add-database-connection.ts
+++ b/enterprise/frontend/src/embedding-sdk-package/cli/steps/add-database-connection.ts
@@ -2,20 +2,21 @@ import { search } from "@inquirer/prompts";
import ora from "ora";
import type { CliStepMethod } from "embedding-sdk-package/cli/types/cli";
-import type { Settings } from "metabase-types/api/settings";
+import type { Engine } from "metabase-types/api";
import { isEngineKey } from "metabase-types/guards";
import { CLI_SHOWN_DB_ENGINES, SAMPLE_DB_ID } from "../constants/database";
import { addDatabaseConnection } from "../utils/add-database-connection";
import { askForDatabaseConnectionInfo } from "../utils/ask-for-db-connection-info";
-import { fetchInstanceSettings } from "../utils/fetch-instance-settings";
+import { fetchEngines } from "../utils/fetch-engines";
export const addDatabaseConnectionStep: CliStepMethod = async (state) => {
- const settings = await fetchInstanceSettings({
+ const engines = await fetchEngines({
instanceUrl: state.instanceUrl ?? "",
+ cookie: state.cookie ?? "",
});
- if (!settings || !settings.engines) {
+ if (!engines) {
return [{ type: "error", message: "Aborted." }, state];
}
@@ -23,7 +24,7 @@ export const addDatabaseConnectionStep: CliStepMethod = async (state) => {
return [{ type: "success" }, { ...state, databaseId: SAMPLE_DB_ID }];
}
- const engineChoices = getEngineChoices(settings);
+ const engineChoices = getEngineChoices(engines);
while (true) {
const engineKey = await search({
@@ -42,7 +43,7 @@ export const addDatabaseConnectionStep: CliStepMethod = async (state) => {
return [{ type: "error", message: "Invalid engine key." }, state];
}
- const engine = settings.engines[engineKey];
+ const engine = engines[engineKey];
const engineName = engine["driver-name"];
const spinner = ora("Adding database connection…");
@@ -66,7 +67,7 @@ export const addDatabaseConnectionStep: CliStepMethod = async (state) => {
spinner.succeed();
- return [{ type: "done" }, { ...state, settings, databaseId }];
+ return [{ type: "done" }, { ...state, databaseId }];
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
@@ -75,7 +76,7 @@ export const addDatabaseConnectionStep: CliStepMethod = async (state) => {
}
};
-const getEngineChoices = (settings: Settings) =>
- Object.entries(settings.engines)
+const getEngineChoices = (engines: Record<string, Engine>) =>
+ Object.entries(engines)
.map(([key, engine]) => ({ name: engine["driver-name"], value: key }))
.filter((engine) => CLI_SHOWN_DB_ENGINES.includes(engine.value));
diff --git a/enterprise/frontend/src/embedding-sdk-package/cli/types/cli.ts b/enterprise/frontend/src/embedding-sdk-package/cli/types/cli.ts
index 3e8143882d6..df97637f4e5 100644
--- a/enterprise/frontend/src/embedding-sdk-package/cli/types/cli.ts
+++ b/enterprise/frontend/src/embedding-sdk-package/cli/types/cli.ts
@@ -1,5 +1,5 @@
import type { CLI_STEPS } from "embedding-sdk-package/cli/run";
-import type { Settings, Table } from "metabase-types/api";
+import type { Table } from "metabase-types/api";
import type { DashboardInfo } from "./dashboard";
@@ -16,9 +16,6 @@ export type CliState = Partial<{
/** User does not have a database, so the sample database is used instead. */
useSampleDatabase: boolean;
- /** Metabase instance settings */
- settings: Settings;
-
/** Database tables present in the instance */
tables: Table[];
diff --git a/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-engines.ts b/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-engines.ts
new file mode 100644
index 00000000000..5d580ff210f
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-engines.ts
@@ -0,0 +1,23 @@
+import type { Engine } from "metabase-types/api";
+
+interface Options {
+ instanceUrl: string;
+ cookie: string;
+}
+
+export async function fetchEngines(
+ options: Options,
+): Promise<Record<string, Engine> | null> {
+ const { instanceUrl, cookie } = options;
+
+ const res = await fetch(`${instanceUrl}/api/setting/engines`, {
+ method: "GET",
+ headers: { "content-type": "application/json", cookie },
+ });
+
+ if (!res.ok) {
+ return null;
+ }
+
+ return res.json();
+}
diff --git a/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-instance-settings.ts b/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-instance-settings.ts
deleted file mode 100644
index 8d1b6465ec3..00000000000
--- a/enterprise/frontend/src/embedding-sdk-package/cli/utils/fetch-instance-settings.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import type { Settings } from "metabase-types/api";
-
-interface Options {
- instanceUrl: string;
-}
-
-export async function fetchInstanceSettings(
- options: Options,
-): Promise<Settings | null> {
- const { instanceUrl } = options;
-
- const res = await fetch(`${instanceUrl}/api/session/properties`, {
- method: "GET",
- headers: { "content-type": "application/json" },
- });
-
- if (!res.ok) {
- return null;
- }
-
- return res.json();
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.tsx b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.tsx
index 3eb08bba51e..a9381ae1fbb 100644
--- a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.tsx
@@ -11,6 +11,7 @@ import {
} from "metabase/admin/databases/components/DatabaseInfoSection";
import {
skipToken,
+ useListEnginesQuery,
useListTransformsQuery,
useListUserAttributesQuery,
} from "metabase/api";
@@ -20,7 +21,6 @@ import { useToast } from "metabase/common/hooks/use-toast";
import { hasDbRoutingEnabled } from "metabase/common/utils/database";
import { getUserIsAdmin } from "metabase/current-user";
import { useSelector } from "metabase/redux";
-import { useSetting } from "metabase/settings";
import {
Alert,
Box,
@@ -51,7 +51,7 @@ export const DatabaseRoutingSection = ({
}) => {
const [sendToast] = useToast();
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const isAdmin = useSelector(getUserIsAdmin);
const userAttribute = database.router_user_attribute ?? undefined;
diff --git a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.unit.spec.tsx
index bb3f9dc9ec5..11f0627cf07 100644
--- a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/DatabaseRoutingSection.unit.spec.tsx
@@ -1,5 +1,6 @@
import {
setupDatabasesEndpoints,
+ setupEnginesEndpoint,
setupListTransformsEndpoint,
setupUserAttributesEndpoint,
} from "__support__/server-mocks";
@@ -28,24 +29,23 @@ const setup = ({
setupUserAttributesEndpoint(["cool_guy", "boss_gal"]);
setupDatabasesEndpoints([database]);
setupListTransformsEndpoint([]);
+ setupEnginesEndpoint(
+ createMockEngines({
+ "bigquery-cloud-sdk": createMockEngine({
+ "driver-name": "Big Query",
+ "extra-info": {
+ "db-routing-info": {
+ text: "custom db routing info.",
+ },
+ },
+ }),
+ }),
+ );
renderWithProviders(<DatabaseRoutingSection database={database} />, {
storeInitialState: {
currentUser: createMockUser({ is_superuser: isAdmin }),
- settings: createMockSettingsState(
- createMockSettings({
- engines: createMockEngines({
- "bigquery-cloud-sdk": createMockEngine({
- "driver-name": "Big Query",
- "extra-info": {
- "db-routing-info": {
- text: "custom db routing info.",
- },
- },
- }),
- }),
- }),
- ),
+ settings: createMockSettingsState(createMockSettings()),
},
});
};
@@ -69,7 +69,7 @@ describe("DatabaseRoutingSection", () => {
expect(screen.getByLabelText("Enable database routing")).toBeEnabled();
});
- it("should render DatabaseRoutingSection with custom db_routing_info", () => {
+ it("should render DatabaseRoutingSection with custom db_routing_info", async () => {
setup({
database: createMockDatabase({
engine: "bigquery-cloud-sdk",
@@ -78,7 +78,9 @@ describe("DatabaseRoutingSection", () => {
});
expect(screen.getByText("Database routing")).toBeInTheDocument();
- expect(screen.getByText("custom db routing info.")).toBeInTheDocument();
+ expect(
+ await screen.findByText("custom db routing info."),
+ ).toBeInTheDocument();
expect(screen.getByText("Enable database routing")).toBeInTheDocument();
expect(screen.getByLabelText("Enable database routing")).toBeEnabled();
});
diff --git a/frontend/src/metabase-types/api/mocks/metabot.ts b/frontend/src/metabase-types/api/mocks/metabot.ts
index a435297da20..23a25f7533a 100644
--- a/frontend/src/metabase-types/api/mocks/metabot.ts
+++ b/frontend/src/metabase-types/api/mocks/metabot.ts
@@ -105,7 +105,6 @@ export const MCP_APPS_BOOTSTRAP_SETTING_KEYS = [
"application-name",
"available-fonts",
"available-locales",
- "available-timezones",
"bug-reporting-enabled",
"cloud-gateway-ips",
"csp-img-allowed-hosts",
diff --git a/frontend/src/metabase-types/api/mocks/settings.ts b/frontend/src/metabase-types/api/mocks/settings.ts
index 48cff5ea911..f7680be12ce 100644
--- a/frontend/src/metabase-types/api/mocks/settings.ts
+++ b/frontend/src/metabase-types/api/mocks/settings.ts
@@ -200,13 +200,6 @@ export const createMockSettings = (
["zh_HK", "Chinese (Hong Kong SAR China)"],
["zh_TW", "Chinese (Taiwan)"],
],
- "available-timezones": [
- // this is a subset of the timezones we have in the real app
- "Europe/Paris",
- "Pacific/Auckland",
- "US/Mountain",
- "UTC",
- ],
"bug-reporting-enabled": false,
"bcc-enabled?": true,
"smtp-override-enabled": false,
@@ -272,7 +265,6 @@ export const createMockSettings = (
"enable-password-login": true,
"enable-public-sharing": false,
"enable-xrays": false,
- engines: createMockEngines(),
"example-dashboard-id": 1,
gsheets: {},
"humanization-strategy": "simple",
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.ts
index 514ab919e8a..088e0eaa066 100644
--- a/frontend/src/metabase-types/api/settings.ts
+++ b/frontend/src/metabase-types/api/settings.ts
@@ -586,7 +586,6 @@ interface PublicSettings {
// Non-null: :public visibility and a total getter (computed from the jar's
// bundled translation resources), so every viewer always receives a list.
"available-locales": LocaleData[];
- "available-timezones": string[] | null;
"bug-reporting-enabled": boolean;
"check-for-updates": boolean;
"cloud-gateway-ips": string[] | null;
@@ -606,7 +605,6 @@ interface PublicSettings {
"enable-password-login": boolean;
"enable-pivoted-exports": boolean;
"enable-sandboxes?": boolean;
- engines: Record<EngineKey, Engine>;
"google-auth-client-id": string | null;
"google-auth-enabled": boolean;
"has-user-setup": boolean;
diff --git a/frontend/src/metabase/admin/app/containers/DeprecationNotice/DeprecationNotice.tsx b/frontend/src/metabase/admin/app/containers/DeprecationNotice/DeprecationNotice.tsx
index eca8d45b5bc..92383bfcf28 100644
--- a/frontend/src/metabase/admin/app/containers/DeprecationNotice/DeprecationNotice.tsx
+++ b/frontend/src/metabase/admin/app/containers/DeprecationNotice/DeprecationNotice.tsx
@@ -1,4 +1,4 @@
-import { useListDatabasesQuery } from "metabase/api";
+import { useListDatabasesQuery, useListEnginesQuery } from "metabase/api";
import { useDispatch, useSelector } from "metabase/redux";
import { disableNotice } from "../../actions";
@@ -10,9 +10,8 @@ import {
const DeprecationNoticeContainer = () => {
const { data: databasesData } = useListDatabasesQuery();
- const hasDeprecated = useSelector((state) =>
- hasDeprecatedDatabase(state, { databases: databasesData?.data }),
- );
+ const { data: engines = {} } = useListEnginesQuery();
+ const hasDeprecated = hasDeprecatedDatabase(engines, databasesData?.data);
const isEnabled = useSelector(isDeprecationNoticeEnabled);
const dispatch = useDispatch();
diff --git a/frontend/src/metabase/admin/app/selectors.ts b/frontend/src/metabase/admin/app/selectors.ts
index a636099e0ae..7d07c82126f 100644
--- a/frontend/src/metabase/admin/app/selectors.ts
+++ b/frontend/src/metabase/admin/app/selectors.ts
@@ -1,20 +1,19 @@
import { isDeprecatedEngine } from "metabase/databases/utils/engine";
import type { State } from "metabase/redux/store";
import { getSetting } from "metabase/settings";
-import type { Database } from "metabase-types/api";
+import type { Database, Engine } from "metabase-types/api";
interface Props {
databases?: Pick<Database, "is_sample" | "engine">[];
}
-export const hasDeprecatedDatabase = (state: State, props: Props): boolean => {
- const engines = getSetting(state, "engines");
- return (
- props.databases?.some(
- (d) => !d.is_sample && d.engine && isDeprecatedEngine(engines, d.engine),
- ) ?? false
- );
-};
+export const hasDeprecatedDatabase = (
+ engines: Record<string, Engine>,
+ databases: Props["databases"],
+): boolean =>
+ databases?.some(
+ (d) => !d.is_sample && d.engine && isDeprecatedEngine(engines, d.engine),
+ ) ?? false;
export const isDeprecationNoticeEnabled = (state: State): boolean => {
// check if the deprecation notice has been dismissed on this version
diff --git a/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.unit.spec.tsx b/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.unit.spec.tsx
index b5c00a06e82..c6f99a90733 100644
--- a/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.unit.spec.tsx
+++ b/frontend/src/metabase/admin/databases/components/DatabaseEditConnectionForm.unit.spec.tsx
@@ -1,4 +1,4 @@
-import { mockSettings } from "__support__/settings";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen } from "__support__/ui";
import { Route } from "metabase/router";
@@ -13,9 +13,9 @@ interface SetupOpts {
}
function setup({ database, isAttachedDWH = false }: SetupOpts = {}) {
- const storeInitialState = createMockState({
- settings: mockSettings({ engines: createMockEngines() }),
- });
+ setupEnginesEndpoint(createMockEngines());
+
+ const storeInitialState = createMockState();
renderWithProviders(
<Route
@@ -35,10 +35,10 @@ function setup({ database, isAttachedDWH = false }: SetupOpts = {}) {
}
describe("DatabaseEditConnectionForm", () => {
- it("renders the editable connection form for an ordinary database", () => {
+ it("renders the editable connection form for an ordinary database", async () => {
setup({ database: { id: 1, engine: "postgres" } });
- expect(screen.getByTestId("database-form")).toBeInTheDocument();
+ expect(await screen.findByTestId("database-form")).toBeInTheDocument();
expect(screen.queryByText(/cannot be edited/i)).not.toBeInTheDocument();
});
diff --git a/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.tsx b/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.tsx
index bcd52397b35..be4ab91cb54 100644
--- a/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.tsx
+++ b/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.tsx
@@ -2,6 +2,7 @@ import { useDisclosure } from "@mantine/hooks";
import { c, t } from "ttag";
import { NewUserModal } from "metabase/admin/people/containers/NewUserModal";
+import { useListEnginesQuery } from "metabase/api";
import { Link } from "metabase/common/components/Link";
import { useDocsUrl } from "metabase/common/hooks";
import { getHelpUrl } from "metabase/common/utils/help-url";
@@ -32,7 +33,7 @@ interface Props {
}
export const DatabaseHelpSidePanel = ({ engineKey, onClose }: Props) => {
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const { url: fullDocsUrl, showMetabaseLinks } = useDocsUrl(
`databases/connections/${ENGINE_DOC_MAP[engineKey]}`,
);
diff --git a/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.unit.spec.tsx b/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.unit.spec.tsx
index f6bdea85894..ea21dc557b8 100644
--- a/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.unit.spec.tsx
+++ b/frontend/src/metabase/admin/databases/components/DatabaseHelpSidePanel/DatabaseHelpSidePanel.unit.spec.tsx
@@ -3,6 +3,7 @@ import userEvent from "@testing-library/user-event";
import fetchMock from "fetch-mock";
import { setupEnterprisePlugins } from "__support__/enterprise";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen, within } from "__support__/ui";
@@ -50,9 +51,9 @@ const setup = (opts: SetupOptions) => {
: undefined,
"token-features": createMockTokenFeatures({ whitelabel: true }),
"is-hosted?": true,
- engines: createMockEngines(),
}),
});
+ setupEnginesEndpoint(createMockEngines());
setupEnterprisePlugins();
renderWithProviders(
@@ -75,7 +76,7 @@ describe("DatabaseHelpSidePanel", () => {
setup({});
});
expect(
- screen.getByRole("link", { name: /Read the full docs/ }),
+ await screen.findByRole("link", { name: /Read the full docs/ }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /Invite a teammate to help you/ }),
@@ -126,7 +127,9 @@ describe("DatabaseHelpSidePanel", () => {
});
expect(onClose).not.toHaveBeenCalled();
- await userEvent.click(screen.getByRole("img", { name: "close icon" }));
+ await userEvent.click(
+ await screen.findByRole("img", { name: "close icon" }),
+ );
expect(onClose).toHaveBeenCalledTimes(1);
});
@@ -136,7 +139,9 @@ describe("DatabaseHelpSidePanel", () => {
setup({ isAdmin: true });
});
await userEvent.click(
- screen.getByRole("button", { name: /Invite a teammate to help you/ }),
+ await screen.findByRole("button", {
+ name: /Invite a teammate to help you/,
+ }),
);
const dialog = screen.getByRole("dialog");
expect(dialog).toBeInTheDocument();
diff --git a/frontend/src/metabase/admin/databases/components/ExistingDatabaseHeader/ExistingDatabaseHeader.tsx b/frontend/src/metabase/admin/databases/components/ExistingDatabaseHeader/ExistingDatabaseHeader.tsx
index 79559589b03..25788606db4 100644
--- a/frontend/src/metabase/admin/databases/components/ExistingDatabaseHeader/ExistingDatabaseHeader.tsx
+++ b/frontend/src/metabase/admin/databases/components/ExistingDatabaseHeader/ExistingDatabaseHeader.tsx
@@ -1,6 +1,6 @@
import { c } from "ttag";
-import { useSetting } from "metabase/settings";
+import { useListEnginesQuery } from "metabase/api";
import { Flex, Stack, Text, Title } from "metabase/ui";
import type { Database } from "metabase-types/api";
import { isEngineKey } from "metabase-types/guards";
@@ -12,7 +12,7 @@ export const ExistingDatabaseHeader = ({
}: {
database: Database;
}) => {
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const engineKey = isEngineKey(database.engine) ? database.engine : undefined;
const driverName = engineKey
? engines[engineKey]?.["driver-name"]
diff --git a/frontend/src/metabase/admin/databases/containers/DatabaseListApp.tsx b/frontend/src/metabase/admin/databases/containers/DatabaseListApp.tsx
index 7e548e52ee3..2b9d8f71e63 100644
--- a/frontend/src/metabase/admin/databases/containers/DatabaseListApp.tsx
+++ b/frontend/src/metabase/admin/databases/containers/DatabaseListApp.tsx
@@ -3,12 +3,12 @@ import { useEffect, useMemo, useState } from "react";
import {
useAddSampleDatabaseMutation,
useListDatabasesQuery,
+ useListEnginesQuery,
} from "metabase/api";
import { LoadingAndGenericErrorWrapper } from "metabase/common/components/LoadingAndGenericErrorWrapper";
import { getUserIsAdmin } from "metabase/current-user";
import { PLUGIN_FEATURE_LEVEL_PERMISSIONS } from "metabase/plugins";
import { useSelector } from "metabase/redux";
-import { useSetting } from "metabase/settings";
import { isSyncInProgress } from "metabase/utils/syncing";
import { DatabaseList } from "../components/DatabaseList";
@@ -22,7 +22,7 @@ export const DatabaseListApp = (props: DatabaseListAppProps) => {
const isAdmin = useSelector(getUserIsAdmin);
const deletes = useSelector(getDeletes);
const deletionError = useSelector(getDeletionError);
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const [addSampleDb, addSampleDbResult] = useAddSampleDatabaseMutation();
diff --git a/frontend/src/metabase/admin/databases/containers/DatabasePage.tsx b/frontend/src/metabase/admin/databases/containers/DatabasePage.tsx
index b7498580c99..4f163d5ea5e 100644
--- a/frontend/src/metabase/admin/databases/containers/DatabasePage.tsx
+++ b/frontend/src/metabase/admin/databases/containers/DatabasePage.tsx
@@ -2,8 +2,8 @@ import { useDisclosure } from "@mantine/hooks";
import { useEffect, useState } from "react";
import { t } from "ttag";
+import { useListEnginesQuery } from "metabase/api";
import { useParams } from "metabase/router";
-import { useSetting } from "metabase/settings";
import { SettingsSection } from "metabase/settings-components";
import {
Box,
@@ -16,6 +16,7 @@ import {
Title,
} from "metabase/ui";
import type { EngineKey } from "metabase-types/api";
+import { isEngineKey } from "metabase-types/guards";
import { DatabaseEditConnectionForm } from "../components/DatabaseEditConnectionForm";
import {
@@ -28,21 +29,23 @@ import { trackHelpButtonClick } from "./analytics";
export function DatabasePage() {
const params = useParams<{ databaseId: string }>();
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const { database, databaseReq, handleCancel, handleOnSubmit, title, config } =
useDatabaseConnection({ databaseId: params.databaseId, engines });
const [showSidePanel, { open: openSidePanel, close: closeSidePanel }] =
useDisclosure(false);
- // Unjustified type cast. FIXME
- const [selectedEngineKey, setSelectedEngineKey] = useState<EngineKey>(
- database?.engine as EngineKey,
- );
+ // The database and its default engine both arrive asynchronously, so the engine
+ // the user picked is tracked separately and takes precedence once it is set.
+ const [pickedEngineKey, setPickedEngineKey] = useState<EngineKey>();
+ const databaseEngineKey = isEngineKey(database?.engine)
+ ? database.engine
+ : undefined;
+ const selectedEngineKey = pickedEngineKey ?? databaseEngineKey;
const helpContentsExist =
!!selectedEngineKey && !!ENGINE_DOC_MAP[selectedEngineKey];
const onEngineChange = (engineKey?: string) => {
- // Unjustified type cast. FIXME
- setSelectedEngineKey(engineKey as EngineKey);
+ setPickedEngineKey(isEngineKey(engineKey) ? engineKey : undefined);
};
useEffect(() => {
@@ -101,7 +104,7 @@ export function DatabasePage() {
</SettingsSection>
</Box>
</Box>
- {showSidePanel && (
+ {showSidePanel && selectedEngineKey && (
<>
<Divider orientation="vertical" h="100%" />
<DatabaseHelpSidePanel
diff --git a/frontend/src/metabase/admin/databases/containers/DatabasePage.unit.spec.tsx b/frontend/src/metabase/admin/databases/containers/DatabasePage.unit.spec.tsx
index 749e8539783..432ff8cca77 100644
--- a/frontend/src/metabase/admin/databases/containers/DatabasePage.unit.spec.tsx
+++ b/frontend/src/metabase/admin/databases/containers/DatabasePage.unit.spec.tsx
@@ -1,7 +1,7 @@
import { waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
-import { mockSettings } from "__support__/settings";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen } from "__support__/ui";
import { Route } from "metabase/router";
@@ -15,29 +15,27 @@ jest.mock(
);
const setup = () => {
+ setupEnginesEndpoint(createMockEngines());
+
renderWithProviders(<Route path="/" element={<DatabasePage />} />, {
withRouter: true,
- storeInitialState: createMockState({
- settings: mockSettings({
- engines: createMockEngines(),
- }),
- }),
+ storeInitialState: createMockState(),
});
};
describe("DatabasePage", () => {
describe("Help button", () => {
- it("should render the 'Help is here' button", () => {
+ it("should render the 'Help is here' button", async () => {
setup();
expect(
- screen.getByRole("button", { name: /Help is here/ }),
+ await screen.findByRole("button", { name: /Help is here/ }),
).toBeInTheDocument();
});
it("should show the side panel when 'Help is here' button is clicked", async () => {
setup();
await userEvent.click(
- screen.getByRole("button", { name: /Help is here/ }),
+ await screen.findByRole("button", { name: /Help is here/ }),
);
await waitFor(() => {
expect(
diff --git a/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.tsx b/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.tsx
index 9ff407d8605..169fd528afc 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.tsx
@@ -4,7 +4,7 @@ import _ from "underscore";
import { CommunityLocalizationNotice } from "metabase/common/components/CommunityLocalizationNotice";
import { useSelector } from "metabase/redux";
import { getApplicationName } from "metabase/selectors/whitelabel";
-import { useSetting } from "metabase/settings";
+import { useListTimezonesQuery, useSetting } from "metabase/settings";
import {
AdminSettingInput,
SettingsPageWrapper,
@@ -16,7 +16,7 @@ import { FormattingWidget } from "../widgets/FormattingWidget";
export function LocalizationSettingsPage() {
const availableLocales = useSetting("available-locales");
- const availableTimezones = useSetting("available-timezones");
+ const { data: availableTimezones } = useListTimezonesQuery();
const applicationName = useSelector(getApplicationName);
return (
diff --git a/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.unit.spec.tsx
index 9b2ddc5b9f0..65fb223fb23 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsPages/LocalizationSettingsPage.unit.spec.tsx
@@ -4,6 +4,7 @@ import {
findRequests,
setupPropertiesEndpoints,
setupSettingsEndpoints,
+ setupTimezonesEndpoint,
setupUpdateSettingEndpoint,
} from "__support__/server-mocks";
import { createMockSettingsState } from "__support__/state";
@@ -22,17 +23,16 @@ const setup = async () => {
"site-locale": "En",
"report-timezone": "",
"start-of-week": "monday",
- // Unjustified type cast. FIXME
- "available-timezones": [
- "Europe/Paris",
- "Pacific/Auckland",
- "US/Mountain",
- "UTC",
- ] as string[],
} as const;
const settings = createMockSettings(localizationSettings);
setupPropertiesEndpoints(settings);
+ setupTimezonesEndpoint([
+ "Europe/Paris",
+ "Pacific/Auckland",
+ "US/Mountain",
+ "UTC",
+ ]);
setupUpdateSettingEndpoint();
setupSettingsEndpoints(
Object.entries(settings).map(([key, value]) =>
diff --git a/frontend/src/metabase/admin/settings/tests/setup.tsx b/frontend/src/metabase/admin/settings/tests/setup.tsx
index ec48c2479c0..8745b4bcf59 100644
--- a/frontend/src/metabase/admin/settings/tests/setup.tsx
+++ b/frontend/src/metabase/admin/settings/tests/setup.tsx
@@ -16,6 +16,7 @@ import {
setupSettingsEndpoints,
setupSlackAppInfoEndpoint,
setupSlackManifestEndpoint,
+ setupTimezonesEndpoint,
setupTokenStatusEndpoint,
setupUploadManagementEndpoint,
setupUserKeyValueEndpoints,
@@ -151,6 +152,7 @@ export const setup = async ({
setupApiKeyEndpoints([]);
setupGroupsEndpoint([]);
setupDatabasesEndpoints([]);
+ setupTimezonesEndpoint(["Europe/Paris", "US/Mountain", "UTC"]);
setupSlackManifestEndpoint();
setupSlackAppInfoEndpoint();
setupUploadManagementEndpoint([]);
diff --git a/frontend/src/metabase/api/database.ts b/frontend/src/metabase/api/database.ts
index 99e34cb0c31..a20735b1ae2 100644
--- a/frontend/src/metabase/api/database.ts
+++ b/frontend/src/metabase/api/database.ts
@@ -7,6 +7,7 @@ import type {
Database,
DatabaseId,
DatabaseUsageInfo,
+ Engine,
Field,
GetDatabaseHealthRequest,
GetDatabaseHealthResponse,
@@ -48,6 +49,14 @@ export const shouldSchemaBePassedAsQueryParam = (schema: SchemaName) =>
export const databaseApi = Api.injectEndpoints({
endpoints: (builder) => ({
+ listEngines: builder.query<Record<string, Engine>, void>({
+ query: () => ({
+ method: "GET",
+ url: "/api/setting/engines",
+ }),
+ // Driver metadata only changes when the instance is upgraded.
+ keepUnusedDataFor: Infinity,
+ }),
listDatabases: builder.query<
ListDatabasesResponse,
ListDatabasesRequest | void
@@ -317,6 +326,7 @@ export const databaseApi = Api.injectEndpoints({
export const {
useListDatabasesQuery,
+ useListEnginesQuery,
useLazyListDatabasesQuery,
useGetDatabaseQuery,
useGetDatabaseHealthQuery,
diff --git a/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.tsx b/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.tsx
index b7a7abdb7b7..5bba7ed733a 100644
--- a/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.tsx
@@ -1,6 +1,8 @@
import { useCallback, useState } from "react";
import { t } from "ttag";
+import { useListEnginesQuery } from "metabase/api";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { LogoIcon } from "metabase/common/components/LogoIcon";
import { MAX_INITIAL_ENGINES_SHOWN } from "metabase/databases/constants";
import {
@@ -47,7 +49,7 @@ export const DatabaseEngineList = ({
const [search, setSearch] = useState("");
const [isExpanded, setIsExpanded] = useState(false);
- const engines = useSetting("engines");
+ const { data: engines = {}, isLoading, error } = useListEnginesQuery();
const options = getEngineOptions(engines);
const elevatedEngines = options.slice(0, MAX_INITIAL_ENGINES_SHOWN);
@@ -66,6 +68,10 @@ export const DatabaseEngineList = ({
}
}, [onSelect, isSetupStep]);
+ if (isLoading || error) {
+ return <LoadingAndErrorWrapper loading={isLoading} error={error} />;
+ }
+
// This is just a temporary way to show a selected item. The plan is to redesign
// this particular bit, and it will live outside this component.
if (isSetupStep && engineKey) {
diff --git a/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.unit.spec.tsx
index 76e35c8d800..e8469123caf 100644
--- a/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.unit.spec.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseEngineList/DatabaseEngineList.unit.spec.tsx
@@ -1,6 +1,7 @@
import userEvent from "@testing-library/user-event";
-import { createMockSettingsState, createMockState } from "__support__/state";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
+import { createMockState } from "__support__/state";
import { renderWithProviders, screen } from "__support__/ui";
import {
ELEVATED_ENGINES,
@@ -42,14 +43,12 @@ const mockEngines: Record<string, Engine> = {
}),
};
-const setup = ({
+const setup = async ({
engines = mockEngines,
}: { engines?: Record<string, Engine> } = {}) => {
- const state = createMockState({
- settings: createMockSettingsState({
- engines,
- }),
- });
+ setupEnginesEndpoint(engines);
+
+ const state = createMockState();
const onSelect = jest.fn();
@@ -57,12 +56,14 @@ const setup = ({
storeInitialState: state,
});
+ await screen.findAllByRole("option");
+
return { onSelect };
};
describe("DatabaseEngineList", () => {
- it("should render initial list of elevated engines", () => {
- setup();
+ it("should render initial list of elevated engines", async () => {
+ await setup();
expect(screen.getAllByRole("option")).toHaveLength(
MAX_INITIAL_ENGINES_SHOWN,
@@ -75,7 +76,7 @@ describe("DatabaseEngineList", () => {
});
it("should expand and collapse the list by clicking on the toggle button", async () => {
- setup();
+ await setup();
await userEvent.click(screen.getByText("Show more"));
expect(screen.getAllByRole("option").length).toBeGreaterThan(
@@ -92,7 +93,7 @@ describe("DatabaseEngineList", () => {
it("should not render the toggle when every engine fits the initial list", async () => {
const { mysql, postgres, sqlserver } = mockEngines;
- setup({ engines: { mysql, postgres, sqlserver } });
+ await setup({ engines: { mysql, postgres, sqlserver } });
expect(screen.getByText("MySQL")).toBeInTheDocument();
expect(screen.queryByText("Show more")).not.toBeInTheDocument();
@@ -108,7 +109,7 @@ describe("DatabaseEngineList", () => {
});
it("should call `onSelect` when a database is selected", async () => {
- const { onSelect } = setup();
+ const { onSelect } = await setup();
await userEvent.click(screen.getByRole("option", { name: "PostgreSQL" }));
@@ -117,7 +118,7 @@ describe("DatabaseEngineList", () => {
});
it("should allow searching for databases", async () => {
- setup();
+ await setup();
const searchInput = screen.getByPlaceholderText("Search databases");
await userEvent.type(searchInput, "mon");
@@ -128,7 +129,7 @@ describe("DatabaseEngineList", () => {
});
it("should allow keyboard navigation", async () => {
- const { onSelect } = setup();
+ const { onSelect } = await setup();
const searchInput = screen.getByPlaceholderText("Search databases");
await userEvent.click(searchInput);
@@ -159,7 +160,7 @@ describe("DatabaseEngineList", () => {
});
it("should show no results message when search has no matches", async () => {
- setup();
+ await setup();
const searchInput = screen.getByPlaceholderText("Search databases");
await userEvent.type(searchInput, "nonexistent");
@@ -171,7 +172,7 @@ describe("DatabaseEngineList", () => {
});
it("starting to search should automatically expand the list", async () => {
- setup();
+ await setup();
const searchInput = screen.getByPlaceholderText("Search databases");
expect(screen.getByText("Show more")).toBeInTheDocument();
@@ -182,7 +183,7 @@ describe("DatabaseEngineList", () => {
});
it("collapsing the list while searching should clear the search value", async () => {
- setup();
+ await setup();
const searchInput = screen.getByPlaceholderText("Search databases");
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.stories.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.stories.tsx
index fb9e711e2d7..ff62a40a6b0 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.stories.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.stories.tsx
@@ -1,4 +1,6 @@
-import { createMockSettingsState, createMockState } from "__support__/state";
+import { HttpResponse, http } from "msw";
+
+import { createMockState } from "__support__/state";
import { ReduxProvider } from "__support__/storybook";
import { DatabaseForm } from "./DatabaseForm";
@@ -7,13 +9,16 @@ import { TEST_ENGINES } from "./tests/setup";
export default {
title: "App/Databases/DatabaseForm",
component: DatabaseForm,
+ parameters: {
+ msw: {
+ handlers: [
+ http.get("/api/setting/engines", () => HttpResponse.json(TEST_ENGINES)),
+ ],
+ },
+ },
};
-const initialState = createMockState({
- settings: createMockSettingsState({
- engines: TEST_ENGINES,
- }),
-});
+const initialState = createMockState();
export const Default = () => (
<ReduxProvider storeInitialState={initialState}>
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
index b7ed2cb2f4c..6c04715957a 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseForm.tsx
@@ -1,7 +1,8 @@
import { useCallback, useMemo } from "react";
+import { useListEnginesQuery } from "metabase/api";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { Form, FormProvider } from "metabase/forms";
-import { useSetting } from "metabase/settings";
import { memoize } from "metabase/utils/memoize";
import type { DatabaseData } from "metabase-types/api";
@@ -63,7 +64,7 @@ export const DatabaseForm = ({
}: DatabaseFormProps): JSX.Element => {
const isAdvanced = config.isAdvanced || false;
- const engines = useSetting("engines");
+ const { data: engines = {}, isLoading, error } = useListEnginesQuery();
const initialEngineKey = useMemo(() => {
return getEngineKey(engines, initialData, isAdvanced);
}, [engines, initialData, isAdvanced]);
@@ -96,6 +97,10 @@ export const DatabaseForm = ({
[engines, isAdvanced, onSubmit],
);
+ if (isLoading || error) {
+ return <LoadingAndErrorWrapper loading={isLoading} error={error} />;
+ }
+
return (
<FormProvider
initialValues={initialValues}
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseTestConnectionButton.tsx b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseTestConnectionButton.tsx
index bf6790f1cc6..bf82b129905 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/DatabaseTestConnectionButton.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/DatabaseTestConnectionButton.tsx
@@ -3,10 +3,9 @@ import { useState } from "react";
import { match } from "ts-pattern";
import { t } from "ttag";
-import { useValidateDatabaseMutation } from "metabase/api";
+import { useListEnginesQuery, useValidateDatabaseMutation } from "metabase/api";
import { getErrorMessage } from "metabase/api/utils";
import { useDebouncedValue } from "metabase/common/hooks/use-debounced-value";
-import { useSetting } from "metabase/settings";
import { Button, Icon, Tooltip } from "metabase/ui";
import type { DatabaseData } from "metabase-types/api";
@@ -62,7 +61,7 @@ const TestResultIcon = ({ result }: { result: TestResult }) =>
export const DatabaseTestConnectionButton = () => {
const { values, validateForm, setFieldError, setFieldTouched } =
useFormikContext<DatabaseData>();
- const engines = useSetting("engines");
+ const { data: engines = {} } = useListEnginesQuery();
const [validateDatabase, { isLoading }] = useValidateDatabaseMutation();
const showLoading = useDebouncedValue(
isLoading,
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 f531e0eada5..8fac8c41a3a 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
@@ -10,7 +10,7 @@ import { TEST_ENGINES, setup } from "./setup";
describe("DatabaseForm", () => {
it("should submit default values", async () => {
- const { onSubmit } = setup();
+ const { onSubmit } = await setup();
const expectedDatabaseName = "My H2 Database";
const expectedConnectionString = "file:/somewhere";
await userEvent.type(
@@ -41,27 +41,27 @@ describe("DatabaseForm", () => {
});
it("should not allow to configure cache ttl", async () => {
- setup();
+ await setup();
await userEvent.click(screen.getByText("Show advanced options"));
expect(
screen.getByText("Choose when syncs and scans happen"),
).toBeInTheDocument();
});
- it("should show the cancel button when rendered in a modal", () => {
- setup({ location: "admin" });
+ it("should show the cancel button when rendered in a modal", async () => {
+ await setup({ location: "admin" });
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument();
});
- it("should not show the cancel button when rendered as a full page", () => {
- setup({ location: "full-page" });
+ it("should not show the cancel button when rendered as a full page", async () => {
+ await setup({ location: "full-page" });
expect(
screen.queryByRole("button", { name: "Cancel" }),
).not.toBeInTheDocument();
});
it("should not render hidden fields", async () => {
- setup();
+ await setup();
await userEvent.click(screen.getByText("Show advanced options"));
expect(screen.queryByText("Destination database")).not.toBeInTheDocument();
});
@@ -105,7 +105,7 @@ describe("DatabaseForm", () => {
}) || [],
},
};
- setup({ engines: mockEngines });
+ await setup({ engines: mockEngines });
await userEvent.click(screen.getByText("Show advanced options"));
expect(screen.queryByText("Destination database")).not.toBeInTheDocument();
expect(
@@ -114,7 +114,7 @@ describe("DatabaseForm", () => {
});
it("should allow tab navigation through form fields", async () => {
- setup();
+ await setup();
// tabs ou tof the search
await userEvent.tab();
@@ -127,7 +127,7 @@ describe("DatabaseForm", () => {
describe("updating existing database", () => {
it("should mark form as dirty only when actual fields are changed (#66684)", async () => {
- setup({
+ await setup({
initialValues: {
id: 1,
name: "My Original H2 Database name",
@@ -167,7 +167,7 @@ describe("DatabaseForm", () => {
describe("DatabaseForm with provider name", () => {
it("submits provider name", async () => {
- const { onSubmit } = setup({
+ const { onSubmit } = await setup({
initialValues: {
engine: "postgres",
},
@@ -193,7 +193,7 @@ describe("DatabaseForm with provider name", () => {
});
it("submits empty provider name if not matched", async () => {
- const { onSubmit } = setup({
+ const { onSubmit } = await setup({
initialValues: {
engine: "postgres",
},
@@ -218,8 +218,12 @@ describe("DatabaseForm with provider name", () => {
});
describe("Connection error handling", () => {
- const errorHandlingSetup = ({ isAdvanced }: { isAdvanced?: boolean }) => {
- setup({
+ const errorHandlingSetup = async ({
+ isAdvanced,
+ }: {
+ isAdvanced?: boolean;
+ }) => {
+ await setup({
engines: TEST_ENGINES,
isAdvanced,
});
@@ -230,16 +234,16 @@ describe("DatabaseForm with provider name", () => {
jest.spyOn(utils, "useHasConnectionError").mockImplementation(() => true);
});
- it("shows error message in the footer if isAdvanced is false (setup page)", () => {
- errorHandlingSetup({ isAdvanced: false });
+ it("shows error message in the footer if isAdvanced is false (setup page)", async () => {
+ await 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 });
+ it("shows error message outside the footer if isAdvanced is true (admin page)", async () => {
+ await errorHandlingSetup({ isAdvanced: true });
// Check error is rendered
expect(screen.getByText(errorMessage)).toBeInTheDocument();
// But not in the footer
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/engine-change.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/engine-change.unit.spec.tsx
index 3332e8b02f5..c2ae44235b7 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/engine-change.unit.spec.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/engine-change.unit.spec.tsx
@@ -1,7 +1,7 @@
import userEvent from "@testing-library/user-event";
import { useState } from "react";
-import { mockSettings } from "__support__/settings";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen, waitFor } from "__support__/ui";
import type { DatabaseData, Engine } from "metabase-types/api";
@@ -26,7 +26,7 @@ const selectDatabaseType = async (driverName: string) => {
describe("DatabaseForm engine change", () => {
it("should keep the values that already have been entered (metabase#74569)", async () => {
- setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
+ await setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
await userEvent.type(screen.getByLabelText("Display name"), "My database");
await userEvent.type(screen.getByLabelText("Host"), "localhost");
@@ -44,7 +44,7 @@ describe("DatabaseForm engine change", () => {
});
it("should submit the values that were entered before the engine changed (metabase#74569)", async () => {
- const { onSubmit } = setup({
+ const { onSubmit } = await setup({
engines: ENGINES,
initialValues: { engine: "postgres" },
});
@@ -77,7 +77,7 @@ describe("DatabaseForm engine change", () => {
});
it("should discard the details that the newly selected engine does not have", async () => {
- setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
+ await setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
await userEvent.type(screen.getByLabelText("Host"), "localhost");
@@ -112,10 +112,10 @@ describe("DatabaseForm engine change", () => {
);
};
+ setupEnginesEndpoint(ENGINES);
+
renderWithProviders(<LateLoadingForm />, {
- storeInitialState: createMockState({
- settings: mockSettings({ engines: ENGINES }),
- }),
+ storeInitialState: createMockState(),
});
expect(await screen.findByDisplayValue("PostgreSQL")).toBeInTheDocument();
@@ -131,7 +131,7 @@ describe("DatabaseForm engine change", () => {
});
it("should discard the connection string, which is engine specific", async () => {
- setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
+ await setup({ engines: ENGINES, initialValues: { engine: "postgres" } });
const connectionStringInput = () =>
screen.getByLabelText("Connection string (optional)");
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/schedule.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/schedule.unit.spec.tsx
index 2c25b1bd2f0..0f10c13aebb 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/schedule.unit.spec.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/schedule.unit.spec.tsx
@@ -39,7 +39,7 @@ const save = async () => {
describe("DatabaseForm scheduling", () => {
it("submits auto_run_queries=false when 'Rerun queries' is turned off (metabase#13187)", async () => {
- const { onSubmit } = setup();
+ const { onSubmit } = await setup();
await fillConnection();
await openAdvancedOptions();
@@ -56,7 +56,7 @@ describe("DatabaseForm scheduling", () => {
});
it("submits is_full_sync=false when the user takes control of scheduling", async () => {
- const { onSubmit } = setup();
+ const { onSubmit } = await setup();
await fillConnection();
await openAdvancedOptions();
@@ -71,7 +71,7 @@ describe("DatabaseForm scheduling", () => {
});
it("submits is_on_demand=true for 'Only when adding a new filter widget' (metabase#57198)", async () => {
- const { onSubmit } = setup();
+ const { onSubmit } = await setup();
await fillConnection();
await openAdvancedOptions();
await enableScheduling();
@@ -90,7 +90,7 @@ describe("DatabaseForm scheduling", () => {
});
it("submits a daily cache schedule for 'Regularly, on a schedule' (metabase#57198)", async () => {
- const { onSubmit } = setup();
+ const { onSubmit } = await setup();
await fillConnection();
await openAdvancedOptions();
await enableScheduling();
@@ -117,7 +117,7 @@ describe("DatabaseForm scheduling", () => {
});
it("renders the saved cache schedule mode for an existing database (round-trip)", async () => {
- setup({
+ await setup({
initialValues: {
id: 1,
name: "My DB",
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
index 39a4c8b0565..4677ccf32dd 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/setup.tsx
@@ -1,7 +1,8 @@
import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { createMockState } from "__support__/state";
-import { renderWithProviders } from "__support__/ui";
+import { renderWithProviders, screen } from "__support__/ui";
import type { FormLocation } from "metabase/databases/types";
import type {
DatabaseData,
@@ -107,7 +108,7 @@ export interface SetupOpts {
location?: FormLocation;
}
-export const setup = ({
+export const setup = async ({
settings,
enterprisePlugins,
engines = TEST_ENGINES,
@@ -115,8 +116,10 @@ export const setup = ({
isAdvanced = true,
location = "admin",
}: SetupOpts = {}) => {
+ setupEnginesEndpoint(engines);
+
const state = createMockState({
- settings: mockSettings({ ...settings, engines }),
+ settings: mockSettings({ ...settings }),
});
if (enterprisePlugins) {
@@ -142,5 +145,7 @@ export const setup = ({
},
);
+ await screen.findByTestId("database-form");
+
return { onSubmit };
};
diff --git a/frontend/src/metabase/databases/components/DatabaseForm/tests/test-connection.unit.spec.tsx b/frontend/src/metabase/databases/components/DatabaseForm/tests/test-connection.unit.spec.tsx
index c701e2740d7..d17d91eddc4 100644
--- a/frontend/src/metabase/databases/components/DatabaseForm/tests/test-connection.unit.spec.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseForm/tests/test-connection.unit.spec.tsx
@@ -48,7 +48,7 @@ const findValidateRequests = async () => {
describe("DatabaseForm > test connection", () => {
it("should not test the connection when a required connection field is missing", async () => {
- setupTestConnection({
+ await setupTestConnection({
initialValues: { engine: "postgres", name: "My database" },
});
@@ -62,7 +62,7 @@ describe("DatabaseForm > test connection", () => {
{ name: "omit the id for a new database", id: undefined },
{ name: "send the id for an existing database", id: 42 },
])("should $name", async ({ id }) => {
- setupTestConnection({ initialValues: { ...POSTGRES_VALUES, id } });
+ await setupTestConnection({ initialValues: { ...POSTGRES_VALUES, id } });
await clickTestConnection();
@@ -78,7 +78,7 @@ describe("DatabaseForm > test connection", () => {
});
it("should show the result until the form is edited, including while re-testing", async () => {
- setupTestConnection({
+ await setupTestConnection({
initialValues: POSTGRES_VALUES,
validateDelayMs: 200,
});
@@ -115,7 +115,10 @@ describe("DatabaseForm > test connection", () => {
])(
"should show the error in the failure icon's tooltip for $name",
async ({ validateResponse, message }) => {
- setupTestConnection({ initialValues: POSTGRES_VALUES, validateResponse });
+ await setupTestConnection({
+ initialValues: POSTGRES_VALUES,
+ validateResponse,
+ });
await clickTestConnection();
expect(
@@ -131,7 +134,7 @@ describe("DatabaseForm > test connection", () => {
);
it("should delay the loader and ignore clicks while a test is running", async () => {
- setupTestConnection({
+ await setupTestConnection({
initialValues: POSTGRES_VALUES,
validateDelayMs: 800,
});
diff --git a/frontend/src/metabase/embedding/setup-guide/components/SetupGuide.unit.spec.tsx b/frontend/src/metabase/embedding/setup-guide/components/SetupGuide.unit.spec.tsx
index dee230ca06f..487671a6c9e 100644
--- a/frontend/src/metabase/embedding/setup-guide/components/SetupGuide.unit.spec.tsx
+++ b/frontend/src/metabase/embedding/setup-guide/components/SetupGuide.unit.spec.tsx
@@ -5,6 +5,7 @@ import {
setupCollectionByIdEndpoint,
setupCollectionItemsEndpoint,
setupDatabaseListEndpoint,
+ setupEnginesEndpoint,
setupRecentViewsAndSelectionsEndpoints,
setupSearchEndpoints,
} from "__support__/server-mocks";
@@ -20,6 +21,7 @@ import {
import {
createMockCollection,
createMockDashboard,
+ createMockEngines,
createMockRecentTableDatabaseInfo,
createMockRecentTableItem,
createMockUser,
@@ -78,6 +80,8 @@ const setup = ({ isAdmin = true, checklist = {} } = {}) => {
"data-isolation-strategy": null,
});
+ setupEnginesEndpoint(createMockEngines());
+
return renderWithProviders(<SetupGuide />, {
storeInitialState: state,
withUndos: true,
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/tests/setup.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/tests/setup.tsx
index e1bbfbf32ab..54f1da022c6 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/tests/setup.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/AddDataModal/tests/setup.tsx
@@ -4,6 +4,7 @@ import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
import {
setupCollectionByIdEndpoint,
setupDatabaseListEndpoint,
+ setupEnginesEndpoint,
setupGdriveGetFolderEndpoint,
setupGdrivePostFolderEndpoint,
setupGdriveServiceAccountEndpoint,
@@ -24,6 +25,7 @@ import type {
import {
createMockCollection,
createMockDatabase,
+ createMockEngines,
createMockSettings,
createMockTokenFeatures,
createMockUser,
@@ -156,6 +158,8 @@ export const setup = ({
);
}
+ setupEnginesEndpoint(createMockEngines());
+
renderWithProviders(<AddDataModal onClose={jest.fn()} opened={opened} />, {
storeInitialState: state,
});
diff --git a/frontend/src/metabase/settings/api.ts b/frontend/src/metabase/settings/api.ts
index a80264e8ffe..6e06fc0292b 100644
--- a/frontend/src/metabase/settings/api.ts
+++ b/frontend/src/metabase/settings/api.ts
@@ -57,6 +57,16 @@ export const settingsApi = Api.injectEndpoints({
}
}),
}),
+ // The timezones this instance can use as a report timezone. Fetched by key
+ // rather than read from the settings payload: the list is large, one admin
+ // page reads it, and it only changes when the instance is upgraded.
+ listTimezones: builder.query<string[], void>({
+ query: () => ({
+ method: "GET",
+ url: "/api/setting/available-timezones",
+ }),
+ keepUnusedDataFor: Infinity,
+ }),
// admin-only endpoint that returns all settings with lots of extra metadata
getAdminSettingsDetails: builder.query<SettingDefinitionMap, void>({
query: () => ({
@@ -177,6 +187,7 @@ export const settingsApi = Api.injectEndpoints({
export const {
useGetSettingQuery,
+ useListTimezonesQuery,
useGetVersionInfoQuery,
useGetAdminSettingsDetailsQuery,
useGetSessionPropertiesQuery,
diff --git a/frontend/src/metabase/settings/index.ts b/frontend/src/metabase/settings/index.ts
index a5831ea408c..82f3f211587 100644
--- a/frontend/src/metabase/settings/index.ts
+++ b/frontend/src/metabase/settings/index.ts
@@ -10,6 +10,7 @@ export {
useGetSettingsQuery,
useGetVersionInfoQuery,
useLazyGetSettingsQuery,
+ useListTimezonesQuery,
useUpdateSettingMutation,
useUpdateSettingsMutation,
} from "./api";
diff --git a/frontend/src/metabase/setup/components/DatabaseStep/DatabaseStep.unit.spec.tsx b/frontend/src/metabase/setup/components/DatabaseStep/DatabaseStep.unit.spec.tsx
index a02687e9fda..c27220b1c84 100644
--- a/frontend/src/metabase/setup/components/DatabaseStep/DatabaseStep.unit.spec.tsx
+++ b/frontend/src/metabase/setup/components/DatabaseStep/DatabaseStep.unit.spec.tsx
@@ -1,6 +1,7 @@
import userEvent from "@testing-library/user-event";
import fetchMock from "fetch-mock";
+import { setupEnginesEndpoint } from "__support__/server-mocks";
import {
createMockSettingsState,
createMockSetupState,
@@ -9,7 +10,10 @@ import {
import { renderWithProviders, screen, within } from "__support__/ui";
import type { SetupStep } from "metabase/redux/store";
import type { DatabaseData } from "metabase-types/api";
-import { createMockDatabaseData } from "metabase-types/api/mocks";
+import {
+ createMockDatabaseData,
+ createMockEngines,
+} from "metabase-types/api/mocks";
import { DatabaseStep } from "./DatabaseStep";
@@ -34,6 +38,8 @@ const setup = ({
}),
});
+ setupEnginesEndpoint(createMockEngines());
+
renderWithProviders(<DatabaseStep stepLabel={0} />, {
storeInitialState: state,
});
diff --git a/frontend/src/metabase/setup/tests/common.unit.spec.tsx b/frontend/src/metabase/setup/tests/common.unit.spec.tsx
index 431cb27a84b..930e37498ad 100644
--- a/frontend/src/metabase/setup/tests/common.unit.spec.tsx
+++ b/frontend/src/metabase/setup/tests/common.unit.spec.tsx
@@ -44,7 +44,7 @@ describe("setup (OSS)", () => {
await clickNextStep(); // Usage question
expectSectionsToHaveLabelsInOrder({ from: 2 });
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(await screen.findByText("Continue with sample data"));
expectSectionsToHaveLabelsInOrder({ from: 3 });
});
@@ -134,7 +134,9 @@ describe("setup (OSS)", () => {
await submitUserInfoStep();
await selectUsageReason("self-service-analytics");
await clickNextStep();
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(
+ await screen.findByText("Continue with sample data"),
+ );
await userEvent.click(screen.getByText("Finish"));
};
@@ -206,7 +208,9 @@ describe("setup (OSS)", () => {
await selectUsageReason("self-service-analytics");
await clickNextStep();
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(
+ await screen.findByText("Continue with sample data"),
+ );
await userEvent.click(screen.getByText("Finish"));
@@ -265,7 +269,9 @@ describe("setup (OSS)", () => {
await submitUserInfoStep();
await selectUsageReason("self-service-analytics");
await clickNextStep();
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(
+ await screen.findByText("Continue with sample data"),
+ );
await userEvent.click(screen.getByText("Finish"));
await userEvent.click(
@@ -292,7 +298,9 @@ describe("setup (OSS)", () => {
await submitUserInfoStep();
await selectUsageReason("self-service-analytics");
await clickNextStep();
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(
+ await screen.findByText("Continue with sample data"),
+ );
await userEvent.click(screen.getByText("Finish"));
diff --git a/frontend/src/metabase/setup/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/setup/tests/enterprise.unit.spec.tsx
index c3347e2ac9d..2825d48d84f 100644
--- a/frontend/src/metabase/setup/tests/enterprise.unit.spec.tsx
+++ b/frontend/src/metabase/setup/tests/enterprise.unit.spec.tsx
@@ -179,7 +179,9 @@ describe("setup (EE build, but no token)", () => {
await submitUserInfoStep();
await selectUsageReason("self-service-analytics");
await clickNextStep();
- await userEvent.click(screen.getByText("Continue with sample data"));
+ await userEvent.click(
+ await screen.findByText("Continue with sample data"),
+ );
await startAiConfigStep();
await userEvent.click(
await screen.findByRole("button", { name: "Metabase AI service" }),
diff --git a/frontend/src/metabase/setup/tests/setup.tsx b/frontend/src/metabase/setup/tests/setup.tsx
index 4381cc742ea..08ff72aa9b2 100644
--- a/frontend/src/metabase/setup/tests/setup.tsx
+++ b/frontend/src/metabase/setup/tests/setup.tsx
@@ -8,6 +8,7 @@ import {
} from "__support__/enterprise";
import {
setupCurrentUserEndpoint,
+ setupEnginesEndpoint,
setupLlmModelsEndpoint,
setupLlmProviderTypesEndpoint,
setupLlmProvidersEndpoint,
@@ -24,6 +25,7 @@ import type {
UsageReason,
} from "metabase-types/api";
import {
+ createMockEngines,
createMockLlmProviderField,
createMockLlmProviderType,
createMockSettings,
@@ -104,6 +106,8 @@ export async function setup({
setupLlmProvidersEndpoint([]);
setupLlmModelsEndpoint([]);
+ setupEnginesEndpoint(createMockEngines());
+
renderWithProviders(<Setup />, { storeInitialState: state });
// there is some async stuff going on with the locale loading
diff --git a/frontend/test/__support__/server-mocks/database.ts b/frontend/test/__support__/server-mocks/database.ts
index 5fb31b3bfbe..27efe835c99 100644
--- a/frontend/test/__support__/server-mocks/database.ts
+++ b/frontend/test/__support__/server-mocks/database.ts
@@ -8,6 +8,7 @@ import type {
Database,
DatabaseId,
DatabaseUsageInfo,
+ Engine,
SchemaName,
} from "metabase-types/api";
@@ -64,6 +65,10 @@ export function setupDatabaseUsageInfoEndpoint(
fetchMock.get(`path:/api/database/${db.id}/usage_info`, usageInfo);
}
+export function setupEnginesEndpoint(engines: Record<string, Engine>) {
+ fetchMock.get("path:/api/setting/engines", engines);
+}
+
export function setupDatabaseListEndpoint(databases: Database[]) {
fetchMock.get(
"path:/api/database",
diff --git a/frontend/test/__support__/server-mocks/settings.ts b/frontend/test/__support__/server-mocks/settings.ts
index 76e8d951c18..c6076653c8c 100644
--- a/frontend/test/__support__/server-mocks/settings.ts
+++ b/frontend/test/__support__/server-mocks/settings.ts
@@ -110,3 +110,7 @@ export function setupGenerateRandomTokenEndpoint(token: string) {
{ name: "generate-random-token" },
);
}
+
+export function setupTimezonesEndpoint(timezones: string[]) {
+ fetchMock.get("path:/api/setting/available-timezones", timezones);
+}
diff --git a/frontend/test/metabase-bootstrap.js b/frontend/test/metabase-bootstrap.js
index 8af5a1db044..5222728fe75 100644
--- a/frontend/test/metabase-bootstrap.js
+++ b/frontend/test/metabase-bootstrap.js
@@ -2,18 +2,6 @@ import "metabase/css/index.module.css";
window.MetabaseBootstrap = {
"enable-xrays": true,
- "available-timezones": [
- "GMT",
- "UTC",
- "US/Alaska",
- "US/Arizona",
- "US/Central",
- "US/Eastern",
- "US/Hawaii",
- "US/Mountain",
- "US/Pacific",
- "America/Costa_Rica",
- ],
"available-locales": [["en", "English"]],
// NOTE: update this when updating types.cljc
types: {
diff --git a/src/metabase/driver/util/settings.clj b/src/metabase/driver/util/settings.clj
index b6433e71363..cc6ee2dc6c8 100644
--- a/src/metabase/driver/util/settings.clj
+++ b/src/metabase/driver/util/settings.clj
@@ -17,4 +17,7 @@
:visibility :public
:setter :none
:getter driver.util/available-drivers-info
- :doc false)
+ :doc false
+ ;; Large enough to dominate the settings payload and the inlined page JSON, and read only by the
+ ;; screens that pick or configure a database, so clients fetch it by key from `GET /api/setting/engines`.
+ :include-in-list? false)
diff --git a/src/metabase/system/settings.clj b/src/metabase/system/settings.clj
index 245720094e4..8bc24d11d95 100644
--- a/src/metabase/system/settings.clj
+++ b/src/metabase/system/settings.clj
@@ -125,7 +125,10 @@
:export? true
:setter :none
:getter (comp sort t/available-zone-ids)
- :doc false)
+ :doc false
+ ;; ~600 zone ids that change only when the instance is upgraded, and only the localization admin page
+ ;; reads them, so clients fetch them by key from `GET /api/setting/available-timezones`.
+ :include-in-list? false)
(defsetting system-timezone
"The timezone used by the system by default. AKA the JVM timezone."
diff --git a/test/metabase/plugins/driver_deprecation_test.clj b/test/metabase/plugins/driver_deprecation_test.clj
index 1858fe8fdcd..40d2810c546 100644
--- a/test/metabase/plugins/driver_deprecation_test.clj
+++ b/test/metabase/plugins/driver_deprecation_test.clj
@@ -1,7 +1,7 @@
(ns metabase.plugins.driver-deprecation-test
(:require
[clojure.test :refer :all]
- [metabase.settings.core :as setting]
+ [metabase.driver.util :as driver.u]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]))
@@ -10,4 +10,4 @@
(deftest driver-deprecation-test
(mt/with-driver :driver-deprecation-test-legacy
(is (= :driver-deprecation-test-new
- (get-in (setting/user-readable-values-map #{:public}) [:engines :driver-deprecation-test-legacy :superseded-by])))))
+ (get-in (driver.u/available-drivers-info) [:driver-deprecation-test-legacy :superseded-by])))))
diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.clj
index 6223ca1ac46..aed7d164247 100644
--- a/test/metabase/session/api_test.clj
+++ b/test/metabase/session/api_test.clj
@@ -23,6 +23,7 @@
[metabase.test.http-client :as client]
[metabase.test.util :as tu]
[metabase.util :as u]
+ [metabase.util.i18n :refer [deferred-tru]]
[metabase.util.json :as json]
[metabase.util.jvm :as u.jvm]
[metabase.util.malli.schema :as ms]
@@ -714,13 +715,21 @@
(mt/with-temporary-raw-setting-values [login-page-illustration-custom (image-data-uri "image/png" "png bytes")]
(fetch-illustration :login-page-illustration-custom 404)))))
+(defsetting test-session-api-i18n-setting
+ "Public setting whose value nests a deferred-tru, so the locale header has something to translate."
+ :encryption :no
+ :visibility :public
+ :setter :none
+ :getter (fn [] {:display-name (deferred-tru "Connection String")})
+ :doc false)
+
(deftest properties-i18n-test
(testing "GET /session/properties"
(testing "Setting the X-Metabase-Locale header should result give you properties in that locale"
(mt/with-mock-i18n-bundles! {"es" {:messages {"Connection String" "Cadena de conexión !"}}}
(is (= "Cadena de conexión !"
(-> (mt/client :get 200 "session/properties" {:request-options {:headers {"x-metabase-locale" "es"}}})
- :engines :h2 :details-fields first :display-name)))))))
+ :test-session-api-i18n-setting :display-name)))))))
(deftest properties-skip-sensitive-test
(testing "GET /session/properties"
diff --git a/test/metabase/settings_rest/api_test.clj b/test/metabase/settings_rest/api_test.clj
index a898e32de2e..0cad9eff30b 100644
--- a/test/metabase/settings_rest/api_test.clj
+++ b/test/metabase/settings_rest/api_test.clj
@@ -150,6 +150,19 @@
(test-api-setting-integer! 42)
(is (= 42 (fetch-setting :test-api-setting-integer 200))))))
+(deftest ^:parallel include-in-list-false-test
+ (testing "a setting marked :include-in-list? false is left out of the bulk payloads but still readable by key"
+ (let [properties (mt/user-http-request :crowberto :get 200 "session/properties")
+ listed (into #{} (map (comp keyword :key)) (mt/user-http-request :crowberto :get 200 "setting"))]
+ (doseq [setting-key [:engines :available-timezones]]
+ (testing setting-key
+ (testing "left out of GET /api/session/properties, which is the payload the page inlines"
+ (is (not (contains? properties setting-key))))
+ (testing "left out of GET /api/setting"
+ (is (not (contains? listed setting-key))))
+ (testing "still served by GET /api/setting/:key"
+ (is (some? (fetch-setting setting-key 200)))))))))
+
(deftest ^:parallel engines-mark-h2-superseded-test
(testing "GET /api/setting/:key"
(testing "H2 should have :superseded-by set so it doesn't show up in the list of available drivers in the UI DB edit forms"
diff --git a/test/metabase/system/settings_test.clj b/test/metabase/system/settings_test.clj
index 9399ee25233..b66404c1592 100644
--- a/test/metabase/system/settings_test.clj
+++ b/test/metabase/system/settings_test.clj
@@ -6,7 +6,7 @@
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.test.util :as tu]
- [metabase.util.i18n :as i18n :refer [tru]]))
+ [metabase.util.i18n :as i18n :refer [deferred-tru tru]]))
(use-fixtures :once (fixtures/initialize :db))
@@ -74,12 +74,21 @@
(is (= nil
(system.settings/site-url))))))
+(setting/defsetting test-nested-i18n-setting
+ "Public setting whose value nests a deferred-tru, the way driver connection properties do."
+ :encryption :no
+ :visibility :public
+ :setter :none
+ :getter (fn [] {:display-name (deferred-tru "Host")})
+ :doc false)
+
(deftest translate-public-setting
- (mt/with-mock-i18n-bundles! {"zz" {:messages {"Host" "HOST"}}}
- (mt/with-user-locale "zz"
- (is (= "HOST"
- (str (get-in (setting/user-readable-values-map #{:public})
- [:engines :postgres :details-fields 0 :fields 0 :display-name])))))))
+ (testing "a deferred-tru nested inside a public setting's value is realized in the user's locale"
+ (mt/with-mock-i18n-bundles! {"zz" {:messages {"Host" "HOST"}}}
+ (mt/with-user-locale "zz"
+ (is (= "HOST"
+ (str (get-in (setting/user-readable-values-map #{:public})
+ [:test-nested-i18n-setting :display-name]))))))))
(deftest tru-translates
(mt/with-mock-i18n-bundles! {"zz" {:messages {"Host" "HOST"}}}