Skip to content

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

fix(modular): fix downloads on dashboards loaded by entityIds (#65613)

Nicolò Pretto671e406c2887
diff --git a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
index 3204b58dd88..eea4824e9cf 100644
--- a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
@@ -291,6 +291,36 @@ describe("scenarios > embedding-sdk > interactive-dashboard", () => {
cy.wait(500);
cy.get("@datasetQuery.all").should("have.length", 1);
});
+
+ idTypes.forEach(({ idType, dashboardIdAlias }) => {
+ it(`should be able to download dashcard results using ${idType}`, () => {
+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query/xlsx").as(
+ "dashcardDownload",
+ );
+
+ cy.get(dashboardIdAlias).then((dashboardId) => {
+ mountSdkContent(
+ <InteractiveDashboard dashboardId={dashboardId} withDownloads />,
+ );
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByText("Orders in a dashboard").should("be.visible");
+
+ // Open dashcard menu
+ H.getDashboardCard().realHover();
+ H.getEmbeddedDashboardCardMenu().click();
+
+ H.popover().findByText("Download results").click();
+ H.popover().findByText(".xlsx").click();
+ H.popover().findByText("Download").click();
+ });
+
+ cy.wait("@dashcardDownload").then((interception) => {
+ expect(interception.response?.statusCode).to.equal(200);
+ });
+ });
+ });
});
describe("scenarios > embedding-sdk > interactive-dashboard > tabs", () => {
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
index 27aa5d4ee13..3e82dedfdee 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
@@ -609,4 +609,27 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
});
});
});
+
+ it("downloads should work when using entity IDs", () => {
+ cy.intercept("POST", "/api/card/*/query/xlsx").as("questionDownload");
+
+ cy.get<string>("@questionEntityId").then((questionEntityId) => {
+ mountSdkContent(
+ <InteractiveQuestion questionId={questionEntityId} withDownloads />,
+ );
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("interactive-question-result-toolbar")
+ .findByTestId("question-download-widget-button")
+ .click();
+
+ cy.findByText(".xlsx").click();
+ cy.findByTestId("download-results-button").click();
+ });
+
+ cy.wait("@questionDownload").then((interception) => {
+ expect(interception.response?.statusCode).to.equal(200);
+ });
+ });
});
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
index 02767e03e9c..747f12b85da 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx
@@ -72,7 +72,8 @@ export const DashCardMenu = ({
const [{ loading: isDownloadingData }, handleDownload] = useDownloadData({
question,
result,
- dashboardId: checkNotNull(dashboardId),
+ // dashboardId can be an entityId and the download endpoint expects a numeric id
+ dashboardId: checkNotNull(dashboard?.id ?? dashboardId),
dashcardId,
uuid,
token,
diff --git a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
index d1bfcc2f8cb..c78ea81d4b2 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx
@@ -29,7 +29,7 @@ export const PublicOrEmbeddedDashCardMenu = ({
const store = useStore();
const token = getDashcardTokenId(dashcard);
const uuid = getDashcardUuid(dashcard);
- const { dashboardId } = useDashboardContext();
+ const { dashboard, dashboardId } = useDashboardContext();
const [menuView, setMenuView] = useState<string | null>(null);
const [isOpen, { close, toggle }] = useDisclosure(false, {
@@ -48,7 +48,8 @@ export const PublicOrEmbeddedDashCardMenu = ({
const [{ loading: isDownloadingData }, handleDownload] = useDownloadData({
question: question,
result,
- dashboardId: checkNotNull(dashboardId),
+ // dashboardId can be an entityId and the download endpoint expects a numeric id
+ dashboardId: checkNotNull(dashboard?.id ?? dashboardId),
dashcardId: dashcard.id,
uuid,
token,