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
feat(sdk): Add "start new conversation" button for MetabotQuestion and adjust its visuals (#63211)
Timofey Kachalov48971b48eb1a
diff --git a/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsxindex 82ea3d44488..d6abb4e1710 100644--- a/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx@@ -115,6 +115,32 @@ describe("scenarios > embedding-sdk > metabot-question", () => {});});+ it("should start a new conversation when clicking a `start new conversation` button", () => {+ setup(metabotResponse);++ mountSdkContent(<MetabotQuestion />);++ getSdkRoot().within(() => {+ cy.findByTestId("metabot-chat-input").type("Show orders {enter}");++ H.mockMetabotResponse({+ statusCode: 200,+ body: metabotRetryResponse,+ });++ cy.findAllByTestId("metabot-chat-message").should("have.length", 2);++ cy.findByTestId("metabot-new-conversation").click();++ cy.findAllByTestId("metabot-chat-message").should("not.exist");+ cy.findByTestId("metabot-chat-input").should("have.value", "");++ cy.findByTestId("metabot-chat-input").type("Show orders {enter}");++ cy.findAllByTestId("metabot-chat-message").should("have.length", 2);+ });+ });+it("should set correct metabot_id both for the a new message and when retrying", () => {setup(metabotResponse);diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsxindex 0af0756ff3a..4dce36a4d8f 100644--- a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx@@ -30,10 +30,6 @@ describe({ numTestsKeptInMemory: 1 },() => {beforeEach(() => {- cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(- "dashcardQuery",- );-signInAsAdminAndEnableEmbeddingSdk();cy.signOut();@@ -199,6 +195,13 @@ describe(it("should show a custom loader when the SDK bundle is loading", () => {sdkBundleCleanup();+ cy.intercept("GET", "/api/card/*", (request) => {+ // Delay request for 500ms to avoid flakiness+ request.continue(+ () => new Promise((resolve) => setTimeout(resolve, 500)),+ );+ });+mountSdkContent(<InteractiveQuestion questionId={ORDERS_QUESTION_ID} />,{diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.module.css b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.module.cssindex 4c836fbe7f2..479b82e2d6b 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.module.css+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.module.css@@ -18,7 +18,7 @@position: relative;max-width: 41.5rem;width: 100%;- box-shadow: 0 2px 13.8px -1px #1871bf52;+ border: 1px solid var(--mb-color-brand);border-radius: 22px;}diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.tsxindex b58ea1d0f8a..1ee173f2d1c 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatEmbedding.tsx@@ -1,5 +1,5 @@import cx from "classnames";-import { useCallback, useEffect, useState } from "react";+import { useEffect, useState } from "react";import { t } from "ttag";import { useSdkDispatch } from "embedding-sdk-bundle/store";@@ -12,7 +12,6 @@ import {Tooltip,UnstyledButton,} from "metabase/ui";-import { MetabotIcon } from "metabase-enterprise/metabot/components/MetabotIcon";import {useMetabotAgent,useMetabotChatHandlers,@@ -30,10 +29,15 @@ export const MetabotChatEmbedding = () => {const metabot = useMetabotAgent();const { handleSubmitInput, handleResetInput } = useMetabotChatHandlers();- const resetInput = useCallback(() => {+ const resetInput = () => {handleResetInput();setInputExpanded(false);- }, [handleResetInput]);+ };++ const startNewConversation = () => {+ resetInput();+ metabot.resetConversation();+ };const [inputExpanded, setInputExpanded] = useState(false);const handleMaybeExpandInput = () => {@@ -66,6 +70,9 @@ export const MetabotChatEmbedding = () => {dispatch(resetConversationId());}, [dispatch]);+ const isOngoingConversation = metabot.messages.length > 0;+ const isPromptDefined = metabot.prompt.length > 0;+return (<Box className={Styles.container} data-testid="metabot-chat"><Flex@@ -74,20 +81,20 @@ export const MetabotChatEmbedding = () => {metabot.isDoingScience && Styles.innerContainerLoading,inputExpanded && Styles.innerContainerExpanded,)}- gap="sm"><Flex- w="33px"- h="24px"+ w="16px"+ h="16px"style={{flexShrink: 0,}}justify="center"+ align="center">{metabot.isDoingScience ? (<Loader size="sm" />) : (- <MetabotIcon isLoading={false} />+ <Icon name="ai" c="var(--mb-color-brand)" size="1rem" />)}</Flex><Textarea@@ -123,7 +130,7 @@ export const MetabotChatEmbedding = () => {}}}/>- {metabot.isDoingScience ? (+ {metabot.isDoingScience && (<UnstyledButtonh="1rem"data-testid="metabot-cancel-request"@@ -133,17 +140,40 @@ export const MetabotChatEmbedding = () => {<Icon name="stop" c="var(--mb-color-text-primary)" size="1rem" /></Tooltip></UnstyledButton>- ) : (- <UnstyledButton- h="1rem"- onClick={resetInput}- data-testid="metabot-close-chat"- style={{- visibility: metabot.prompt.length > 0 ? "visible" : "hidden",- }}- >- <Icon name="close" c="var(--mb-color-text-primary)" size="1rem" />- </UnstyledButton>+ )}++ {!metabot.isDoingScience && (+ <>+ {isOngoingConversation && !isPromptDefined && (+ <UnstyledButton+ h="1rem"+ onClick={startNewConversation}+ data-testid="metabot-new-conversation"+ >+ <Tooltip label={t`Start new chat`}>+ <Icon+ name="edit_document_outlined"+ c="var(--mb-color-text-primary)"+ size="1rem"+ />+ </Tooltip>+ </UnstyledButton>+ )}++ {isPromptDefined && (+ <UnstyledButton+ h="1rem"+ onClick={resetInput}+ data-testid="metabot-close-chat"+ >+ <Icon+ name="close"+ c="var(--mb-color-text-primary)"+ size="1rem"+ />+ </UnstyledButton>+ )}+ </>)}</Flex></Box>diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.module.css b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.module.cssdeleted file mode 100644index 3c88b10ffbf..00000000000--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.module.css+++ /dev/null@@ -1,33 +0,0 @@-.dot {- transition: all 200ms ease;-}--@keyframes fade-in-out {- 0% {- opacity: 0;- }-- 50% {- opacity: 1;- }-- 100% {- opacity: 0;- }-}--.dotLoading {- animation: fade-in-out 1800ms infinite linear alternate;-}--.dotOneLoading {- animation-delay: 0ms;-}--.dotTwoLoading {- animation-delay: 600ms;-}--.dotThreeLoading {- animation-delay: -600ms;-}diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.tsxdeleted file mode 100644index 62d2a91d444..00000000000--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/MetabotIcon.tsx+++ /dev/null@@ -1,116 +0,0 @@-import cx from "classnames";--import Styles from "./MetabotIcon.module.css";--const COLORS = {- brand: "var(--mb-color-brand)",- brandLighter: "var(--mb-color-brand-lighter)",- focus: "var(--mb-color-focus)",- summarize: "var(--mb-color-summarize)",-};--export const MetabotIcon = ({ isLoading }: { isLoading: boolean }) => {- const dotsStrokeColor = isLoading ? COLORS.summarize : COLORS.brand;- const dotsFillColor = isLoading ? COLORS.summarize : COLORS.focus;-- return (- <svg- width="33"- height="24"- viewBox="0 0 33 24"- fill="none"- xmlns="http://www.w3.org/2000/svg"- >- <rect- x="0.75"- y="0.75"- width="30.8721"- height="22.5"- rx="3.25"- fill={COLORS.focus}- stroke={COLORS.brand}- strokeWidth="1.5"- />- <rect- x="3.90698"- y="3.34961"- width="24.5581"- height="14.5116"- rx="2"- fill={COLORS.brandLighter}- stroke={COLORS.brand}- strokeWidth="1.5"- />- {isLoading && (- <>- <path- fillRule="evenodd"- clipRule="evenodd"- d="M18 13H15V12H18V13Z"- fill={COLORS.brand}- />- <path- d="M10 8.5C10 9 10.8 10 12 10C13.2 10 13.8333 9 14 8.5"- stroke={COLORS.brand}- />- <path- d="M19 8.5C19 9 19.8 10 21 10C22.2 10 22.8333 9 23 8.5"- stroke={COLORS.brand}- />- </>- )}- {!isLoading && (- <>- <path- d="M17.3023 11.4414H17.8605C17.8605 12.4289 17.2754 13.1158 16.186 13.1158C15.0967 13.1158 14.5116 12.4289 14.5116 11.4414H15.0698C15.0698 11.9995 15.3488 12.5577 16.186 12.5577C17.0233 12.5577 17.3023 11.9995 17.3023 11.4414Z"- fill={COLORS.brand}- />- <circle cx="11.5814" cy="8.7912" r="0.976744" fill={COLORS.brand} />- <ellipse- cx="20.5117"- cy="8.7912"- rx="0.976745"- ry="0.976744"- fill={COLORS.brand}- />- </>- )}- {/* dots */}- {isLoading && (- <circle- cx="21.1163"- cy="20.6509"- r="1.11628"- fill={dotsFillColor}- className={cx(- Styles.dot,- isLoading && Styles.dotLoading,- isLoading && Styles.dotOneLoading,- )}- />- )}- <path- d="M27.9651 20.6514C27.9651 20.9918 27.6892 21.2677 27.3488 21.2677C27.0085 21.2677 26.7325 20.9918 26.7325 20.6514C26.7325 20.3111 27.0085 20.0352 27.3488 20.0352C27.6892 20.0352 27.9651 20.3111 27.9651 20.6514Z"- fill={dotsFillColor}- stroke={dotsStrokeColor}- className={cx(- Styles.dot,- isLoading && Styles.dotLoading,- isLoading && Styles.dotTwoLoading,- )}- />- <circle- cx="24.2791"- cy="20.6514"- r="0.61628"- fill={dotsFillColor}- stroke={dotsStrokeColor}- className={cx(- Styles.dot,- isLoading && Styles.dotLoading,- isLoading && Styles.dotThreeLoading,- )}- />- </svg>- );-};diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/index.ts b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/index.tsdeleted file mode 100644index b874722c8e3..00000000000--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotIcon/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./MetabotIcon";diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/edit_document_outlined.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/edit_document_outlined.svgnew file mode 100644index 00000000000..20670b6917c--- /dev/null+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/edit_document_outlined.svg@@ -0,0 +1,4 @@+<svg viewBox="0 0 16 16" fill="transparent" xmlns="http://www.w3.org/2000/svg">+ <path d="M8 2H3.33333C2.97971 2 2.64057 2.14048 2.39052 2.39052C2.14048 2.64057 2 2.97971 2 3.33333V12.6667C2 13.0203 2.14048 13.3594 2.39052 13.6095C2.64057 13.8595 2.97971 14 3.33333 14H12.6667C13.0203 14 13.3594 13.8595 13.6095 13.6095C13.8595 13.3594 14 13.0203 14 12.6667V8" stroke="currentColor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M12.2514 1.75015C12.5166 1.48493 12.8763 1.33594 13.2514 1.33594C13.6264 1.33594 13.9861 1.48493 14.2514 1.75015C14.5166 2.01537 14.6656 2.37508 14.6656 2.75015C14.6656 3.12522 14.5166 3.48493 14.2514 3.75015L8.2427 9.75948C8.0844 9.91765 7.88883 10.0334 7.67403 10.0962L5.7587 10.6562C5.70133 10.6729 5.64052 10.6739 5.58264 10.6591C5.52475 10.6442 5.47192 10.6141 5.42966 10.5719C5.38741 10.5296 5.35729 10.4768 5.34246 10.4189C5.32763 10.361 5.32863 10.3002 5.34536 10.2428L5.90536 8.32748C5.96838 8.11285 6.08439 7.91752 6.2427 7.75948L12.2514 1.75015Z" stroke="currentColor" stroke-linejoin="round"/>+</svg>diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts b/frontend/src/metabase/ui/components/icons/Icon/icons/index.tsindex 262af47f734..8c90c8f7104 100644--- a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts@@ -128,6 +128,8 @@ import dyno_component from "./dyno.svg?component";import dyno_source from "./dyno.svg?source";import edit_document_component from "./edit_document.svg?component";import edit_document_source from "./edit_document.svg?source";+import edit_document_outlined_component from "./edit_document_outlined.svg?component";+import edit_document_outlined_source from "./edit_document_outlined.svg?source";import ellipsis_component from "./ellipsis.svg?component";import ellipsis_source from "./ellipsis.svg?source";import embed_component from "./embed.svg?component";@@ -713,6 +715,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =component: edit_document_component,source: edit_document_source,},+ edit_document_outlined: {+ component: edit_document_outlined_component,+ source: edit_document_outlined_source,+ },ellipsis: {component: ellipsis_component,source: ellipsis_source,@@ -1476,6 +1482,7 @@ export type IconName =| "download"| "dyno"| "edit_document"+ | "edit_document_outlined"| "ellipsis"| "embed"| "empty"