Skip to content
Snippets Groups Projects
Unverified Commit baf69d50 authored by Nicolò Pretto's avatar Nicolò Pretto Committed by GitHub
Browse files

embed-homepage ms2: connect example dashboard (#41180)


* connect the example dashboard id setting to the embedding homepage (#41138)

* connect the example dashboard id setting to the embedding homepage

* fix types

* Update frontend/src/metabase/home/components/EmbedHomepage/StaticTabContent.tsx

Co-authored-by: default avatarDenis Berezin <denis.berezin@metabase.com>

---------

Co-authored-by: default avatarDenis Berezin <denis.berezin@metabase.com>

* use isNotNull

---------

Co-authored-by: default avatarDenis Berezin <denis.berezin@metabase.com>
parent dd40ac5f
No related branches found
No related tags found
No related merge requests found
...@@ -167,6 +167,7 @@ export const createMockSettings = ( ...@@ -167,6 +167,7 @@ export const createMockSettings = (
"enable-public-sharing": false, "enable-public-sharing": false,
"enable-xrays": false, "enable-xrays": false,
engines: createMockEngines(), engines: createMockEngines(),
"example-dashboard-id": 1,
"has-user-setup": true, "has-user-setup": true,
"hide-embed-branding?": true, "hide-embed-branding?": true,
"show-static-embed-terms": true, "show-static-embed-terms": true,
......
...@@ -197,6 +197,7 @@ interface InstanceSettings { ...@@ -197,6 +197,7 @@ interface InstanceSettings {
"enable-query-caching"?: boolean; "enable-query-caching"?: boolean;
"enable-public-sharing": boolean; "enable-public-sharing": boolean;
"enable-xrays": boolean; "enable-xrays": boolean;
"example-dashboard-id": number | null;
"search-typeahead-enabled": boolean; "search-typeahead-enabled": boolean;
"show-homepage-data": boolean; "show-homepage-data": boolean;
"show-homepage-pin-message": boolean; "show-homepage-pin-message": boolean;
......
...@@ -27,7 +27,7 @@ export const Default: Story = { ...@@ -27,7 +27,7 @@ export const Default: Story = {
return ( return (
<EmbedHomepageView <EmbedHomepageView
{...args} {...args}
exampleDashboardId={args.hasExampleDashboard ? 1 : undefined} exampleDashboardId={args.hasExampleDashboard ? 1 : null}
key={args.defaultTab} key={args.defaultTab}
/> />
); );
......
...@@ -14,7 +14,7 @@ export const EmbedHomepage = () => { ...@@ -14,7 +14,7 @@ export const EmbedHomepage = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const embeddingAutoEnabled = useSetting("setup-embedding-autoenabled"); const embeddingAutoEnabled = useSetting("setup-embedding-autoenabled");
const licenseActiveAtSetup = useSetting("setup-license-active-at-setup"); const licenseActiveAtSetup = useSetting("setup-license-active-at-setup");
const exampleDashboardId = undefined; // will come from a setting const exampleDashboardId = useSetting("example-dashboard-id");
const interactiveEmbeddingQuickStartUrl = useSelector(state => const interactiveEmbeddingQuickStartUrl = useSelector(state =>
// eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to admins // eslint-disable-next-line no-unconditional-metabase-links-render -- only visible to admins
......
...@@ -19,7 +19,7 @@ import type { EmbedHomepageDismissReason } from "./types"; ...@@ -19,7 +19,7 @@ import type { EmbedHomepageDismissReason } from "./types";
export type EmbedHomepageViewProps = { export type EmbedHomepageViewProps = {
embeddingAutoEnabled: boolean; embeddingAutoEnabled: boolean;
exampleDashboardId?: number; exampleDashboardId: number | null;
licenseActiveAtSetup: boolean; licenseActiveAtSetup: boolean;
defaultTab: "interactive" | "static"; defaultTab: "interactive" | "static";
onDismiss: (reason: EmbedHomepageDismissReason) => void; onDismiss: (reason: EmbedHomepageDismissReason) => void;
......
...@@ -2,6 +2,7 @@ import { Link } from "react-router"; ...@@ -2,6 +2,7 @@ import { Link } from "react-router";
import { t, jt } from "ttag"; import { t, jt } from "ttag";
import ExternalLink from "metabase/core/components/ExternalLink"; import ExternalLink from "metabase/core/components/ExternalLink";
import { isNotNull } from "metabase/lib/types";
import { Anchor, Button, Icon, Text, List } from "metabase/ui"; import { Anchor, Button, Icon, Text, List } from "metabase/ui";
import type { EmbedHomepageViewProps } from "./EmbedHomepageView"; import type { EmbedHomepageViewProps } from "./EmbedHomepageView";
...@@ -31,7 +32,7 @@ export const StaticTabContent = ({ ...@@ -31,7 +32,7 @@ export const StaticTabContent = ({
</List.Item> </List.Item>
)} )}
<List.Item>{jt`${ <List.Item>{jt`${
exampleDashboardId !== undefined ? t`Select` : `Create` isNotNull(exampleDashboardId) ? t`Select` : `Create`
} a question or dashboard to embed. Then click ${( } a question or dashboard to embed. Then click ${(
<strong key="bold">{t`share`}</strong> <strong key="bold">{t`share`}</strong>
)}`}</List.Item> )}`}</List.Item>
...@@ -41,7 +42,7 @@ export const StaticTabContent = ({ ...@@ -41,7 +42,7 @@ export const StaticTabContent = ({
<List.Item>{t`Embed the dashboard into your app using an iframe, the URL and the signed token. `}</List.Item> <List.Item>{t`Embed the dashboard into your app using an iframe, the URL and the signed token. `}</List.Item>
</List> </List>
{exampleDashboardId && ( {isNotNull(exampleDashboardId) && (
<Link to={`/dashboard/${exampleDashboardId}`}> <Link to={`/dashboard/${exampleDashboardId}`}>
<Button <Button
variant="filled" variant="filled"
......
...@@ -26,6 +26,34 @@ describe("EmbedHomepage (OSS)", () => { ...@@ -26,6 +26,34 @@ describe("EmbedHomepage (OSS)", () => {
); );
}); });
it("should link to the example dashboard if `example-dashboard-id` is set", () => {
setup({ settings: { "example-dashboard-id": 1 } });
expect(
screen.getByText("Select a question", { exact: false }),
).toBeInTheDocument();
expect(
screen.getByRole("link", {
name: /Embed this example dashboard/i,
}),
).toHaveAttribute("href", "/dashboard/1");
});
it("should prompt to create a question if `example-dashboard-id` is not set", () => {
setup({ settings: { "example-dashboard-id": null } });
expect(
screen.getByText("Create a question", { exact: false }),
).toBeInTheDocument();
expect(
screen.queryByRole("link", {
name: "Embed this example dashboard",
}),
).not.toBeInTheDocument();
});
it("should prompt to enable embedding if it wasn't auto enabled", () => { it("should prompt to enable embedding if it wasn't auto enabled", () => {
setup({ settings: { "setup-embedding-autoenabled": false } }); setup({ settings: { "setup-embedding-autoenabled": false } });
......
import fetchMock from "fetch-mock"; import fetchMock from "fetch-mock";
import { Route } from "react-router";
import { setupEnterprisePlugins } from "__support__/enterprise"; import { setupEnterprisePlugins } from "__support__/enterprise";
import { import {
...@@ -47,5 +48,8 @@ export async function setup({ ...@@ -47,5 +48,8 @@ export async function setup({
setupEnterprisePlugins(); setupEnterprisePlugins();
} }
renderWithProviders(<EmbedHomepage />, { storeInitialState: state }); renderWithProviders(<Route path="/" component={EmbedHomepage} />, {
storeInitialState: state,
withRouter: true,
});
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment