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
Show usage terms before enabling modular embedding from theme preview (#84151)
Sébastien88d8f7744806
diff --git a/e2e/test/scenarios/embedding/embedding-theme-editor/theme-editor.cy.spec.ts b/e2e/test/scenarios/embedding/embedding-theme-editor/theme-editor.cy.spec.tsindex 5dc45722246..431a5a974e6 100644--- a/e2e/test/scenarios/embedding/embedding-theme-editor/theme-editor.cy.spec.ts+++ b/e2e/test/scenarios/embedding/embedding-theme-editor/theme-editor.cy.spec.ts@@ -64,6 +64,7 @@ describe(it("loads the theme editor page and shows the theme name", () => {H.updateSetting("enable-embedding-modular", false);+ H.updateSetting("show-modular-embed-terms", false);createThemeViaApi("My custom theme").then((theme) => {visitThemeEditor(theme.id);@@ -316,6 +317,30 @@ describe(});});+ it("asks to accept the usage conditions before enabling embedding for the first time", () => {+ H.updateSetting("enable-embedding-modular", false);+ H.updateSetting("show-modular-embed-terms", true);++ createThemeViaApi("Preview test").then((theme) => {+ visitThemeEditor(theme.id);+ });++ H.main()+ .findByText(/enable modular embedding and agree to the/)+ .should("be.visible");++ H.main()+ .findByRole("button", { name: /Enable modular embedding/ })+ .click();++ H.modal()+ .findByText("Each end user needs their own Metabase account")+ .should("be.visible");+ cy.findByRole("button", { name: "Agree" }).click();++ H.main().findByText("Theme preview").should("be.visible");+ });+describe("preview picker", () => {beforeEach(() => {H.updateSetting("enable-embedding-modular", true);diff --git a/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.tsx b/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.tsxindex 98f503003aa..ec30e24566a 100644--- a/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.tsx+++ b/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.tsx@@ -1,5 +1,7 @@+import { useDisclosure } from "@mantine/hooks";import { c, t } from "ttag";+import { EmbeddingLegaleseModal } from "metabase/embedding/settings/EmbeddingLegaleseModal";import { useUpdateSettingsMutation } from "metabase/settings";import { Anchor, Button, Center, Stack, Text } from "metabase/ui";@@ -13,12 +15,18 @@ export function EnableEmbeddingPrompt({isTermsAccepted,}: EnableEmbeddingPromptProps) {const [updateSettings] = useUpdateSettingsMutation();+ const [+ isLegaleseModalOpen,+ { open: openLegaleseModal, close: closeLegaleseModal },+ ] = useDisclosure(false);- const handleEnable = async () => {- await updateSettings({- "enable-embedding-modular": true,- ...(!isTermsAccepted && { "show-modular-embed-terms": false }),- });+ const handleClick = async () => {+ if (!isTermsAccepted) {+ openLegaleseModal();+ return;+ }++ await updateSettings({ "enable-embedding-modular": true });};const usageConditionsLink = (@@ -31,14 +39,11 @@ export function EnableEmbeddingPrompt({</Anchor>);- const message = !isEnabled- ? c(- "Prompt to enable modular embedding to see a live preview of an embedding theme.",- ).t`Enable modular embedding to see a live preview of your theme.`- : c(- "{0} is a link to the embedding conditions, for users to accept them and see a live preview of their theme.",- )- .jt`Accept the ${usageConditionsLink} to see a live preview of your theme.`;+ const message = getMessage({+ isEnabled,+ isTermsAccepted,+ usageConditionsLink,+ });const buttonLabel = !isEnabled? t`Enable modular embedding`@@ -50,10 +55,41 @@ export function EnableEmbeddingPrompt({<Text ta="center" c="text-secondary">{message}</Text>- <Button variant="filled" onClick={handleEnable}>+ <Button variant="filled" onClick={handleClick}>{buttonLabel}</Button></Stack>+ {!isTermsAccepted && (+ <EmbeddingLegaleseModal+ opened={isLegaleseModalOpen}+ onClose={closeLegaleseModal}+ settingKey="enable-embedding-modular"+ />+ )}</Center>);}++function getMessage({+ isEnabled,+ isTermsAccepted,+ usageConditionsLink,+}: EnableEmbeddingPromptProps & { usageConditionsLink: JSX.Element }) {+ if (isEnabled) {+ return c(+ "{0} is a link to the embedding conditions, for users to accept them and see a live preview of their theme.",+ )+ .jt`Accept the ${usageConditionsLink} to see a live preview of your theme.`;+ }++ if (!isTermsAccepted) {+ return c(+ "{0} is a link to the embedding conditions, for users to accept them and enable modular embedding to see a live preview of their theme.",+ )+ .jt`To see a live preview of your theme, enable modular embedding and agree to the ${usageConditionsLink}.`;+ }++ return c(+ "Prompt to enable modular embedding to see a live preview of an embedding theme.",+ ).t`Enable modular embedding to see a live preview of your theme.`;+}diff --git a/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.unit.spec.tsx b/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.unit.spec.tsxindex 0e867fa8530..f2f50f7b76f 100644--- a/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.unit.spec.tsx+++ b/frontend/src/metabase/embedding/themes/components/ThemeEditor/EnableEmbeddingPrompt.unit.spec.tsx@@ -1,14 +1,26 @@+import userEvent from "@testing-library/user-event";++import {+ findRequests,+ setupPropertiesEndpoints,+ setupSettingsEndpoints,+ setupUpdateSettingsEndpoint,+} from "__support__/server-mocks";import { renderWithProviders, screen } from "__support__/ui";+import { createMockSettings } from "metabase-types/api/mocks";import { EnableEmbeddingPrompt } from "./EnableEmbeddingPrompt";-const setup = ({- isEnabled,- isTermsAccepted,-}: {+interface SetupOpts {isEnabled: boolean;isTermsAccepted: boolean;-}) => {+}++const setup = ({ isEnabled, isTermsAccepted }: SetupOpts) => {+ setupPropertiesEndpoints(createMockSettings());+ setupSettingsEndpoints([]);+ setupUpdateSettingsEndpoint();+renderWithProviders(<EnableEmbeddingPromptisEnabled={isEnabled}@@ -18,8 +30,8 @@ const setup = ({};describe("EnableEmbeddingPrompt", () => {- it("prompts to enable modular embedding when it is disabled", () => {- setup({ isEnabled: false, isTermsAccepted: false });+ it("enables modular embedding right away when the terms are already accepted", async () => {+ setup({ isEnabled: false, isTermsAccepted: true });expect(screen.getByText(@@ -27,22 +39,53 @@ describe("EnableEmbeddingPrompt", () => {),).toBeInTheDocument();expect(+ screen.queryByRole("link", { name: "usage conditions" }),+ ).not.toBeInTheDocument();++ await userEvent.click(screen.getByRole("button", { name: "Enable modular embedding" }),+ );++ const puts = await findRequests("PUT");+ expect(puts).toHaveLength(1);+ expect(puts[0].body).toEqual({ "enable-embedding-modular": true });+ });++ it("shows the usage conditions before enabling modular embedding for the first time", async () => {+ setup({ isEnabled: false, isTermsAccepted: false });++ expect(+ screen.getByText(/enable modular embedding and agree to the/),).toBeInTheDocument();expect(- screen.queryByRole("link", { name: "usage conditions" }),- ).not.toBeInTheDocument();+ screen.getByRole("link", { name: "usage conditions" }),+ ).toHaveAttribute("href", "https://metabase.com/license/embedding");++ await userEvent.click(+ screen.getByRole("button", { name: "Enable modular embedding" }),+ );++ expect(+ await screen.findByText("Each end user needs their own Metabase account"),+ ).toBeInTheDocument();+ expect(await findRequests("PUT")).toHaveLength(0);++ await userEvent.click(screen.getByRole("button", { name: "Agree" }));++ const puts = await findRequests("PUT");+ expect(puts).toHaveLength(1);+ expect(puts[0].body).toEqual({+ "enable-embedding-modular": true,+ "show-modular-embed-terms": false,+ });});- it("links to the usage conditions when only the terms are pending", () => {+ it("links to the usage conditions when only the terms are pending", async () => {setup({ isEnabled: true, isTermsAccepted: false });expect(screen.getByText(/to see a live preview of your theme\./),).toBeInTheDocument();- expect(- screen.getByRole("button", { name: "Accept and continue" }),- ).toBeInTheDocument();const link = screen.getByRole("link", { name: "usage conditions" });expect(link).toHaveAttribute(@@ -50,5 +93,14 @@ describe("EnableEmbeddingPrompt", () => {"https://metabase.com/license/embedding",);expect(link).toHaveAttribute("target", "_blank");++ await userEvent.click(+ screen.getByRole("button", { name: "Accept and continue" }),+ );++ expect(+ await screen.findByText("Each end user needs their own Metabase account"),+ ).toBeInTheDocument();+ expect(await findRequests("PUT")).toHaveLength(0);});});