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
Replace interactive embedding card in embed modal with embed flow (#63942)
Phoomparin Mano0bf1ac867f27
diff --git a/e2e/test/scenarios/sharing/public-sharing-embed-button-behavior.cy.spec.js b/e2e/test/scenarios/sharing/public-sharing-embed-button-behavior.cy.spec.jsindex 07655d8d10e..ab1f6991131 100644--- a/e2e/test/scenarios/sharing/public-sharing-embed-button-behavior.cy.spec.js+++ b/e2e/test/scenarios/sharing/public-sharing-embed-button-behavior.cy.spec.js@@ -179,7 +179,7 @@ describe("embed modal display", () => {});describe("when the user has a paid instance", () => {- it("should display a disabled state and a link to the Interactive embedding settings", () => {+ it("should display a disabled state and a link to the Embedded Analytics JS settings", () => {H.activateToken("pro-self-hosted");H.visitDashboard("@dashboardId");@@ -187,14 +187,14 @@ describe("embed modal display", () => {H.getEmbedModalSharingPane().within(() => {cy.findByText("Static embedding").should("be.visible");- cy.findByText("Interactive embedding").should("be.visible");+ cy.findByText("Embedded Analytics JS").should("be.visible");- cy.findByRole("article", { name: "Interactive embedding" }).within(+ cy.findByRole("article", { name: "Embedded Analytics JS" }).within(() => {cy.findByText("Disabled.").should("be.visible");cy.findByText("Enable in admin settings").should("be.visible")- .and("have.attr", "href", "/admin/embedding/interactive");+ .and("have.attr", "href", "/admin/embedding/modular");},);});@@ -212,15 +212,15 @@ describe("embed modal display", () => {H.getEmbedModalSharingPane().within(() => {cy.findByText("Static embedding").should("be.visible");- cy.findByText("Interactive embedding").should("be.visible");+ cy.findByText("Embedded Analytics JS").should("be.visible");- cy.findByRole("link", { name: "Interactive embedding" }).should(+ cy.findByRole("link", { name: "Embedded Analytics JS" }).should("have.attr","href",- "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedding-interactive&utm_content=static-embed-popover&source_plan=oss",+ "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedded-analytics-js&utm_content=static-embed-popover&source_plan=oss",);- cy.findByRole("article", { name: "Interactive embedding" }).within(+ cy.findByRole("article", { name: "Embedded Analytics JS" }).within(() => {cy.findByText("Learn more").should("be.visible");cy.findByText("Disabled.").should("not.exist");diff --git a/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.ts b/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.tsnew file mode 100644index 00000000000..bd94921259f--- /dev/null+++ b/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.ts@@ -0,0 +1,73 @@+import {+ ORDERS_DASHBOARD_ID,+ ORDERS_QUESTION_ID,+} from "e2e/support/cypress_sample_instance_data";++import { getEmbedSidebar } from "../embedding/sdk-iframe-embedding-setup/helpers";++const { H } = cy;++describe("embed flow pre-selection from sharing modal", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ H.updateSetting("enable-embedding-simple", true);+ });++ it("pre-selects dashboard in embed flow when opened from dashboard sharing modal", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);+ H.openSharingMenu("Embed");++ H.getEmbedModalSharingPane().within(() => {+ cy.findByRole("link", { name: "Embedded Analytics JS" }).click();+ });++ cy.location("search").should((search) => {+ const params = new URLSearchParams(search);++ expect(params.get("resource_type")).to.equal("dashboard");+ expect(params.get("resource_id")).to.equal(String(ORDERS_DASHBOARD_ID));+ });++ cy.log("should navigate to embed options step");+ getEmbedSidebar().within(() => {+ cy.findByText("Behavior").should("be.visible");+ cy.findByText("Appearance").should("be.visible");+ });++ H.waitForSimpleEmbedIframesToLoad();++ H.getSimpleEmbedIframeContent()+ .findByText("Orders in a dashboard", { timeout: 10_000 })+ .should("be.visible");+ });++ it("pre-selects question in embed flow when opened from question sharing modal", () => {+ H.visitQuestion(ORDERS_QUESTION_ID);+ H.openSharingMenu("Embed");++ H.getEmbedModalSharingPane().within(() => {+ cy.findByRole("link", { name: "Embedded Analytics JS" }).click();+ });++ cy.location("search").should((search) => {+ const params = new URLSearchParams(search);++ expect(params.get("resource_type")).to.equal("question");+ expect(params.get("resource_id")).to.equal(String(ORDERS_QUESTION_ID));+ });++ cy.log("should navigate to embed options step");+ getEmbedSidebar().within(() => {+ cy.findByText("Behavior").should("be.visible");+ cy.findByText("Appearance").should("be.visible");+ });++ H.waitForSimpleEmbedIframesToLoad();++ H.getSimpleEmbedIframeContent()+ .findByText("Orders", { timeout: 10_000 })+ .should("be.visible");+ });+});diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/SdkIframeEmbedSetupProvider.tsx b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/SdkIframeEmbedSetupProvider.tsxindex ca5404572d8..b0a2f11b40c 100644--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/SdkIframeEmbedSetupProvider.tsx+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/SdkIframeEmbedSetupProvider.tsx@@ -6,7 +6,7 @@ import {useState,} from "react";import { useLocation } from "react-use";-import { match } from "ts-pattern";+import { P, match } from "ts-pattern";import _ from "underscore";import { useSearchQuery } from "metabase/api";@@ -60,21 +60,46 @@ export const SdkIframeEmbedSetupProvider = ({const modelCount = searchData?.total ?? 0;- // Embedding Hub: pre-specifies the auth method to use- const authMethodOverride = useMemo(() => {- return new URLSearchParams(location.search).get("auth_method");+ // EmbeddingHub passes `auth_method`.+ // EmbedContentModal passes `resource_type` and `resource_id`.+ const urlParams = useMemo(() => {+ const params = new URLSearchParams(location.search);++ return {+ authMethod: params.get("auth_method"),+ resourceType: params.get("resource_type"),+ resourceId: params.get("resource_id"),+ };}, [location.search]);const defaultSettings = useMemo(() => {- return getDefaultSdkIframeEmbedSettings(- "dashboard",- recentDashboards[0]?.id ?? EMBED_FALLBACK_DASHBOARD_ID,- );- }, [recentDashboards]);-- const [currentStep, setCurrentStep] = useState<SdkIframeEmbedSetupStep>(- "select-embed-experience",- );+ return match([urlParams.resourceType, urlParams.resourceId])+ .with(["dashboard", P.nonNullable], ([, id]) =>+ getDefaultSdkIframeEmbedSettings("dashboard", id),+ )+ .with(["question", P.nonNullable], ([, id]) =>+ getDefaultSdkIframeEmbedSettings("chart", id),+ )+ .otherwise(() =>+ getDefaultSdkIframeEmbedSettings(+ "dashboard",+ recentDashboards[0]?.id ?? EMBED_FALLBACK_DASHBOARD_ID,+ ),+ );+ }, [recentDashboards, urlParams]);++ // Default to the embed options step if both resource type and id are provided.+ // This is to skip the experience and resource selection steps as we know both.+ const defaultStep: SdkIframeEmbedSetupStep = useMemo(() => {+ if (urlParams.resourceType !== null && urlParams.resourceId !== null) {+ return "select-embed-options";+ }++ return "select-embed-experience";+ }, [urlParams]);++ const [currentStep, setCurrentStep] =+ useState<SdkIframeEmbedSetupStep>(defaultStep);const settings = useMemo(() => {const latestSettings = rawSettings ?? defaultSettings;@@ -176,8 +201,8 @@ export const SdkIframeEmbedSetupProvider = ({// Override the persisted settings if `auth_method` is specified.// This is used for Embedding Hub.- ...(authMethodOverride !== null && {- useExistingUserSession: authMethodOverride === "user_session",+ ...(urlParams.authMethod !== null && {+ useExistingUserSession: urlParams.authMethod === "user_session",}),});@@ -188,7 +213,7 @@ export const SdkIframeEmbedSetupProvider = ({isEmbedSettingsLoaded,settings,isRecentsLoading,- authMethodOverride,+ urlParams,]);return (diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsxindex b40b1345551..c1ef542ba40 100644--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx@@ -95,3 +95,24 @@ describe("Embed flow > forward and backward navigation", () => {expect(screen.getByRole("button", { name: "Back" })).toBeDisabled();});});++describe("Embed flow > pre-selection via url parameter", () => {+ it("pre-selects question when resource_type=question is in URL", async () => {+ setup({+ simpleEmbeddingEnabled: true,+ urlSearchParams: "?resource_type=question&resource_id=456",+ });++ // Starts at the "select embed options" step.+ expect(screen.getByText("Behavior")).toBeInTheDocument();+ expect(screen.getByText("Appearance")).toBeInTheDocument();++ // Going back to the "select resource" step shows that it is expecting a chart.+ await userEvent.click(screen.getByRole("button", { name: "Back" }));+ expect(screen.getByText("Select a chart to embed")).toBeInTheDocument();++ // Going back to the "select experience" step shows that it is expecting a chart.+ await userEvent.click(screen.getByRole("button", { name: "Back" }));+ expect(screen.getByRole("radio", { name: /Chart/ })).toBeChecked();+ });+});diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/test-setup.tsx b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/test-setup.tsxindex 81dcd20a8f7..f43f97df087 100644--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/test-setup.tsx+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/components/tests/test-setup.tsx@@ -14,15 +14,27 @@ import {import { SdkIframeEmbedSetup } from "../SdkIframeEmbedSetup";+const mockUseLocation = jest.fn();++jest.mock("react-use", () => ({+ ...jest.requireActual("react-use"),+ useLocation: () => mockUseLocation(),+}));+export const setup = (options?: {simpleEmbeddingEnabled?: boolean;jwtReady?: boolean;+ urlSearchParams?: string;}) => {setupRecentViewsAndSelectionsEndpoints([], ["selections", "views"]);setupDashboardEndpoints(createMockDashboard());setupUpdateSettingsEndpoint();setupUpdateSettingEndpoint();+ mockUseLocation.mockReturnValue({+ search: options?.urlSearchParams || "",+ });+renderWithProviders(<SdkIframeEmbedSetup />, {storeInitialState: createMockState({settings: createMockSettingsState({diff --git a/frontend/src/metabase/admin/upsells/UpsellSdkCta.tsx b/frontend/src/metabase/admin/upsells/UpsellEmbedJsCta.tsxsimilarity index 68%rename from frontend/src/metabase/admin/upsells/UpsellSdkCta.tsxrename to frontend/src/metabase/admin/upsells/UpsellEmbedJsCta.tsxindex 850a4ac5e49..616bc604817 100644--- a/frontend/src/metabase/admin/upsells/UpsellSdkCta.tsx+++ b/frontend/src/metabase/admin/upsells/UpsellEmbedJsCta.tsx@@ -1,21 +1,23 @@import { t } from "ttag";-import { useSelector } from "metabase/lib/redux";+import { useHasTokenFeature } from "metabase/common/hooks";import { isEEBuild } from "metabase/lib/utils";-import { PLUGIN_ADMIN_SETTINGS, PLUGIN_EMBEDDING } from "metabase/plugins";+import { PLUGIN_ADMIN_SETTINGS } from "metabase/plugins";import { Box } from "metabase/ui";import { UpsellCta } from "./components/UpsellCta";import { trackUpsellClicked } from "./components/analytics";import { useUpsellLink } from "./components/use-upsell-link";-export function useUpsellSdkCta() {- const campaign = "embedding-interactive";+export function useUpsellEmbedJsCta({+ embedFlowUrl,+}: {+ embedFlowUrl: string;+}) {+ const campaign = "embedded-analytics-js";const location = "static-embed-popover";- const isInteractiveEmbeddingEnabled = useSelector(- PLUGIN_EMBEDDING.isInteractiveEmbeddingEnabled,- );+ const isEmbedJsEnabled = useHasTokenFeature("embedding_simple");const { triggerUpsellFlow } = PLUGIN_ADMIN_SETTINGS.useUpsellFlow({campaign,@@ -30,10 +32,8 @@ export function useUpsellSdkCta() {location,});- if (isInteractiveEmbeddingEnabled) {- return {- internalLink: "/admin/embedding/interactive",- };+ if (isEmbedJsEnabled) {+ return { internalLink: embedFlowUrl };}return {@@ -43,9 +43,9 @@ export function useUpsellSdkCta() {};}-export function UpsellSdkCta() {+export function UpsellEmbedJsCta({ embedFlowUrl }: { embedFlowUrl: string }) {const { url, internalLink, triggerUpsellFlow, trackUpsell } =- useUpsellSdkCta();+ useUpsellEmbedJsCta({ embedFlowUrl });if (!isEEBuild()) {return null;diff --git a/frontend/src/metabase/public/components/EmbedModal/EmbedModal.tsx b/frontend/src/metabase/public/components/EmbedModal/EmbedModal.tsxindex 6b266396356..08d426aa883 100644--- a/frontend/src/metabase/public/components/EmbedModal/EmbedModal.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/EmbedModal.tsx@@ -1,11 +1,14 @@-import { useState } from "react";+import { useMemo, useState } from "react";+import { Link } from "react-router";import { t } from "ttag";import Modal from "metabase/common/components/Modal";+import CS from "metabase/css/core/index.css";import { useSelector } from "metabase/lib/redux";import type { EmbedModalStep } from "metabase/public/lib/types";import { getSetting } from "metabase/selectors/settings";import { getApplicationName } from "metabase/selectors/whitelabel";+import { Group, Icon, Stack, Text } from "metabase/ui";import { EmbedModalHeader } from "./EmbedModal.styled";@@ -49,11 +52,17 @@ export const EmbedModal = ({ children, isOpen, onClose }: EmbedModalProps) => {setEmbedType(null);};+ const modalTitle = useMemo(() => {+ if (isEmbeddingSetupStage) {+ return <EmbedModalTitle applicationName={applicationName} />;+ }+ }, [isEmbeddingSetupStage, applicationName]);+return (<ModalisOpen={isOpen}onClose={onEmbedClose}- title={isEmbeddingSetupStage ? t`Embed ${applicationName}` : undefined}+ title={modalTitle}fitformModal={false}// needed to allow selecting with the mouse on the code samples@@ -68,3 +77,16 @@ export const EmbedModal = ({ children, isOpen, onClose }: EmbedModalProps) => {</Modal>);};++const EmbedModalTitle = ({ applicationName }: { applicationName: string }) => (+ <Stack gap="sm">+ <Text fw="bold" fz="h2">{t`Embed ${applicationName}`}</Text>++ <Link to="/admin/embedding/modular" className={CS.link} target="_blank">+ <Group gap="xs">+ <Text c="brand">{t`Embedding settings`}</Text>+ <Icon c="brand" name="external" />+ </Group>+ </Link>+ </Stack>+);diff --git a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.common.unit.spec.tsx b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.common.unit.spec.tsxindex a0029c72f8a..baa499e142c 100644--- a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.common.unit.spec.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.common.unit.spec.tsx@@ -1,6 +1,8 @@import { screen, within } from "@testing-library/react";import userEvent from "@testing-library/user-event";+import { createMockTokenFeatures } from "metabase-types/api/mocks";+import { setup } from "./setup";describe("EmbedModalContent", () => {@@ -10,8 +12,8 @@ describe("EmbedModalContent", () => {setup();expect(screen.getByText("Static embedding")).toBeInTheDocument();- expect(screen.getByText("Interactive embedding")).toBeInTheDocument();- expect(screen.getByText("Embedded analytics SDK")).toBeInTheDocument();+ expect(screen.getByText("Embedded Analytics JS")).toBeInTheDocument();+ expect(screen.getByText("SDK for React")).toBeInTheDocument();});});@@ -71,7 +73,7 @@ describe("EmbedModalContent", () => {});describe("Interactive Embedding", () => {- const INTERACTIVE_EMBEDDING_TITLE = "Interactive embedding";+ const INTERACTIVE_EMBEDDING_TITLE = "Embedded Analytics JS";describe("when Interactive Embedding is disabled", () => {it("should mention Interactive Embedding and lead users to learn more link", () => {@@ -82,7 +84,7 @@ describe("EmbedModalContent", () => {screen.queryByRole("link", { name: INTERACTIVE_EMBEDDING_TITLE }),).toHaveProperty("href",- "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedding-interactive&utm_content=static-embed-popover&source_plan=oss",+ "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedded-analytics-js&utm_content=static-embed-popover&source_plan=oss",);// We show the learn more link@@ -116,7 +118,7 @@ describe("EmbedModalContent", () => {screen.queryByRole("link", { name: INTERACTIVE_EMBEDDING_TITLE }),).toHaveProperty("href",- "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedding-interactive&utm_content=static-embed-popover&source_plan=oss",+ "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedded-analytics-js&utm_content=static-embed-popover&source_plan=oss",);// We show the learn more link@@ -131,16 +133,17 @@ describe("EmbedModalContent", () => {});describe("Embedding SDK", () => {- const SDK_TITLE = "Embedded analytics SDK";+ const SDK_TITLE = "SDK for React";describe("when the SDK is disabled", () => {it("should mention the sdk and tell admin to enable the SDK in the setting", () => {- setup();+ setup({+ tokenFeatures: createMockTokenFeatures(),+ });- // The card is not clickableexpect(- screen.queryByRole("link", { name: SDK_TITLE }),- ).not.toBeInTheDocument();+ screen.getByRole("link", { name: SDK_TITLE }),+ ).toBeInTheDocument();// We show the link at the bottom of the cardconst withinSdkCard = within(@@ -163,11 +166,9 @@ describe("EmbedModalContent", () => {},});- // The card is clickableexpect(screen.getByRole("link", { name: SDK_TITLE })).toHaveProperty("href",- // I have no idea why only this URL is absolute in the test, it is relative in the markup 🤷- "http://localhost/admin/embedding/modular",+ "https://www.metabase.com/docs/latest/embedding/sdk/introduction.html?utm_source=product&utm_medium=docs&utm_content=embed-modal&source_plan=oss",);// We don't show the link at the bottom of the carddiff --git a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.enterprise.unit.spec.tsx b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.enterprise.unit.spec.tsxindex 401e76d09d0..bd2433be1b1 100644--- a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.enterprise.unit.spec.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.enterprise.unit.spec.tsx@@ -12,7 +12,7 @@ function setupEnterprise(opts?: Partial<SetupOpts>) {describe("EmbedModalContent", () => {describe("Interactive Embedding", () => {- const INTERACTIVE_EMBEDDING_TITLE = "Interactive embedding";+ const INTERACTIVE_EMBEDDING_TITLE = "Embedded Analytics JS";describe("when Interactive Embedding is disabled", () => {it("should mention Interactive Embedding and lead users to learn more link", () => {@@ -23,7 +23,7 @@ describe("EmbedModalContent", () => {screen.queryByRole("link", { name: "Learn more" }),).toHaveProperty("href",- "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedding-interactive&utm_content=static-embed-popover&source_plan=oss",+ "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedded-analytics-js&utm_content=static-embed-popover&source_plan=oss",);// We show the learn more link@@ -57,7 +57,7 @@ describe("EmbedModalContent", () => {screen.queryByRole("link", { name: "Learn more" }),).toHaveProperty("href",- "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedding-interactive&utm_content=static-embed-popover&source_plan=oss",+ "https://www.metabase.com/product/embedded-analytics?utm_source=product&utm_medium=upsell&utm_campaign=embedded-analytics-js&utm_content=static-embed-popover&source_plan=oss",);// We show the learn more linkdiff --git a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.premium.unit.spec.tsx b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.premium.unit.spec.tsxindex 36d7f5a990c..fd5b5939d9c 100644--- a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.premium.unit.spec.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/EmbedModalContent.premium.unit.spec.tsx@@ -8,14 +8,14 @@ function setupPremium(opts?: Partial<SetupOpts>) {setup({...opts,hasEnterprisePlugins: true,- tokenFeatures: createMockTokenFeatures({ embedding: true }),+ tokenFeatures: createMockTokenFeatures({ embedding_simple: true }),isHosted: true,});}describe("EmbedModalContent", () => {describe("Interactive Embedding", () => {- const INTERACTIVE_EMBEDDING_TITLE = "Interactive embedding";+ const INTERACTIVE_EMBEDDING_TITLE = "Embedded Analytics JS";describe("when Interactive Embedding is disabled", () => {it("should mention Interactive Embedding and tell admin to enable Interactive Embedding in the setting", () => {@@ -37,7 +37,7 @@ describe("EmbedModalContent", () => {withinInteractiveEmbeddingCard.getByRole("link", {name: "Enable in admin settings",}),- ).toHaveAttribute("href", "/admin/embedding/interactive");+ ).toHaveAttribute("href", "/admin/embedding/modular");});});@@ -55,7 +55,7 @@ describe("EmbedModalContent", () => {).toHaveProperty("href",// I have no idea why only this URL is absolute in the test, it is relative in the markup 🤷- "http://localhost/admin/embedding/interactive",+ "http://localhost/embed-js?resource_type=dashboard",);// We don't show the link at the bottom of the carddiff --git a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/setup.tsx b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/setup.tsxindex 20f896838d2..4a85fa1ac82 100644--- a/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/setup.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/EmbedModalContent/tests/setup.tsx@@ -5,7 +5,10 @@ import { mockSettings } from "__support__/settings";import { renderWithProviders } from "__support__/ui";import type { EmbedResource } from "metabase/public/lib/types";import type { TokenFeatures } from "metabase-types/api";-import { createMockUser } from "metabase-types/api/mocks";+import {+ createMockTokenFeatures,+ createMockUser,+} from "metabase-types/api/mocks";import type { EmbedModalContentProps } from "../EmbedModalContent";import { EmbedModalContent } from "../EmbedModalContent";@@ -48,7 +51,7 @@ export function setup(onDeletePublicLink = jest.fn(),} = {},hasEnterprisePlugins,- tokenFeatures,+ tokenFeatures = createMockTokenFeatures(),isHosted,}: SetupOpts = {props: {},@@ -58,6 +61,7 @@ export function setup("token-features": tokenFeatures,"enable-embedding-static": enableEmbeddingStatic,"enable-embedding-interactive": enableEmbeddingInteractive,+ "enable-embedding-simple": enableEmbeddingInteractive,"enable-embedding-sdk": enableEmbeddingSdk,"embedding-secret-key": "my_super_secret_key","is-hosted?": isHosted ?? false,diff --git a/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SelectEmbedTypePane.tsx b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SelectEmbedTypePane.tsxindex 99fa086045c..868afdaa6e0 100644--- a/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SelectEmbedTypePane.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SelectEmbedTypePane.tsx@@ -1,20 +1,23 @@import cx from "classnames";import type React from "react";-import { type ComponentProps, useState } from "react";+import { useMemo, useState } from "react";import { t } from "ttag";import {- UpsellSdkCta,- useUpsellSdkCta,-} from "metabase/admin/upsells/UpsellSdkCta";+ UpsellEmbedJsCta,+ useUpsellEmbedJsCta,+} from "metabase/admin/upsells/UpsellEmbedJsCta";import { UpsellGem } from "metabase/admin/upsells/components";import ExternalLink from "metabase/common/components/ExternalLink";import Link from "metabase/common/components/Link";-import { useDocsUrl, useSetting } from "metabase/common/hooks";+import {+ useDocsUrl,+ useHasTokenFeature,+ useSetting,+} from "metabase/common/hooks";import CS from "metabase/css/core/index.css";import type { ExportFormatType } from "metabase/embedding/components/PublicLinkPopover/types";import { useSelector } from "metabase/lib/redux";-import { PLUGIN_EMBEDDING } from "metabase/plugins";import { trackPublicLinkRemoved } from "metabase/public/lib/analytics";import { getPublicEmbedHTML } from "metabase/public/lib/code";import type {@@ -26,8 +29,8 @@ import { Group, Icon, List, Stack, Text, UnstyledButton } from "metabase/ui";import { PublicEmbedCard } from "./PublicEmbedCard";import { SharingPaneButton } from "./SharingPaneButton/SharingPaneButton";+import EmbeddedJsIllustration from "./illustrations/embedded-analytics-js.svg?component";import SdkIllustration from "./illustrations/embedding-sdk.svg?component";-import InteractiveEmbeddingIllustration from "./illustrations/interactive-embedding.svg?component";import StaticEmbeddingIllustration from "./illustrations/static-embedding.svg?component";interface SelectEmbedTypePaneProps {@@ -47,7 +50,19 @@ export function SelectEmbedTypePane({getPublicUrl,goToNextStep,}: SelectEmbedTypePaneProps) {- const { url } = useUpsellSdkCta();+ const embedFlowUrl = useMemo(() => {+ const params = new URLSearchParams();++ params.set("resource_type", resourceType);++ if (resource.id) {+ params.set("resource_id", resource.id.toString());+ }++ return "/embed-js?" + params.toString();+ }, [resourceType, resource.id]);++ const { url } = useUpsellEmbedJsCta({ embedFlowUrl });const hasPublicLink = resource.public_uuid != null;const utmTags = {@@ -60,6 +75,11 @@ export function SelectEmbedTypePane({utm: utmTags,});+ // eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to admins+ const { url: sdkDocsUrl } = useDocsUrl("embedding/sdk/introduction", {+ utm: utmTags,+ });+const isPublicSharingEnabled = useSelector((state) =>getSetting(state, "enable-public-sharing"),);@@ -92,13 +112,10 @@ export function SelectEmbedTypePane({}};- const isInteractiveEmbeddingAvailable = useSelector(- PLUGIN_EMBEDDING.isInteractiveEmbeddingEnabled,- );+ const isEmbedJsAvailable = useHasTokenFeature("embedding_simple");+ const isEmbeddingSdkAvailable = useHasTokenFeature("embedding_sdk");const isStaticEmbeddingEnabled = useSetting("enable-embedding-static");- const isInteractiveEmbeddingEnabled = useSetting(- "enable-embedding-interactive",- );+ const isEmbedJsEnabled = useSetting("enable-embedding-simple");const isEmbeddingSdkEnabled = useSetting("enable-embedding-sdk");return (@@ -110,7 +127,7 @@ export function SelectEmbedTypePane({align="stretch"><Group gap="lg" maw="100%" align="stretch">- {/* STATIC EMBEDDING*/}+ {/* Static Embedding */}<SharingPaneButtontitle={t`Static embedding`}illustration={<StaticEmbeddingIllustration />}@@ -125,56 +142,62 @@ export function SelectEmbedTypePane({</List></SharingPaneButton>- {/* INTERACTIVE EMBEDDING */}- <MaybeLinkInteractiveEmbedding- shouldRenderLink={- !isInteractiveEmbeddingAvailable || isInteractiveEmbeddingEnabled- }+ {/* Embedded Analytics JS: render either upsell or embed flow link */}+ <MaybeLinkEmbedJs+ shouldRenderLink={!isEmbedJsAvailable || isEmbedJsEnabled}+ embedFlowUrl={embedFlowUrl}><SharingPaneButton- title={t`Interactive embedding`}- badge={<UpsellGem />}- illustration={<InteractiveEmbeddingIllustration />}- isDisabled={- isInteractiveEmbeddingAvailable && !isInteractiveEmbeddingEnabled+ title={t`Embedded Analytics JS`}+ badge={!isEmbedJsAvailable && <UpsellGem />}+ illustration={<EmbeddedJsIllustration />}+ isDisabled={isEmbedJsAvailable && !isEmbedJsEnabled}+ disabledLink="/admin/embedding/modular"+ actionHint={+ !isEmbedJsAvailable ? (+ <UpsellEmbedJsCta embedFlowUrl={embedFlowUrl} />+ ) : undefined}- disabledLink={"/admin/embedding/interactive"}><List>- {/* eslint-disable-next-line no-literal-metabase-strings -- only admin sees this */}- <List.Item>{t`Embed all of Metabase in an iframe.`}</List.Item>- <List.Item>{t`Let people click to explore.`}</List.Item>+ <List.Item>{t`A simple way to embed using plain JavaScript`}</List.Item>+ <List.Item>{t`Embed static or interactive dashboards and charts with drill-down, the query builder or let people browse and manage collections.`}</List.Item><List.Item>- {t`Customize appearance with your logo, font, and colors.`}{" "}- {!isInteractiveEmbeddingAvailable && <LearnMore url={url} />}+ {t`Advanced customizations for styling.`} <br />{" "}+ {!isEmbedJsAvailable && <LearnMore url={url} />}</List.Item></List>- {!isInteractiveEmbeddingAvailable && <UpsellSdkCta />}</SharingPaneButton>- </MaybeLinkInteractiveEmbedding>+ </MaybeLinkEmbedJs>- {/* REACT SDK */}- <MaybeLink- to="/admin/embedding/modular"- shouldRenderLink={isEmbeddingSdkEnabled}- aria-label={t`Embedded analytics SDK`}- >+ {/* SDK for React */}+ <ExternalLink href={sdkDocsUrl} className={CS.noDecoration}><SharingPaneButton- title={t`Embedded analytics SDK`}- badge={<UpsellGem />}+ title={t`SDK for React`}+ badge={!isEmbeddingSdkAvailable && <UpsellGem />}illustration={<SdkIllustration />}isDisabled={!isEmbeddingSdkEnabled}disabledLink={"/admin/embedding/modular"}+ actionHint={+ <Group gap="xs">+ <Text c="brand" fw="bold">+ {t`Go to quick start`}+ </Text>++ <Icon name="external" c="brand" aria-hidden />+ </Group>+ }><List>{/* eslint-disable-next-line no-literal-metabase-strings -- visible only to admin */}- <List.Item>{t`Embed Metabase components with React (like standalone charts, dashboards, the Query Builder, and more)`}</List.Item>+ <List.Item>{t`Embed Metabase components with React (like standalone charts, dashboards, the query builder, and more)`}</List.Item><List.Item>{t`Manage access and interactivity per component`}</List.Item><List.Item>{t`Advanced customization options for styling`}</List.Item></List></SharingPaneButton>- </MaybeLink>+ </ExternalLink></Group>+<Group justify="space-between">{/* PUBLIC EMBEDDING */}{isPublicSharingEnabled ? (@@ -218,16 +241,18 @@ function LearnMore({ url }: { url: string | undefined }) {);}-interface MaybeLinkInteractiveEmbeddingProps {- shouldRenderLink?: boolean;- children: React.ReactNode;-}--function MaybeLinkInteractiveEmbedding({+function MaybeLinkEmbedJs({shouldRenderLink,+ embedFlowUrl,...props-}: MaybeLinkInteractiveEmbeddingProps) {- const { url, internalLink, triggerUpsellFlow } = useUpsellSdkCta();+}: {+ shouldRenderLink?: boolean;+ embedFlowUrl: string;+ children: React.ReactNode;+}) {+ const { url, internalLink, triggerUpsellFlow } = useUpsellEmbedJsCta({+ embedFlowUrl,+ });if (!shouldRenderLink) {return props.children;@@ -238,7 +263,7 @@ function MaybeLinkInteractiveEmbedding({<UnstyledButtononClick={triggerUpsellFlow}type="button"- aria-label={t`Interactive embedding`}+ aria-label={t`Embedded Analytics JS`}>{props.children}</UnstyledButton>@@ -251,7 +276,7 @@ function MaybeLinkInteractiveEmbedding({{...props}href={url}target="_blank"- aria-label={t`Interactive embedding`}+ aria-label={t`Embedded Analytics JS`}/>);}@@ -261,22 +286,10 @@ function MaybeLinkInteractiveEmbedding({<Link{...props}to={internalLink}- aria-label={t`Interactive embedding`}+ aria-label={t`Embedded Analytics JS`}/>);}return props.children;}--interface MaybeLinkProps extends ComponentProps<typeof Link> {- shouldRenderLink?: boolean;-}--function MaybeLink({ shouldRenderLink, ...props }: MaybeLinkProps) {- if (shouldRenderLink) {- return <Link {...props} />;- }-- return props.children;-}diff --git a/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SharingPaneButton/SharingPaneButton.tsx b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SharingPaneButton/SharingPaneButton.tsxindex a469d80443b..6a38b6db857 100644--- a/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SharingPaneButton/SharingPaneButton.tsx+++ b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/SharingPaneButton/SharingPaneButton.tsx@@ -16,6 +16,7 @@ type SharingOptionProps = {"data-testid"?: string;isDisabled?: boolean;disabledLink: string;+ actionHint?: ReactNode;};export const SharingPaneButton = ({@@ -27,6 +28,7 @@ export const SharingPaneButton = ({"data-testid": dataTestId,isDisabled,disabledLink,+ actionHint,}: SharingOptionProps) => {return (<Paper@@ -42,14 +44,27 @@ export const SharingPaneButton = ({w="22rem"aria-label={title}>- <Stack pb={isDisabled ? "md" : undefined}>- <Center mb={32}>{illustration}</Center>- <Group align="center" gap="sm">- {badge}- <Title order={2}>{title}</Title>- </Group>- {children}+ <Stack justify="space-between" h="100%">+ <Stack pb={isDisabled ? "md" : undefined}>+ <Center mb={32}>{illustration}</Center>+ <Group align="center" gap="sm">+ {badge}+ <Title order={2}>{title}</Title>+ </Group>+ {children}+ </Stack>++ {!isDisabled && (+ <Stack mt="lg" w="100%" align="flex-end">+ {actionHint ?? (+ <Text c="brand" fw="bold">+ {t`Embed`}+ </Text>+ )}+ </Stack>+ )}</Stack>+{isDisabled && (<Boxpos="absolute"diff --git a/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/illustrations/embedded-analytics-js.svg b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/illustrations/embedded-analytics-js.svgnew file mode 100644index 00000000000..f327c79f0a3--- /dev/null+++ b/frontend/src/metabase/public/components/EmbedModal/SelectEmbedTypePane/illustrations/embedded-analytics-js.svg@@ -0,0 +1,16 @@+<svg width="121" height="96" viewBox="0 0 121 96" fill="none" xmlns="http://www.w3.org/2000/svg">+<g clip-path="url(#clip0_17201_1069)">+<rect x="4.08398" y="3.75" width="112.5" height="88.5" rx="8.25" stroke="#EEEEEE" stroke-width="7.5"/>+<g clip-path="url(#clip1_17201_1069)">+<path d="M33.8695 68.9095C32.7775 68.9485 31.9195 68.656 31.2955 68.032C30.6715 67.408 30.3595 66.6085 30.3595 65.6335C30.3595 64.8925 30.5935 64.249 31.0615 63.703C31.4905 63.118 32.134 62.806 32.992 62.767L34.747 62.65C36.463 62.533 37.75 62.0065 38.608 61.0705C39.505 60.0955 39.9535 58.711 39.9535 56.917V30.592C39.9535 29.344 40.2655 28.408 40.8895 27.784C41.5525 27.121 42.4885 26.7895 43.6975 26.7895C44.9065 26.7895 45.823 27.121 46.447 27.784C47.11 28.408 47.4415 29.344 47.4415 30.592V56.8585C47.4415 59.3155 46.993 61.402 46.096 63.118C45.238 64.834 43.951 66.1795 42.235 67.1545C40.519 68.0905 38.3935 68.6365 35.8585 68.7925L33.8695 68.9095ZM70.6363 69.085C68.9203 69.085 67.2043 68.9485 65.4883 68.6755C63.7723 68.4415 62.1538 68.071 60.6328 67.564C59.1118 67.018 57.7468 66.355 56.5378 65.575C55.8358 65.107 55.3483 64.5415 55.0753 63.8785C54.8023 63.2155 54.7048 62.572 54.7828 61.948C54.8998 61.285 55.1533 60.7195 55.5433 60.2515C55.9723 59.7445 56.4988 59.4325 57.1228 59.3155C57.7468 59.1985 58.4293 59.374 59.1703 59.842C60.8863 60.856 62.6998 61.597 64.6108 62.065C66.5218 62.533 68.5303 62.767 70.6363 62.767C73.7173 62.767 75.9598 62.26 77.3638 61.246C78.7678 60.193 79.4698 58.8475 79.4698 57.2095C79.4698 55.8445 78.9628 54.772 77.9488 53.992C76.9738 53.212 75.2773 52.5685 72.8593 52.0615L66.4243 50.716C62.7193 49.936 59.9503 48.6295 58.1173 46.7965C56.3233 44.9245 55.4263 42.4675 55.4263 39.4255C55.4263 37.5145 55.8163 35.779 56.5963 34.219C57.3763 32.659 58.4683 31.3135 59.8723 30.1825C61.3153 29.0515 63.0118 28.1935 64.9618 27.6085C66.9508 26.9845 69.1348 26.6725 71.5138 26.6725C73.8538 26.6725 76.0768 26.965 78.1828 27.55C80.2888 28.135 82.1803 28.993 83.8573 30.124C84.4813 30.553 84.8908 31.0795 85.0858 31.7035C85.3198 32.3275 85.3783 32.9515 85.2613 33.5755C85.1443 34.1605 84.8713 34.6675 84.4423 35.0965C84.0133 35.5255 83.4673 35.779 82.8043 35.857C82.1803 35.935 81.4588 35.74 80.6398 35.272C79.1968 34.453 77.7343 33.868 76.2523 33.517C74.7703 33.166 73.1713 32.9905 71.4553 32.9905C69.6613 32.9905 68.1208 33.244 66.8338 33.751C65.5468 34.258 64.5523 34.9795 63.8503 35.9155C63.1873 36.8125 62.8558 37.885 62.8558 39.133C62.8558 40.537 63.3238 41.668 64.2598 42.526C65.1958 43.345 66.7948 43.9885 69.0568 44.4565L75.4333 45.802C79.2943 46.621 82.1608 47.908 84.0328 49.663C85.9438 51.418 86.8993 53.758 86.8993 56.683C86.8993 58.555 86.5093 60.2515 85.7293 61.7725C84.9883 63.2935 83.8963 64.6 82.4533 65.692C81.0493 66.784 79.3528 67.6225 77.3638 68.2075C75.3748 68.7925 73.1323 69.085 70.6363 69.085Z" fill="#C5C7D0"/>+</g>+</g>+<defs>+<clipPath id="clip0_17201_1069">+<rect width="120" height="96" fill="white" transform="translate(0.333984)"/>+</clipPath>+<clipPath id="clip1_17201_1069">+<rect width="72" height="72" fill="white" transform="translate(24.334 12)"/>+</clipPath>+</defs>+</svg>