Skip to content
Snippets Groups Projects
Unverified Commit b9f55626 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Misc zoom-in-timeseries drill fixes (#36505)

parent b95eb1a4
Branches
Tags
No related merge requests found
import type { DatetimeUnit } from "metabase-types/api";
import {
createOrdersCreatedAtDatasetColumn,
createOrdersQuantityDatasetColumn,
......@@ -17,8 +18,7 @@ import {
createNotEditableQuery,
} from "./drills-common";
// eslint-disable-next-line jest/no-disabled-tests
describe.skip("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
describe("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
const drillType = "drill-thru/zoom-in.timeseries";
const stageIndex = 0;
const aggregationColumn = createCountDatasetColumn();
......@@ -27,12 +27,28 @@ describe.skip("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
});
describe.each([
{ bucketName: "Year", displayName: "See this year by quarters" },
{ bucketName: "Quarter", displayName: "See this quarter by months" },
{ bucketName: "Month", displayName: "See this month by weeks" },
{ bucketName: "Day", displayName: "See this day by hour" },
{ bucketName: "Hour", displayName: "See this hour by minute" },
])("$bucketName", ({ bucketName, displayName }) => {
{
bucketName: "Year",
unit: "year",
displayName: "See this year by quarter",
},
{
bucketName: "Quarter",
unit: "quarter",
displayName: "See this quarter by month",
},
{
bucketName: "Month",
unit: "month",
displayName: "See this month by week",
},
{ bucketName: "Day", unit: "day", displayName: "See this day by hour" },
{
bucketName: "Hour",
unit: "hour",
displayName: "See this hour by minute",
},
])("$bucketName", ({ bucketName, unit, displayName }) => {
it("should drill thru an aggregated cell", () => {
const query = createQueryWithClauses({
aggregations: [{ operatorName: "count" }],
......@@ -51,7 +67,8 @@ describe.skip("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
},
breakouts: [
{
column: breakoutColumn,
// QP results metadata will come back with the temporal unit like this
column: { ...breakoutColumn, unit: unit as DatetimeUnit },
value: "2020-01-01",
},
],
......@@ -93,7 +110,7 @@ describe.skip("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
},
breakouts: [
{
column: breakoutColumn,
column: { ...breakoutColumn, unit: unit as DatetimeUnit },
value: "2020-01-01",
},
{
......@@ -135,7 +152,7 @@ describe.skip("drill-thru/zoom-in.timeseries (metabase#36173)", () => {
],
});
const clickObject = createLegendItemClickObject({
column: breakoutColumn,
column: { ...breakoutColumn, unit: unit as DatetimeUnit },
value: "2020-01-01",
});
const { drill, drillInfo } = findDrillThru(
......
......@@ -59,21 +59,19 @@
For example: The month of a year, days or weeks of a quarter, smaller lat/long regions, etc.
This is different from the `:drill-thru/zoom` type, which is for showing the details of a single object."
;; TODO: This naming is confusing. Fix it?
[query :- ::lib.schema/query
stage-number :- :int
{:keys [column dimensions value]} :- ::lib.schema.drill-thru/context]
[query :- ::lib.schema/query
stage-number :- :int
{:keys [dimensions], :as _context} :- ::lib.schema.drill-thru/context]
(when (and (lib.drill-thru.common/mbql-stage? query stage-number)
column
(not-empty dimensions)
(some? value))
(when-let [dimension (matching-breakout-dimension query stage-number dimensions)]
(when-let [next-unit (next-breakout-unit (:column dimension))]
{:lib/type :metabase.lib.drill-thru/drill-thru
:display-name (describe-next-unit next-unit)
:type :drill-thru/zoom-in.timeseries
:dimension dimension
:next-unit next-unit}))))
(not-empty dimensions))
(when-let [{:keys [value], :as dimension} (matching-breakout-dimension query stage-number dimensions)]
(when value
(when-let [next-unit (next-breakout-unit (:column dimension))]
{:lib/type :metabase.lib.drill-thru/drill-thru
:display-name (describe-next-unit next-unit)
:type :drill-thru/zoom-in.timeseries
:dimension dimension
:next-unit next-unit})))))
(mu/defmethod lib.drill-thru.common/drill-thru-method :drill-thru/zoom-in.timeseries
[query :- ::lib.schema/query
......
......@@ -120,3 +120,47 @@
:query-type :aggregated
:column-name "sum"
:expected {:type :drill-thru/zoom-in.timeseries}})))
(deftest ^:parallel returns-zoom-in-timeseries-e2e-test-2
(testing "zoom-in.timeseries should be returned for a"
(let [query (-> (lib/query meta/metadata-provider (meta/table-metadata :orders))
(lib/aggregate (lib/count))
(lib/breakout (-> (meta/field-metadata :orders :created-at)
(lib/with-temporal-bucket :year))))
created-at-col (m/find-first #(= (:name %) "CREATED_AT")
(lib/returned-columns query))
_ (is (some? created-at-col))]
(doseq [[message context] {"pivot cell (no column, value = NULL) (#36173)"
{:value :null
:column nil
:column-ref nil
:dimensions [{:column created-at-col
:column-ref (lib/ref created-at-col)
:value "2022-12-01T00:00:00+02:00"}]}
"for a legend item (no column, no value) (#36173)"
{:value nil
:column nil
:column-ref nil
:dimensions [{:column created-at-col
:column-ref (lib/ref created-at-col)
:value "2022-12-01T00:00:00+02:00"}]}}]
(testing message
(let [[drill :as drills] (filter #(= (:type %) :drill-thru/zoom-in.timeseries)
(lib/available-drill-thrus query -1 context))]
(is (= 1
(count drills)))
(is (=? {:lib/type :metabase.lib.drill-thru/drill-thru
:display-name "See this year by quarter"
:type :drill-thru/zoom-in.timeseries
:dimension {:column {:name "CREATED_AT"}
:value "2022-12-01T00:00:00+02:00"}
:next-unit :quarter}
drill))
(is (=? {:stages [{:aggregation [[:count {}]]
:breakout [[:field {:temporal-unit :quarter} (meta/id :orders :created-at)]],
:filters [[:=
{}
[:field {:temporal-unit :year} (meta/id :orders :created-at)]
"2022-12-01T00:00:00+02:00"]]}]}
(lib/drill-thru query -1 drill)))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment