Skip to content
Snippets Groups Projects
Unverified Commit 1ef37190 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #8237 from metabase/xray-fixes

X-ray fixes
parents 239dc708 2d46a58e
Branches
Tags
No related merge requests found
(ns metabase.automagic-dashboards.comparison
(:require [clojure.string :as str]
[medley.core :as m]
(:require [medley.core :as m]
[metabase.api.common :as api]
[metabase.automagic-dashboards
[core :refer [->root ->field automagic-analysis ->related-entity cell-title source-name capitalize-first encode-base64-json]]
[core :refer [->root ->field automagic-analysis ->related-entity cell-title source-name capitalize-first encode-base64-json metric-name]]
[filters :as filters]
[populate :as populate]]
[metabase.models
[metric :refer [Metric]]
[table :refer [Table]]]
[metabase.models.table :refer [Table]]
[metabase.query-processor.middleware.expand-macros :refer [merge-filter-clauses segment-parse-filter]]
[metabase.query-processor.util :as qp.util]
[metabase.related :as related]
......@@ -16,7 +13,7 @@
[puppetlabs.i18n.core :as i18n :refer [tru]]))
(def ^:private ^{:arglists '([root])} comparison-name
(some-fn :comparison-name :full-name))
(comp capitalize-first (some-fn :comparison-name :full-name)))
(defn- dashboard->cards
[dashboard]
......@@ -42,11 +39,6 @@
(def ^:private ^{:arglists '([card])} display-type
(comp qp.util/normalize-token :display))
(defn- overlay-comparison?
[card]
(and (-> card display-type (#{:bar :line}))
(-> card :series empty?)))
(defn- inject-filter
"Inject filter clause into card."
[{:keys [query-filter cell-query] :as root} card]
......@@ -60,6 +52,11 @@
(-> card (qp.util/get-in-normalized [:dataset_query :query :aggregation]) count (> 1))
(-> card (qp.util/get-in-normalized [:dataset_query :query :breakout]) count (> 1))))
(defn- overlay-comparison?
[card]
(and (-> card display-type (#{:bar :line}))
(not (multiseries? card))))
(defn- comparison-row
[dashboard row left right card]
(if (:display card)
......@@ -151,10 +148,8 @@
(defn- series-labels
[card]
(get-in card [:visualization_settings :graph.series_labels]
(for [[op & args] (qp.util/get-in-normalized card [:dataset_query :query :aggregation])]
(if (= (qp.util/normalize-token op) :metric)
(-> args first Metric :name)
(-> op name str/capitalize)))))
(map (comp capitalize-first metric-name)
(qp.util/get-in-normalized card [:dataset_query :query :aggregation]))))
(defn- unroll-multiseries
[card]
......@@ -229,8 +224,7 @@
(assoc :comparison-name (->> opts
:left
:cell-query
(cell-title left)
capitalize-first)))
(cell-title left))))
right (cond-> right
(part-vs-whole-comparison? left right)
(assoc :comparison-name (condp instance? (:entity right)
......
......@@ -83,7 +83,8 @@
(def ^:private ^{:arglists '([metric])} adhoc-metric?
(complement (some-fn saved-metric? custom-expression?)))
(defn- metric-name
(defn metric-name
"Return the name of the metric or name by describing it."
[[op & args :as metric]]
(cond
(qp.expand/ga-metric? metric) (-> args first str (subs 3) str/capitalize)
......
......@@ -161,7 +161,7 @@
(let [filter-id (-> candidate ((juxt :id :name :unit)) hash str)
candidate (assoc candidate :fk-map (build-fk-map fks candidate))
dashcards (:ordered_cards dashboard)
dashcards-new (map #(add-filter % filter-id candidate) dashcards)]
dashcards-new (keep #(add-filter % filter-id candidate) dashcards)]
;; Only add filters that apply to all cards.
(if (= (count dashcards) (count dashcards-new))
(-> dashboard
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment