Skip to content

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

fix(embed-js): adjust experience reset logic to avoid unexpected experience resets (#68273)

Timofey Kachalovd5ad9d6142a4
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common.cy.spec.ts
index a583007453b..7cfcbf31927 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/common.cy.spec.ts
@@ -1,7 +1,11 @@
+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
+import { embedModalEnableEmbedding } from "e2e/support/helpers";
+
import {
getEmbedSidebar,
navigateToEntitySelectionStep,
navigateToGetCodeStep,
+ visitNewEmbedPage,
} from "./helpers";
const { H } = cy;
@@ -15,6 +19,7 @@ describe("scenarios > embedding > sdk iframe embed setup > common", () => {
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");
@@ -85,4 +90,64 @@ describe("scenarios > embedding > sdk iframe embed setup > common", () => {
.contains("General")
.should("be.visible");
});
+
+ describe("auth type switch", () => {
+ it("should reset experience to a default only when switching from SSO to Guest auth type and the current experience does not support guest embeds", () => {
+ visitNewEmbedPage();
+
+ getEmbedSidebar().within(() => {
+ cy.findByLabelText("Metabase account (SSO)").click();
+
+ cy.findByLabelText("Browser").click();
+ cy.findByLabelText("Browser").should("be.checked");
+
+ cy.findByLabelText("Guest").click();
+
+ cy.findByLabelText("Dashboard").should("be.checked");
+
+ cy.findByLabelText("Chart").click();
+ cy.findByLabelText("Chart").should("be.checked");
+
+ cy.findByLabelText("Metabase account (SSO)").click();
+
+ cy.findByLabelText("Chart").should("be.checked");
+
+ cy.findByLabelText("Guest").click();
+
+ cy.findByLabelText("Chart").should("be.checked");
+ });
+ });
+
+ it("should not reset experience when changing auth type for Embed JS wizard opened from an entity page", () => {
+ H.visitQuestion(ORDERS_QUESTION_ID);
+
+ H.openSharingMenu("Embed");
+
+ getEmbedSidebar().within(() => {
+ embedModalEnableEmbedding();
+
+ H.waitForSimpleEmbedIframesToLoad();
+
+ H.getSimpleEmbedIframeContent().within(() => {
+ cy.findByText("Orders").should("be.visible");
+ });
+
+ cy.findByLabelText("Metabase account (SSO)").click();
+
+ H.waitForSimpleEmbedIframesToLoad();
+
+ H.getSimpleEmbedIframeContent().within(() => {
+ cy.findByText("Orders").should("be.visible");
+ });
+
+ cy.findByLabelText("Guest").click();
+
+ H.waitForSimpleEmbedIframesToLoad();
+
+ H.getSimpleEmbedIframeContent().within(() => {
+ cy.findByText("Orders").should("be.visible");
+ });
+ });
+ });
+ });
});
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 1e3bc60354b..07235d98559 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
@@ -8,6 +8,8 @@ import {
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 { isQuestionOrDashboardExperience } from "metabase/embedding/embedding-iframe-sdk-setup/utils/is-question-or-dashboard-experience";
+import { isStepWithResource } from "metabase/embedding/embedding-iframe-sdk-setup/utils/is-step-with-resource";
import { useDispatch } from "metabase/lib/redux";
import { isEEBuild } from "metabase/lib/utils";
import { closeModal } from "metabase/redux/ui";
@@ -15,8 +17,10 @@ import { Card, Flex, HoverCard, Icon, Radio, Stack, Text } from "metabase/ui";
export const AuthenticationSection = () => {
const {
+ experience,
isSimpleEmbedFeatureAvailable,
isFirstStep,
+ currentStep,
settings,
updateSettings,
} = useSdkIframeEmbedSetupContext();
@@ -32,8 +36,13 @@ export const AuthenticationSection = () => {
const isGuest = value === "guest-embed";
const isSso = value === "sso";
- if (isGuest) {
- // Reset experience to default when switching to guest embeds
+ // Reset experience to default when switching to guest embeds from non-supported experience
+ const shouldSwitchExperience =
+ isGuest &&
+ !isStepWithResource(currentStep) &&
+ !isQuestionOrDashboardExperience(experience);
+
+ if (shouldSwitchExperience) {
handleEmbedExperienceChange(DEFAULT_EXPERIENCE);
}