diff --git a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js index 1a4bfb054b31725f45fd4641569da91862c1b87c..ba06be055aa6b9ea4ea5fb01cfa5746151e215a8 100644 --- a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js +++ b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js @@ -343,41 +343,6 @@ describe("scenarios > visualizations > bar chart", () => { // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage cy.findByText("Category is Doohickey").should("be.visible"); }); - - it("native question should drill-through correctly when stacking", () => { - cy.createNativeQuestion( - { - name: "native question", - native: { - query: ` - SELECT - PRODUCTS.CATEGORY AS "Category", - DATE_TRUNC('month', PRODUCTS.CREATED_AT) AS "CREATED_AT", - COUNT(*) AS "count" - FROM - PRODUCTS - GROUP BY - PRODUCTS.CATEGORY, - DATE_TRUNC('month', PRODUCTS.CREATED_AT) - `, - }, - display: "bar", - visualization_settings: { "stackable.stack_type": "stacked" }, - }, - { visitQuestion: true }, - ); - - cy.log("open drill menu"); - - cy.findAllByTestId("legend-item").findByText("Doohickey").click(); - popover().findByText("See these native questions").click(); - - cy.log("show filter pill"); - cy.findByTestId("filters-visibility-control").click(); - cy.findByTestId("filter-pill") - .findByText("Category is Doohickey") - .should("be.visible"); - }); }); it("supports up to 100 series (metabase#28796)", () => { diff --git a/src/metabase/lib/drill_thru/automatic_insights.cljc b/src/metabase/lib/drill_thru/automatic_insights.cljc index df252c346ddfef6aefe8477cfcd0728cf2c84b3b..4f7d045bcf05a20ca3f3715b065120a52b7ce9b9 100644 --- a/src/metabase/lib/drill_thru/automatic_insights.cljc +++ b/src/metabase/lib/drill_thru/automatic_insights.cljc @@ -5,6 +5,7 @@ [metabase.lib.metadata :as lib.metadata] [metabase.lib.schema :as lib.schema] [metabase.lib.schema.drill-thru :as lib.schema.drill-thru] + [metabase.lib.underlying :as lib.underlying] [metabase.lib.util :as lib.util] [metabase.util.malli :as mu])) @@ -21,8 +22,7 @@ stage-number :- :int {:keys [column column-ref dimensions value]} :- ::lib.schema.drill-thru/context] (when (and (lib.drill-thru.common/mbql-stage? query stage-number) - ;; HACK: This is a not a great way to disable this drill for queries whose source is a native query. - (not= (:lib/source column) :source/native) + (lib.underlying/has-aggregation-or-breakout? query) ;; Column with no value is not allowed - that's a column header click. Other combinations are allowed. (or (not column) (some? value)) (lib.metadata/setting query :enable-xrays) diff --git a/src/metabase/lib/drill_thru/underlying_records.cljc b/src/metabase/lib/drill_thru/underlying_records.cljc index f79fb4e9013f36832de09a45f2c1e2f9e12b239b..6b588bc3939535bfce3875776a19af51e962b195 100644 --- a/src/metabase/lib/drill_thru/underlying_records.cljc +++ b/src/metabase/lib/drill_thru/underlying_records.cljc @@ -72,9 +72,8 @@ ;; - value is nil ;; - dimensions holds only the legend's column, eg. Products.CATEGORY. (when (and (lib.drill-thru.common/mbql-stage? query stage-number) - ;; HACK: This is a not a great way to disable this drill for queries whose source is a native query. - (not= (:lib/source column) :source/native) - ;; Underlying records requires an aggregation. Either we clicked the aggregation, or there are dimensions. + (lib.underlying/has-aggregation-or-breakout? query) + ;; Either we clicked the aggregation, or there are dimensions. (or (= (:lib/source column) :source/aggregations) (not-empty dimensions)) ;; Either we need both column and value (cell/map/data point click) or neither (chart legend click). diff --git a/src/metabase/lib/underlying.cljc b/src/metabase/lib/underlying.cljc index 735046561c2e84062964667e6dcf3853f1627c82..46ee580ff4e0826a5a7ad1b10f5fbe867db3ccb8 100644 --- a/src/metabase/lib/underlying.cljc +++ b/src/metabase/lib/underlying.cljc @@ -63,3 +63,8 @@ prev-col (lib.equality/find-matching-column query -2 (lib.ref/ref column) prev-cols)] (when prev-col (recur (update query :stages pop) prev-col)))))))) + +(mu/defn has-aggregation-or-breakout? + "Whether the `query` has an aggregation or breakout clause in some query stage." + [query :- ::lib.schema/query] + (some? (pop-until-aggregation-or-breakout query)))