Skip to content

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

[Metabot] Fix Admin AI sidebar disappearing (#71597)

Sloan Sparger686087f2ec2f
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminLayout.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminLayout.tsx
new file mode 100644
index 00000000000..9aef486cc79
--- /dev/null
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminLayout.tsx
@@ -0,0 +1,14 @@
+import ErrorBoundary from "metabase/ErrorBoundary";
+import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";
+
+import { MetabotNavPane } from "./MetabotNavPane";
+
+export const MetabotAdminLayout = ({
+ children,
+}: {
+ children: React.ReactNode;
+}) => (
+ <AdminSettingsLayout sidebar={<MetabotNavPane />}>
+ <ErrorBoundary>{children}</ErrorBoundary>
+ </AdminSettingsLayout>
+);
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.tsx
index 9158015c608..281416c2fb4 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.tsx
@@ -1,364 +1,15 @@
-import { useDisclosure } from "@mantine/hooks";
-import { type ReactNode, useEffect, useMemo } from "react";
import { IndexRoute, Route } from "react-router";
-import { push } from "react-router-redux";
-import { P, match } from "ts-pattern";
-import { c, t } from "ttag";
-import _ from "underscore";
-import ErrorBoundary from "metabase/ErrorBoundary";
-import { SettingsSection } from "metabase/admin/components/SettingsSection";
-import { SettingHeader } from "metabase/admin/settings/components/SettingHeader";
-import {
- skipToken,
- useGetCollectionQuery,
- useListMetabotsQuery,
- useUpdateMetabotMutation,
-} from "metabase/api";
-import { useAdminSetting } from "metabase/api/utils/settings";
-import { canonicalCollectionId } from "metabase/collections/utils";
-import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { CollectionPickerModal } from "metabase/common/components/Pickers/CollectionPicker";
-import { useSetting, useToast } from "metabase/common/hooks";
-import { getIcon } from "metabase/lib/icon";
-import { useDispatch } from "metabase/lib/redux";
-import {
- FIXED_METABOT_ENTITY_IDS,
- FIXED_METABOT_IDS,
-} from "metabase/metabot/constants";
-import {
- PLUGIN_EMBEDDING_IFRAME_SDK,
- PLUGIN_EMBEDDING_SDK,
- PLUGIN_MODERATION,
-} from "metabase/plugins";
-import {
- Box,
- Button,
- Flex,
- Icon,
- Loader,
- Stack,
- Switch,
- Text,
-} from "metabase/ui";
-import type {
- Collection,
- CollectionEssentials,
- EnterpriseSettingKey,
- MetabotInfo,
-} from "metabase-types/api";
-
-import { MetabotPromptSuggestionPane } from "./MetabotAdminSuggestedPrompts";
-import { MetabotNavPane } from "./MetabotNavPane";
+import { MetabotAdminLayout } from "./MetabotAdminLayout";
+import { MetabotConfig } from "./MetabotConfig";
import { MetabotSetup } from "./MetabotSetup";
-import { useMetabotIdPath } from "./utils";
export function getAdminRoutes() {
return [
- <IndexRoute key="index" component={MetabotAdminPage} />,
- <Route key="setup" path="setup" component={MetabotSetup} />,
- <Route key="metabot" path=":metabotId" component={MetabotAdminPage} />,
+ <Route key="layout" component={MetabotAdminLayout}>
+ <IndexRoute key="index" component={MetabotConfig} />
+ <Route key="setup" path="setup" component={MetabotSetup} />
+ <Route key="metabot" path=":metabotId" component={MetabotConfig} />
+ </Route>,
];
}
-
-export function MetabotAdminPage() {
- const isConfigured = useSetting("llm-metabot-configured?");
-
- const metabotId = useMetabotIdPath() ?? FIXED_METABOT_IDS.DEFAULT;
- const { data, isLoading, error } = useListMetabotsQuery();
-
- const metabot = data?.items?.find((bot) => bot.id === metabotId);
-
- const dispatch = useDispatch();
-
- const hasEmbedding =
- PLUGIN_EMBEDDING_SDK.isEnabled() || PLUGIN_EMBEDDING_IFRAME_SDK.isEnabled();
-
- const metabots = useMemo(() => _.sortBy(data?.items ?? [], "id"), [data]);
-
- useEffect(() => {
- if (!isConfigured) {
- dispatch(push("/admin/metabot/setup"));
- }
- }, [isConfigured, dispatch]);
-
- useEffect(() => {
- if (metabotId === FIXED_METABOT_IDS.EMBEDDED && !hasEmbedding) {
- dispatch(push(`/admin/metabot/${FIXED_METABOT_IDS.DEFAULT}`));
- }
- }, [metabotId, hasEmbedding, dispatch]);
-
- useEffect(() => {
- if (!metabot && metabots.length) {
- dispatch(push(`/admin/metabot/${metabots[0]?.id}`));
- }
- }, [metabots, metabotId, dispatch, metabot, isLoading]);
-
- if (isLoading || !metabot || !isConfigured) {
- return (
- <LoadingAndErrorWrapper
- loading={isLoading || !data}
- error={match({ isLoading, error, metabot, isConfigured })
- .with(
- { isLoading: false, error: P.not(null), isConfigured: true },
- () => t`Error fetching Metabots`,
- )
- .with(
- { isLoading: false, metabot: undefined, isConfigured: true },
- () => t`Not found.`,
- )
- .otherwise(() => null)}
- />
- );
- }
-
- const isEmbedMetabot =
- metabot.entity_id === FIXED_METABOT_ENTITY_IDS.EMBEDDED;
-
- const enabledSettingKey: EnterpriseSettingKey = isEmbedMetabot
- ? "embedded-metabot-enabled?"
- : "metabot-enabled?";
-
- return (
- <AdminSettingsLayout sidebar={<MetabotNavPane />}>
- <ErrorBoundary>
- <SettingsSection key={metabotId}>
- <Box>
- <SettingHeader
- id="configure-metabot"
- title={c("{0} is the name of an AI assistant")
- .t`Configure ${metabot.name}`}
- description={c("{0} is the name of an AI assistant") // eslint-disable-next-line metabase/no-literal-metabase-strings -- admin ui
- .t`${metabot.name} is Metabase's AI agent. To help ${metabot.name} more easily find and focus on the data you care about most, configure what content it should be able to access or use to create queries.`}
- />
- {isEmbedMetabot && (
- <Text c="text-secondary" maw="40rem">
- {t`If you're embedding the Metabot component in an app, you can specify a different collection that embedded Metabot is allowed to use for creating queries.`}
- </Text>
- )}
- <MetabotEnabledToggle
- settingKey={enabledSettingKey}
- isEmbedMetabot={isEmbedMetabot}
- />
- </Box>
-
- <MetabotSettingsBody settingKey={enabledSettingKey}>
- <PLUGIN_MODERATION.MetabotVerifiedContentConfigurationPane
- metabot={metabot}
- />
-
- <MetabotCollectionConfigurationPane
- metabot={metabot}
- title={
- isEmbedMetabot
- ? undefined
- : t`Collection for natural language querying`
- }
- />
-
- <MetabotPromptSuggestionPane metabot={metabot} />
- </MetabotSettingsBody>
- </SettingsSection>
- </ErrorBoundary>
- </AdminSettingsLayout>
- );
-}
-
-function MetabotEnabledToggle({
- settingKey,
- isEmbedMetabot = false,
-}: {
- settingKey: EnterpriseSettingKey;
- isEmbedMetabot?: boolean;
-}) {
- const { value, updateSetting, isLoading } = useAdminSetting(settingKey);
-
- const handleToggle = async (checked: boolean) => {
- await updateSetting({ key: settingKey, value: checked });
- };
-
- return (
- <Box mt="lg">
- <SettingHeader
- id="enable-metabot"
- title={isEmbedMetabot ? t`Enable Embedded Metabot` : t`Enable Metabot`}
- description={
- isEmbedMetabot
- ? undefined
- : t`Metabot is Metabase's AI assistant. When enabled, Metabot will be available to help users create queries, analyze data, and answer questions about your data.` // eslint-disable-line metabase/no-literal-metabase-strings -- admin UI
- }
- />
- <Flex align="center" gap="md" mt="md">
- <Switch
- data-testid="metabot-enabled-toggle"
- checked={!!value}
- onChange={(e) => handleToggle(e.target.checked)}
- disabled={isLoading}
- w="auto"
- size="sm"
- />
- <Text c={value ? "text-primary" : "text-secondary"} fw="500">
- {isEmbedMetabot
- ? value
- ? t`Embedded Metabot is enabled`
- : t`Embedded Metabot is disabled`
- : value
- ? t`Metabot is enabled`
- : t`Metabot is disabled`}
- </Text>
- </Flex>
- </Box>
- );
-}
-
-function MetabotSettingsBody({
- settingKey,
- children,
-}: {
- settingKey: EnterpriseSettingKey;
- children: ReactNode;
-}) {
- const { value } = useAdminSetting(settingKey);
- const isDisabled = value === false;
-
- return (
- <Stack
- gap="lg"
- opacity={isDisabled ? 0.4 : 1}
- aria-disabled={isDisabled || undefined}
- style={{
- pointerEvents: isDisabled ? "none" : "auto",
- transition: "opacity 150ms ease",
- }}
- >
- {children}
- </Stack>
- );
-}
-
-function MetabotCollectionConfigurationPane({
- metabot,
- title,
-}: {
- metabot: MetabotInfo;
- title?: string;
-}) {
- const metabotId = metabot.id;
- const metabotName = metabot.name;
-
- const {
- data: collection,
- isLoading,
- error,
- } = useGetCollectionQuery({
- id: metabot.collection_id ?? "root",
- });
-
- const [updateMetabot, { isLoading: isUpdating }] = useUpdateMetabotMutation();
- const [isOpen, { open, close }] = useDisclosure(false);
- const [sendToast] = useToast();
-
- if (isLoading || !collection || error) {
- return (
- <LoadingAndErrorWrapper
- loading={isLoading}
- error={error ? t`Error fetching Metabot configuration` : null}
- />
- );
- }
-
- const handleUpdateCollectionId = async (
- newEntity: Pick<MetabotInfo, "id" | "name">,
- ) => {
- close();
- const result = await updateMetabot({
- id: metabotId,
- collection_id: canonicalCollectionId(newEntity.id),
- });
-
- if (result.error) {
- sendToast({
- message: t`Error setting ${newEntity.name}`,
- icon: "warning",
- });
- }
- };
-
- const defaultTitle = c("{0} is the name of an AI assistant")
- .t`Collection ${metabotName} can use`;
-
- return (
- <Box>
- <SettingHeader id="allow-metabot" title={title ?? defaultTitle} />
- <CollectionInfo collection={collection} />
- <Flex gap="md" mt="md">
- <Button onClick={open} leftSection={isUpdating && <Loader size="xs" />}>
- {match({ isMutating: isUpdating, collection })
- .with({ isMutating: true }, () => t`Updating collection...`)
- .with({ collection: undefined }, () => t`Pick a collection`)
- .otherwise(() => t`Pick a different collection`)}
- </Button>
- </Flex>
- {isOpen && (
- <CollectionPickerModal
- title={t`Select a collection`}
- value={{
- id: collection?.id ?? null,
- model: "collection",
- }}
- onChange={(item) =>
- handleUpdateCollectionId(item as Pick<MetabotInfo, "id" | "name">)
- }
- onClose={close}
- options={{
- hasRootCollection: true,
- hasPersonalCollections: false,
- }}
- />
- )}
- </Box>
- );
-}
-
-function CollectionInfo({ collection }: { collection: Collection }) {
- const { data: collectionInfo } = useGetCollectionQuery(
- collection?.id ? { id: collection.id } : skipToken,
- );
-
- if (!collection || !collectionInfo) {
- return null;
- }
-
- const parent = collectionInfo?.effective_ancestors?.slice(-1)?.[0];
-
- return (
- <Flex align="center" gap="sm" c="text-tertiary" mb="sm">
- {parent && (
- <>
- <CollectionDisplay collection={parent} />
- <Text c="text-tertiary" fw="bold">
- /
- </Text>
- </>
- )}
- <CollectionDisplay collection={collectionInfo} />
- </Flex>
- );
-}
-
-const CollectionDisplay = ({
- collection,
-}: {
- collection: CollectionEssentials;
-}) => {
- const icon = getIcon({ model: "collection", ...collection });
- return (
- <Flex align="center" gap="sm">
- <Icon {...icon} c={icon.color ?? "brand"} />
- <Text c="text-secondary" fw="bold">
- {collection.name}
- </Text>
- </Flex>
- );
-};
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.tsx
new file mode 100644
index 00000000000..5e6d5b904e8
--- /dev/null
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.tsx
@@ -0,0 +1,347 @@
+import { useDisclosure } from "@mantine/hooks";
+import { type ReactNode, useEffect, useMemo } from "react";
+import { push } from "react-router-redux";
+import { P, match } from "ts-pattern";
+import { c, t } from "ttag";
+import _ from "underscore";
+
+import { SettingsSection } from "metabase/admin/components/SettingsSection";
+import { SettingHeader } from "metabase/admin/settings/components/SettingHeader";
+import {
+ skipToken,
+ useGetCollectionQuery,
+ useListMetabotsQuery,
+ useUpdateMetabotMutation,
+} from "metabase/api";
+import { useAdminSetting } from "metabase/api/utils/settings";
+import { canonicalCollectionId } from "metabase/collections/utils";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
+import { CollectionPickerModal } from "metabase/common/components/Pickers/CollectionPicker";
+import { useSetting, useToast } from "metabase/common/hooks";
+import { getIcon } from "metabase/lib/icon";
+import { useDispatch } from "metabase/lib/redux";
+import {
+ FIXED_METABOT_ENTITY_IDS,
+ FIXED_METABOT_IDS,
+} from "metabase/metabot/constants";
+import {
+ PLUGIN_EMBEDDING_IFRAME_SDK,
+ PLUGIN_EMBEDDING_SDK,
+ PLUGIN_MODERATION,
+} from "metabase/plugins";
+import {
+ Box,
+ Button,
+ Flex,
+ Icon,
+ Loader,
+ Stack,
+ Switch,
+ Text,
+} from "metabase/ui";
+import type {
+ Collection,
+ CollectionEssentials,
+ EnterpriseSettingKey,
+ MetabotInfo,
+} from "metabase-types/api";
+
+import { MetabotPromptSuggestionPane } from "./MetabotAdminSuggestedPrompts";
+import { useMetabotIdPath } from "./utils";
+
+export function MetabotConfig() {
+ const isConfigured = useSetting("llm-metabot-configured?");
+
+ const metabotId = useMetabotIdPath() ?? FIXED_METABOT_IDS.DEFAULT;
+ const { data, isLoading, error } = useListMetabotsQuery();
+
+ const metabot = data?.items?.find((bot) => bot.id === metabotId);
+
+ const dispatch = useDispatch();
+
+ const hasEmbedding =
+ PLUGIN_EMBEDDING_SDK.isEnabled() || PLUGIN_EMBEDDING_IFRAME_SDK.isEnabled();
+
+ const metabots = useMemo(() => _.sortBy(data?.items ?? [], "id"), [data]);
+
+ useEffect(() => {
+ if (!isConfigured) {
+ dispatch(push("/admin/metabot/setup"));
+ }
+ }, [isConfigured, dispatch]);
+
+ useEffect(() => {
+ if (metabotId === FIXED_METABOT_IDS.EMBEDDED && !hasEmbedding) {
+ dispatch(push(`/admin/metabot/${FIXED_METABOT_IDS.DEFAULT}`));
+ }
+ }, [metabotId, hasEmbedding, dispatch]);
+
+ useEffect(() => {
+ if (!metabot && metabots.length) {
+ dispatch(push(`/admin/metabot/${metabots[0]?.id}`));
+ }
+ }, [metabots, metabotId, dispatch, metabot, isLoading]);
+
+ if (isLoading || !metabot || !isConfigured) {
+ return (
+ <LoadingAndErrorWrapper
+ loading={isLoading || !data}
+ error={match({ isLoading, error, metabot, isConfigured })
+ .with(
+ { isLoading: false, error: P.not(null), isConfigured: true },
+ () => t`Error fetching Metabots`,
+ )
+ .with(
+ { isLoading: false, metabot: undefined, isConfigured: true },
+ () => t`Not found.`,
+ )
+ .otherwise(() => null)}
+ />
+ );
+ }
+
+ const isEmbedMetabot =
+ metabot.entity_id === FIXED_METABOT_ENTITY_IDS.EMBEDDED;
+
+ const enabledSettingKey: EnterpriseSettingKey = isEmbedMetabot
+ ? "embedded-metabot-enabled?"
+ : "metabot-enabled?";
+
+ return (
+ <SettingsSection key={metabotId}>
+ <Box>
+ <SettingHeader
+ id="configure-metabot"
+ title={c("{0} is the name of an AI assistant")
+ .t`Configure ${metabot.name}`}
+ description={c("{0} is the name of an AI assistant") // eslint-disable-next-line metabase/no-literal-metabase-strings -- admin ui
+ .t`${metabot.name} is Metabase's AI agent. To help ${metabot.name} more easily find and focus on the data you care about most, configure what content it should be able to access or use to create queries.`}
+ />
+ {isEmbedMetabot && (
+ <Text c="text-secondary" maw="40rem">
+ {t`If you're embedding the Metabot component in an app, you can specify a different collection that embedded Metabot is allowed to use for creating queries.`}
+ </Text>
+ )}
+ <MetabotEnabledToggle
+ settingKey={enabledSettingKey}
+ isEmbedMetabot={isEmbedMetabot}
+ />
+ </Box>
+
+ <MetabotSettingsBody settingKey={enabledSettingKey}>
+ <PLUGIN_MODERATION.MetabotVerifiedContentConfigurationPane
+ metabot={metabot}
+ />
+
+ <MetabotCollectionConfigurationPane
+ metabot={metabot}
+ title={
+ isEmbedMetabot
+ ? undefined
+ : t`Collection for natural language querying`
+ }
+ />
+
+ <MetabotPromptSuggestionPane metabot={metabot} />
+ </MetabotSettingsBody>
+ </SettingsSection>
+ );
+}
+
+function MetabotEnabledToggle({
+ settingKey,
+ isEmbedMetabot = false,
+}: {
+ settingKey: EnterpriseSettingKey;
+ isEmbedMetabot?: boolean;
+}) {
+ const { value, updateSetting, isLoading } = useAdminSetting(settingKey);
+
+ const handleToggle = async (checked: boolean) => {
+ await updateSetting({ key: settingKey, value: checked });
+ };
+
+ return (
+ <Box mt="lg">
+ <SettingHeader
+ id="enable-metabot"
+ title={isEmbedMetabot ? t`Enable Embedded Metabot` : t`Enable Metabot`}
+ description={
+ isEmbedMetabot
+ ? undefined
+ : t`Metabot is Metabase's AI assistant. When enabled, Metabot will be available to help users create queries, analyze data, and answer questions about your data.` // eslint-disable-line metabase/no-literal-metabase-strings -- admin UI
+ }
+ />
+ <Flex align="center" gap="md" mt="md">
+ <Switch
+ data-testid="metabot-enabled-toggle"
+ checked={!!value}
+ onChange={(e) => handleToggle(e.target.checked)}
+ disabled={isLoading}
+ w="auto"
+ size="sm"
+ />
+ <Text c={value ? "text-primary" : "text-secondary"} fw="500">
+ {isEmbedMetabot
+ ? value
+ ? t`Embedded Metabot is enabled`
+ : t`Embedded Metabot is disabled`
+ : value
+ ? t`Metabot is enabled`
+ : t`Metabot is disabled`}
+ </Text>
+ </Flex>
+ </Box>
+ );
+}
+
+function MetabotSettingsBody({
+ settingKey,
+ children,
+}: {
+ settingKey: EnterpriseSettingKey;
+ children: ReactNode;
+}) {
+ const { value } = useAdminSetting(settingKey);
+ const isDisabled = value === false;
+
+ return (
+ <Stack
+ gap="lg"
+ opacity={isDisabled ? 0.4 : 1}
+ aria-disabled={isDisabled || undefined}
+ style={{
+ pointerEvents: isDisabled ? "none" : "auto",
+ transition: "opacity 150ms ease",
+ }}
+ >
+ {children}
+ </Stack>
+ );
+}
+
+function MetabotCollectionConfigurationPane({
+ metabot,
+ title,
+}: {
+ metabot: MetabotInfo;
+ title?: string;
+}) {
+ const metabotId = metabot.id;
+ const metabotName = metabot.name;
+
+ const {
+ data: collection,
+ isLoading,
+ error,
+ } = useGetCollectionQuery({
+ id: metabot.collection_id ?? "root",
+ });
+
+ const [updateMetabot, { isLoading: isUpdating }] = useUpdateMetabotMutation();
+ const [isOpen, { open, close }] = useDisclosure(false);
+ const [sendToast] = useToast();
+
+ if (isLoading || !collection || error) {
+ return (
+ <LoadingAndErrorWrapper
+ loading={isLoading}
+ error={error ? t`Error fetching Metabot configuration` : null}
+ />
+ );
+ }
+
+ const handleUpdateCollectionId = async (
+ newEntity: Pick<MetabotInfo, "id" | "name">,
+ ) => {
+ close();
+ const result = await updateMetabot({
+ id: metabotId,
+ collection_id: canonicalCollectionId(newEntity.id),
+ });
+
+ if (result.error) {
+ sendToast({
+ message: t`Error setting ${newEntity.name}`,
+ icon: "warning",
+ });
+ }
+ };
+
+ const defaultTitle = c("{0} is the name of an AI assistant")
+ .t`Collection ${metabotName} can use`;
+
+ return (
+ <Box>
+ <SettingHeader id="allow-metabot" title={title ?? defaultTitle} />
+ <CollectionInfo collection={collection} />
+ <Flex gap="md" mt="md">
+ <Button onClick={open} leftSection={isUpdating && <Loader size="xs" />}>
+ {match({ isMutating: isUpdating, collection })
+ .with({ isMutating: true }, () => t`Updating collection...`)
+ .with({ collection: undefined }, () => t`Pick a collection`)
+ .otherwise(() => t`Pick a different collection`)}
+ </Button>
+ </Flex>
+ {isOpen && (
+ <CollectionPickerModal
+ title={t`Select a collection`}
+ value={{
+ id: collection?.id ?? null,
+ model: "collection",
+ }}
+ onChange={(item) =>
+ handleUpdateCollectionId(item as Pick<MetabotInfo, "id" | "name">)
+ }
+ onClose={close}
+ options={{
+ hasRootCollection: true,
+ hasPersonalCollections: false,
+ }}
+ />
+ )}
+ </Box>
+ );
+}
+
+function CollectionInfo({ collection }: { collection: Collection }) {
+ const { data: collectionInfo } = useGetCollectionQuery(
+ collection?.id ? { id: collection.id } : skipToken,
+ );
+
+ if (!collection || !collectionInfo) {
+ return null;
+ }
+
+ const parent = collectionInfo?.effective_ancestors?.slice(-1)?.[0];
+
+ return (
+ <Flex align="center" gap="sm" c="text-tertiary" mb="sm">
+ {parent && (
+ <>
+ <CollectionDisplay collection={parent} />
+ <Text c="text-tertiary" fw="bold">
+ /
+ </Text>
+ </>
+ )}
+ <CollectionDisplay collection={collectionInfo} />
+ </Flex>
+ );
+}
+
+const CollectionDisplay = ({
+ collection,
+}: {
+ collection: CollectionEssentials;
+}) => {
+ const icon = getIcon({ model: "collection", ...collection });
+ return (
+ <Flex align="center" gap="sm">
+ <Icon {...icon} c={icon.color ?? "brand"} />
+ <Text c="text-secondary" fw="bold">
+ {collection.name}
+ </Text>
+ </Flex>
+ );
+};
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.unit.spec.tsx
similarity index 93%
rename from frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.unit.spec.tsx
rename to frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.unit.spec.tsx
index f656bf7a2e6..a01427e2e02 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotAdminPage.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotConfig.unit.spec.tsx
@@ -19,6 +19,7 @@ import {
} from "__support__/server-mocks/metabot";
import { mockSettings } from "__support__/settings";
import {
+ act,
mockGetBoundingClientRect,
renderWithProviders,
screen,
@@ -40,7 +41,7 @@ import {
} from "metabase-types/api/mocks";
import { createMockSettingsState } from "metabase-types/store/mocks";
-import { MetabotAdminPage } from "./MetabotAdminPage";
+import { MetabotConfig } from "./MetabotConfig";
import * as hooks from "./utils";
const mockPathParam = (id: MetabotId) => {
@@ -129,7 +130,7 @@ const setup = async (
);
const view = renderWithProviders(
- <Route path="/admin/metabot*" component={MetabotAdminPage} />,
+ <Route path="/admin/metabot*" component={MetabotConfig} />,
{
withRouter: true,
initialRoute: `/admin/metabot/${initialPathParam}`,
@@ -171,7 +172,7 @@ const setupContentVerificationPlugin = () => {
setupEnterprisePlugins();
};
-describe("MetabotAdminPage", () => {
+describe("MetabotConfig", () => {
afterEach(() => {
reinitialize();
});
@@ -225,19 +226,6 @@ describe("MetabotAdminPage", () => {
expect(call?.options?.body).toBe(JSON.stringify({ value: false }));
});
- it("should not show Embedded Metabot nav item without embedding features", async () => {
- await setup();
- expect(await screen.findByText("Metabot")).toBeInTheDocument();
- expect(screen.queryByText("Embedded Metabot")).not.toBeInTheDocument();
- });
-
- it("should show Embedded Metabot nav item with embedding features", async () => {
- setupEmbeddingPlugin();
- await setup();
- expect(await screen.findByText("Metabot")).toBeInTheDocument();
- expect(screen.getByText("Embedded Metabot")).toBeInTheDocument();
- });
-
it("should show collection picker for default metabot with NLQ title", async () => {
await setup();
expect(await screen.findByText("Configure Metabot")).toBeInTheDocument();
@@ -284,11 +272,13 @@ describe("MetabotAdminPage", () => {
it("should be able to switch between metabots", async () => {
setupEmbeddingPlugin();
- await setup(FIXED_METABOT_IDS.DEFAULT);
+ const { history } = await setup(FIXED_METABOT_IDS.DEFAULT);
expect(await screen.findByText("Configure Metabot")).toBeInTheDocument();
mockPathParam(FIXED_METABOT_IDS.EMBEDDED);
- await userEvent.click(await screen.findByText("Embedded Metabot"));
+ act(() => {
+ history?.push(`/admin/metabot/${FIXED_METABOT_IDS.EMBEDDED}`);
+ });
expect(await screen.findByText("Collection Two")).toBeInTheDocument();
});
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.tsx
index f29d245470c..53d933c3b91 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.tsx
@@ -14,7 +14,6 @@ import {
useAdminSetting,
useAdminSettings,
} from "metabase/api/utils";
-import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";
import { useSetting } from "metabase/common/hooks";
import {
Badge,
@@ -31,7 +30,6 @@ import type {
SettingDefinition,
} from "metabase-types/api";
-import { MetabotNavPane } from "./MetabotNavPane";
import { MetabotProviderApiKey } from "./MetabotProviderApiKey";
import {
API_KEY_SETTING_BY_PROVIDER,
@@ -132,102 +130,97 @@ export function MetabotSetup() {
(!hasConfiguredSettingValue(selectedApiKeySetting) || !!apiKeyError);
return (
- <AdminSettingsLayout sidebar={<MetabotNavPane />}>
- <SettingsSection
- title={
- <Flex justify="space-between" align="center">
- <div>{t`Connect to an AI provider`}</div>
- {isConnected ? (
- <Badge bg="success" variant="filled" size="sm">
- {t`Connected`}
- </Badge>
- ) : (
- <Badge
- bg="background-tertiary"
- c="text-tertiary"
- variant="filled"
- size="sm"
- >
- {t`Not connected`}
- </Badge>
- )}
- </Flex>
- }
- description={t`Select your AI provider and configure your API key to get started with Metabot.`}
- >
- <Stack gap="md">
- <Select
- label={t`Provider`}
- placeholder={t`Select a provider`}
- description={t`Choose your preferred AI provider.`}
- data={providerOptions}
- value={provider}
- onChange={handleProviderChange}
- disabled={isEnvSetting}
- renderOption={({ option }) => (
- <Group
- gap="xs"
- p="sm"
- justify="space-between"
- wrap="nowrap"
- w="100%"
- >
- <Text
- lh="1rem"
- c={option.disabled ? "text-tertiary" : undefined}
- >
- {option.label}
- </Text>
- {!isAvailableProvider(option.value as MetabotProvider) && (
- <Text c="text-tertiary" lh="1rem" size="sm">
- {t`Coming soon`}
- </Text>
- )}
- </Group>
- )}
- />
-
- {provider && isApiKeyMetabotProvider(provider) && (
- <MetabotProviderApiKey provider={provider} error={apiKeyError} />
+ <SettingsSection
+ title={
+ <Flex justify="space-between" align="center">
+ <div>{t`Connect to an AI provider`}</div>
+ {isConnected ? (
+ <Badge bg="success" variant="filled" size="sm">
+ {t`Connected`}
+ </Badge>
+ ) : (
+ <Badge
+ bg="background-tertiary"
+ c="text-tertiary"
+ variant="filled"
+ size="sm"
+ >
+ {t`Not connected`}
+ </Badge>
)}
-
- {!needsApiKey && (
- <Select
- label={t`Model`}
- placeholder={
- provider
- ? metabotSettingsQuery.isFetching
- ? t`Loading models...`
- : t`Select a model`
- : t`Select a provider first`
- }
- description={t`Available models are fetched from the selected provider using its configured API key.`}
- error={modelError}
- data={modelOptions}
- value={model}
- onChange={handleModelChange}
- disabled={isEnvSetting || needsApiKey}
- searchable
- nothingFoundMessage={t`No models found`}
- />
+ </Flex>
+ }
+ description={t`Select your AI provider and configure your API key to get started with Metabot.`}
+ >
+ <Stack gap="md">
+ <Select
+ label={t`Provider`}
+ placeholder={t`Select a provider`}
+ description={t`Choose your preferred AI provider.`}
+ data={providerOptions}
+ value={provider}
+ onChange={handleProviderChange}
+ disabled={isEnvSetting}
+ renderOption={({ option }) => (
+ <Group
+ gap="xs"
+ p="sm"
+ justify="space-between"
+ wrap="nowrap"
+ w="100%"
+ >
+ <Text lh="1rem" c={option.disabled ? "text-tertiary" : undefined}>
+ {option.label}
+ </Text>
+ {!isAvailableProvider(option.value as MetabotProvider) && (
+ <Text c="text-tertiary" lh="1rem" size="sm">
+ {t`Coming soon`}
+ </Text>
+ )}
+ </Group>
)}
+ />
- {envSettingName && <SetByEnvVar varName={envSettingName} />}
+ {provider && isApiKeyMetabotProvider(provider) && (
+ <MetabotProviderApiKey provider={provider} error={apiKeyError} />
+ )}
- {updateMetabotSettingsResult.isLoading && (
- <Text size="sm" c="text-secondary">
- {t`Saving provider settings...`}
- </Text>
- )}
-
- {saveError && (
- <Text size="sm" c="error">
- {saveError}
- </Text>
- )}
- </Stack>
- </SettingsSection>
- </AdminSettingsLayout>
+ {!needsApiKey && (
+ <Select
+ label={t`Model`}
+ placeholder={
+ provider
+ ? metabotSettingsQuery.isFetching
+ ? t`Loading models...`
+ : t`Select a model`
+ : t`Select a provider first`
+ }
+ description={t`Available models are fetched from the selected provider using its configured API key.`}
+ error={modelError}
+ data={modelOptions}
+ value={model}
+ onChange={handleModelChange}
+ disabled={isEnvSetting || needsApiKey}
+ searchable
+ nothingFoundMessage={t`No models found`}
+ />
+ )}
+
+ {envSettingName && <SetByEnvVar varName={envSettingName} />}
+
+ {updateMetabotSettingsResult.isLoading && (
+ <Text size="sm" c="text-secondary">
+ {t`Saving provider settings...`}
+ </Text>
+ )}
+
+ {saveError && (
+ <Text size="sm" c="error">
+ {saveError}
+ </Text>
+ )}
+ </Stack>
+ </SettingsSection>
);
}
diff --git a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.unit.spec.tsx
index c02ef0abffc..8faf88734b3 100644
--- a/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotAdmin/MetabotSetup.unit.spec.tsx
@@ -20,10 +20,6 @@ import { createMockSettingsState } from "metabase-types/store/mocks";
import { MetabotSetup } from "./MetabotSetup";
import type { MetabotApiKeyProvider } from "./utils";
-jest.mock("./MetabotNavPane", () => ({
- MetabotNavPane: () => <div>Metabot navigation</div>,
-}));
-
jest.mock("./MetabotProviderApiKey", () => ({
MetabotProviderApiKey: ({
provider,