Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

feat(embed-js): Change `guest embeds disabled` tooltip to display a link to admin settings (#67925)

Timofey Kachalovb374706a41b6
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts
index 58232aa82b3..264cde35552 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts
@@ -22,7 +22,9 @@ describe(suiteTitle, () => {
cy.signInAsAdmin();
H.activateToken("bleeding-edge");
H.enableTracking();
+
H.updateSetting("enable-embedding-simple", true);
+ H.updateSetting("enable-embedding-static", true);
cy.intercept("GET", "/api/dashboard/*").as("dashboard");
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
@@ -64,6 +66,48 @@ describe(suiteTitle, () => {
});
});
+ it("shows the `guest embeds disabled` icon + tooltip when guest embeds disabled", () => {
+ H.updateSetting("enable-embedding-static", false);
+
+ H.visitQuestion(ORDERS_COUNT_QUESTION_ID);
+
+ visitNewEmbedPage({ waitForResource: false });
+
+ cy.url().should("not.match", /\/admin\/embedding\/guest/);
+
+ getEmbedSidebar().within(() => {
+ cy.findByTestId("guest-embeds-disabled-info-icon").should("be.visible");
+ cy.findByTestId("guest-embeds-disabled-info-icon").click();
+ });
+
+ H.hovercard()
+ .findByText(/You can enable guest embeds in/)
+ .should("exist");
+
+ H.hovercard()
+ .findByText(/admin settings/)
+ .click();
+
+ cy.findAllByTestId(/(sdk-setting-card|guest-embeds-setting-card)/)
+ .first()
+ .within(() => {
+ cy.url().should("match", /\/admin\/embedding\/guest/);
+ cy.findByText("Enable guest embeds").should("be.visible");
+ });
+ });
+
+ it("hides the `guest embeds disabled` icon + tooltip when guest embeds enabled", () => {
+ H.updateSetting("enable-embedding-static", true);
+
+ H.visitQuestion(ORDERS_COUNT_QUESTION_ID);
+
+ visitNewEmbedPage({ waitForResource: false });
+
+ getEmbedSidebar().within(() => {
+ cy.findByTestId("guest-embeds-disabled-info-icon").should("not.exist");
+ });
+ });
+
it("shows the most recent question from the activity log when selected", () => {
const questionName = "Orders, Count";
diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx
index 2ddae30a3e8..1e3bc60354b 100644
--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx
+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx
@@ -1,14 +1,17 @@
import type { ReactNode } from "react";
-import { t } from "ttag";
+import { Link } from "react-router";
+import { c, t } from "ttag";
-import { TooltipWarning } from "metabase/embedding/embedding-iframe-sdk-setup/components/Common/TooltipWarning";
import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";
import {
DEFAULT_EXPERIENCE,
useHandleExperienceChange,
} from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change";
import { getAuthTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings";
-import { Card, Radio, Stack, Text } from "metabase/ui";
+import { useDispatch } from "metabase/lib/redux";
+import { isEEBuild } from "metabase/lib/utils";
+import { closeModal } from "metabase/redux/ui";
+import { Card, Flex, HoverCard, Icon, Radio, Stack, Text } from "metabase/ui";
export const AuthenticationSection = () => {
const {
@@ -79,16 +82,45 @@ const WithGuestEmbedsDisabledWarning = ({
}: {
children: (data: { disabled: boolean }) => ReactNode;
}) => {
+ const dispatch = useDispatch();
+
const { isGuestEmbedsEnabled } = useSdkIframeEmbedSetupContext();
- const disabled = !isGuestEmbedsEnabled;
+ // We show the icon only in the EE build. For the OSS build we show the EnableEmbeddingCard
+ const showIcon = isEEBuild();
return (
- <TooltipWarning
- tooltip={t`Disabled in the admin settings`}
- disabled={disabled}
- >
- {children}
- </TooltipWarning>
+ <Flex align="center" gap="xs">
+ {children({ disabled: !isGuestEmbedsEnabled })}
+
+ <HoverCard>
+ {showIcon && !isGuestEmbedsEnabled && (
+ <HoverCard.Target>
+ <Icon
+ data-testid="guest-embeds-disabled-info-icon"
+ name="info"
+ size={14}
+ c="text-secondary"
+ />
+ </HoverCard.Target>
+ )}
+
+ <HoverCard.Dropdown p="sm">
+ <Text>{c(
+ "{0} is a link to guest embeds settings page with text 'admin settings'",
+ ).jt`You can enable guest embeds in ${(
+ <Link
+ key="admin-settings-link"
+ to="/admin/embedding/guest"
+ onClick={() => dispatch(closeModal())}
+ >
+ <Text display="inline" c="text-brand" fw="bold">{c(
+ "is a link in a sentence 'You can enable guest embeds in admin settings'",
+ ).t`admin settings`}</Text>
+ </Link>
+ )}`}</Text>
+ </HoverCard.Dropdown>
+ </HoverCard>
+ </Flex>
);
};