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
Fix static embedding or public embed outside iframe not working with #theme (#65740)
Mahatthana (Kelvin) Nomsawadi62fe686ffc5e
diff --git a/e2e/test/scenarios/sharing/public-dashboard.cy.spec.js b/e2e/test/scenarios/sharing/public-dashboard.cy.spec.jsindex f0535054815..d2289ff8a54 100644--- a/e2e/test/scenarios/sharing/public-dashboard.cy.spec.js+++ b/e2e/test/scenarios/sharing/public-dashboard.cy.spec.js@@ -306,6 +306,25 @@ describe("scenarios > public > dashboard", () => {expect(element.href).to.eq("https://metabase.com/");});});++ it("should support #theme=dark (metabase#65731)", () => {+ const dashboardName = "Dashboard Theme Test";+ H.createDashboardWithQuestions({+ dashboardName,+ questions: [],+ }).then(({ dashboard }) => {+ H.visitPublicDashboard(dashboard.id, {+ hash: {+ theme: "dark",+ },+ });+ });++ cy.log("dark theme should have white text");+ cy.findByRole("heading", {+ name: dashboardName,+ }).should("have.css", "color", "rgba(255, 255, 255, 0.95)");+ });});describe("scenarios [EE] > public > dashboard", () => {diff --git a/e2e/test/scenarios/sharing/public-question.cy.spec.js b/e2e/test/scenarios/sharing/public-question.cy.spec.jsindex d703966297b..9e21b392e84 100644--- a/e2e/test/scenarios/sharing/public-question.cy.spec.js+++ b/e2e/test/scenarios/sharing/public-question.cy.spec.js@@ -2,7 +2,7 @@ const { H } = cy;import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-const { PEOPLE } = SAMPLE_DATABASE;+const { PEOPLE, ORDERS_ID } = SAMPLE_DATABASE;const questionData = {name: "Parameterized Public Question",@@ -192,6 +192,27 @@ describe("scenarios > public > question", () => {});});});++ it("should support #theme=dark (metabase#65731)", () => {+ const questionName = "Orders Theme Test";+ H.createQuestion({+ name: questionName,+ query: {+ "source-table": ORDERS_ID,+ },+ }).then(({ body: { id } }) => {+ H.visitPublicQuestion(id, {+ hash: {+ theme: "dark",+ },+ });+ });++ cy.log("dark theme should have white text");+ cy.findByRole("heading", {+ name: questionName,+ }).should("have.css", "color", "rgba(255, 255, 255, 0.95)");+ });});describe("scenarios > question > public link with extension", () => {diff --git a/frontend/src/metabase/app-embed.js b/frontend/src/metabase/app-embed.jsindex 2c716c1912a..b0804f9d38e 100644--- a/frontend/src/metabase/app-embed.js+++ b/frontend/src/metabase/app-embed.js@@ -3,8 +3,12 @@* file 'LICENSE-EMBEDDING.txt', which is part of this source code package.*/+import { setIsStaticEmbedding } from "metabase/embedding/config";+import { init } from "./app";import { publicReducers } from "./reducers-public";import { getRoutes } from "./routes-embed";+setIsStaticEmbedding();+init(publicReducers, getRoutes, () => {});diff --git a/frontend/src/metabase/app-public.js b/frontend/src/metabase/app-public.jsindex a34bc882f2b..1da3ab18571 100644--- a/frontend/src/metabase/app-public.js+++ b/frontend/src/metabase/app-public.js@@ -1,5 +1,9 @@+import { setIsPublicEmbedding } from "metabase/embedding/config";+import { init } from "./app";import { publicReducers } from "./reducers-public";import { getRoutes } from "./routes-public";+setIsPublicEmbedding();+init(publicReducers, getRoutes, () => {});diff --git a/frontend/src/metabase/embedding/config.ts b/frontend/src/metabase/embedding/config.tsnew file mode 100644index 00000000000..89231a96c3e--- /dev/null+++ b/frontend/src/metabase/embedding/config.ts@@ -0,0 +1,25 @@+type InternalEmbeddingConfig = {+ isPublicEmbedding: boolean;+ isStaticEmbedding: boolean;+};++const EMBEDDING_CONFIG: InternalEmbeddingConfig = {+ isPublicEmbedding: false,+ isStaticEmbedding: false,+};++export function setIsPublicEmbedding() {+ EMBEDDING_CONFIG.isPublicEmbedding = true;+}++export function setIsStaticEmbedding() {+ EMBEDDING_CONFIG.isStaticEmbedding = true;+}++export function isPublicEmbedding() {+ return EMBEDDING_CONFIG.isPublicEmbedding;+}++export function isStaticEmbedding() {+ return EMBEDDING_CONFIG.isStaticEmbedding;+}diff --git a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsxindex 4f65f0ac337..c398e092a62 100644--- a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx+++ b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx@@ -11,11 +11,14 @@ import {useState,} from "react";+import {+ isPublicEmbedding,+ isStaticEmbedding,+} from "metabase/embedding/config";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";import { parseHashOptions } from "metabase/lib/browser";import { mutateColors } from "metabase/lib/colors/colors";import type { DisplayTheme } from "metabase/public/lib/types";-import { getIsEmbeddingIframe } from "metabase/selectors/embed";import { getThemeOverrides } from "../../../theme";import { ColorSchemeProvider, useColorScheme } from "../ColorSchemeProvider";@@ -154,7 +157,7 @@ const useColorSchemeFromHash = ({export const ThemeProvider = (props: ThemeProviderProps) => {const schemeFromHash = useColorSchemeFromHash({- enabled: getIsEmbeddingIframe(),+ enabled: isStaticEmbedding() || isPublicEmbedding(),});const forceColorScheme = props.displayTheme? getColorSchemeFromDisplayTheme(props.displayTheme)