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
use parseAttributeValue on custom-context to parse stringified JSON values (#73390)
Nicolò Pretto920ea341cb7d
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.tsindex 563682be3c9..f4b6db03429 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts@@ -265,7 +265,8 @@ describe("scenarios > embedding > sdk iframe embedding > guest token refresh", (component: "metabase-dashboard",attributes: {token: expiredToken,- "custom-context": "test-custom-context",+ "custom-context":+ '{"param":"value","nested":{"a":1}}',},},],@@ -275,7 +276,7 @@ describe("scenarios > embedding > sdk iframe embedding > guest token refresh", (expect(interception.request.body).to.deep.include({entityType: "dashboard",entityId: dashboardId,- customContext: "test-custom-context",+ customContext: { param: "value", nested: { a: 1 } },});});diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.tsindex b203af30313..b0a72940803 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts@@ -606,7 +606,10 @@ export abstract class MetabaseEmbedElement<T extends string[] = string[]>// Only works in React 19const objectCustomContext = this["custom-context"];- const stringCustomContext = this.getAttribute("custom-context");+ // parseAttributeValue parses it if it's a stringified JSON+ const stringCustomContext = parseAttributeValue(+ this.getAttribute("custom-context"),+ );const customContext = objectCustomContext ?? stringCustomContext;const body = {entityType,diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.tsindex ec315c5a23c..3004778283d 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts@@ -320,6 +320,31 @@ describe("embed.js script tag for sdk iframe embedding", () => {);});+ it("should parse a stringified JSON passed to custom-context", async () => {+ fetchMock.post("path:/mock-provider", { jwt: "refreshed-token" });++ const { triggerIframeMessage } = setupGuestEmbed({+ dashboardId: "1",+ customContext: '{"param":"value","nested":{"a":1}}',+ });++ triggerIframeMessage({+ type: "metabase.embed.requestGuestTokenRefresh",+ data: { expiredToken: "any.expired.token" },+ });+ await flushPromises();++ const call = fetchMock.callHistory.lastCall("path:/mock-provider");+ expect(call?.options).toMatchObject({+ method: "post",+ body: JSON.stringify({+ entityType: "dashboard",+ entityId: 1,+ customContext: { param: "value", nested: { a: 1 } },+ }),+ });+ });+it("sends reportAuthenticationError to iframe when provider returns HTTP error", async () => {fetchMock.post("path:/mock-provider", 403);