| (mu/defn automatic-insights-drill :- [:maybe ::lib.schema.drill-thru/drill-thru]
"Automatic insights appears:
- When clicking on a value with a breakout - eg. a point in a time series, a cell of a table, a bar or pie slice
- Or when clicking a pivot cell, with a value but no column.
- Or when clicking a chart legend, in which case there's no column or value set.
- There must be at least 1 breakout
- X-rays must be enabled (check the settings)
There are two forms: X-ray, and \"Compare to the rest\". This is a simple user choice and does not need extra data."
[query :- ::lib.schema/query
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)
(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)
(not-empty dimensions))
{:lib/type :metabase.lib.drill-thru/drill-thru
:type :drill-thru/automatic-insights
:column-ref column-ref
:dimensions dimensions})) |