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
update embedding homepage to reference embed js (#62169)
Nicolò Prettob98becc8b73f
diff --git a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.stories.tsx b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.stories.tsxindex 923bff4facb..5a947e0f2c2 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.stories.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.stories.tsx@@ -31,9 +31,8 @@ export const Default: Story = {},args: {hasExampleDashboard: true,- licenseActiveAtSetup: true,- interactiveEmbeddingQuickstartUrl:- "https://www.metabase.com/docs/latest/embedding/interactive-embedding-quick-start-guide.html",+ variant: "ee",+ hasEmbeddingFeature: false,embeddingDocsUrl:"https://www.metabase.com/docs/latest/embedding/start.html",analyticsDocsUrl:diff --git a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.tsx b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.tsxindex 652361e58f2..5f07de48e46 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepage.tsx@@ -2,9 +2,10 @@ import { useState } from "react";import { t } from "ttag";import { useSendProductFeedbackMutation } from "metabase/api/product-feedback";-import { useSetting } from "metabase/common/hooks";+import { useHasTokenFeature, useSetting } from "metabase/common/hooks";import { getPlan } from "metabase/common/utils/plan";import { useDispatch, useSelector } from "metabase/lib/redux";+import { isEEBuild } from "metabase/lib/utils";import { addUndo } from "metabase/redux/undo";import { getDocsUrl, getSetting } from "metabase/selectors/settings";import type { EmbeddingHomepageDismissReason } from "metabase-types/api";@@ -16,16 +17,10 @@ import { dismissEmbeddingHomepage } from "./actions";export const EmbedHomepage = () => {const [feedbackModalOpened, setFeedbackModalOpened] = useState(false);const dispatch = useDispatch();- const licenseActiveAtSetup = useSetting("setup-license-active-at-setup");const exampleDashboardId = useSetting("example-dashboard-id");const [sendProductFeedback] = useSendProductFeedbackMutation();+ const hasEmbeddingFeature = useHasTokenFeature("embedding");- const interactiveEmbeddingQuickStartUrl = useSelector((state) =>- // eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to admins- getDocsUrl(state, {- page: "embedding/interactive-embedding-quick-start-guide",- }),- );const embeddingDocsUrl = useSelector((state) =>// eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to adminsgetDocsUrl(state, { page: "embedding/start" }),@@ -41,6 +36,11 @@ export const EmbedHomepage = () => {getDocsUrl(state, { page: "embedding/static-embedding" }),);+ const embedJsDocsUrl = useSelector((state) =>+ // eslint-disable-next-line no-unconditional-metabase-links-render -- this is only visible to admins+ getDocsUrl(state, { page: "embedding/embedded-analytics-js" }),+ );+const plan = useSelector((state) =>getPlan(getSetting(state, "token-features")),);@@ -77,15 +77,16 @@ export const EmbedHomepage = () => {}};+ const variant = isEEBuild() ? "ee" : "oss/starter";+return (<><EmbedHomepageViewonDismiss={onDismiss}exampleDashboardId={exampleDashboardId}- licenseActiveAtSetup={licenseActiveAtSetup}- interactiveEmbeddingQuickstartUrl={- interactiveEmbeddingQuickStartUrl + utmTags- }+ embedJsDocsUrl={embedJsDocsUrl + utmTags}+ variant={variant}+ hasEmbeddingFeature={hasEmbeddingFeature}embeddingDocsUrl={embeddingDocsUrl + utmTags}analyticsDocsUrl={// eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to adminsdiff --git a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepageView.tsx b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepageView.tsxindex 204811a36b5..f8a31d3c2eb 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepageView.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/EmbedHomepageView.tsx@@ -1,45 +1,95 @@+import { match } from "ts-pattern";import { t } from "ttag";import { Box, Card, Stack, Text, Title } from "metabase/ui";import type { EmbeddingHomepageDismissReason } from "metabase-types/api";+import { EmbedJsContent } from "./EmbedJsContent";import { HeaderWithDismiss } from "./HeaderWithDismiss";-import { InteractiveContent } from "./InteractiveContent";import { NeedMoreInfoCard } from "./NeedMoreInfoCard";import { SDKContent } from "./SDKContent";import { StaticEmbedContent } from "./StaticEmbedContent";export type EmbedHomepageViewProps = {exampleDashboardId: number | null;- licenseActiveAtSetup: boolean;+ variant: "oss/starter" | "ee";+ hasEmbeddingFeature: boolean;onDismiss: (reason: EmbeddingHomepageDismissReason) => void;// links- interactiveEmbeddingQuickstartUrl: string;learnMoreInteractiveEmbedUrl: string;learnMoreStaticEmbedUrl: string;sdkQuickstartUrl: string;sdkDocsUrl: string;+ embedJsDocsUrl: string;embeddingDocsUrl: string;analyticsDocsUrl: string;};export const EmbedHomepageView = (props: EmbedHomepageViewProps) => {const {- interactiveEmbeddingQuickstartUrl,exampleDashboardId,learnMoreStaticEmbedUrl,- learnMoreInteractiveEmbedUrl,sdkQuickstartUrl,sdkDocsUrl,+ embedJsDocsUrl,onDismiss,embeddingDocsUrl,analyticsDocsUrl,+ variant,+ hasEmbeddingFeature,} = props;const exampleDashboardLink = exampleDashboardId? `/dashboard/${exampleDashboardId}`: undefined;+ const content = match(variant)+ .with("oss/starter", () => {+ return (+ <>+ <StaticEmbedContent+ exampleDashboardLink={exampleDashboardLink}+ learnMoreStaticEmbedUrl={learnMoreStaticEmbedUrl}+ showImage+ />++ <EmbedJsContent+ variant={variant}+ embedJsDocsUrl={embedJsDocsUrl}+ hasEmbeddingFeature={hasEmbeddingFeature}+ />++ <SDKContent+ sdkQuickstartUrl={sdkQuickstartUrl}+ sdkDocsUrl={sdkDocsUrl}+ />+ </>+ );+ })+ .with("ee", () => {+ return (+ <>+ <EmbedJsContent+ variant={variant}+ embedJsDocsUrl={embedJsDocsUrl}+ hasEmbeddingFeature={hasEmbeddingFeature}+ showImage+ />++ <SDKContent+ sdkQuickstartUrl={sdkQuickstartUrl}+ sdkDocsUrl={sdkDocsUrl}+ />++ <StaticEmbedContent+ exampleDashboardLink={exampleDashboardLink}+ learnMoreStaticEmbedUrl={learnMoreStaticEmbedUrl}+ />+ </>+ );+ })+ .exhaustive();+return (<Stack maw={550}><HeaderWithDismiss onDismiss={onDismiss} />@@ -54,23 +104,7 @@ export const EmbedHomepageView = (props: EmbedHomepageViewProps) => {{t`Give your customers secure, multi-tenant access to their data with as much (or as little) interactivity and tools to explore data as you want, with as much customization as you need. Embed dashboards, charts—even Metabase's query editor—with iframes or as individual React components.`}</Text></Box>-- <StaticEmbedContent- exampleDashboardLink={exampleDashboardLink}- learnMoreStaticEmbedUrl={learnMoreStaticEmbedUrl}- />-- <SDKContent- sdkQuickstartUrl={sdkQuickstartUrl}- sdkDocsUrl={sdkDocsUrl}- />-- <InteractiveContent- interactiveEmbeddingQuickstartUrl={- interactiveEmbeddingQuickstartUrl- }- learnMoreInteractiveEmbedUrl={learnMoreInteractiveEmbedUrl}- />+ {content}</Stack></Card>diff --git a/frontend/src/metabase/home/components/EmbedHomepage/EmbedJsContent.tsx b/frontend/src/metabase/home/components/EmbedHomepage/EmbedJsContent.tsxnew file mode 100644index 00000000000..14566814e9a--- /dev/null+++ b/frontend/src/metabase/home/components/EmbedHomepage/EmbedJsContent.tsx@@ -0,0 +1,73 @@+// eslint-disable-next-line no-restricted-imports+import styled from "@emotion/styled";+import { Link } from "react-router";+import { match } from "ts-pattern";+import { t } from "ttag";++import ExternalLink from "metabase/common/components/ExternalLink";+import { Box, Button, Group, Text } from "metabase/ui";++type EmbedJsContentProps = {+ embedJsDocsUrl: string;+ showImage?: boolean;+ hasEmbeddingFeature?: boolean;+ variant: "oss/starter" | "ee";+};++export const EmbedJsContent = ({+ embedJsDocsUrl,+ showImage,+ hasEmbeddingFeature,+ variant,+}: EmbedJsContentProps) => {+ const cta = match({ variant, hasEmbeddingFeature })+ .with({ variant: "ee", hasEmbeddingFeature: true }, () => (+ <Button component={Link} to={"/embed-js"} variant="outline">+ {t`Start embedding`}+ </Button>+ ))+ .with({ variant: "ee", hasEmbeddingFeature: false }, () => (+ <Button component={Link} to={"/admin/settings/license"} variant="outline">+ {t`Activate license`}+ </Button>+ ))+ .otherwise(() => null);++ return (+ <Box component="section" aria-labelledby="embed-js-title">+ <Text+ fw="bold"+ mb="sm"+ size="lg"+ color="text-medium"+ id="embed-js-title"+ >{t`Embedded analytics JS`}</Text>+ <Text mb="md">+ {/* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */}+ {t`Embedded analytics JS is a JavaScript library built on top of Metabase’s Embedded analytics SDK for React, but it does not require using React or setting up full SDK embedding. Unlike with interactive embedding, where you embed the entire Metabase app in an iframe, Embedded analytics JS lets you choose from a set of predefined components like a single chart, a dashboard with optional drill-through, or query builder, and customize those components.`}+ </Text>+ {showImage && (+ <EmbedJsImage+ src="/app/assets/img/embed-js-example.png"+ alt="Embedded analytics JS example"+ />+ )}+ <Group gap="md">+ {cta}++ <ExternalLink href={embedJsDocsUrl}>+ <Button+ variant={cta ? "subtle" : "outline"}+ >{t`Read the docs`}</Button>+ </ExternalLink>+ </Group>+ </Box>+ );+};++const EmbedJsImage = styled.img`+ width: 100%;+ margin-bottom: 1rem;+ border-radius: 8px;+ border: 1px solid ${({ theme }) => theme.colors.border};+`;diff --git a/frontend/src/metabase/home/components/EmbedHomepage/InteractiveContent.tsx b/frontend/src/metabase/home/components/EmbedHomepage/InteractiveContent.tsxdeleted file mode 100644index ef7de109a3a..00000000000--- a/frontend/src/metabase/home/components/EmbedHomepage/InteractiveContent.tsx+++ /dev/null@@ -1,35 +0,0 @@-import { t } from "ttag";--import ExternalLink from "metabase/common/components/ExternalLink";-import { Box, Button, Group, Text } from "metabase/ui";--type InteractiveContentProps = {- interactiveEmbeddingQuickstartUrl: string;- learnMoreInteractiveEmbedUrl: string;-};--export const InteractiveContent = ({- interactiveEmbeddingQuickstartUrl,- learnMoreInteractiveEmbedUrl,-}: InteractiveContentProps) => (- <Box>- <Text- fw="bold"- mb="sm"- size="lg"- color="text-medium"- >{t`Interactive embedding`}</Text>- <Text mb="md">- {/* eslint-disable-next-line no-literal-metabase-strings -- only visible to admins */}- {t`Interactive embedding allows you to embed the full Metabase app with iframes. It offers settings to customize appearance and includes the query builder with row-level access.`}- </Text>- <Group gap="md">- <ExternalLink href={interactiveEmbeddingQuickstartUrl}>- <Button variant="outline">{t`Check out the Quickstart`}</Button>- </ExternalLink>- <ExternalLink href={learnMoreInteractiveEmbedUrl}>- <Button variant="subtle">{t`Read the docs`}</Button>- </ExternalLink>- </Group>- </Box>-);diff --git a/frontend/src/metabase/home/components/EmbedHomepage/SDKContent.tsx b/frontend/src/metabase/home/components/EmbedHomepage/SDKContent.tsxindex 52aa9c76a98..167abd741df 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/SDKContent.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/SDKContent.tsx@@ -12,10 +12,10 @@ export const SDKContent = ({sdkQuickstartUrl,sdkDocsUrl,}: SDKContentProps) => (- <Box>+ <Box component="section" aria-labelledby="sdk-title"><Group gap="sm" align="center" mb="sm">- <Text fw="bold" size="lg" color="text-medium">- {t`Embedded analytics SDK`}+ <Text fw="bold" size="lg" color="text-medium" id="sdk-title">+ {t`Embedded analytics SDK for React`}</Text></Group><Text mb="md">diff --git a/frontend/src/metabase/home/components/EmbedHomepage/StaticEmbedContent.tsx b/frontend/src/metabase/home/components/EmbedHomepage/StaticEmbedContent.tsxindex 24895efaaa7..20bb4473efe 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/StaticEmbedContent.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/StaticEmbedContent.tsx@@ -11,27 +11,32 @@ import { trackEmbeddingHomepageExampleDashboardClick } from "./analytics";type StaticEmbedContentProps = {exampleDashboardLink?: string;learnMoreStaticEmbedUrl: string;+ showImage?: boolean;};export const StaticEmbedContent = ({exampleDashboardLink,learnMoreStaticEmbedUrl,+ showImage,}: StaticEmbedContentProps) => (- <Box>+ <Box component="section" aria-labelledby="static-embed-title"><Textfw="bold"mb="sm"size="lg"color="text-medium"+ id="static-embed-title">{t`Static embedding`}</Text><Text mb="md">{/* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */}{t`Embed a dashboard in a 'Powered by Metabase' iframe with interactivity limited to filters and tooltips, and a few customization options. The iframe loads a Metabase URL secured with a signed JSON Web Token (JWT). Appears with "Powered by Metabase", on Open Source and Starter plans, with the option to remove on Pro and Enterprise. As the simplest form of embedding, you can add a dashboard into your app in a few minutes with just a snippet.`}</Text>- <StaticEmbedImage- src="/app/assets/img/static-embedding-example.png"- alt="Static embedding example"- />+ {showImage && (+ <StaticEmbedImage+ src="/app/assets/img/static-embedding-example.png"+ alt="Static embedding example"+ />+ )}<Group gap="md">{exampleDashboardLink && (<Linkdiff --git a/frontend/src/metabase/home/components/EmbedHomepage/tests/EmbedHomepage.unit.spec.tsx b/frontend/src/metabase/home/components/EmbedHomepage/tests/EmbedHomepage.unit.spec.tsxindex fab8dccdaef..f8895ddc0e5 100644--- a/frontend/src/metabase/home/components/EmbedHomepage/tests/EmbedHomepage.unit.spec.tsx+++ b/frontend/src/metabase/home/components/EmbedHomepage/tests/EmbedHomepage.unit.spec.tsx@@ -1,6 +1,6 @@import userEvent from "@testing-library/user-event";-import { screen } from "__support__/ui";+import { screen, within } from "__support__/ui";import {getLastFeedbackCall,@@ -21,14 +21,21 @@ describe("EmbedHomepage (OSS)", () => {);});- it("should link to the docs for interactive embedding", () => {+ it("should link to the docs for embed js embedding", () => {setup();- expect(- screen.getAllByRole("link", { name: "Read the docs" })[2],- ).toHaveAttribute(+ const embedJsSection = screen.getByRole("region", {+ name: "Embedded analytics JS",+ });++ // Then find the "Read the docs" button within that section+ const readEmbedJsDocsLink = within(embedJsSection).getByRole("link", {+ name: "Read the docs",+ });++ expect(readEmbedJsDocsLink).toHaveAttribute("href",- "https://www.metabase.com/docs/latest/embedding/interactive-embedding.html?utm_source=product&source_plan=oss&utm_content=embedding-homepage",+ "https://www.metabase.com/docs/latest/embedding/embedded-analytics-js.html?utm_source=product&source_plan=oss&utm_content=embedding-homepage",);});@@ -46,9 +53,15 @@ describe("EmbedHomepage (OSS)", () => {it("should link to the SDK docs", () => {setup();- expect(- screen.getAllByRole("link", { name: "Read the docs" })[1],- ).toHaveAttribute(+ const sdkSection = screen.getByRole("region", {+ name: "Embedded analytics SDK for React",+ });++ const readSdkDocsLink = within(sdkSection).getByRole("link", {+ name: "Read the docs",+ });++ expect(readSdkDocsLink).toHaveAttribute("href","https://metaba.se/sdk-docs?utm_source=product&source_plan=oss&utm_content=embedding-homepage",);diff --git a/resources/frontend_client/app/assets/img/embed-js-example.png b/resources/frontend_client/app/assets/img/embed-js-example.pngnew file mode 100644index 00000000000..551b3cc3e1eBinary files /dev/null and b/resources/frontend_client/app/assets/img/embed-js-example.png differ