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
Fixed custom actions from the `mapQuestionClickActions` plugin not appearing in `EditableDashboard` click action popover (#82832)
Timofey Kachalov6c4b0182c116
diff --git a/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsxindex b3d7e91ad0a..b4a1dba44d5 100644--- a/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/plugins.cy.spec.tsx@@ -1,4 +1,8 @@-import { InteractiveDashboard } from "@metabase/embedding-sdk-react";+import {+ EditableDashboard,+ InteractiveDashboard,+ type MetabasePluginsConfig,+} from "@metabase/embedding-sdk-react";import { useState } from "react";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";@@ -111,7 +115,7 @@ describe("scenarios > embedding-sdk > plugins", () => {mountSdkContent(<InteractiveDashboard dashboardId={dashboardId} />, {sdkProviderProps: {pluginsConfig: {- mapQuestionClickActions: (clickActions: ClickAction[]) => [+ mapQuestionClickActions: (clickActions) => [...clickActions,CUSTOM_ACTION_WITH_VIEW,],@@ -212,6 +216,102 @@ describe("scenarios > embedding-sdk > plugins", () => {});});+ describe("The `mapQuestionClickActions` plugin should work for `EditableDashboard`", () => {+ beforeEach(() => {+ setup(() => {+ createDashboardWithQuestions({+ dashboardName: "Orders in a dashboard",+ questions: [BASE_QUESTION],+ cards: [+ {+ size_x: 12,+ col: 0,+ },+ ],+ }).then(({ dashboard }) => {+ cy.wrap(dashboard.id).as("dashboardId");+ });+ });+ });++ it("should open a click actions popover with a custom item from component plugins", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(+ <EditableDashboard+ dashboardId={dashboardId}+ plugins={{+ 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 open a click actions popover with a custom item from global plugins", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(<EditableDashboard dashboardId={dashboardId} />, {+ sdkProviderProps: {+ pluginsConfig: {+ mapQuestionClickActions: (clickActions) => [+ ...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 open a click actions popover with a custom item when the same plugins are passed to both the provider and the component", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ const plugins: MetabasePluginsConfig = {+ mapQuestionClickActions: (clickActions) => [+ ...clickActions,+ CUSTOM_ACTION_WITH_VIEW,+ ],+ };++ mountSdkContent(+ <EditableDashboard dashboardId={dashboardId} plugins={plugins} />,+ { sdkProviderProps: { pluginsConfig: plugins } },+ );+ });++ 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");+ });+ });+ });+describe("The `mapQuestionClickActions` plugin should work for `InteractiveQuestion`", () => {beforeEach(() => {setup(() => {@@ -225,7 +325,7 @@ describe("scenarios > embedding-sdk > plugins", () => {it("should open a click actions popover with a custom item", () => {mountInteractiveQuestion({plugins: {- mapQuestionClickActions: (clickActions: ClickAction[]) => [+ mapQuestionClickActions: (clickActions) => [...clickActions,CUSTOM_ACTION_WITH_VIEW,],diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsxindex 22af55d35d1..e8b778faee3 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx@@ -6,6 +6,9 @@ import { SdkInternalNavigationProvider } from "embedding-sdk-bundle/components/pimport { useSdkInternalNavigation } from "embedding-sdk-bundle/components/private/SdkInternalNavigation/context";import { createEmbeddingSdkMode } from "embedding-sdk-bundle/lib/modes/EmbeddingSdkMode";import { getEmbeddingMode } from "embedding-sdk-bundle/lib/modes/getEmbeddingMode";+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 { DASHBOARD_EDITING_ACTIONS } from "metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/constants";import { DASHBOARD_ACTION } from "metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys";import type { MetabasePluginsConfig as InternalMetabasePluginsConfig } from "metabase/embedding-sdk/types/plugins";@@ -28,6 +31,7 @@ export type EditableDashboardProps = SdkDashboardProps &EditableDashboardOwnProps;const EditableDashboardContent = (props: EditableDashboardProps) => {+ const globalPlugins = useSdkSelector(getPlugins);const { push: pushNavigation } = useSdkInternalNavigation();const {@@ -59,15 +63,18 @@ const EditableDashboardContent = (props: EditableDashboardProps) => {DASHBOARD_ACTION.REFRESH_INDICATOR,];+ const plugins: MetabasePluginsConfig = useMemo(() => {+ return { ...globalPlugins, ...props.plugins };+ }, [globalPlugins, props.plugins]);+const clickActionMode = useMemo(() =>getEmbeddingMode({queryMode: createEmbeddingSdkMode({ pushNavigation }),// Unjustified type cast. FIXME- plugins: props.drillThroughQuestionProps- ?.plugins as InternalMetabasePluginsConfig,+ plugins: plugins as InternalMetabasePluginsConfig,}),- [pushNavigation, props.drillThroughQuestionProps?.plugins],+ [plugins, pushNavigation],);return (