Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Include documents and dashboards in dependencies (#64888)

Riley Thompsone937214a8de0
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 7a31d2a17a7..6663764c96d 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -1728,13 +1728,15 @@
revisions
settings
task
- util}}
+ util
+ enterprise/documents}}
enterprise/documents
{:team "UX West"
:api #{metabase-enterprise.documents.api
metabase-enterprise.documents.core
- metabase-enterprise.documents.init}
+ metabase-enterprise.documents.init
+ metabase-enterprise.documents.prose-mirror}
:uses #{activity-feed
api
app-db
@@ -1884,6 +1886,7 @@
app-db
audit-app
driver
+ events
legacy-mbql
lib
models
diff --git a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
index 845e149b0db..d83dcb1a301 100644
--- a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
@@ -118,7 +118,7 @@ describe("scenarios > dependencies > dependency graph", () => {
H.entityPickerModal().within(() => {
H.entityPickerModalTab(tabName).click();
cy.findByPlaceholderText(/Search/).type(itemName);
- cy.findByText(/result for/).should("be.visible");
+ cy.findByText(/result for/).should("exist");
cy.findByText(itemName).click();
});
graphEntryButton().should("have.text", itemName);
@@ -174,19 +174,19 @@ describe("scenarios > dependencies > dependency graph", () => {
itemIcon: "table",
});
testEntityPicker({
- tabName: "Collections",
+ tabName: "Questions",
itemName: "Orders, Count, Grouped by Created At (year)",
itemLevel: 1,
itemIcon: "line",
});
testEntityPicker({
- tabName: "Collections",
+ tabName: "Models",
itemName: "Orders Model",
itemLevel: 1,
itemIcon: "model",
});
testEntityPicker({
- tabName: "Collections",
+ tabName: "Metrics",
itemName: TABLE_BASED_METRIC_NAME,
itemLevel: 1,
itemIcon: "metric",
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
index c21b528367d..c56a2f4bb6d 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
@@ -128,17 +128,23 @@
breakages (dependencies/errors-from-proposed-edits {:snippet [snippet]})]
(broken-cards-response breakages)))
-(defn- entity-keys [entity-type]
- (case entity-type
- :table [:name :description :display_name :db_id :db :schema :fields]
- :card [:name :type :display :database_id :view_count
- :created_at :creator :description
- :result_metadata :last-edit-info
- :collection :collection_id :dashboard :dashboard_id
- :moderation_reviews]
- :snippet [:name :description]
- :transform [:name :description :table]
- []))
+(def ^:private entity-keys
+ {:table [:name :description :display_name :db_id :db :schema :fields]
+ :card [:name :type :display :database_id :view_count
+ :created_at :creator :creator_id :description
+ :result_metadata :last-edit-info
+ :collection :collection_id :dashboard :dashboard_id
+ :moderation_reviews]
+ :snippet [:name :description]
+ :transform [:name :description :table]
+ :dashboard [:name :description :view_count
+ :created_at :creator :creator_id :last-edit-info
+ :collection :collection_id
+ :moderation_reviews]
+ :document [:name :description :view_count
+ :created_at :creator
+ :collection :collection_id]
+ :sandbox [:table :table_id]})
(defn- format-subentity [entity]
(case (t2/model entity)
@@ -157,7 +163,10 @@
{:table :model/Table
:card :model/Card
:snippet :model/NativeQuerySnippet
- :transform :model/Transform})
+ :transform :model/Transform
+ :dashboard :model/Dashboard
+ :document :model/Document
+ :sandbox :model/Sandbox})
(defn- readable-node?
"Check if the user can read the entity represented by `[entity-type entity-id]`."
@@ -211,20 +220,24 @@
(mapcat (fn [[entity-type entity-ids]]
(->> (cond-> (t2/select (entity-model entity-type)
:id [:in entity-ids])
- (= entity-type :card) (-> (t2/hydrate :creator :dashboard [:collection :is_personal] :moderation_reviews)
- (->> (map collection.root/hydrate-root-collection))
- (revisions/with-last-edit-info :card))
- (= entity-type :table) (t2/hydrate :fields :db)
- (= entity-type :transform) (t2/hydrate :table-with-db-and-fields))
+ (= entity-type :card) (-> (t2/hydrate :creator :dashboard [:collection :is_personal] :moderation_reviews)
+ (->> (map collection.root/hydrate-root-collection))
+ (revisions/with-last-edit-info :card))
+ (= entity-type :table) (t2/hydrate :fields :db)
+ (= entity-type :transform) (t2/hydrate :table-with-db-and-fields)
+ (= entity-type :dashboard) (-> (t2/hydrate :creator [:collection :is_personal] :moderation_reviews)
+ (->> (map collection.root/hydrate-root-collection))
+ (revisions/with-last-edit-info :dashboard))
+ (= entity-type :document) (-> (t2/hydrate :creator [:collection :is_personal])
+ (->> (map collection.root/hydrate-root-collection)))
+ (= entity-type :sandbox) (t2/hydrate [:table :db :fields]))
(mapv #(entity-value entity-type % usages))))
nodes-by-type)))
(api.macros/defendpoint :get "/graph"
- "TODO: This endpoint is supposed to take an :id and :type of an entity (currently :table, :card, :snippet,
- or :transform) and return the entity with all its upstream and downstream dependencies that should be fetched
- recursively. :edges match our :model/Dependency format. Each node in :nodes has :id, :type, and :data, and :data
- depends on the node type. For :table, there should be :display_name. For :card, there should be :name
- and :type. For :snippet -> :name. For :transform -> :name."
+ "This endpoint takes an :id and a supported entity :type, and returns a graph of all its upstream dependencies.
+ The graph is represented by a list of :nodes and a list of :edges. Each node has an :id, :type, :data (which
+ depends on the node type), and a map of :dependent_counts per entity type. Each edge is a :model/Dependency"
[_route-params
{:keys [id type]} :- [:map
[:id {:optional true} ms/PositiveInt]
@@ -237,7 +250,7 @@
downstream-graph (graph/cached-graph (readable-graph-dependents))
nodes (into (set starting-nodes)
(graph/transitive upstream-graph starting-nodes))
- edges (graph/calc-edges downstream-graph nodes)]
+ edges (graph/calc-edges-between downstream-graph nodes)]
{:nodes (expanded-nodes downstream-graph nodes)
:edges edges}))
@@ -245,16 +258,14 @@
[:map
[:id ms/PositiveInt]
[:type (ms/enum-decode-keyword (vec (keys entity-model)))]
- [:dependent_type (ms/enum-decode-keyword [:table :card :snippet :transform])]
+ [:dependent_type (ms/enum-decode-keyword (vec (keys entity-model)))]
[:dependent_card_type {:optional true} (ms/enum-decode-keyword
[:question :model :metric])]])
(api.macros/defendpoint :get "/graph/dependents"
- "TODO: This endpoint is supposed to take an :id and :type of an entity (currently :table, :card, :snippet,
- or :transform) and return the entity with all its upstream and downstream dependencies that should be fetched
- recursively. :edges match our :model/Dependency format. Each node in :nodes has :id, :type, and :data, and :data
- depends on the node type. For :table, there should be :display_name. For :card, there should be :name
- and :type. For :snippet -> :name. For :transform -> :name."
+ "This endpoint takes an :id, :type, :dependent_type, and an optional :dependent_card_type, and returns a list of
+ all that entity's dependents with :dependent_type. If the :dependent_type is :card, the dependents are further
+ filtered by :dependent_card_type."
[_route-params
{:keys [id type dependent_type dependent_card_type]} :- dependents-args]
(api/read-check (entity-model type) id)
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj
index 66256381782..99d4eb2a0c8 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj
@@ -2,6 +2,7 @@
(:require
[metabase-enterprise.dependencies.native-validation :as deps.native]
[metabase-enterprise.dependencies.schema :as deps.schema]
+ [metabase-enterprise.documents.prose-mirror :as prose-mirror]
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.lib.schema :as lib.schema]
@@ -30,8 +31,13 @@
(mu/defn upstream-deps:card :- ::deps.schema/upstream-deps
"Given a Toucan `:model/Card`, return its upstream dependencies as a map from the kind to a set of IDs."
- [{query :dataset_query :as _toucan-card} :- ::queries.schema/card]
- (upstream-deps:query query))
+ [{query :dataset_query :as card} :- ::queries.schema/card]
+ (let [query-deps (upstream-deps:query query)
+ param-card-ids (keep #(-> % :values_source_config :card_id) (:parameters card))]
+ (reduce (fn [deps card-id]
+ (update deps :card (fnil conj #{}) card-id))
+ query-deps
+ param-card-ids)))
(mu/defn upstream-deps:transform :- ::deps.schema/upstream-deps
"Given a Transform (in Toucan form), return its upstream dependencies."
@@ -58,3 +64,67 @@
[entity-type entity-id]))))
(vals template_tags))]
(u/group-by first second conj #{} dependencies)))
+
+(mu/defn upstream-deps:dashboard :- ::deps.schema/upstream-deps
+ "Given a dashboard, return its upstream dependencies"
+ [{:keys [dashcards series-card-ids] :as dashboard}]
+ (let [card-ids (into #{} (keep :card_id dashcards))
+ param-card-ids (into #{} (keep (comp :card_id :values_source_config) (:parameters dashboard)))
+ vis-setting-target-ids (fn [link-type]
+ (into #{} (keep (fn [dashcard]
+ (let [cb (:click_behavior (:visualization_settings dashcard))]
+ (when (= (:linkType cb) link-type)
+ (:targetId cb))))
+ dashcards)))
+ vis-setting-card-ids (vis-setting-target-ids "question")
+ vis-setting-dashboard-ids (vis-setting-target-ids "dashboard")
+ column-setting-target-ids (fn [link-type]
+ (reduce into #{}
+ (map (fn [dashcard]
+ (keep (fn [[_col col-setting]]
+ (let [cb (:click_behavior col-setting)]
+ (when (= (:linkType cb) link-type)
+ (:targetId cb))))
+ (:column_settings (:visualization_settings dashcard))))
+ dashcards)))
+ column-setting-card-ids (column-setting-target-ids "question")
+ column-setting-dashboard-ids (column-setting-target-ids "dashboard")
+ all-card-ids (reduce into #{} [card-ids
+ series-card-ids
+ param-card-ids
+ vis-setting-card-ids
+ column-setting-card-ids])
+ all-dashboard-ids (into vis-setting-dashboard-ids column-setting-dashboard-ids)]
+ {:card all-card-ids
+ :dashboard all-dashboard-ids}))
+
+;; Modified implementation of documents.models.document/document-deps
+(defn- document-deps
+ [{:keys [content_type] :as document}]
+ (when (= content_type prose-mirror/prose-mirror-content-type)
+ (prose-mirror/collect-ast document (fn [{:keys [type attrs]}]
+ (cond
+ (and (= prose-mirror/smart-link-type type)
+ (#{"card" "dashboard" "table"} (:model attrs)))
+ [(keyword (:model attrs)) (:entityId attrs)]
+
+ (= prose-mirror/card-embed-type type)
+ [:card (:id attrs)]
+
+ :else
+ nil)))))
+
+(mu/defn upstream-deps:document :- ::deps.schema/upstream-deps
+ "Given a document, return its upstream dependencies"
+ [document]
+ (reduce (fn [deps [dep-type dep-id]]
+ (update deps dep-type (fnil conj #{}) dep-id))
+ {}
+ (document-deps document)))
+
+(mu/defn upstream-deps:sandbox :- ::deps.schema/upstream-deps
+ "Given a sandbox, return its upstream dependencies"
+ [sandbox]
+ (if-let [card-id (:card_id sandbox)]
+ {:card #{card-id}}
+ {}))
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/events.clj b/enterprise/backend/src/metabase_enterprise/dependencies/events.clj
index 7337a3e9c81..74cbe56fb6f 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/events.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/events.clj
@@ -120,3 +120,75 @@
[_ {:keys [object]}]
(when (premium-features/has-feature? :dependencies)
(transform-table-deps! object)))
+
+;; ### Dashboards
+(derive ::dashboard-deps :metabase/event)
+(derive :event/dashboard-create ::dashboard-deps)
+(derive :event/dashboard-update ::dashboard-deps)
+
+(methodical/defmethod events/publish-event! ::dashboard-deps
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/with-transaction [_conn]
+ (let [dashboard-id (:id object)
+ dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ series-card-ids (when (seq dashcards)
+ (t2/select-fn-set :card_id :model/DashboardCardSeries
+ :dashboardcard_id [:in (map :id dashcards)]))
+ dashboard (assoc object :dashcards dashcards :series-card-ids series-card-ids)]
+ (models.dependency/replace-dependencies! :dashboard dashboard-id (deps.calculation/upstream-deps:dashboard dashboard)))
+ (when (not= (:dependency_analysis_version object) models.dependency/current-dependency-analysis-version)
+ (t2/update! :model/Dashboard (:id object)
+ {:dependency_analysis_version models.dependency/current-dependency-analysis-version})))))
+
+(derive ::dashboard-delete :metabase/event)
+(derive :event/dashboard-delete ::dashboard-delete)
+
+(methodical/defmethod events/publish-event! ::dashboard-delete
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/delete! :model/Dependency :from_entity_type :dashboard :from_entity_id (:id object))))
+
+;; ### Documents
+(derive ::document-deps :metabase/event)
+(derive :event/document-create ::document-deps)
+(derive :event/document-update ::document-deps)
+
+(methodical/defmethod events/publish-event! ::document-deps
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/with-transaction [_conn]
+ (models.dependency/replace-dependencies! :document (:id object) (deps.calculation/upstream-deps:document object))
+ (when (not= (:dependency_analysis_version object) models.dependency/current-dependency-analysis-version)
+ (t2/update! :model/Document (:id object)
+ {:dependency_analysis_version models.dependency/current-dependency-analysis-version})))))
+
+(derive ::document-delete :metabase/event)
+(derive :event/document-delete ::document-delete)
+
+(methodical/defmethod events/publish-event! ::document-delete
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/delete! :model/Dependency :from_entity_type :document :from_entity_id (:id object))))
+
+;; ### Sandboxes
+(derive ::sandbox-deps :metabase/event)
+(derive :event/sandbox-create ::sandbox-deps)
+(derive :event/sandbox-update ::sandbox-deps)
+
+(methodical/defmethod events/publish-event! ::sandbox-deps
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/with-transaction [_conn]
+ (models.dependency/replace-dependencies! :sandbox (:id object) (deps.calculation/upstream-deps:sandbox object))
+ (when (not= (:dependency_analysis_version object) models.dependency/current-dependency-analysis-version)
+ (t2/update! :model/Sandbox (:id object)
+ {:dependency_analysis_version models.dependency/current-dependency-analysis-version})))))
+
+(derive ::sandbox-delete :metabase/event)
+(derive :event/sandbox-delete ::sandbox-delete)
+
+(methodical/defmethod events/publish-event! ::sandbox-delete
+ [_ {:keys [object]}]
+ (when (premium-features/has-feature? :dependencies)
+ (t2/delete! :model/Dependency :from_entity_type :sandbox :from_entity_id (:id object))))
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj
index 05f18d6719d..f2d96a84e13 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj
@@ -236,6 +236,15 @@
(lib.metadata/native-query-snippet (inner-mp mp) id))
(u/normalize-map updates)))}))
+(defmethod add-override :dashboard [^OverridingMetadataProvider mp _entity-type _id _updates]
+ mp)
+
+(defmethod add-override :document [^OverridingMetadataProvider mp _entity-type _id _updates]
+ mp)
+
+(defmethod add-override :sandbox [^OverridingMetadataProvider mp _entity-type _id _updates]
+ mp)
+
(defn all-overrides
"Returns all the overrides by ID, in the same form as the map input to [[with-deps]]:
`{:card [1 2 3], :transform [45 99]}."
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj b/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj
index 4e1d7fd43dc..6772d49e939 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj
@@ -8,4 +8,7 @@
[:card {:optional true} [:set ::lib.schema.id/card]]
[:table {:optional true} [:set ::lib.schema.id/table]]
[:snippet {:optional true} [:set ::lib.schema.id/snippet]]
- [:transform {:optional true} [:set ::lib.schema.id/transform]]])
+ [:transform {:optional true} [:set ::lib.schema.id/transform]]
+ [:dashboard {:optional true} [:set ::lib.schema.id/dashboard]]
+ [:document {:optional true} [:set ::lib.schema.id/document]]
+ [:sandbox {:optional true} [:set ::lib.schema.id/sandbox]]])
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj b/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj
index 1621f79f8c3..a01e9a8e609 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj
@@ -32,7 +32,13 @@
[]
(t/to-millis-from-epoch (t/instant)))
-(def ^:private entities [:model/Card :model/Transform :model/NativeQuerySnippet])
+(def ^:private entities
+ [:model/Card
+ :model/Transform
+ :model/NativeQuerySnippet
+ :model/Dashboard
+ :model/Document
+ :model/Sandbox])
;; In-memory state for tracking failed entities
;; Stores {:model/Type {id {:fail-count N :next-retry-timestamp M}}}
diff --git a/enterprise/backend/src/metabase_enterprise/documents/models/document.clj b/enterprise/backend/src/metabase_enterprise/documents/models/document.clj
index 79a01c2c83a..c1cb9c1d800 100644
--- a/enterprise/backend/src/metabase_enterprise/documents/models/document.clj
+++ b/enterprise/backend/src/metabase_enterprise/documents/models/document.clj
@@ -157,7 +157,7 @@
(defmethod serdes/make-spec "Document"
[_model-name _opts]
{:copy [:archived :archived_directly :content_type :entity_id :name :collection_position]
- :skip [:view_count :last_viewed_at]
+ :skip [:view_count :last_viewed_at :dependency_analysis_version]
:transform {:created_at (serdes/date)
:updated_at (serdes/date)
:document {:export-with-context export-document-content
diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj b/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj
index 4a6da2f2a81..1349568f0ee 100644
--- a/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj
+++ b/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj
@@ -7,7 +7,9 @@
system."
(:require
[medley.core :as m]
+ [metabase.api.common :as api]
[metabase.audit-app.core :as audit]
+ [metabase.events.core :as events]
;; legacy usage -- do not use in new code
^{:clj-kondo/ignore [:discouraged-namespace]} [metabase.legacy-mbql.normalize :as mbql.normalize]
[metabase.lib.schema.id :as lib.schema.id]
@@ -190,8 +192,16 @@
(t2/update! :model/Sandbox
id
(u/select-keys-when sandbox :present #{:card_id :attribute_remappings})))
- (t2/select-one :model/Sandbox :id id))
- (first (t2/insert-returning-instances! :model/Sandbox sandbox))))))
+ (let [updated-sandbox (t2/select-one :model/Sandbox :id id)]
+ (events/publish-event! :event/sandbox-update
+ {:object updated-sandbox
+ :user-id api/*current-user-id*})
+ updated-sandbox))
+ (let [inserted-sandbox (first (t2/insert-returning-instances! :model/Sandbox sandbox))]
+ (events/publish-event! :event/sandbox-create
+ {:object inserted-sandbox
+ :user-id api/*current-user-id*})
+ inserted-sandbox)))))
(t2/define-before-insert :model/Sandbox
[{:keys [table_id group_id], :as gtap}]
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj
new file mode 100644
index 00000000000..6d1d9a23866
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj
@@ -0,0 +1,255 @@
+(ns metabase-enterprise.dependencies.calculation-test
+ (:require
+ [clojure.test :refer [deftest is]]
+ [metabase-enterprise.dependencies.calculation :as calculation]
+ [metabase.lib.core :as lib]
+ [metabase.lib.metadata :as lib.metadata]
+ [metabase.test :as mt]
+ [toucan2.core :as t2]))
+
+(deftest ^:parallel upstream-deps-card-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)
+ product-category (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-temp [:model/Card {prod-card-id :id :as prod-card} {:dataset_query (lib/query mp products)}
+ :model/Card widget-card {:dataset_query (-> (lib/query mp (lib.metadata/card mp prod-card-id))
+ (lib/filter (lib/= product-category
+ "Widget")))}]
+ (is (= {:card #{}
+ :table #{products-id}}
+ (calculation/upstream-deps:card prod-card)))
+ (is (= {:card #{prod-card-id}
+ :table #{}}
+ (calculation/upstream-deps:card widget-card))))))
+
+(deftest ^:parallel upstream-deps-card-join-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ orders-id (mt/id :orders)
+ products (lib.metadata/table mp products-id)
+ orders (lib.metadata/table mp orders-id)]
+ (mt/with-temp [:model/Card {products-card-id :id :as products-card} {:dataset_query (lib/query mp products)}
+ :model/Card joined-card {:dataset_query (-> (lib/query mp (lib.metadata/card mp products-card-id))
+ (lib/join orders))}]
+ (is (= {:card #{}
+ :table #{products-id}}
+ (calculation/upstream-deps:card products-card)))
+ (is (= {:card #{products-card-id}
+ :table #{orders-id}}
+ (calculation/upstream-deps:card joined-card))))))
+
+(deftest ^:parallel upstream-deps-card-native-with-parameter-source-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)
+ category-field (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-temp [:model/Card {category-values-card-id :id :as category-values-card}
+ {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count))
+ (lib/breakout category-field))}
+ :model/Card native-card
+ {:database_id (mt/id)
+ :dataset_query {:database (mt/id)
+ :type :native
+ :native {:query "SELECT * FROM PRODUCTS WHERE CATEGORY = {{category}}"
+ :template-tags {"category" {:id "category-id"
+ :name "category"
+ :display-name "Category"
+ :type :dimension
+ :dimension [:field (mt/id :products :category) nil]
+ :widget-type :string/=
+ :default nil}}}}
+ :parameters [{:id "category-param"
+ :type "category"
+ :values_source_type "card"
+ :values_source_config {:card_id category-values-card-id}}]}]
+ (is (= {:card #{}
+ :table #{products-id}}
+ (calculation/upstream-deps:card category-values-card)))
+ (is (= {:card #{category-values-card-id}
+ :table #{products-id}}
+ (calculation/upstream-deps:card native-card))))))
+
+(deftest ^:parallel upstream-deps-dashboard-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)]
+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id :as dashboard} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id card-id}]
+ (let [dashboard (-> dashboard
+ (t2/hydrate :dashcards))]
+ (is (= {:card #{card-id}
+ :dashboard #{}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-series-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ orders-id (mt/id :orders)
+ products (lib.metadata/table mp products-id)
+ orders (lib.metadata/table mp orders-id)]
+ (mt/with-temp [:model/Card {main-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Card {series-card-id :id} {:dataset_query (lib/query mp orders)}
+ :model/Dashboard {dashboard-id :id :as dashboard} {}
+ :model/DashboardCard {dashcard-id :id} {:dashboard_id dashboard-id
+ :card_id main-card-id}
+ :model/DashboardCardSeries _ {:dashboardcard_id dashcard-id
+ :card_id series-card-id
+ :position 0}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ series-card-ids (when (seq dashcards)
+ (t2/select-fn-set :card_id :model/DashboardCardSeries
+ :dashboardcard_id [:in (map :id dashcards)]))
+ dashboard (assoc dashboard :dashcards dashcards :series-card-ids series-card-ids)]
+ (is (= {:card #{main-card-id series-card-id}
+ :dashboard #{}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-parameter-source-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)
+ category-field (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-temp [:model/Card {category-values-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count))
+ (lib/breakout category-field))}
+ :model/Card {filtered-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id} {:parameters [{:id "category-param"
+ :type "category"
+ :values_source_type "card"
+ :values_source_config {:card_id category-values-card-id}}]}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id filtered-card-id}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ dashboard (-> (t2/select-one :model/Dashboard :id dashboard-id)
+ (assoc :dashcards dashcards))]
+ (is (= {:card #{filtered-card-id category-values-card-id}
+ :dashboard #{}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-click-behavior-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)]
+ (mt/with-temp [:model/Card {count-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count)))
+ :display :scalar}
+ :model/Card {target-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id count-card-id
+ :visualization_settings {:click_behavior {:type "link"
+ :linkType "question"
+ :targetId target-card-id}}}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ dashboard {:id dashboard-id
+ :dashcards dashcards}]
+ (is (= {:card #{count-card-id target-card-id}
+ :dashboard #{}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-column-click-behavior-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)
+ category-field (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-temp [:model/Card {table-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/breakout category-field)
+ (lib/aggregate (lib/count)))
+ :display :table}
+ :model/Card {target-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id table-card-id
+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"
+ :linkType "question"
+ :targetId target-card-id}}}}}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ dashboard {:id dashboard-id
+ :dashcards dashcards}]
+ (is (= {:card #{table-card-id target-card-id}
+ :dashboard #{}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-dashboard-click-behavior-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)]
+ (mt/with-temp [:model/Card {count-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count)))
+ :display :scalar}
+ :model/Dashboard {target-dashboard-id :id} {}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id count-card-id
+ :visualization_settings {:click_behavior {:type "link"
+ :linkType "dashboard"
+ :targetId target-dashboard-id}}}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ dashboard {:id dashboard-id
+ :dashcards dashcards}]
+ (is (= {:card #{count-card-id}
+ :dashboard #{target-dashboard-id}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-dashboard-with-column-dashboard-click-behavior-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)
+ category-field (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-temp [:model/Card {table-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/breakout category-field)
+ (lib/aggregate (lib/count)))
+ :display :table}
+ :model/Dashboard {target-dashboard-id :id} {}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id table-card-id
+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"
+ :linkType "dashboard"
+ :targetId target-dashboard-id}}}}}]
+ (let [dashcards (t2/select :model/DashboardCard :dashboard_id dashboard-id)
+ dashboard {:id dashboard-id
+ :dashcards dashcards}]
+ (is (= {:card #{table-card-id}
+ :dashboard #{target-dashboard-id}}
+ (calculation/upstream-deps:dashboard dashboard)))))))
+
+(deftest ^:parallel upstream-deps-document-test
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)]
+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Card {embedded-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/Document document {:content_type "application/json+vnd.prose-mirror"
+ :document {:type "doc"
+ :content [{:type "paragraph"
+ :content [{:type "smartLink"
+ :attrs {:entityId card-id
+ :model "card"}}
+ {:type "smartLink"
+ :attrs {:entityId dashboard-id
+ :model "dashboard"}}
+ {:type "smartLink"
+ :attrs {:entityId products-id
+ :model "table"}}]}
+ {:type "cardEmbed"
+ :attrs {:id embedded-card-id}}]}}]
+ (is (= {:card #{card-id embedded-card-id}
+ :dashboard #{dashboard-id}
+ :table #{products-id}}
+ (calculation/upstream-deps:document document))))))
+
+(deftest upstream-deps-sandbox-test
+ (mt/with-premium-features #{:sandboxes}
+ (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "sandbox group"}
+ :model/Card {sandbox-card-id :id} {}
+ :model/Sandbox sandbox {:group_id group-id
+ :table_id (mt/id :products)
+ :card_id sandbox-card-id}]
+ (is (= {:card #{sandbox-card-id}}
+ (calculation/upstream-deps:sandbox sandbox))))))
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj
new file mode 100644
index 00000000000..c56baf858fa
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj
@@ -0,0 +1,209 @@
+(ns metabase-enterprise.dependencies.events-test
+ (:require
+ [clojure.test :refer [deftest is]]
+ [metabase.api.common :as api]
+ [metabase.events.core :as events]
+ [metabase.lib.core :as lib]
+ [metabase.lib.metadata :as lib.metadata]
+ [metabase.test :as mt]
+ [toucan2.core :as t2]))
+
+(deftest dashboard-update-sets-correct-dependencies
+ (mt/with-test-user :rasta
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ orders-id (mt/id :orders)
+ products (lib.metadata/table mp products-id)
+ orders (lib.metadata/table mp orders-id)
+ category-field (lib.metadata/field mp (mt/id :products :category))]
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/Card {basic-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Card {series-card-id :id} {:dataset_query (lib/query mp orders)}
+ :model/Card {param-source-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count))
+ (lib/breakout category-field))}
+ :model/Dashboard {dashboard-id :id :as dashboard} {:parameters [{:id "category-param"
+ :type "category"
+ :values_source_type "card"
+ :values_source_config {:card_id param-source-card-id}}]}
+ :model/DashboardCard {basic-dashcard-id :id} {:dashboard_id dashboard-id
+ :card_id basic-card-id}
+ :model/DashboardCardSeries _ {:dashboardcard_id basic-dashcard-id
+ :card_id series-card-id
+ :position 0}]
+ (events/publish-event! :event/dashboard-create {:object dashboard :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id basic-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id series-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id param-source-card-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id dashboard-id)))))
+ (t2/delete! :model/DashboardCard :id basic-dashcard-id)
+ (t2/update! :model/Dashboard dashboard-id {:parameters []})
+ (mt/with-temp [:model/Card {scalar-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/aggregate (lib/count)))
+ :display :scalar}
+ :model/Card {scalar-click-target-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id scalar-card-id
+ :visualization_settings {:click_behavior {:type "link"
+ :linkType "question"
+ :targetId scalar-click-target-card-id}}}
+ :model/Card {scalar-card-2-id :id} {:dataset_query (-> (lib/query mp orders)
+ (lib/aggregate (lib/count)))
+ :display :scalar}
+ :model/Dashboard {scalar-click-target-dashboard-id :id} {}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id scalar-card-2-id
+ :visualization_settings {:click_behavior {:type "link"
+ :linkType "dashboard"
+ :targetId scalar-click-target-dashboard-id}}}
+ :model/Card {table-card-id :id} {:dataset_query (-> (lib/query mp products)
+ (lib/breakout category-field)
+ (lib/aggregate (lib/count)))
+ :display :table}
+ :model/Card {column-click-target-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id table-card-id
+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"
+ :linkType "question"
+ :targetId column-click-target-card-id}}}}}
+ :model/Dashboard {column-click-target-dashboard-id :id} {}
+ :model/Card {table-card-2-id :id} {:dataset_query (-> (lib/query mp orders)
+ (lib/breakout category-field)
+ (lib/aggregate (lib/count)))
+ :display :table}
+ :model/DashboardCard _ {:dashboard_id dashboard-id
+ :card_id table-card-2-id
+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"
+ :linkType "dashboard"
+ :targetId column-click-target-dashboard-id}}}}}]
+ (let [updated-dashboard (t2/select-one :model/Dashboard :id dashboard-id)]
+ (events/publish-event! :event/dashboard-update {:object updated-dashboard :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id scalar-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id scalar-click-target-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id scalar-card-2-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :dashboard
+ :to_entity_id scalar-click-target-dashboard-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id table-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id column-click-target-card-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :card
+ :to_entity_id table-card-2-id}
+ {:from_entity_type :dashboard
+ :from_entity_id dashboard-id
+ :to_entity_type :dashboard
+ :to_entity_id column-click-target-dashboard-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id dashboard-id)))))
+ (t2/delete! :model/Dashboard dashboard-id)
+ (events/publish-event! :event/dashboard-delete {:object updated-dashboard :user-id api/*current-user-id*})
+ (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id))))))))))
+
+(deftest document-update-sets-correct-dependencies
+ (mt/with-test-user :rasta
+ (let [mp (mt/metadata-provider)
+ products-id (mt/id :products)
+ products (lib.metadata/table mp products-id)]
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Card {embedded-card-id :id} {:dataset_query (lib/query mp products)}
+ :model/Dashboard {dashboard-id :id} {}
+ :model/Document {document-id :id :as document} {:content_type "application/json+vnd.prose-mirror"
+ :document {:type "doc"
+ :content [{:type "paragraph"
+ :content [{:type "smartLink"
+ :attrs {:entityId card-id
+ :model "card"}}]}
+ {:type "cardEmbed"
+ :attrs {:id embedded-card-id}}]}}]
+ (events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :document
+ :from_entity_id document-id
+ :to_entity_type :card
+ :to_entity_id card-id}
+ {:from_entity_type :document
+ :from_entity_id document-id
+ :to_entity_type :card
+ :to_entity_id embedded-card-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id document-id)))))
+ (let [updated-doc (assoc document :document {:type "doc"
+ :content [{:type "paragraph"
+ :content [{:type "smartLink"
+ :attrs {:entityId dashboard-id
+ :model "dashboard"}}
+ {:type "smartLink"
+ :attrs {:entityId products-id
+ :model "table"}}]}]})]
+ (t2/update! :model/Document document-id updated-doc)
+ (events/publish-event! :event/document-update {:object updated-doc :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :document
+ :from_entity_id document-id
+ :to_entity_type :dashboard
+ :to_entity_id dashboard-id}
+ {:from_entity_type :document
+ :from_entity_id document-id
+ :to_entity_type :table
+ :to_entity_id products-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id document-id)))))
+ (t2/delete! :model/Document document-id)
+ (events/publish-event! :event/document-delete {:object document :user-id api/*current-user-id*})
+ (is (empty? (t2/select :model/Dependency :from_entity_id document-id)))))))))
+
+(deftest sandbox-update-sets-correct-dependencies
+ (mt/with-premium-features #{:sandboxes}
+ (mt/with-test-user :rasta
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "sandbox group"}
+ :model/Card {card1-id :id} {}
+ :model/Card {card2-id :id} {}
+ :model/Sandbox {sandbox-id :id :as sandbox} {:group_id group-id
+ :table_id (mt/id :products)
+ :card_id card1-id}]
+ (events/publish-event! :event/sandbox-create {:object sandbox :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :sandbox
+ :from_entity_id sandbox-id
+ :to_entity_type :card
+ :to_entity_id card1-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id sandbox-id)))))
+ (t2/update! :model/Sandbox sandbox-id (assoc sandbox :card_id card2-id))
+ (let [updated-sandbox (t2/select-one :model/Sandbox :id sandbox-id)]
+ (events/publish-event! :event/sandbox-update {:object updated-sandbox :user-id api/*current-user-id*})
+ (is (=? #{{:from_entity_type :sandbox
+ :from_entity_id sandbox-id
+ :to_entity_type :card
+ :to_entity_id card2-id}}
+ (into #{} (map #(dissoc % :id)
+ (t2/select :model/Dependency :from_entity_id sandbox-id)))))
+ (t2/delete! :model/Sandbox sandbox-id)
+ (events/publish-event! :event/sandbox-delete {:object sandbox :user-id api/*current-user-id*})
+ (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj b/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj
index 544bf231c42..29a6e0a856c 100644
--- a/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj
@@ -367,7 +367,7 @@
(let [spec (serdes/make-spec "Document" {})]
(is (= [:archived :archived_directly :content_type :entity_id :name :collection_position]
(:copy spec)))
- (is (= [:view_count :last_viewed_at] (:skip spec)))
+ (is (= [:view_count :last_viewed_at :dependency_analysis_version] (:skip spec)))
(is (contains? (:transform spec) :created_at))
(is (contains? (:transform spec) :document))
(is (contains? (:transform spec) :updated_at))
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
index 99194864a8d..02ea65152df 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
@@ -23,7 +23,8 @@
:card_id true
:table_id true
:group_id true
- :attribute_remappings {:foo 1}})
+ :attribute_remappings {:foo 1}
+ :dependency_analysis_version 0})
(defmacro ^:private with-gtap-cleanup!
"Invokes `body` ensuring any `Sandbox` created will be removed afterward. Leaving behind a GTAP can
diff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
index cd0cb6c9f6f..4bcf19269f9 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
@@ -11,9 +11,12 @@ import {
import type {
CardDependencyNode,
Comment,
+ DashboardDependencyNode,
DependencyGraph,
DependencyNode,
+ DocumentDependencyNode,
PythonLibrary,
+ SandboxDependencyNode,
SnippetDependencyNode,
TableDependencyNode,
Transform,
@@ -32,6 +35,7 @@ export const ENTERPRISE_TAG_TYPES = [
"gsheets-status",
"document",
"comment",
+ "sandbox",
"transform-tag",
"transform-job",
"transform-job-via-tag",
@@ -190,6 +194,42 @@ function provideSnippetDependencyNodeTags(
return [idTag("snippet", node.id)];
}
+function provideDashboardDependencyNodeTags(
+ node: DashboardDependencyNode,
+): TagDescription<EnterpriseTagType>[] {
+ return [
+ idTag("dashboard", node.id),
+ ...(node.data.creator != null ? provideUserTags(node.data.creator) : []),
+ ...(node.data["last-edit-info"] != null
+ ? provideUserTags(node.data["last-edit-info"])
+ : []),
+ ...(node.data.collection != null
+ ? provideCollectionTags(node.data.collection)
+ : []),
+ ];
+}
+
+function provideDocumentDependencyNodeTags(
+ node: DocumentDependencyNode,
+): TagDescription<EnterpriseTagType>[] {
+ return [
+ idTag("document", node.id),
+ ...(node.data.creator != null ? provideUserTags(node.data.creator) : []),
+ ...(node.data.collection != null
+ ? provideCollectionTags(node.data.collection)
+ : []),
+ ];
+}
+
+function provideSandboxDependencyNodeTags(
+ node: SandboxDependencyNode,
+): TagDescription<EnterpriseTagType>[] {
+ return [
+ idTag("sandbox", node.id),
+ ...(node.data.table ? provideTableTags(node.data.table) : []),
+ ];
+}
+
export function provideDependencyNodeTags(
node: DependencyNode,
): TagDescription<EnterpriseTagType>[] {
@@ -202,6 +242,12 @@ export function provideDependencyNodeTags(
return provideTransformDependencyNodeTags(node);
case "snippet":
return provideSnippetDependencyNodeTags(node);
+ case "dashboard":
+ return provideDashboardDependencyNodeTags(node);
+ case "document":
+ return provideDocumentDependencyNodeTags(node);
+ case "sandbox":
+ return provideSandboxDependencyNodeTags(node);
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
index aa81e70fb0a..8a7936cd2b6 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
@@ -45,7 +45,7 @@ function ListItem({ node }: ListItemProps) {
return (
<Stack className={S.item} p="lg" gap="sm" aria-label={label}>
- <Group justify="space-between">
+ <Group justify="space-between" wrap="nowrap">
<GraphLink
label={label}
icon={getNodeIcon(node)}
@@ -60,7 +60,10 @@ function ListItem({ node }: ListItemProps) {
) : null}
</Group>
{(location != null || (link != null && viewCount != null)) && (
- <Group justify={location != null ? "space-between" : "flex-end"}>
+ <Group
+ justify={location != null ? "space-between" : "flex-end"}
+ wrap="nowrap"
+ >
{location != null && (
<GraphBreadcrumbs location={location} ml="1rem" pl="sm" />
)}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
index 80e851c30f1..1f25b699010 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
@@ -25,5 +25,11 @@ export function getHeaderLabel(
return t`Transforms that use ${nodeLabel}`;
case "snippet":
return t`Snippets that use ${nodeLabel}`;
+ case "dashboard":
+ return t`Dashboards that use ${nodeLabel}`;
+ case "document":
+ return t`Documents that use ${nodeLabel}`;
+ case "sandbox":
+ return t`Row and column security rules that use ${nodeLabel}`;
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/constants.ts
index b621fe11928..08ab20aa313 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/constants.ts
@@ -1,4 +1,4 @@
-// order of options matches the UI
+// defines the order of options in the UI
export const FILTER_OPTIONS = [
"verified",
"in-dashboard",
@@ -6,5 +6,5 @@ export const FILTER_OPTIONS = [
"not-in-personal-collection",
] as const;
-// order of options matches the UI
+// defines the order of options in the UI
export const SORT_COLUMNS = ["view-count", "name", "location"] as const;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
index 67101e8accc..393654ab7da 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
@@ -43,34 +43,51 @@ function isMatchingSearchQuery(
const FILTERS: Record<FilterOption, FilterCallback> = {
verified: (node) => {
- if (node.type !== "card") {
- return false;
+ switch (node.type) {
+ case "card":
+ case "dashboard": {
+ const lastReview = node.data.moderation_reviews?.find(
+ (review) => review.most_recent,
+ );
+ return lastReview != null && lastReview.status === "verified";
+ }
+ default:
+ return false;
}
- const lastReview = node.data.moderation_reviews?.find(
- (review) => review.most_recent,
- );
- return lastReview != null && lastReview.status === "verified";
},
"in-dashboard": (node) => {
- if (node.type !== "card") {
- return false;
+ switch (node.type) {
+ case "card": {
+ const dashboard = node.data.dashboard;
+ return dashboard != null;
+ }
+ default:
+ return false;
}
- const dashboard = node.data.dashboard;
- return dashboard != null;
},
"in-official-collection": (node) => {
- if (node.type !== "card") {
- return false;
+ switch (node.type) {
+ case "card":
+ case "dashboard":
+ case "document": {
+ const collection = node.data.collection;
+ return collection != null && collection.authority_level === "official";
+ }
+ default:
+ return false;
}
- const collection = node.data.collection;
- return collection != null && collection.authority_level === "official";
},
"not-in-personal-collection": (node) => {
- if (node.type !== "card") {
- return false;
+ switch (node.type) {
+ case "card":
+ case "dashboard":
+ case "document": {
+ const collection = node.data.collection;
+ return collection != null && !collection.is_personal;
+ }
+ default:
+ return false;
}
- const collection = node.data.collection;
- return collection != null && !collection.is_personal;
},
};
@@ -81,15 +98,28 @@ export function canFilterByOption(
const type = getDependencyType(groupType);
switch (option) {
case "verified":
+ switch (type) {
+ case "card":
+ case "dashboard":
+ return true;
+ default:
+ return false;
+ }
case "in-dashboard":
+ switch (type) {
+ case "card":
+ return true;
+ default:
+ return false;
+ }
case "in-official-collection":
case "not-in-personal-collection":
switch (type) {
case "card":
+ case "dashboard":
+ case "document":
return true;
- case "table":
- case "transform":
- case "snippet":
+ default:
return false;
}
}
@@ -144,25 +174,21 @@ export function canSortByColumn(
case "question":
case "model":
case "metric":
+ case "dashboard":
+ case "document":
return true;
- case "table":
- case "transform":
- case "snippet":
+ default:
return false;
}
- break;
case "view-count":
switch (groupType) {
case "question":
+ case "dashboard":
+ case "document":
return true;
- case "model":
- case "metric":
- case "table":
- case "transform":
- case "snippet":
+ default:
return false;
}
- break;
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.tsx
index 66ed0fa987a..a378add3c70 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.tsx
@@ -6,6 +6,10 @@ import {
EntityPickerModal,
type EntityPickerTab,
} from "metabase/common/components/EntityPicker";
+import {
+ DashboardPicker,
+ type DashboardPickerStatePath,
+} from "metabase/common/components/Pickers/DashboardPicker";
import {
QuestionPicker,
type QuestionPickerStatePath,
@@ -21,19 +25,11 @@ import {
isActivityModel,
} from "metabase-types/api";
-import { SEARCH_MODELS } from "../constants";
-
import {
+ DASHBOARD_PICKER_OPTIONS,
ENTITY_PICKER_OPTIONS,
- QUESTION_FOLDER_MODELS,
- QUESTION_MODELS,
- QUESTION_MODELS_WITH_DASHBOARDS,
QUESTION_PICKER_OPTIONS,
RECENTS_CONTEXT,
- TABLE_FOLDER_MODELS,
- TABLE_MODELS,
- TRANSFORM_FOLDER_MODELS,
- TRANSFORM_MODELS,
} from "./constants";
import type {
EntryPickerItem,
@@ -41,12 +37,16 @@ import type {
EntryPickerItemModel,
} from "./types";
import {
+ getDashboardPickerItem,
getEntryPickerItem,
getEntryPickerValue,
+ getMetricPickerItem,
+ getModelPickerItem,
getQuestionPickerItem,
getTablePickerValue,
getTransformPickerItem,
hasAvailableModels,
+ selectOnlyCards,
} from "./utils";
type EntryPickerModalProps = {
@@ -62,8 +62,12 @@ export function EntryPickerModal({
}: EntryPickerModalProps) {
const [tablesPath, setTablesPath] = useState<TablePickerStatePath>();
const [questionsPath, setQuestionsPath] = useState<QuestionPickerStatePath>();
+ const [modelsPath, setModelsPath] = useState<QuestionPickerStatePath>();
+ const [metricsPath, setMetricsPath] = useState<QuestionPickerStatePath>();
+ const [dashboardsPath, setDashboardsPath] =
+ useState<DashboardPickerStatePath>();
const { data: searchResponse, isLoading: isSearchLoading } = useSearchQuery({
- models: SEARCH_MODELS,
+ models: ["card"],
limit: 0,
calculate_available_models: true,
});
@@ -83,8 +87,8 @@ export function EntryPickerModal({
computedTabs.push({
id: "tables-tab",
displayName: t`Tables`,
- models: TABLE_MODELS,
- folderModels: TABLE_FOLDER_MODELS,
+ models: ["table"],
+ folderModels: ["database", "schema"],
icon: "table",
render: ({ onItemSelect }) => (
<TablePicker
@@ -96,12 +100,12 @@ export function EntryPickerModal({
),
});
- if (hasAvailableModels(searchResponse, TRANSFORM_MODELS)) {
+ if (hasAvailableModels(searchResponse, ["transform"])) {
computedTabs.push({
id: "transforms-tab",
displayName: t`Transforms`,
- models: TRANSFORM_MODELS,
- folderModels: TRANSFORM_FOLDER_MODELS,
+ models: ["transform"],
+ folderModels: [],
icon: "refresh_downstream",
render: ({ onItemSelect }) => (
<PLUGIN_TRANSFORMS.TransformPicker
@@ -112,29 +116,99 @@ export function EntryPickerModal({
});
}
- if (hasAvailableModels(searchResponse, QUESTION_MODELS)) {
+ if (hasAvailableModels(searchResponse, ["card"])) {
computedTabs.push({
- id: "collections-tab",
- displayName: t`Collections`,
- models: QUESTION_MODELS,
- folderModels: QUESTION_FOLDER_MODELS,
- icon: "folder",
+ id: "questions-tab",
+ displayName: t`Questions`,
+ models: ["card"],
+ folderModels: ["collection", "dashboard"],
+ icon: "table2",
render: ({ onItemSelect }) => (
<QuestionPicker
initialValue={value ? getQuestionPickerItem(value) : undefined}
- models={QUESTION_MODELS_WITH_DASHBOARDS}
+ models={["card", "dashboard"]}
options={QUESTION_PICKER_OPTIONS}
path={questionsPath}
+ onInit={selectOnlyCards(onItemSelect)}
+ onItemSelect={selectOnlyCards(onItemSelect)}
+ onPathChange={setQuestionsPath}
+ />
+ ),
+ });
+ }
+
+ if (hasAvailableModels(searchResponse, ["dataset"])) {
+ computedTabs.push({
+ id: "models-tab",
+ displayName: t`Models`,
+ models: ["dataset"],
+ folderModels: ["collection"],
+ icon: "model",
+ render: ({ onItemSelect }) => (
+ <QuestionPicker
+ initialValue={value ? getModelPickerItem(value) : undefined}
+ models={["dataset"]}
+ options={QUESTION_PICKER_OPTIONS}
+ path={modelsPath}
onInit={onItemSelect}
onItemSelect={onItemSelect}
- onPathChange={setQuestionsPath}
+ onPathChange={setModelsPath}
+ />
+ ),
+ });
+ }
+
+ if (hasAvailableModels(searchResponse, ["metric"])) {
+ computedTabs.push({
+ id: "metrics-tab",
+ displayName: t`Metrics`,
+ models: ["metric"],
+ folderModels: ["collection"],
+ icon: "metric",
+ render: ({ onItemSelect }) => (
+ <QuestionPicker
+ initialValue={value ? getMetricPickerItem(value) : undefined}
+ models={["metric"]}
+ options={DASHBOARD_PICKER_OPTIONS}
+ path={metricsPath}
+ onInit={onItemSelect}
+ onItemSelect={onItemSelect}
+ onPathChange={setMetricsPath}
+ />
+ ),
+ });
+ }
+
+ if (hasAvailableModels(searchResponse, ["dashboard"])) {
+ computedTabs.push({
+ id: "dashboards-tab",
+ displayName: t`Dashboards`,
+ models: ["dashboard"],
+ folderModels: ["collection"],
+ icon: "dashboard",
+ render: ({ onItemSelect }) => (
+ <DashboardPicker
+ initialValue={value ? getDashboardPickerItem(value) : undefined}
+ models={["dashboard"]}
+ options={QUESTION_PICKER_OPTIONS}
+ path={dashboardsPath}
+ onItemSelect={onItemSelect}
+ onPathChange={setDashboardsPath}
/>
),
});
}
return computedTabs;
- }, [value, searchResponse, tablesPath, questionsPath]);
+ }, [
+ value,
+ searchResponse,
+ tablesPath,
+ questionsPath,
+ modelsPath,
+ metricsPath,
+ dashboardsPath,
+ ]);
const handleItemSelect = (item: EntryPickerItem) => {
const value = getEntryPickerValue(item);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/constants.ts
index 3305efa74c7..12be07ce37d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/constants.ts
@@ -2,48 +2,9 @@ import {
type EntityPickerModalOptions,
defaultOptions,
} from "metabase/common/components/EntityPicker";
-import type {
- QuestionPickerModel,
- QuestionPickerOptions,
-} from "metabase/common/components/Pickers/QuestionPicker";
-import type {
- CollectionItemModel,
- RecentContexts,
- SearchModel,
-} from "metabase-types/api";
-
-import type { EntryPickerItemModel } from "./types";
-
-export const TABLE_MODELS: EntryPickerItemModel[] = ["table"];
-
-export const TABLE_FOLDER_MODELS: EntryPickerItemModel[] = [
- "database",
- "schema",
-];
-
-export const TRANSFORM_MODELS: (EntryPickerItemModel & SearchModel)[] = [
- "transform",
-];
-
-export const TRANSFORM_FOLDER_MODELS: EntryPickerItemModel[] = [];
-
-export const QUESTION_MODELS: (EntryPickerItemModel & QuestionPickerModel)[] = [
- "card",
- "dataset",
- "metric",
-];
-
-export const QUESTION_MODELS_WITH_DASHBOARDS: CollectionItemModel[] = [
- "card",
- "dataset",
- "metric",
- "dashboard",
-];
-
-export const QUESTION_FOLDER_MODELS: EntryPickerItemModel[] = [
- "collection",
- "dashboard",
-];
+import type { DashboardPickerOptions } from "metabase/common/components/Pickers/DashboardPicker";
+import type { QuestionPickerOptions } from "metabase/common/components/Pickers/QuestionPicker";
+import type { RecentContexts } from "metabase-types/api";
export const RECENTS_CONTEXT: RecentContexts[] = ["selections"];
@@ -57,3 +18,8 @@ export const QUESTION_PICKER_OPTIONS: QuestionPickerOptions = {
showRootCollection: true,
showPersonalCollections: true,
};
+
+export const DASHBOARD_PICKER_OPTIONS: DashboardPickerOptions = {
+ showRootCollection: true,
+ showPersonalCollections: true,
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts
index 5a45cb0a743..4bc16a5dbbe 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts
@@ -1,3 +1,4 @@
+import type { DashboardPickerItem } from "metabase/common/components/Pickers/DashboardPicker";
import type { QuestionPickerItem } from "metabase/common/components/Pickers/QuestionPicker";
import type {
TablePickerItem,
@@ -46,7 +47,21 @@ export function getTablePickerItem(
};
}
-function getQuestionPickerModel(type: CardType): QuestionPickerItem["model"] {
+export function getTransformPickerItem(
+ node: DependencyNode,
+): TransformPickerItem | undefined {
+ if (node.type !== "transform") {
+ return;
+ }
+
+ return {
+ id: node.id,
+ name: node.data.name,
+ model: "transform",
+ };
+}
+
+function getCardPickerModel(type: CardType): QuestionPickerItem["model"] {
switch (type) {
case "question":
return "card";
@@ -57,32 +72,46 @@ function getQuestionPickerModel(type: CardType): QuestionPickerItem["model"] {
}
}
-export function getQuestionPickerItem(
+function getCardPickerItem(
node: DependencyNode,
+ cardType: CardType,
): QuestionPickerItem | undefined {
- if (node.type !== "card") {
+ if (node.type !== "card" || node.data.type !== cardType) {
return;
}
return {
id: node.id,
name: node.data.name,
- model: getQuestionPickerModel(node.data.type),
+ model: getCardPickerModel(node.data.type),
};
}
-export function getTransformPickerItem(
+export function getQuestionPickerItem(
node: DependencyNode,
-): TransformPickerItem | undefined {
- if (node.type !== "transform") {
+): QuestionPickerItem | undefined {
+ return getCardPickerItem(node, "question");
+}
+
+export function getModelPickerItem(
+ node: DependencyNode,
+): QuestionPickerItem | undefined {
+ return getCardPickerItem(node, "model");
+}
+
+export function getMetricPickerItem(
+ node: DependencyNode,
+): QuestionPickerItem | undefined {
+ return getCardPickerItem(node, "metric");
+}
+
+export function getDashboardPickerItem(
+ node: DependencyNode,
+): DashboardPickerItem | undefined {
+ if (node.type !== "dashboard") {
return;
}
-
- return {
- id: node.id,
- name: node.data.name,
- model: "transform",
- };
+ return { id: node.id, model: "dashboard", name: node.data.name };
}
export function getEntryPickerItem(
@@ -90,8 +119,11 @@ export function getEntryPickerItem(
): EntryPickerItem | undefined {
return (
getTablePickerItem(node) ??
+ getTransformPickerItem(node) ??
getQuestionPickerItem(node) ??
- getTransformPickerItem(node)
+ getModelPickerItem(node) ??
+ getMetricPickerItem(node) ??
+ getDashboardPickerItem(node)
);
}
@@ -119,3 +151,10 @@ export function hasAvailableModels(
const availableModels = response?.available_models ?? [];
return models.some((model) => availableModels.includes(model));
}
+
+export function selectOnlyCards(
+ onItemSelect: (item: QuestionPickerItem) => void,
+) {
+ return (item: QuestionPickerItem) =>
+ item.model === "card" ? onItemSelect(item) : undefined;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/SearchModelPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/SearchModelPicker.tsx
index ce897a60860..f30904c82e6 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/SearchModelPicker.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/SearchModelPicker.tsx
@@ -14,8 +14,6 @@ import {
} from "metabase/ui";
import type { SearchModel } from "metabase-types/api";
-import { SEARCH_MODELS } from "../../constants";
-
import S from "./SearchModelPicker.module.css";
import { getSearchModelItems } from "./utils";
@@ -61,7 +59,7 @@ function SearchModelPopover({
onSearchModelsChange,
}: SearchModelPopoverProps) {
const { data, isLoading } = useSearchQuery({
- models: SEARCH_MODELS,
+ models: ["card"],
limit: 0,
calculate_available_models: true,
});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
index 03670b404cc..3e246f186e1 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
@@ -12,10 +12,12 @@ import type { SearchModelItem } from "./types";
export function getSearchModelItems(data: SearchResponse): SearchModelItem[] {
const allLabels: Record<EnabledSearchModel, string> = {
table: t`Tables`,
+ transform: t`Transforms`,
card: t`Questions`,
dataset: t`Models`,
metric: t`Metrics`,
- transform: t`Transforms`,
+ dashboard: t`Dashboards`,
+ document: t`Transforms`,
};
const allItems = ENABLED_SEARCH_MODELS.map((model) => ({
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/constants.ts
index 3262b012347..f26d64a6313 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/constants.ts
@@ -2,23 +2,28 @@ import type { DependencyGroupType, SearchModel } from "metabase-types/api";
export type EnabledSearchModel = (typeof ENABLED_SEARCH_MODELS)[number];
+// defines the order of options in the UI
export const ENABLED_SEARCH_MODELS = [
+ "table",
+ "transform",
"card",
"dataset",
"metric",
- "table",
- "transform",
+ "dashboard",
+ "document",
] as const satisfies SearchModel[];
export const ENABLED_SEARCH_MODEL_TO_GROUP_TYPE: Record<
EnabledSearchModel,
DependencyGroupType
> = {
+ table: "table",
+ transform: "transform",
card: "question",
dataset: "model",
metric: "metric",
- table: "table",
- transform: "transform",
+ dashboard: "dashboard",
+ document: "document",
};
export const SEARCH_MODELS: SearchModel[] = ENABLED_SEARCH_MODELS;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
index d6a8d12275c..12e9184a87b 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
@@ -32,7 +32,7 @@ export function PanelBody({ node }: PanelBodyProps) {
<Stack className={S.body} p="lg" gap="lg">
<DescriptionSection node={node} />
<CreatorAndLastEditorSection node={node} />
- <GeneratedTableSection node={node} />
+ <TableSection node={node} />
<FieldsSection node={node} />
</Stack>
);
@@ -44,10 +44,13 @@ type SectionProps = {
function DescriptionSection({ node }: SectionProps) {
const description = getNodeDescription(node);
+ if (description == null) {
+ return null;
+ }
return (
<Box c={description ? "text-primary" : "text-secondary"} lh="h4">
- {description ?? t`No description`}
+ {description.length > 0 ? description : t`No description`}
</Box>
);
}
@@ -95,7 +98,7 @@ function CreatorAndLastEditorSection({ node }: SectionProps) {
);
}
-function GeneratedTableSection({ node }: SectionProps) {
+function TableSection({ node }: SectionProps) {
const info = getNodeTableInfo(node);
if (info == null) {
return null;
@@ -103,8 +106,8 @@ function GeneratedTableSection({ node }: SectionProps) {
return (
<Stack gap="sm" lh="1rem">
- <Title order={6}>{t`Generated table`}</Title>
- <Group justify="space-between">
+ <Title order={6}>{info.label}</Title>
+ <Group justify="space-between" wrap="nowrap">
<GraphLink label={info.title.label} icon="table" url={info.title.url} />
<GraphExternalLink
label={info.metadata.label}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts
index 8c416b25973..f1822b8bd56 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts
@@ -1,6 +1,7 @@
import type { NodeLink } from "../../types";
export type NodeTableInfo = {
+ label: string;
title: NodeLink;
metadata: NodeLink;
location: NodeLink[] | null;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
index 0ec7ccd899c..e6946167fdd 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
@@ -4,6 +4,7 @@ import * as Urls from "metabase/lib/urls";
import type {
CardCreatorInfo,
DependencyNode,
+ Field,
LastEditInfo,
} from "metabase-types/api";
@@ -12,10 +13,13 @@ import type { NodeTableInfo } from "./types";
export function getNodeCreatedAt(node: DependencyNode): string | null {
switch (node.type) {
case "card":
+ case "dashboard":
+ case "document":
return node.data.created_at;
case "table":
case "transform":
case "snippet":
+ case "sandbox":
return null;
}
}
@@ -23,10 +27,13 @@ export function getNodeCreatedAt(node: DependencyNode): string | null {
export function getNodeCreatedBy(node: DependencyNode): CardCreatorInfo | null {
switch (node.type) {
case "card":
+ case "dashboard":
+ case "document":
return node.data.creator ?? null;
case "table":
case "transform":
case "snippet":
+ case "sandbox":
return null;
}
}
@@ -34,10 +41,13 @@ export function getNodeCreatedBy(node: DependencyNode): CardCreatorInfo | null {
export function getNodeLastEditedAt(node: DependencyNode): string | null {
switch (node.type) {
case "card":
+ case "dashboard":
return node.data["last-edit-info"]?.timestamp ?? null;
case "table":
case "transform":
case "snippet":
+ case "document":
+ case "sandbox":
return null;
}
}
@@ -45,16 +55,19 @@ export function getNodeLastEditedAt(node: DependencyNode): string | null {
export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {
switch (node.type) {
case "card":
+ case "dashboard":
return node.data["last-edit-info"] ?? null;
case "table":
case "transform":
case "snippet":
+ case "document":
+ case "sandbox":
return null;
}
}
export function getNodeTableInfo(node: DependencyNode): NodeTableInfo | null {
- if (node.type !== "transform") {
+ if (node.type !== "transform" && node.type !== "sandbox") {
return null;
}
@@ -64,6 +77,7 @@ export function getNodeTableInfo(node: DependencyNode): NodeTableInfo | null {
}
return {
+ label: node.type === "transform" ? t`Generated table` : t`Restricted table`,
title: {
label: table.display_name,
url: Urls.dependencyGraph({ entry: { id: table.id, type: "table" } }),
@@ -87,15 +101,18 @@ export function getNodeTableInfo(node: DependencyNode): NodeTableInfo | null {
};
}
-export function getNodeFields(node: DependencyNode) {
+export function getNodeFields(node: DependencyNode): Field[] {
switch (node.type) {
case "card":
return node.data.result_metadata ?? [];
case "table":
return node.data.fields ?? [];
case "transform":
+ case "sandbox":
return node.data.table?.fields ?? [];
case "snippet":
+ case "dashboard":
+ case "document":
return [];
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
index e245260dd8c..030b7f1b8b3 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
@@ -12,6 +12,9 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {
table = 0,
transform = 0,
snippet = 0,
+ dashboard = 0,
+ document = 0,
+ sandbox = 0,
} = node.dependents_count ?? {};
const groups: DependentGroup[] = [
@@ -21,6 +24,9 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {
{ type: "table", count: table },
{ type: "transform", count: transform },
{ type: "snippet", count: snippet },
+ { type: "dashboard", count: dashboard },
+ { type: "document", count: document },
+ { type: "sandbox", count: sandbox },
];
return groups.filter(({ count }) => count !== 0);
@@ -30,16 +36,15 @@ export function getDependencyGroupTitle(
node: DependencyNode,
groups: DependentGroup[],
) {
+ if (node.type === "transform") {
+ return t`Generates`;
+ }
+ if (node.type === "sandbox") {
+ return t`Restricts table data`;
+ }
if (groups.length === 0) {
return t`Nothing uses this`;
}
- if (
- node.type === "transform" &&
- groups.length === 1 &&
- groups[0].type === "table"
- ) {
- return t`Generates`;
- }
return t`Used by`;
}
@@ -60,5 +65,15 @@ export function getDependentGroupLabel({
return ngettext(msgid`${count} transform`, `${count} transforms`, count);
case "snippet":
return ngettext(msgid`${count} snippet`, `${count} snippet`, count);
+ case "dashboard":
+ return ngettext(msgid`${count} dashboard`, `${count} dashboards`, count);
+ case "document":
+ return ngettext(msgid`${count} document`, `${count} documents`, count);
+ case "sandbox":
+ return ngettext(
+ msgid`${count} row and column security rule`,
+ `${count} row and column security rules`,
+ count,
+ );
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
index df329a6065d..e04089f0ebf 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
@@ -87,11 +87,24 @@ export function findNode(
}
export function getNodeLabel(node: DependencyNode): string {
- return node.type === "table" ? node.data.display_name : node.data.name;
+ switch (node.type) {
+ case "table":
+ return node.data.display_name;
+ case "sandbox":
+ return node.data.table?.display_name ?? t`Row and column security rule`;
+ default:
+ return node.data.name;
+ }
}
export function getNodeDescription(node: DependencyNode): string | null {
- return node.data.description;
+ switch (node.type) {
+ case "document":
+ case "sandbox":
+ return null;
+ default:
+ return node.data.description ?? "";
+ }
}
export function getNodeIcon(node: DependencyNode): IconName {
@@ -127,6 +140,12 @@ export function getNodeIconWithType(
return "refresh_downstream";
case "snippet":
return "sql";
+ case "dashboard":
+ return "dashboard";
+ case "document":
+ return "document";
+ case "sandbox":
+ return "permissions_limited";
}
}
@@ -162,6 +181,28 @@ export function getNodeLink(node: DependencyNode): NodeLink | null {
label: t`View this transform`,
url: Urls.transform(node.id),
};
+ case "dashboard":
+ return {
+ label: `View this dashboard`,
+ url: Urls.dashboard({ id: node.id, name: node.data.name }),
+ };
+ case "document":
+ return {
+ label: `View this document`,
+ url: Urls.document({ id: node.id }),
+ };
+ case "sandbox":
+ if (node.data.table != null) {
+ return {
+ label: `View this permission`,
+ url: Urls.tableDataPermissions(
+ node.data.table.db_id,
+ node.data.table.schema,
+ node.data.table.id,
+ ),
+ };
+ }
+ return null;
case "snippet":
return null;
}
@@ -201,8 +242,20 @@ export function getNodeLocationInfo(node: DependencyNode): NodeLink[] | null {
];
}
return null;
+ case "dashboard":
+ case "document":
+ if (node.data.collection != null) {
+ return [
+ {
+ label: node.data.collection.name,
+ url: Urls.collection(node.data.collection),
+ },
+ ];
+ }
+ return null;
case "transform":
case "snippet":
+ case "sandbox":
return null;
}
}
@@ -215,9 +268,13 @@ export function getNodeViewCount(node: DependencyNode): number | null {
return node.data.type === "question"
? (node.data.view_count ?? null)
: null;
+ case "dashboard":
+ case "document":
+ return node.data.view_count ?? null;
case "table":
case "transform":
case "snippet":
+ case "sandbox":
return null;
}
}
@@ -264,5 +321,11 @@ export function getNodeTypeInfo(node: DependencyNode): NodeTypeInfo {
return { label: t`Transform`, color: "warning" };
case "snippet":
return { label: t`Snippet`, color: "text-secondary" };
+ case "dashboard":
+ return { label: t`Dashboard`, color: "filter" };
+ case "document":
+ return { label: t`Document`, color: "text-secondary" };
+ case "sandbox":
+ return { label: t`Row and column security rule`, color: "error" };
}
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
index 3250dcbe5fd..c567760df90 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
@@ -13,14 +13,17 @@ export function parseParams(
};
}
-function parseDependencyType(type: unknown): DependencyType | undefined {
+function parseDependencyType(type: unknown): DependencyType | null {
switch (type) {
case "card":
case "table":
case "transform":
case "snippet":
+ case "dashboard":
+ case "document":
+ case "sandbox":
return type;
default:
- return undefined;
+ return null;
}
}
diff --git a/frontend/src/metabase-types/api/dashboard.ts b/frontend/src/metabase-types/api/dashboard.ts
index 64b7ed5c55e..274198efcfa 100644
--- a/frontend/src/metabase-types/api/dashboard.ts
+++ b/frontend/src/metabase-types/api/dashboard.ts
@@ -1,6 +1,7 @@
import type { EmbeddingParameters } from "metabase/public/lib/types";
import type {
BaseEntityId,
+ CardCreatorInfo,
CardDisplayType,
ClickBehavior,
Collection,
@@ -44,6 +45,7 @@ export interface Dashboard {
entity_id: BaseEntityId;
created_at: string;
creator_id: UserId;
+ creator?: CardCreatorInfo;
updated_at: string;
collection?: Collection | null;
collection_id: CollectionId | null;
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index b9b4dfd7180..b606c3b2c37 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -1,10 +1,19 @@
import type { Card, CardType } from "./card";
+import type { Dashboard } from "./dashboard";
+import type { Document } from "./document";
import type { NativeQuerySnippet } from "./snippets";
-import type { Table } from "./table";
+import type { Table, TableId } from "./table";
import type { Transform } from "./transform";
export type DependencyId = number;
-export type DependencyType = "card" | "table" | "transform" | "snippet";
+export type DependencyType =
+ | "card"
+ | "table"
+ | "transform"
+ | "snippet"
+ | "dashboard"
+ | "document"
+ | "sandbox";
export type DependencyGroupType = CardType | Exclude<DependencyType, "card">;
export type DependencyEntry = {
@@ -56,6 +65,32 @@ export type SnippetDependencyNodeData = Pick<
"name" | "description"
>;
+export type DashboardDependencyNodeData = Pick<
+ Dashboard,
+ | "name"
+ | "description"
+ | "created_at"
+ | "creator"
+ | "last-edit-info"
+ | "collection_id"
+ | "collection"
+ | "moderation_reviews"
+> & {
+ view_count?: number | null;
+};
+
+export type DocumentDependencyNodeData = Pick<
+ Document,
+ "name" | "created_at" | "creator" | "collection_id" | "collection"
+> & {
+ view_count?: number | null;
+};
+
+export type SandboxDependencyNodeData = {
+ table_id: TableId;
+ table?: Table | null;
+};
+
export type TableDependencyNode = BaseDependencyNode<
"table",
TableDependencyNodeData
@@ -76,11 +111,29 @@ export type SnippetDependencyNode = BaseDependencyNode<
SnippetDependencyNodeData
>;
+export type DashboardDependencyNode = BaseDependencyNode<
+ "dashboard",
+ DashboardDependencyNodeData
+>;
+
+export type DocumentDependencyNode = BaseDependencyNode<
+ "document",
+ DocumentDependencyNodeData
+>;
+
+export type SandboxDependencyNode = BaseDependencyNode<
+ "sandbox",
+ SandboxDependencyNodeData
+>;
+
export type DependencyNode =
| TableDependencyNode
| TransformDependencyNode
| CardDependencyNode
- | SnippetDependencyNode;
+ | SnippetDependencyNode
+ | DashboardDependencyNode
+ | DocumentDependencyNode
+ | SandboxDependencyNode;
export type DependencyEdge = {
from_entity_id: DependencyId;
diff --git a/frontend/src/metabase-types/api/document.ts b/frontend/src/metabase-types/api/document.ts
index 95be0f7a40c..a427180a603 100644
--- a/frontend/src/metabase-types/api/document.ts
+++ b/frontend/src/metabase-types/api/document.ts
@@ -1,7 +1,7 @@
import type { JSONContent } from "@tiptap/core";
import type { Card } from "./card";
-import type { CollectionId } from "./collection";
+import type { Collection, CollectionId } from "./collection";
import type { BaseUser, UserId } from "./user";
export type DocumentId = number;
@@ -14,6 +14,7 @@ export type Document = {
name: string;
version: number;
collection_id: CollectionId | null;
+ collection?: Collection | null;
created_at: string;
updated_at: string;
archived: boolean;
diff --git a/frontend/src/metabase/lib/urls/index.ts b/frontend/src/metabase/lib/urls/index.ts
index 5569a2fe6de..8c091d1e378 100644
--- a/frontend/src/metabase/lib/urls/index.ts
+++ b/frontend/src/metabase/lib/urls/index.ts
@@ -9,6 +9,7 @@ export * from "./dependencies";
export * from "./documents";
export * from "./indexed-entities";
export * from "./modelToUrl";
+export * from "./permissions";
export * from "./misc";
export * from "./models";
export * from "./pulses";
diff --git a/frontend/src/metabase/lib/urls/permissions.ts b/frontend/src/metabase/lib/urls/permissions.ts
new file mode 100644
index 00000000000..7c97f792271
--- /dev/null
+++ b/frontend/src/metabase/lib/urls/permissions.ts
@@ -0,0 +1,9 @@
+import type { DatabaseId, TableId } from "metabase-types/api";
+
+export function tableDataPermissions(
+ databaseId: DatabaseId,
+ schema: string | null,
+ tableId: TableId,
+) {
+ return `/admin/permissions/data/database/${databaseId}/schema/${encodeURIComponent(schema ?? "")}/table/${tableId}`;
+}
diff --git a/resources/migrations/057_update_migrations.yaml b/resources/migrations/057_update_migrations.yaml
index 5a6a5402068..4058a2fc30d 100644
--- a/resources/migrations/057_update_migrations.yaml
+++ b/resources/migrations/057_update_migrations.yaml
@@ -1664,6 +1664,84 @@ databaseChangeLog:
columns:
- column:
name: dependency_analysis_version
+ - changeSet:
+ id: v57.2025-09-18T10:06:00
+ author: rileythomp
+ comment: Add dependency_analysis_version to report_dashboard
+ changes:
+ - addColumn:
+ tableName: report_dashboard
+ columns:
+ - column:
+ name: dependency_analysis_version
+ type: smallint
+ defaultValue: 0
+ remarks: Version of the dependency analysis for this entity.
+ constraints:
+ nullable: false
+ - changeSet:
+ id: v57.2025-09-18T10:07:00
+ author: rileythomp
+ comment: Add index for dependency_analysis_version to report_dashboard
+ changes:
+ - createIndex:
+ tableName: report_dashboard
+ indexName: idx_report_dashboard_dependency_analysis_version
+ columns:
+ - column:
+ name: dependency_analysis_version
+ - changeSet:
+ id: v57.2025-09-18T10:08:00
+ author: rileythomp
+ comment: Add dependency_analysis_version to document
+ changes:
+ - addColumn:
+ tableName: document
+ columns:
+ - column:
+ name: dependency_analysis_version
+ type: smallint
+ defaultValue: 0
+ remarks: Version of the dependency analysis for this entity.
+ constraints:
+ nullable: false
+ - changeSet:
+ id: v57.2025-09-18T10:09:00
+ author: rileythomp
+ comment: Add index for dependency_analysis_version to document
+ changes:
+ - createIndex:
+ tableName: document
+ indexName: idx_document_dependency_analysis_version
+ columns:
+ - column:
+ name: dependency_analysis_version
+ - changeSet:
+ id: v57.2025-09-18T10:10:00
+ author: rileythomp
+ comment: Add dependency_analysis_version to sandboxes
+ changes:
+ - addColumn:
+ tableName: sandboxes
+ columns:
+ - column:
+ name: dependency_analysis_version
+ type: smallint
+ defaultValue: 0
+ remarks: Version of the dependency analysis for this entity.
+ constraints:
+ nullable: false
+ - changeSet:
+ id: v57.2025-09-18T10:11:00
+ author: rileythomp
+ comment: Add index for dependency_analysis_version to sandboxes
+ changes:
+ - createIndex:
+ tableName: sandboxes
+ indexName: idx_sandboxes_dependency_analysis_version
+ columns:
+ - column:
+ name: dependency_analysis_version
- changeSet:
id: v57.2025-09-19T11:30:20
diff --git a/src/metabase/dashboards/models/dashboard.clj b/src/metabase/dashboards/models/dashboard.clj
index 5cf744d76e4..0eaae38c91f 100644
--- a/src/metabase/dashboards/models/dashboard.clj
+++ b/src/metabase/dashboards/models/dashboard.clj
@@ -397,7 +397,8 @@
:skip [;; those stats are inherently local state
:view_count :last_viewed_at
;; this is deprecated
- :cache_ttl]
+ :cache_ttl
+ :dependency_analysis_version]
:transform {:created_at (serdes/date)
:initially_published_at (serdes/date)
:collection_id (serdes/fk :model/Collection)
diff --git a/src/metabase/graph/core.cljc b/src/metabase/graph/core.cljc
index db296852c4d..0b995d04dcd 100644
--- a/src/metabase/graph/core.cljc
+++ b/src/metabase/graph/core.cljc
@@ -75,7 +75,7 @@
(recur new-children))
(drop (count key-seq) (->iterable))))))
-(defn calc-edges
+(defn calc-edges-between
"Calculates the edges within `nodes`, based on `graph`."
[graph nodes]
(let [node-set (into #{} nodes)
diff --git a/src/metabase/lib/schema/id.cljc b/src/metabase/lib/schema/id.cljc
index 8112685b0f4..91148677dca 100644
--- a/src/metabase/lib/schema/id.cljc
+++ b/src/metabase/lib/schema/id.cljc
@@ -89,3 +89,11 @@
(mr/def ::collection
"Valid Collection ID"
pos-int?)
+
+(mr/def ::document
+ "Valid Document ID"
+ pos-int?)
+
+(mr/def ::sandbox
+ "Valid Sandbox ID"
+ pos-int?)
diff --git a/src/metabase/revisions/impl/dashboard.clj b/src/metabase/revisions/impl/dashboard.clj
index 63bfb891b33..a44064169e6 100644
--- a/src/metabase/revisions/impl/dashboard.clj
+++ b/src/metabase/revisions/impl/dashboard.clj
@@ -18,6 +18,7 @@
;; > The position this Dashboard should appear in the Dashboards list,
;; lower-numbered positions appearing before higher numbered ones.
;; TODO: querying on stats we don't have any dashboard that has a position, maybe we could just drop it?
+ :dependency_analysis_version
:public_uuid :made_public_by_id
:position :initially_published_at :view_count
:last_viewed_at})