Skip to content
Snippets Groups Projects
Unverified Commit 1f6a9022 authored by Simon Belak's avatar Simon Belak Committed by GitHub
Browse files

Merge pull request #9488 from metabase/xray-better-interesting-filters

Make xray dashboard filters more diverse
parents 44c10681 0e0700a5
Branches
Tags
No related merge requests found
......@@ -1123,14 +1123,14 @@
(->> field-reference (field-reference->field root) field-name))
([{:keys [display_name unit] :as field}]
(cond->> display_name
(and (filters/periodic-datetime? field) unit) (tru "{0} of {1}" (unit-name unit)))))
(some-> unit date/date-extract-units) (tru "{0} of {1}" (unit-name unit)))))
(defmethod humanize-filter-value :=
[root [_ field-reference value]]
(let [field (field-reference->field root field-reference)
field-name (field-name field)]
(if (or (filters/datetime? field)
(filters/periodic-datetime? field))
(if (or (isa? (:base_type field) :type/DateTime)
(field/unix-timestamp? field))
(tru "{0} is {1}" field-name (humanize-datetime value (:unit field)))
(tru "{0} is {1}" field-name value))))
......
......@@ -50,16 +50,10 @@
identity)
(filter field-reference?)))
(def ^{:arglists '([field])} periodic-datetime?
"Is `field` a periodic datetime (eg. day of month)?"
(comp #{:minute-of-hour :hour-of-day :day-of-week :day-of-month :day-of-year :week-of-year
:month-of-year :quarter-of-year}
:unit))
(defn datetime?
"Is `field` a datetime?"
[field]
(and (not (periodic-datetime? field))
(and (not ((disj metabase.util.date/date-extract-units :year) (:unit field)))
(or (isa? (:base_type field) :type/DateTime)
(field/unix-timestamp? field))))
......@@ -75,6 +69,23 @@
(isa? special_type :type/CreationTimestamp) inc
(#{:type/State :type/Country} special_type) inc))
(defn- interleave-all
[& colls]
(lazy-seq
(when-not (empty? colls)
(concat (map first colls) (apply interleave-all (keep (comp seq rest) colls))))))
(defn- sort-by-interestingness
[fields]
(->> fields
(map #(assoc % :interestingness (interestingness %)))
(sort-by interestingness >)
(partition-by :interestingness)
(mapcat (fn [fields]
(->> fields
(group-by (juxt :base_type :special_type))
vals
(apply interleave-all))))))
(defn interesting-fields
"Pick out interesting fields and sort them by interestingness."
......@@ -83,7 +94,7 @@
(filter (fn [{:keys [special_type] :as field}]
(or (datetime? field)
(isa? special_type :type/Category))))
(sort-by interestingness >)))
sort-by-interestingness))
(defn- candidates-for-filtering
[fieldset cards]
......@@ -160,7 +171,7 @@
field/with-targets)]
(->> dimensions
remove-unqualified
(sort-by interestingness >)
sort-by-interestingness
(take max-filters)
(reduce
(fn [dashboard candidate]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment