The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Hide Metabot logo on AI exploration page when illustrations are disabled (#73464)
Andrei Chernykha40cbe873c84
diff --git a/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.css b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.cssindex 419c7f1bb55..7f96e10dc62 100644--- a/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.css+++ b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.css@@ -77,10 +77,7 @@}.sendButton {- width: 2rem;- height: 2rem;- padding: 0;- min-width: unset;+ color: var(--mb-color-background-primary);&:disabled,&:disabled:hover {diff --git a/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsx b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsxindex f7144439e5e..6462eab037d 100644--- a/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsx+++ b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsx@@ -8,13 +8,14 @@ import _ from "underscore";import { useGetSuggestedMetabotPromptsQuery } from "metabase/api";import { MetabotLogo } from "metabase/common/components/MetabotLogo";+import { useSetting } from "metabase/common/hooks";import { MetabotPromptInput } from "metabase/metabot/components/MetabotPromptInput";import { QueryBuilder } from "metabase/query_builder/containers/QueryBuilder";import { useDispatch } from "metabase/redux";import { useRouter } from "metabase/router";import {+ ActionIcon,Box,- Button,Icon,Paper,Stack,@@ -70,6 +71,7 @@ const MetabotQueryBuilderInner = () => {const [title] = useState(getTitleText);const [hasError, setHasError] = useState(false);+ const showIllustrations = useSetting("metabot-show-illustrations");const suggestedPromptsReq = useGetSuggestedMetabotPromptsQuery({metabot_id: metabotId,@@ -169,7 +171,7 @@ const MetabotQueryBuilderInner = () => {<Box className={S.page}><Box className={S.centeredContainer}><Box className={S.greeting}>- <MetabotLogo className={S.greetingIcon} />+ {showIllustrations && <MetabotLogo className={S.greetingIcon} />}<Text fz={{ base: "xl", sm: 32 }} fw={600} c="text-primary">{title}</Text>@@ -205,16 +207,18 @@ const MetabotQueryBuilderInner = () => {) : (<div />)}- <Button+ <ActionIconclassName={S.sendButton}variant="filled"+ size="2rem"disabled={inputDisabled}loading={isDoingScience}onClick={handleEditorSubmit}data-testid="metabot-send-message"+ aria-label={t`Send`}><Icon name="arrow_up" />- </Button>+ </ActionIcon></Box></Paper>diff --git a/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.unit.spec.tsxnew file mode 100644index 00000000000..b8283767ea9--- /dev/null+++ b/frontend/src/metabase/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.unit.spec.tsx@@ -0,0 +1,106 @@+import type { ComponentType } from "react";+import { Route } from "react-router";++import { mockSettings } from "__support__/settings";+import { renderWithProviders, screen } from "__support__/ui";+import { useGetSuggestedMetabotPromptsQuery } from "metabase/api";+import {+ useMetabotAgent,+ useUserMetabotPermissions,+} from "metabase/metabot/hooks";+import { createMockState } from "metabase/redux/store/mocks";++import { MetabotQueryBuilder } from "./MetabotQueryBuilder";++jest.mock("metabase/api", () => ({+ ...jest.requireActual("metabase/api"),+ useGetSuggestedMetabotPromptsQuery: jest.fn(),+}));++jest.mock("metabase/metabot/hooks", () => ({+ ...jest.requireActual("metabase/metabot/hooks"),+ useMetabotAgent: jest.fn(),+ useUserMetabotPermissions: jest.fn(),+}));++// Hide the QueryBuilder prop type the wrapper inherits — it's irrelevant+// since the canUseNlq path renders the inner component with no props.+const TestSubject = MetabotQueryBuilder as ComponentType;++type SetupOptions = {+ showIllustrations?: boolean;+ prompt?: string;+ suggestedPrompts?: { prompt: string }[];+};++function setup({+ showIllustrations = true,+ prompt = "",+ suggestedPrompts = [],+}: SetupOptions = {}) {+ jest.mocked(useUserMetabotPermissions).mockReturnValue({+ canUseNlq: true,+ } as any);+ jest.mocked(useMetabotAgent).mockReturnValue({+ setVisible: jest.fn(),+ resetConversation: jest.fn(),+ submitInput: jest.fn(),+ cancelRequest: jest.fn(),+ setPrompt: jest.fn(),+ metabotId: "default",+ isDoingScience: false,+ prompt,+ promptInputRef: { current: null },+ } as any);+ jest.mocked(useGetSuggestedMetabotPromptsQuery).mockReturnValue({+ currentData: { prompts: suggestedPrompts },+ } as any);++ const settings = mockSettings({+ "metabot-show-illustrations": showIllustrations,+ });++ return renderWithProviders(<Route path="/" component={TestSubject} />, {+ withRouter: true,+ storeInitialState: createMockState({ settings }),+ });+}++describe("MetabotQueryBuilder", () => {+ beforeEach(() => {+ jest.clearAllMocks();+ });++ it("renders the Metabot illustration when metabot-show-illustrations is true", () => {+ setup({ showIllustrations: true });+ expect(screen.getByRole("img", { name: "Metabot" })).toBeInTheDocument();+ });++ it("hides the Metabot illustration when metabot-show-illustrations is false", () => {+ setup({ showIllustrations: false });+ expect(+ screen.queryByRole("img", { name: "Metabot" }),+ ).not.toBeInTheDocument();+ });++ it("renders suggested prompts when the API returns them", () => {+ setup({+ suggestedPrompts: [+ { prompt: "Show me top customers" },+ { prompt: "How many orders this month?" },+ ],+ });+ expect(screen.getByText("Show me top customers")).toBeInTheDocument();+ expect(screen.getByText("How many orders this month?")).toBeInTheDocument();+ });++ it("disables the send button when the prompt is empty", () => {+ setup({ prompt: "" });+ expect(screen.getByTestId("metabot-send-message")).toBeDisabled();+ });++ it("enables the send button when the prompt is non-empty", () => {+ setup({ prompt: "anything" });+ expect(screen.getByTestId("metabot-send-message")).toBeEnabled();+ });+});