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
fix(sdk-bundle): fallback and warn on invalid layout in MetabotQuestion (#64478)
Phoomparin Manoeae65a4980d6
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 f541d538521..007c091eabc 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@@ -239,6 +239,29 @@ describe("scenarios > embedding-sdk > metabot-question", () => {);});});++ it("should fallback to sidebar layout when invalid layout prop is provided and show a warning", () => {+ setup(metabotResponse);++ cy.window().then((win) => {+ cy.spy(win.console, "warn").as("consoleWarn");+ });++ mountSdkContent(<MetabotQuestion layout="foobar" />);++ getSdkRoot().within(() => {+ cy.findByTestId("metabot-question-container").should(+ "have.attr",+ "data-layout",+ "sidebar",+ );+ });++ cy.get("@consoleWarn").should(+ "have.been.calledWith",+ 'Invalid layout for MetabotQuestion: foobar. Valid values are "stacked", "sidebar", or "auto"',+ );+ });});const mockSuggestedPrompts = () => {diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsxindex a84598c813d..b5260eb95cb 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx@@ -1,6 +1,6 @@import { useElementSize } from "@mantine/hooks";import { useId, useMemo } from "react";-import { match } from "ts-pattern";+import { P, match } from "ts-pattern";import { FlexibleSizeComponent } from "embedding-sdk-bundle/components/private/FlexibleSizeComponent";import { withPublicComponentWrapper } from "embedding-sdk-bundle/components/private/PublicComponentWrapper";@@ -43,10 +43,18 @@ const MetabotQuestionInner = ({const derivedLayout = useMemo(() => {return match(layout)- .with("auto", () =>- containerWidth <= MAX_MOBILE_CONTAINER_WIDTH ? "stacked" : "sidebar",- )- .otherwise((layout) => layout);+ .with(P.union("stacked", "sidebar"), (layout) => layout)+ .otherwise((layout) => {+ if (layout !== "auto") {+ console.warn(+ `Invalid layout for MetabotQuestion: ${layout}. Valid values are "stacked", "sidebar", or "auto"`,+ );+ }++ return containerWidth <= MAX_MOBILE_CONTAINER_WIDTH+ ? "stacked"+ : "sidebar";+ });}, [layout, containerWidth]);function renderQuestion() {