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
feat(sdk): plugins passed to the provider are passed down to the (#64920)
Nicolò Pretto67d603aa42f2
diff --git a/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsxindex 87894199cd0..b3d7e91ad0a 100644--- a/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx@@ -80,7 +80,7 @@ describe("scenarios > embedding-sdk > plugins", () => {});});- it("should open a click actions popover with a custom item", () => {+ it("should open a click actions popover with a custom item from component plugins", () => {cy.get<string>("@dashboardId").then((dashboardId) => {mountSdkContent(<InteractiveDashboard@@ -106,6 +106,31 @@ describe("scenarios > embedding-sdk > plugins", () => {});});+ it("should open a click actions popover with a custom item from global plugins (EMB-894)", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(<InteractiveDashboard dashboardId={dashboardId} />, {+ sdkProviderProps: {+ pluginsConfig: {+ mapQuestionClickActions: (clickActions: ClickAction[]) => [+ ...clickActions,+ CUSTOM_ACTION_WITH_VIEW,+ ],+ },+ },+ });+ });++ getSdkRoot().within(() => {+ cy.findByText("Facebook").click();++ cy.findByTestId("click-actions-popover").within(() => {+ cy.findByText("Custom element").click();+ });++ cy.findByTestId("click-actions-popover").should("not.exist");+ });+ });+it("should execute action immediately when returning a single object with onClick", () => {cy.get<string>("@dashboardId").then((dashboardId) => {const onClickSpy = cy.spy().as("onClickSpy");diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsxindex 2732e09b487..6cb8c7bacbc 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx@@ -1,5 +1,8 @@-import { useCallback } from "react";+import { useCallback, useMemo } from "react";+import { useSdkSelector } from "embedding-sdk-bundle/store";+import { getPlugins } from "embedding-sdk-bundle/store/selectors";+import type { MetabasePluginsConfig } from "embedding-sdk-bundle/types/plugins";import { PublicOrEmbeddedDashCardMenu } from "metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu";import { DASHBOARD_ACTION } from "metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys";import { isQuestionCard } from "metabase/dashboard/utils";@@ -20,14 +23,20 @@ import { interactiveDashboardSchema } from "./InteractiveDashboard.schema";export type InteractiveDashboardProps = SdkDashboardProps;const InteractiveDashboardInner = (props: InteractiveDashboardProps) => {+ const globalPlugins = useSdkSelector(getPlugins);++ const plugins: MetabasePluginsConfig = useMemo(() => {+ return { ...globalPlugins, ...props.plugins };+ }, [globalPlugins, props.plugins]);+const getClickActionMode: ClickActionModeGetter = useCallback(({ question }) =>getEmbeddingMode({question,queryMode: EmbeddingSdkMode,- plugins: props.plugins as InternalMetabasePluginsConfig,+ plugins: plugins as InternalMetabasePluginsConfig,}),- [props.plugins],+ [plugins],);return (