Skip to content
Snippets Groups Projects
Unverified Commit 8a5abd51 authored by metamben's avatar metamben Committed by GitHub
Browse files

Implement MLv1 compatible display names for bucketed fields (#30698)

Implement MLv1 compatible display names for bucketed fields
parent e3fa56d4
No related branches found
No related tags found
No related merge requests found
......@@ -117,7 +117,7 @@ describe("binning related reproductions", () => {
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Sort").click();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Created At (month)").click();
cy.findByText("Created At: Month").click();
// Change the binning of the breakout field
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
......@@ -128,7 +128,7 @@ describe("binning related reproductions", () => {
cy.findByText("Quarter").click();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Created At (quarter)");
cy.findByText("Created At: Quarter");
});
it("should render binning options when joining on the saved native question (metabase#18646)", () => {
......
(ns metabase.lib.field
(:require
[clojure.string :as str]
[medley.core :as m]
[metabase.lib.aggregation :as lib.aggregation]
[metabase.lib.binning :as lib.binning]
......@@ -197,8 +198,10 @@
(str join-display-name " → " field-display-name)
field-display-name)]
(cond
temporal-unit (lib.util/format "%s (%s)" display-name (name temporal-unit))
binning (lib.util/format "%s: %s" display-name (lib.binning/binning-display-name binning field-metadata))
temporal-unit (lib.util/format "%s: %s" display-name (-> (name temporal-unit)
(str/replace \- \space)
u/capitalize-en))
binning (lib.util/format "%s: %s" display-name (lib.binning/binning-display-name binning field-metadata))
:else display-name)))
(defmethod lib.metadata.calculation/display-name-method :field
......
......@@ -25,7 +25,7 @@
{:base-type :type/Date, :temporal-unit :year}
(meta/id :checkins :date)]]}]}
query))
(is (= "Checkins, Count, Grouped by Date (year)"
(is (= "Checkins, Count, Grouped by Date: Year"
(lib/display-name query query)
(lib/describe-query query)
(lib/suggested-name query)))))
......
......@@ -131,19 +131,19 @@
(deftest ^:parallel unresolved-lib-field-with-temporal-bucket-test
(let [query (lib/query-for-table-name meta/metadata-provider "CHECKINS")
f (lib/with-temporal-bucket (lib/field (meta/id :checkins :date)) :year)]
f (lib/with-temporal-bucket (lib/field (meta/id :checkins :date)) :day-of-month)]
(is (fn? f))
(let [field (f query -1)]
(is (=? [:field {:temporal-unit :year} (meta/id :checkins :date)]
(is (=? [:field {:temporal-unit :day-of-month} (meta/id :checkins :date)]
field))
(testing "(lib/temporal-bucket <column-metadata>)"
(is (= :year
(is (= :day-of-month
(lib/temporal-bucket (lib.metadata.calculation/metadata query -1 field)))))
(testing "(lib/temporal-bucket <field-ref>)"
(is (= {:lib/type :type/temporal-bucketing-option
:unit :year}
:unit :day-of-month}
(lib/temporal-bucket-option field))))
(is (= "Date (year)"
(is (= "Date: Day of month"
(lib.metadata.calculation/display-name query -1 field))))))
(def ^:private temporal-bucketing-mock-metadata
......
......@@ -52,6 +52,8 @@
(deftest ^:parallel describe-temporal-unit-test
(is (= ""
(lib.temporal-bucket/describe-temporal-unit nil)))
(is (= "Day of month"
(lib.temporal-bucket/describe-temporal-unit :day-of-month)))
(is (= "Day"
(lib.temporal-bucket/describe-temporal-unit :day)
(lib.temporal-bucket/describe-temporal-unit 1 :day)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment