Skip to content

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

Fix download not getting parameters from visualized dashcards (#64754)

Mahatthana (Kelvin) Nomsawadi92cea5d4f553
diff --git a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
index 10fc1b2a20d..79fb169faa1 100644
--- a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
@@ -1524,3 +1524,112 @@ SELECT 'group_2', 'sub_group_2', 52, 'group_2__sub_group_2';
const scalarContainer = () => cy.findByTestId("scalar-container");
const previousValue = () => cy.findByTestId("scalar-previous-value");
+
+describe("issue 63416", () => {
+ const questionDetails = {
+ name: "63416 Question",
+ query: {
+ "source-table": ORDERS_ID,
+ aggregation: [["count"]],
+ breakout: [
+ [
+ "field",
+ ORDERS.CREATED_AT,
+ {
+ "base-type": "type/DateTime",
+ "temporal-unit": "month",
+ },
+ ],
+ ],
+ filter: [">=", ["field", ORDERS.CREATED_AT, null], "2024-01-01"],
+ },
+ };
+
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+
+ const textFilter = createMockParameter({
+ name: "Text",
+ slug: "string",
+ id: "5aefc726",
+ type: "string/=",
+ sectionId: "string",
+ });
+
+ H.createDashboardWithQuestions({
+ dashboardDetails: {
+ parameters: [textFilter],
+ },
+ questions: [questionDetails],
+ }).then(({ dashboard, questions }) => {
+ H.updateDashboardCards({
+ dashboard_id: dashboard.id,
+ cards: [
+ {
+ card_id: questions[0].id,
+ parameter_mappings: [
+ {
+ parameter_id: textFilter.id,
+ card_id: questions[0].id,
+ target: [
+ "dimension",
+ [
+ "field",
+ PRODUCTS.CATEGORY,
+ {
+ "base-type": "type/Text",
+ "source-field": ORDERS.PRODUCT_ID,
+ },
+ ],
+ { "stage-number": 0 },
+ ],
+ },
+ ],
+ },
+ ],
+ });
+
+ H.visitDashboard(dashboard.id);
+ });
+ });
+
+ it("should download visualizer dashboard card without additional dataset with proper parameter values (metabase#63416)", () => {
+ H.editDashboard();
+
+ H.showDashcardVisualizerModalSettings(0, {
+ isVisualizerCard: false,
+ });
+ H.modal()
+ .findByLabelText("Description")
+ .type("Make this a visualizer card");
+
+ H.saveDashcardVisualizerModal();
+
+ H.saveDashboard();
+
+ H.toggleFilterWidgetValues(["Doohickey"]);
+
+ H.downloadAndAssert(
+ {
+ fileType: "csv",
+ isDashboard: true,
+ logResults: true,
+ downloadMethod: "POST",
+ downloadUrl: "/api/dashboard/10/dashcard/*/card/*/query/csv",
+ },
+ (sheet) => {
+ expect(sheet["A1"].v).to.eq("Created At: Month");
+ expect(sheet["B1"].v).to.eq("Count");
+
+ expect(sheet["A2"].v).to.eq("January, 2024");
+ expect(sheet["B2"].v).to.eq(113);
+
+ expect(sheet["A3"].v).to.eq("February, 2024");
+ expect(sheet["B3"].v).to.eq(87);
+
+ H.assertSheetRowsCount(28)(sheet);
+ },
+ );
+ });
+});
diff --git a/frontend/src/metabase-types/api/dataset.ts b/frontend/src/metabase-types/api/dataset.ts
index 498c1e23fed..a501e59a0ba 100644
--- a/frontend/src/metabase-types/api/dataset.ts
+++ b/frontend/src/metabase-types/api/dataset.ts
@@ -177,7 +177,7 @@ export type SingleSeries = {
* COLUMN_2, etc.) to their original values (count, avg, etc.).
*/
columnValuesMapping?: Record<string, VisualizerColumnValueSource[]>;
-} & Pick<Dataset, "error" | "started_at" | "data">;
+} & Pick<Dataset, "error" | "started_at" | "data" | "json_query">;
export type SingleSeriesWithTranslation = SingleSeries & {
data: Dataset["data"] & {
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx
index ef42a5e2302..ff5f1654426 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx
@@ -334,6 +334,8 @@ export function DashCardVisualization({
started_at: new Date().toISOString(),
columnValuesMapping,
+
+ json_query: rawSeries[0].json_query,
},
];