Skip to content
Snippets Groups Projects
Unverified Commit 4f1e359e authored by bryan's avatar bryan Committed by GitHub
Browse files

Hydrate root-collection on card and dashboard (#31337)

* use hydrate-root-collection on card and dashboard

- GET /api/card/:id
- GET /api/dashboard/:id

* include missing ns require

* copy root-collection-with-ui-details into collection.root

* import the var from collection.root

* remove unused require
parent 6cb73b41
No related merge requests found
......@@ -25,6 +25,7 @@
ViewLog]]
[metabase.models.card :as card]
[metabase.models.collection :as collection]
[metabase.models.collection.root :as collection.root]
[metabase.models.humanization :as humanization]
[metabase.models.interface :as mi]
[metabase.models.moderation-review :as moderation-review]
......@@ -198,6 +199,7 @@
:last_query_start
:collection
[:moderation_reviews :moderator_details])
collection.root/hydrate-root-collection
(cond-> ;; card
(:dataset raw-card) (t2/hydrate :persisted))
api/read-check
......
......@@ -16,6 +16,7 @@
[metabase.mbql.util :as mbql.u]
[metabase.models.card :refer [Card]]
[metabase.models.collection :as collection]
[metabase.models.collection.root :as collection.root]
[metabase.models.dashboard :as dashboard :refer [Dashboard]]
[metabase.models.dashboard-card :as dashboard-card :refer [DashboardCard]]
[metabase.models.dashboard-tab :as dashboard-tab]
......@@ -228,6 +229,7 @@
:param_fields
:param_values
:collection)
collection.root/hydrate-root-collection
api/read-check
api/check-not-archived
hide-unreadable-cards
......
......@@ -4,6 +4,7 @@
[compojure.core :refer [DELETE GET POST PUT]]
[metabase.api.common :as api]
[metabase.models.collection :as collection]
[metabase.models.collection.root :as collection.root]
[metabase.models.timeline :as timeline :refer [Timeline]]
[metabase.models.timeline-event
:as timeline-event
......@@ -51,7 +52,7 @@
(collection/visible-collection-ids->honeysql-filter-clause
(collection/permissions-set->visible-collection-ids @api/*current-user-permissions-set*))]
:order-by [[:%lower.name :asc]]})
(map timeline/hydrate-root-collection))]
(map collection.root/hydrate-root-collection))]
(cond->> (t2/hydrate timelines :creator [:collection :can_write])
(= include "events")
(map #(timeline-event/include-events-singular % {:events/all? archived?})))))
......@@ -71,7 +72,7 @@
;; `collection_id` `nil` means we need to assoc 'root' collection
;; because hydrate `:collection` needs a proper `:id` to work.
(nil? (:collection_id timeline))
timeline/hydrate-root-collection
collection.root/hydrate-root-collection
(= include "events")
(timeline-event/include-events-singular {:events/all? archived?
......
......@@ -7,7 +7,6 @@
[clojure.core.memoize :as memoize]
[clojure.set :as set]
[clojure.string :as str]
[medley.core :as m]
[metabase.api.common
:as api
:refer [*current-user-id* *current-user-permissions-set*]]
......@@ -36,7 +35,7 @@
(comment collection.root/keep-me)
(comment mdb.connection/keep-me) ;; for [[memoize/ttl]]
(p/import-vars [collection.root root-collection])
(p/import-vars [collection.root root-collection root-collection-with-ui-details])
(def ^:private ^:const collection-slug-max-length
"Maximum number of characters allowed in a Collection `slug`."
......@@ -190,16 +189,6 @@
(let [msg (tru "Personal Collections must be in the default namespace")]
(throw (ex-info msg {:status-code 400, :errors {:personal_owner_id msg}})))))
(defn root-collection-with-ui-details
"The special Root Collection placeholder object with some extra details to facilitate displaying it on the FE."
[collection-namespace]
(m/assoc-some root-collection
:name (case (keyword collection-namespace)
:snippets (tru "Top folder")
(tru "Our analytics"))
:namespace collection-namespace
:id "root"))
(def ^:private CollectionWithLocationOrRoot
(s/cond-pre
RootCollection
......
(ns metabase.models.collection.root
(:require
[medley.core :as m]
[metabase.models.interface :as mi]
[metabase.models.permissions :as perms]
[metabase.public-settings.premium-features :as premium-features]
[metabase.shared.util.i18n :refer [tru]]
[metabase.util :as u]
[potemkin.types :as p.types]
[toucan2.protocols :as t2.protocols]))
[toucan2.protocols :as t2.protocols]
[toucan2.tools.hydrate :refer [hydrate]]))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Root Collection Special Placeholder Object |
......@@ -46,3 +49,24 @@
[x]
;; TODO -- not sure this makes sense because other places we check whether `::is-root?` is present or not.
(instance? RootCollection x))
(defn root-collection-with-ui-details
"The special Root Collection placeholder object with some extra details to facilitate displaying it on the FE."
[collection-namespace]
(m/assoc-some root-collection
:name (case (keyword collection-namespace)
:snippets (tru "Top folder")
(tru "Our analytics"))
:namespace collection-namespace
:id "root"))
(defn- hydrated-root-collection
[]
(-> (root-collection-with-ui-details nil)
(hydrate :can_write)))
(defn hydrate-root-collection
"Hydrate `:collection` onto entity when the id is `nil`."
[{:keys [collection_id] :as entity}]
(cond-> entity
(nil? collection_id) (assoc :collection (hydrated-root-collection))))
(ns metabase.models.timeline
(:require
[java-time :as t]
[metabase.models.collection :as collection]
[metabase.models.collection.root :as collection.root]
[metabase.models.permissions :as perms]
[metabase.models.serialization :as serdes]
[metabase.models.timeline-event :as timeline-event]
......@@ -39,18 +39,6 @@
;;;; functions
(defn- root-collection
[]
(-> (collection/root-collection-with-ui-details nil)
(t2/hydrate :can_write)))
(defn hydrate-root-collection
"Hydrate `:collection` on [[Timelines]] when the id is `nil`."
[{:keys [collection_id] :as timeline}]
(if (nil? collection_id)
(assoc timeline :collection (root-collection))
timeline))
(defn timelines-for-collection
"Load timelines based on `collection-id` passed in (nil means the root collection). Hydrates the events on each
timeline at `:events` on the timeline."
......@@ -60,7 +48,7 @@
:archived (boolean archived?))
:creator
[:collection :can_write])
(nil? collection-id) (->> (map hydrate-root-collection))
(nil? collection-id) (->> (map collection.root/hydrate-root-collection))
events? (timeline-event/include-events options)))
(defmethod serdes/hash-fields :model/Timeline
......
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