Skip to content

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

Broken & unreferenced entities - add pagination, expose tables (#68110)

Alexander Polyankin7cd7ef457aad
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index c934bb8575d..48676a2c7db 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -1987,6 +1987,7 @@
premium-features
queries
query-processor
+ request
revisions
settings
task
diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
index 754e66acb5d..0c15c6b5393 100644
--- a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
@@ -168,14 +168,14 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should filter by location", () => {
- createEntities({ withPersonalCollection: true });
+ createEntities();
H.DataStudio.Tasks.visitUnreferencedEntities();
checkList({
visibleEntities: [
MODEL_FOR_MODEL_DATA_SOURCE,
+ MODEL_FOR_METRIC_DATA_SOURCE,
SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,
],
- hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],
});
H.DataStudio.Tasks.filterButton().click();
@@ -183,18 +183,18 @@ describe("scenarios > dependencies > unreferenced list", () => {
checkList({
visibleEntities: [
MODEL_FOR_MODEL_DATA_SOURCE,
- MODEL_FOR_METRIC_DATA_SOURCE,
SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,
],
+ hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],
});
H.popover().findByText("Include items in personal collections").click();
checkList({
visibleEntities: [
MODEL_FOR_MODEL_DATA_SOURCE,
+ MODEL_FOR_METRIC_DATA_SOURCE,
SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,
],
- hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],
});
});
});
@@ -259,9 +259,8 @@ describe("scenarios > dependencies > unreferenced list", () => {
function createEntities({
withReferences = false,
- withPersonalCollection = false,
-}: { withReferences?: boolean; withPersonalCollection?: boolean } = {}) {
- createModelContent({ withReferences, withPersonalCollection });
+}: { withReferences?: boolean } = {}) {
+ createModelContent({ withReferences });
createSegmentContent({ withReferences });
createMetricContent({ withReferences });
createSnippetContent({ withReferences });
@@ -269,10 +268,8 @@ function createEntities({
function createModelContent({
withReferences = false,
- withPersonalCollection = false,
}: {
withReferences?: boolean;
- withPersonalCollection?: boolean;
}) {
createModelWithTableDataSource({
name: MODEL_FOR_QUESTION_DATA_SOURCE,
@@ -302,9 +299,7 @@ function createModelContent({
createModelWithTableDataSource({
name: MODEL_FOR_METRIC_DATA_SOURCE,
tableId: ORDERS_ID,
- collectionId: withPersonalCollection
- ? ADMIN_PERSONAL_COLLECTION_ID
- : undefined,
+ collectionId: ADMIN_PERSONAL_COLLECTION_ID,
}).then(({ body: model }) => {
if (withReferences) {
createMetricWithModelDataSource({
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
index 873da0f0975..4a920f25cc8 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
@@ -24,6 +24,7 @@
[metabase.native-query-snippets.core :as native-query-snippets]
[metabase.permissions.core :as perms]
[metabase.queries.schema :as queries.schema]
+ [metabase.request.core :as request]
[metabase.revisions.core :as revisions]
[metabase.util.i18n :refer [tru]]
[metabase.util.malli :as mu]
@@ -570,28 +571,8 @@
(or (not= dependent_type :card)
(= (-> % :data :type) dependent_card_type))))))))
-(defn- personal-collection-filter
- "Returns a HoneySQL WHERE clause to exclude items in personal collections.
- Only applies to collection-based entities (card, dashboard, document, snippet).
- Returns nil for non-collection entities or when include-personal-collections is true."
- [entity-type include-personal-collections]
- (when-not include-personal-collections
- (case entity-type
- (:card :dashboard :document :snippet)
- (let [personal-ids (t2/select-pks-vec :model/Collection
- :personal_owner_id [:not= nil]
- :location "/")]
- (when (seq personal-ids)
- [:or
- [:= :entity.collection_id nil]
- [:and
- [:= :collection.personal_owner_id nil]
- (into [:and]
- (for [pid personal-ids]
- [:not-like :collection.location (str "/" pid "/%")]))]]))
- nil)))
-
-(defn- unreferenced-query [entity-type card-types query include-archived-items include-personal-collections]
+(defn- dependency-items-query
+ [{:keys [query-type entity-type card-types query include-archived-items include-personal-collections]}]
(let [table-name (case entity-type
:card :report_card
:table :metabase_table
@@ -606,6 +587,20 @@
:table :entity.display_name
:sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
:entity.name)
+ join (case query-type
+ :unreferenced [:dependency [:and
+ [:= :dependency.to_entity_id :entity.id]
+ [:= :dependency.to_entity_type [:inline (name entity-type)]]]]
+ :broken [:analysis_finding [:and
+ [:= :analysis_finding.analyzed_entity_id :entity.id]
+ [:= :analysis_finding.analyzed_entity_type (name entity-type)]]])
+ join-filter (case query-type
+ :unreferenced [:= :dependency.id nil]
+ :broken [:= :analysis_finding.result false])
+
+ database-filter (when (= entity-type :table)
+ [:and [:not :database.is_sample] [:not :database.is_audit]])
+ needs-database-join? (= entity-type :table)
archived-filter (when (= include-archived-items :exclude)
(case entity-type
(:card :dashboard :document :snippet :segment :measure)
@@ -615,19 +610,31 @@
[:= :entity.active true]
[:= :entity.visibility_type nil]]
nil))
- personal-filter (personal-collection-filter entity-type include-personal-collections)
+ personal-filter (when-not include-personal-collections
+ (case entity-type
+ (:card :dashboard :document :snippet)
+ (let [personal-ids (t2/select-pks-vec :model/Collection
+ :personal_owner_id [:not= nil]
+ :location "/")]
+ (when (seq personal-ids)
+ [:or
+ [:= :entity.collection_id nil]
+ [:and
+ [:= :collection.personal_owner_id nil]
+ (into [:and]
+ (for [pid personal-ids]
+ [:not-like :collection.location (str "/" pid "/%")]))]]))
+ nil))
needs-collection-join? (and (not include-personal-collections)
(#{:card :dashboard :document :snippet} entity-type))]
{:select [[[:inline (name entity-type)] :entity_type]
[:entity.id :entity_id]
[name-column :sort_key]]
:from [[table-name :entity]]
- :left-join (cond-> [:dependency [:and
- [:= :dependency.to_entity_id :entity.id]
- [:= :dependency.to_entity_type [:inline (name entity-type)]]]]
- needs-collection-join?
- (conj :collection [:= :entity.collection_id :collection.id]))
- :where (cond->> [:= :dependency.id nil]
+ :left-join (cond-> join
+ needs-database-join? (conj [:metabase_database :database] [:= :entity.db_id :database.id])
+ needs-collection-join? (conj :collection [:= :entity.collection_id :collection.id]))
+ :where (cond->> join-filter
(and (= entity-type :card)
(seq card-types))
(conj [:and [:in :entity.type (mapv name card-types)]])
@@ -635,13 +642,16 @@
(and query (not= entity-type :sandbox))
(conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]])
+ database-filter
+ (conj [:and database-filter])
+
archived-filter
(conj [:and archived-filter])
personal-filter
(conj [:and personal-filter]))}))
-(def ^:private unreferenced-items-args
+(def ^:private dependency-items-args
[:map
[:types {:optional true} [:or
::deps.dependency-types/dependency-types
@@ -653,101 +663,69 @@
[:archived {:optional true} :boolean]
[:include_personal_collections {:optional true} :boolean]])
-(api.macros/defendpoint :get "/graph/unreferenced" :- [:sequential ::entity]
+(def ^:private dependency-items-response
+ [:map
+ [:data [:sequential ::entity]]
+ [:total nat-int?]
+ [:offset nat-int?]
+ [:limit ms/PositiveInt]])
+
+(api.macros/defendpoint :get "/graph/unreferenced" :- dependency-items-response
"Returns a list of all unreferenced items in the instance.
An unreferenced item is one that is not a dependency of any other item.
Accepts optional parameters for filtering:
- - types: List of entity types to include (e.g., [:card :transform :snippet :dashboard])
- - card_types: List of card types to include when filtering cards (e.g., [:question :model :metric])
- - query: Search string to filter by name or location
- - archived: Controls whether archived entities are included
- - include_personal_collections: Controls whether items in personal collections are included (default: false)
-
- Returns a list of unreferenced items, each with :id, :type, and :data fields."
+ - `types`: List of entity types to include (e.g., [:card :transform :snippet :dashboard])
+ - `card_types`: List of card types to include when filtering cards (e.g., [:question :model :metric])
+ - `query`: Search string to filter by name or location
+ - `archived`: Controls whether archived entities are included
+ - `include_personal_collections`: Controls whether items in personal collections are included (default: false)
+ - `offset`: Default 0
+ - `limit`: Default 50
+
+ Returns a map with:
+ - `data`: List of unreferenced items, each with `:id`, `:type`, and `:data` fields
+ - `total`: Total count of matched items
+ - `offset`: Applied offset
+ - `limit`: Applied limit"
[_route-params
{:keys [types card_types query archived include_personal_collections]
:or {types (vec deps.dependency-types/dependency-types)
card_types (vec lib.schema.metadata/card-types)
- include_personal_collections false}} :- unreferenced-items-args]
- (let [include-archived-items (if archived :all :exclude)
+ include_personal_collections false}} :- dependency-items-args]
+ (let [offset (or (request/offset) 0)
+ limit (or (request/limit) 50)
+ include-archived-items (if archived :all :exclude)
graph-opts {:include-archived-items include-archived-items}
selected-types (cond->> (if (sequential? types) types [types])
;; Sandboxes don't support query filtering, so exclude them when a query is provided
query (remove #{:sandbox}))
card-types (if (sequential? card_types) card_types [card_types])
- union-queries (map #(unreferenced-query % card-types query include-archived-items include_personal_collections)
+ union-queries (map #(dependency-items-query {:query-type :unreferenced
+ :entity-type %
+ :card-types card-types
+ :query query
+ :include-archived-items include-archived-items
+ :include-personal-collections include_personal_collections})
selected-types)
union-query {:union-all union-queries}
- all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))
+ all-ids (->> (t2/query (assoc union-query
+ :order-by [[:sort_key :asc]]
+ :offset offset
+ :limit limit))
(map (fn [{:keys [entity_id entity_type]}]
[(keyword entity_type) entity_id])))
- downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))]
- (expanded-nodes downstream-graph all-ids {:include-errors? false})))
-
-(def ^:private broken-items-args
- [:map
- [:types {:optional true} [:or
- ::deps.dependency-types/dependency-types
- [:sequential ::deps.dependency-types/dependency-types]]]
- [:card_types {:optional true} [:or
- (ms/enum-decode-keyword lib.schema.metadata/card-types)
- [:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]]
- [:query {:optional true} :string]
- [:archived {:optional true} :boolean]
- [:include_personal_collections {:optional true} :boolean]])
-
-(defn- broken-query [entity-type card-types query include-archived-items include-personal-collections]
- (let [table-name (case entity-type
- :card :report_card
- :table :metabase_table
- :transform :transform
- :snippet :native_query_snippet
- :dashboard :report_dashboard
- :document :document
- :sandbox :sandboxes
- :segment :segment
- :measure :measure)
- name-column (case entity-type
- :table :entity.display_name
- :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
- :entity.name)
- archived-filter (when (= include-archived-items :exclude)
- (case entity-type
- (:card :dashboard :document :snippet :segment :measure)
- [:= :entity.archived false]
- :table
- [:and
- [:= :entity.active true]
- [:= :entity.visibility_type nil]]
- nil))
- personal-filter (personal-collection-filter entity-type include-personal-collections)
- needs-collection-join? (and (not include-personal-collections)
- (#{:card :dashboard :document :snippet} entity-type))]
- {:select [[[:inline (name entity-type)] :entity_type]
- [:entity.id :entity_id]
- [name-column :sort_key]]
- :from [[table-name :entity]]
- :left-join (cond-> [:analysis_finding [:and
- [:= :analysis_finding.analyzed_entity_id :entity.id]
- [:= :analysis_finding.analyzed_entity_type (name entity-type)]]]
- needs-collection-join?
- (conj :collection [:= :entity.collection_id :collection.id]))
- :where (cond->> [:= :analysis_finding.result false]
- (and (= entity-type :card)
- (seq card-types))
- (conj [:and [:in :entity.type (mapv name card-types)]])
-
- (and query (not= entity-type :sandbox))
- (conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]])
-
- archived-filter
- (conj [:and archived-filter])
-
- personal-filter
- (conj [:and personal-filter]))}))
-
-(api.macros/defendpoint :get "/graph/broken" :- [:sequential ::entity]
+ downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))
+ total (-> (t2/query {:select [[:%count.* :total]]
+ :from [[union-query :subquery]]})
+ first
+ :total)]
+ {:data (expanded-nodes downstream-graph all-ids {:include-errors? false})
+ :limit limit
+ :offset offset
+ :total total}))
+
+(api.macros/defendpoint :get "/graph/broken" :- dependency-items-response
"Returns a list of all items with broken queries.
Accepts optional parameters for filtering:
@@ -756,27 +734,50 @@
- `query`: Search string to filter by name or location
- `archived`: Controls whether archived entities are included
- `include_personal_collections`: Controls whether items in personal collections are included (default: false)
-
- Returns a list of broken items, each with `:id`, `:type`, `:data`, and `:error`s fields."
+ - `offset`: Default 0
+ - `limit`: Default 50
+
+ Returns a map with:
+ - `data`: List of broken items, each with `:id`, `:type`, `:data`, and `:error`s fields
+ - `total`: Total count of matched items
+ - `offset`: Applied offset
+ - `limit`: Applied limit"
[_route-params
{:keys [types card_types query archived include_personal_collections]
:or {types (vec deps.dependency-types/dependency-types)
card_types (vec lib.schema.metadata/card-types)
- include_personal_collections false}} :- broken-items-args]
- (let [include-archived-items (if archived :all :exclude)
+ include_personal_collections false}} :- dependency-items-args]
+ (let [offset (or (request/offset) 0)
+ limit (or (request/limit) 50)
+ include-archived-items (if archived :all :exclude)
graph-opts {:include-archived-items include-archived-items}
selected-types (cond->> (if (sequential? types) types [types])
;; Sandboxes don't support query filtering, so exclude them when a query is provided
query (remove #{:sandbox}))
card-types (if (sequential? card_types) card_types [card_types])
- union-queries (map #(broken-query % card-types query include-archived-items include_personal_collections)
+ union-queries (map #(dependency-items-query {:query-type :broken
+ :entity-type %
+ :card-types card-types
+ :query query
+ :include-archived-items include-archived-items
+ :include-personal-collections include_personal_collections})
selected-types)
union-query {:union-all union-queries}
- all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))
+ all-ids (->> (t2/query (assoc union-query
+ :order-by [[:sort_key :asc]]
+ :offset offset
+ :limit limit))
(map (fn [{:keys [entity_id entity_type]}]
[(keyword entity_type) entity_id])))
- downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))]
- (expanded-nodes downstream-graph all-ids {:include-errors? true})))
+ downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))
+ total (-> (t2/query {:select [[:%count.* :total]]
+ :from [[union-query :subquery]]})
+ first
+ :total)]
+ {:data (expanded-nodes downstream-graph all-ids {:include-errors? true})
+ :offset offset
+ :limit limit
+ :total total}))
(def ^{:arglists '([request respond raise])} routes
"`/api/ee/dependencies` routes."
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index b663d4c084f..d801d438161 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -6,6 +6,7 @@
[metabase-enterprise.dependencies.findings :as dependencies.findings]
[metabase-enterprise.dependencies.task.backfill :as dependencies.backfill]
[metabase.collections.models.collection :as collection]
+ [metabase.core.core :as mbc]
[metabase.events.core :as events]
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
@@ -1033,9 +1034,9 @@
(lib/query mp))}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=unreftest")]
- (is (=? [{:id unreffed-card-id
- :type "card"
- :data {:name "Unreferenced Card - unreftest"}}]
+ (is (=? {:data [{:id unreffed-card-id
+ :type "card"
+ :data {:name "Unreferenced Card - unreftest"}}]}
response))))))))
(deftest ^:sequential unreferenced-tables-test
@@ -1049,9 +1050,9 @@
:dataset_query (lib/query mp (lib.metadata/table mp referenced-table-id))}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=unreftest")]
- (is (=? [{:id unreffed-table-id
- :type "table"
- :data {:name "Unreferenced Table - unreftest"}}]
+ (is (=? {:data [{:id unreffed-table-id
+ :type "table"
+ :data {:name "Unreferenced Table - unreftest"}}]}
response))))))))
(deftest ^:sequential unreferenced-transforms-test
@@ -1079,9 +1080,9 @@
:transform-id referenced-transform-id}})
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=transform&query=unreftest")]
- (is (=? [{:id unreffed-transform-id
- :type "transform"
- :data {:name "Unreferenced Transform - unreftest"}}]
+ (is (=? {:data [{:id unreffed-transform-id
+ :type "transform"
+ :data {:name "Unreferenced Transform - unreftest"}}]}
response))))))))
(deftest ^:sequential unreferenced-snippets-test
@@ -1104,9 +1105,9 @@
:dataset_query native-query}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=snippet&query=unreftest")]
- (is (=? [{:id unreffed-snippet-id
- :type "snippet"
- :data {:name "Unreferenced Snippet - unreftest"}}]
+ (is (=? {:data [{:id unreffed-snippet-id
+ :type "snippet"
+ :data {:name "Unreferenced Snippet - unreftest"}}]}
response))))))))))
(deftest ^:sequential unreferenced-dashboards-test
@@ -1124,9 +1125,9 @@
:content_type "application/json+vnd.prose-mirror"}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=unreftest")]
- (is (=? [{:id unreffed-dashboard-id
- :type "dashboard"
- :data {:name "Unreferenced Dashboard - unreftest"}}]
+ (is (=? {:data [{:id unreffed-dashboard-id
+ :type "dashboard"
+ :data {:name "Unreferenced Dashboard - unreftest"}}]}
response)))))))
(deftest ^:sequential unreferenced-documents-test
@@ -1142,9 +1143,9 @@
:content_type "application/json+vnd.prose-mirror"}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=document&query=unreftest")]
- (is (=? [{:id unreffed-document-id
- :type "document"
- :data {:name "Unreferenced Document - unreftest"}}]
+ (is (=? {:data [{:id unreffed-document-id
+ :type "document"
+ :data {:name "Unreferenced Document - unreftest"}}]}
response)))))))
(deftest ^:sequential unreferenced-sandboxes-test
@@ -1161,9 +1162,9 @@
:card_id sandbox-card-id}]
(while (#'dependencies.backfill/backfill-dependencies!))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=sandbox")]
- (is (=? [{:id sandbox-id
- :type "sandbox"
- :data {:table {:name "PRODUCTS"}}}]
+ (is (=? {:data [{:id sandbox-id
+ :type "sandbox"
+ :data {:table {:name "PRODUCTS"}}}]}
response))))))))
(deftest ^:sequential unreferenced-card-types-test
@@ -1180,28 +1181,28 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "filtering by model only"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=model&query=cardtype")]
- (is (=? [{:id unreffed-model-id
- :type "card"
- :data {:name "A - Unreferenced Model - cardtype"
- :type "model"}}]
+ (is (=? {:data [{:id unreffed-model-id
+ :type "card"
+ :data {:name "A - Unreferenced Model - cardtype"
+ :type "model"}}]}
response))))
(testing "filtering by metric only"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=metric&query=cardtype")]
- (is (=? [{:id unreffed-metric-id
- :type "card"
- :data {:name "B - Unreferenced Metric - cardtype"
- :type "metric"}}]
+ (is (=? {:data [{:id unreffed-metric-id
+ :type "card"
+ :data {:name "B - Unreferenced Metric - cardtype"
+ :type "metric"}}]}
response))))
(testing "filtering by model and metric as the default card types"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&query=cardtype")]
- (is (=? [{:id unreffed-model-id
- :type "card"
- :data {:name "A - Unreferenced Model - cardtype"
- :type "model"}}
- {:id unreffed-metric-id
- :type "card"
- :data {:name "B - Unreferenced Metric - cardtype"
- :type "metric"}}]
+ (is (=? {:data [{:id unreffed-model-id
+ :type "card"
+ :data {:name "A - Unreferenced Model - cardtype"
+ :type "model"}}
+ {:id unreffed-metric-id
+ :type "card"
+ :data {:name "B - Unreferenced Metric - cardtype"
+ :type "metric"}}]}
response)))))))))
(deftest ^:sequential unreferenced-archived-card-test
@@ -1219,12 +1220,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived card"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=archivedtest")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids unreffed-card-id))
(is (not (contains? card-ids archived-card-id)))))
(testing "archived=true includes archived card"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=archivedtest&archived=true")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids unreffed-card-id))
(is (contains? card-ids archived-card-id)))))))))
@@ -1237,12 +1238,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived dashboard"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=archivedtest")
- dashboard-ids (set (map :id response))]
+ dashboard-ids (set (map :id (:data response)))]
(is (contains? dashboard-ids unreffed-dashboard-id))
(is (not (contains? dashboard-ids archived-dashboard-id)))))
(testing "archived=true includes archived dashboard"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=archivedtest&archived=true")
- dashboard-ids (set (map :id response))]
+ dashboard-ids (set (map :id (:data response)))]
(is (contains? dashboard-ids unreffed-dashboard-id))
(is (contains? dashboard-ids archived-dashboard-id))))))))
@@ -1255,12 +1256,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived document"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=document&query=archivedtest")
- document-ids (set (map :id response))]
+ document-ids (set (map :id (:data response)))]
(is (contains? document-ids unreffed-document-id))
(is (not (contains? document-ids archived-document-id)))))
(testing "archived=true includes archived document"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=document&query=archivedtest&archived=true")
- document-ids (set (map :id response))]
+ document-ids (set (map :id (:data response)))]
(is (contains? document-ids unreffed-document-id))
(is (contains? document-ids archived-document-id))))))))
@@ -1275,12 +1276,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived snippet"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=snippet&query=archivedtest")
- snippet-ids (set (map :id response))]
+ snippet-ids (set (map :id (:data response)))]
(is (contains? snippet-ids unreffed-snippet-id))
(is (not (contains? snippet-ids archived-snippet-id)))))
(testing "archived=true includes archived snippet"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=snippet&query=archivedtest&archived=true")
- snippet-ids (set (map :id response))]
+ snippet-ids (set (map :id (:data response)))]
(is (contains? snippet-ids unreffed-snippet-id))
(is (contains? snippet-ids archived-snippet-id))))))))
@@ -1301,12 +1302,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived segment"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=segment&query=archivedtest")
- segment-ids (set (map :id response))]
+ segment-ids (set (map :id (:data response)))]
(is (contains? segment-ids unreffed-segment-id))
(is (not (contains? segment-ids archived-segment-id)))))
(testing "archived=true includes archived segment"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=segment&query=archivedtest&archived=true")
- segment-ids (set (map :id response))]
+ segment-ids (set (map :id (:data response)))]
(is (contains? segment-ids unreffed-segment-id))
(is (contains? segment-ids archived-segment-id)))))))))
@@ -1326,17 +1327,53 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes inactive and hidden tables"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=archivedtest")
- table-ids (set (map :id response))]
+ table-ids (set (map :id (:data response)))]
(is (contains? table-ids active-table-id))
(is (not (contains? table-ids inactive-table-id)))
(is (not (contains? table-ids hidden-table-id)))))
(testing "archived=true includes inactive and hidden tables"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=archivedtest&archived=true")
- table-ids (set (map :id response))]
+ table-ids (set (map :id (:data response)))]
(is (contains? table-ids active-table-id))
(is (contains? table-ids inactive-table-id))
(is (contains? table-ids hidden-table-id))))))))
+(deftest ^:sequential unreferenced-pagination-test
+ (testing "GET /api/ee/dependencies/unreferenced - should paginate results"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/Table {table1-id :id} {:name "Table 1 - unreftest"}
+ :model/Table {table2-id :id} {:name "Table 2 - unreftest"}
+ :model/Table {table3-id :id} {:name "Table 3 - unreftest"}]
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (is (=? {:data [{:id table1-id} {:id table2-id}]
+ :total 3
+ :offset 0
+ :limit 2}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=unreftest&offset=0&limit=2")))
+ (is (=? {:data [{:id table3-id}]
+ :total 3
+ :offset 2
+ :limit 2}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=unreftest&offset=2&limit=2")))))))
+
+(deftest ^:sequential unreferenced-sample-db-test
+ (testing "GET /api/ee/dependencies/unreferenced - should not return tables from the sample database"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/Database {db-id :id} {:is_sample true}
+ :model/Table _ {:db_id db-id :name "Sample DB table - unreftest"}]
+ (is (=? {:data []
+ :total 0}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=unreftest")))))))
+
+(deftest ^:sequential unreferenced-audit-db-test
+ (testing "GET /api/ee/dependencies/unreferenced - should not return tables from the audit database"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-empty-h2-app-db!
+ (mbc/ensure-audit-db-installed!)
+ (is (=? {:data []
+ :total 0}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=notification")))))))
+
(deftest ^:sequential broken-questions-test
(testing "GET /api/ee/dependencies/broken - only broken questions are returned"
(mt/with-premium-features #{:dependencies}
@@ -1350,9 +1387,9 @@
:dataset_query (lib/native-query mp "not a query")}]
(while (> (dependencies.findings/analyze-batch! :card 50) 0))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest")]
- (is (=? [{:id broken-card-id
- :type "card"
- :data {:name "Broken Card - brokentest"}}]
+ (is (=? {:data [{:id broken-card-id
+ :type "card"
+ :data {:name "Broken Card - brokentest"}}]}
response))))))))
(deftest ^:sequential broken-transforms-test
@@ -1372,9 +1409,9 @@
:name "referenced_transform_table"}}]
(while (> (dependencies.findings/analyze-batch! :transform 50) 0))
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=transform&query=brokentest")]
- (is (=? [{:id broken-transform-id
- :type "transform"
- :data {:name "Broken Transform - brokentest"}}]
+ (is (=? {:data [{:id broken-transform-id
+ :type "transform"
+ :data {:name "Broken Transform - brokentest"}}]}
response))))))))
(deftest ^:sequential broken-card-types-test
@@ -1390,28 +1427,28 @@
(while (> (dependencies.findings/analyze-batch! :card 50) 0))
(testing "filtering by model only"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=model&query=cardtype")]
- (is (=? [{:id broken-model-id
- :type "card"
- :data {:name "A - Broken Model - cardtype"
- :type "model"}}]
+ (is (=? {:data [{:id broken-model-id
+ :type "card"
+ :data {:name "A - Broken Model - cardtype"
+ :type "model"}}]}
response))))
(testing "filtering by metric only"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=metric&query=cardtype")]
- (is (=? [{:id broken-metric-id
- :type "card"
- :data {:name "B - Broken Metric - cardtype"
- :type "metric"}}]
+ (is (=? {:data [{:id broken-metric-id
+ :type "card"
+ :data {:name "B - Broken Metric - cardtype"
+ :type "metric"}}]}
response))))
(testing "filtering by model and metric as the default card types"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=cardtype")]
- (is (=? [{:id broken-model-id
- :type "card"
- :data {:name "A - Broken Model - cardtype"
- :type "model"}}
- {:id broken-metric-id
- :type "card"
- :data {:name "B - Broken Metric - cardtype"
- :type "metric"}}]
+ (is (=? {:data [{:id broken-model-id
+ :type "card"
+ :data {:name "A - Broken Model - cardtype"
+ :type "model"}}
+ {:id broken-metric-id
+ :type "card"
+ :data {:name "B - Broken Metric - cardtype"
+ :type "metric"}}]}
response)))))))))
(deftest ^:sequential broken-archived-card-test
@@ -1428,12 +1465,12 @@
(while (> (dependencies.findings/analyze-batch! :card 50) 0))
(testing "archived=false (default) excludes archived broken card"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=archivedbrokentestcard")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids broken-card-id))
(is (not (contains? card-ids archived-broken-card-id)))))
(testing "archived=true includes archived broken card"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=archivedbrokentestcard&archived=true")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids broken-card-id))
(is (contains? card-ids archived-broken-card-id)))))))))
@@ -1451,12 +1488,12 @@
(while (> (dependencies.findings/analyze-batch! :segment 50) 0))
(testing "archived=false (default) excludes archived broken segment"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=segment&query=archivedbrokentest")
- segment-ids (set (map :id response))]
+ segment-ids (set (map :id (:data response)))]
(is (contains? segment-ids broken-segment-id))
(is (not (contains? segment-ids archived-broken-segment-id)))))
(testing "archived=true includes archived broken segment"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=segment&query=archivedbrokentest&archived=true")
- segment-ids (set (map :id response))]
+ segment-ids (set (map :id (:data response)))]
(is (contains? segment-ids broken-segment-id))
(is (contains? segment-ids archived-broken-segment-id))))))))
@@ -1481,12 +1518,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "archived=false (default) excludes archived measure"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=measure&query=archivedtest")
- measure-ids (set (map :id response))]
+ measure-ids (set (map :id (:data response)))]
(is (contains? measure-ids unreffed-measure-id))
(is (not (contains? measure-ids archived-measure-id)))))
(testing "archived=true includes archived measure"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=measure&query=archivedtest&archived=true")
- measure-ids (set (map :id response))]
+ measure-ids (set (map :id (:data response)))]
(is (contains? measure-ids unreffed-measure-id))
(is (contains? measure-ids archived-measure-id)))))))))
@@ -1515,13 +1552,13 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "include_personal_collections=false (default) excludes cards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=personalcolltest")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (not (contains? card-ids card-in-personal)))
(is (not (contains? card-ids card-in-sub-personal)))
(is (contains? card-ids card-regular))))
(testing "include_personal_collections=true includes cards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=personalcolltest&include_personal_collections=true")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids card-in-personal))
(is (contains? card-ids card-in-sub-personal))
(is (contains? card-ids card-regular))))))))))
@@ -1539,12 +1576,12 @@
(while (#'dependencies.backfill/backfill-dependencies!))
(testing "include_personal_collections=false (default) excludes dashboards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=personalcolltest")
- dashboard-ids (set (map :id response))]
+ dashboard-ids (set (map :id (:data response)))]
(is (not (contains? dashboard-ids dash-in-personal)))
(is (contains? dashboard-ids dash-regular))))
(testing "include_personal_collections=true includes dashboards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=personalcolltest&include_personal_collections=true")
- dashboard-ids (set (map :id response))]
+ dashboard-ids (set (map :id (:data response)))]
(is (contains? dashboard-ids dash-in-personal))
(is (contains? dashboard-ids dash-regular)))))))))
@@ -1566,11 +1603,33 @@
(while (> (dependencies.findings/analyze-batch! :card 50) 0))
(testing "include_personal_collections=false (default) excludes broken cards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (not (contains? card-ids broken-in-personal)))
(is (contains? card-ids broken-regular))))
(testing "include_personal_collections=true includes broken cards in personal collections"
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest&include_personal_collections=true")
- card-ids (set (map :id response))]
+ card-ids (set (map :id (:data response)))]
(is (contains? card-ids broken-in-personal))
(is (contains? card-ids broken-regular))))))))))
+
+(deftest ^:sequential broken-pagination-test
+ (testing "GET /api/ee/dependencies/broken - should paginate results"
+ (mt/with-premium-features #{:dependencies}
+ (let [mp (mt/metadata-provider)]
+ (mt/with-temp [:model/Card {card1-id :id} {:name "Card 1 - brokentest"
+ :type :question
+ :dataset_query (lib/native-query mp "not a query")}
+ :model/Card {card2-id :id} {:name "Card 2 - brokentest"
+ :type :question
+ :dataset_query (lib/native-query mp "not a query")}]
+ (while (> (dependencies.findings/analyze-batch! :card 50) 0))
+ (is (=? {:data [{:id card1-id}]
+ :total 2
+ :offset 0
+ :limit 1}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest&offset=0&limit=1")))
+ (is (=? {:data [{:id card2-id}]
+ :total 2
+ :offset 1
+ :limit 1}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest&offset=1&limit=1"))))))))
diff --git a/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts b/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts
index e3d5d0e8a3c..fb2e4fb0a67 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts
@@ -7,8 +7,10 @@ import type {
DependencyNode,
GetDependencyGraphRequest,
ListBrokenGraphNodesRequest,
+ ListBrokenGraphNodesResponse,
ListNodeDependentsRequest,
ListUnreferencedGraphNodesRequest,
+ ListUnreferencedGraphNodesResponse,
} from "metabase-types/api";
import { EnterpriseApi } from "./api";
@@ -43,7 +45,7 @@ export const dependencyApi = EnterpriseApi.injectEndpoints({
nodes ? provideDependencyNodeListTags(nodes) : [],
}),
listBrokenGraphNodes: builder.query<
- DependencyNode[],
+ ListBrokenGraphNodesResponse,
ListBrokenGraphNodesRequest
>({
query: (params) => ({
@@ -51,11 +53,11 @@ export const dependencyApi = EnterpriseApi.injectEndpoints({
url: "/api/ee/dependencies/graph/broken",
params,
}),
- providesTags: (nodes) =>
- nodes ? provideDependencyNodeListTags(nodes) : [],
+ providesTags: (response) =>
+ response ? provideDependencyNodeListTags(response.data) : [],
}),
listUnreferencedGraphNodes: builder.query<
- DependencyNode[],
+ ListUnreferencedGraphNodesResponse,
ListUnreferencedGraphNodesRequest
>({
query: (params) => ({
@@ -63,8 +65,8 @@ export const dependencyApi = EnterpriseApi.injectEndpoints({
url: "/api/ee/dependencies/graph/unreferenced",
params,
}),
- providesTags: (nodes) =>
- nodes ? provideDependencyNodeListTags(nodes) : [],
+ providesTags: (response) =>
+ response ? provideDependencyNodeListTags(response.data) : [],
}),
checkCardDependencies: builder.query<
CheckDependenciesResponse,
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
index 3206d79573d..a9cc46cac7c 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
@@ -14,8 +14,10 @@ import { getCardTypes, getDependencyTypes, isSameNode } from "../../utils";
import S from "./DependencyList.module.css";
import { ListBody } from "./ListBody";
import { ListHeader } from "./ListHeader";
+import { ListPaginationControls } from "./ListPaginationControls";
import { ListSearchBar } from "./ListSearchBar";
import { ListSidebar } from "./ListSidebar";
+import { PAGE_SIZE } from "./constants";
import type { DependencyListMode } from "./types";
import { getAvailableGroupTypes } from "./utils";
@@ -38,18 +40,18 @@ export function DependencyList({
: useListUnreferencedGraphNodesQuery;
const availableGroupTypes = getAvailableGroupTypes(mode);
- const {
- data: nodes = [],
- isFetching,
- isLoading,
- error,
- } = useListGraphNodesQuery({
+ const { data, isFetching, isLoading, error } = useListGraphNodesQuery({
query: params.query,
types: getDependencyTypes(params.groupTypes ?? availableGroupTypes),
card_types: getCardTypes(params.groupTypes ?? availableGroupTypes),
- include_personal_collections: params.includePersonalCollections,
+ include_personal_collections: params.includePersonalCollections ?? true,
+ offset: (params.page ?? 0) * PAGE_SIZE,
+ limit: PAGE_SIZE,
});
+ const nodes = data?.data ?? [];
+ const totalNodesCount = data?.total ?? 0;
+
const selectedNode =
selectedEntry != null
? nodes.find((node) => isSameNode(node, selectedEntry))
@@ -77,6 +79,14 @@ export function DependencyList({
onSelect={setSelectedEntry}
/>
)}
+ {!isLoading && error == null && (
+ <ListPaginationControls
+ params={params}
+ pageNodesCount={nodes.length}
+ totalNodesCount={totalNodesCount}
+ onParamsChange={onParamsChange}
+ />
+ )}
</Stack>
{selectedNode != null && (
<ListSidebar
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
index 01582c3d0ce..86b860f2e52 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
@@ -19,6 +19,7 @@ function getNodeNameColumn(): TreeTableColumnDef<DependencyNode> {
id: "name",
header: t`Name`,
minWidth: 100,
+ enableSorting: false,
accessorFn: (node) => getNodeLabel(node),
cell: ({ row }) => {
const node = row.original;
@@ -32,6 +33,7 @@ function getNodeLocationColumn(): TreeTableColumnDef<DependencyNode> {
id: "location",
header: t`Location`,
minWidth: 100,
+ enableSorting: false,
accessorFn: (node) => {
const location = getNodeLocationInfo(node);
const links = location?.links ?? [];
@@ -49,6 +51,7 @@ function getNodeErrorsColumn(): TreeTableColumnDef<DependencyNode> {
id: "error",
header: t`Errors`,
minWidth: 100,
+ enableSorting: false,
accessorFn: (node) => node.errors?.length ?? 0,
cell: ({ row }) => {
const node = row.original;
@@ -66,6 +69,7 @@ function getNodeDependentsCountColumn(): TreeTableColumnDef<DependencyNode> {
id: "dependents-count",
header: t`Downstream dependents`,
minWidth: 100,
+ enableSorting: false,
accessorFn: (node) => getNodeDependentsCount(node),
cell: ({ row }) => {
const node = row.original;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/ListPaginationControls.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/ListPaginationControls.tsx
new file mode 100644
index 00000000000..e77b60831c9
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/ListPaginationControls.tsx
@@ -0,0 +1,35 @@
+import { PaginationControls } from "metabase/common/components/PaginationControls";
+import type * as Urls from "metabase/lib/urls";
+import { Flex } from "metabase/ui";
+
+import { PAGE_SIZE } from "../constants";
+
+type ListPaginationControlsProps = {
+ params: Urls.DependencyListParams;
+ pageNodesCount: number;
+ totalNodesCount: number;
+ onParamsChange: (params: Urls.DependencyListParams) => void;
+};
+
+export function ListPaginationControls({
+ params,
+ pageNodesCount,
+ totalNodesCount,
+ onParamsChange,
+}: ListPaginationControlsProps) {
+ const { page = 0 } = params;
+
+ return (
+ <Flex justify="end">
+ <PaginationControls
+ page={page}
+ pageSize={PAGE_SIZE}
+ itemsLength={pageNodesCount}
+ total={totalNodesCount}
+ showTotal
+ onPreviousPage={() => onParamsChange({ ...params, page: page - 1 })}
+ onNextPage={() => onParamsChange({ ...params, page: page + 1 })}
+ />
+ </Flex>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/index.ts
new file mode 100644
index 00000000000..fcf3b29abb2
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListPaginationControls/index.ts
@@ -0,0 +1 @@
+export * from "./ListPaginationControls";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx
index 6971cb09311..410e6de62ca 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx
@@ -13,13 +13,15 @@ export function LocationFilterPicker({
params,
onParamsChange,
}: LocationFilterPickerProps) {
+ const { includePersonalCollections = true } = params;
+
const handleIncludeInPersonalCollectionsChange = (
event: ChangeEvent<HTMLInputElement>,
) => {
const newValue = event.target.checked;
onParamsChange({
...params,
- includePersonalCollections: newValue || undefined,
+ includePersonalCollections: newValue,
});
};
@@ -28,6 +30,7 @@ export function LocationFilterPicker({
<Stack gap="sm" mt="sm">
<Checkbox
label={t`Include items in personal collections`}
+ checked={includePersonalCollections}
onChange={handleIncludeInPersonalCollectionsChange}
/>
</Stack>
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
index b78be9b1d7c..3249a561b0d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
@@ -2,7 +2,7 @@ import { Fragment } from "react";
import { Link } from "react-router";
import { t } from "ttag";
-import { Anchor, Box, Card, Group, Icon, Stack, Title } from "metabase/ui";
+import { Anchor, Card, Group, Icon, Stack, Title } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
import { getNodeLocationInfo } from "../../../../utils";
@@ -25,7 +25,7 @@ export function SidebarLocationInfo({ node }: SidebarLocationInfoProps) {
<Card p="md" shadow="none" withBorder>
{locationInfo.links.map((link, linkIndex) => (
<Fragment key={linkIndex}>
- {linkIndex > 0 && <Box>/</Box>}
+ {linkIndex > 0 && <span>/</span>}
<Anchor component={Link} to={link.url} target="_blank">
<Group gap="sm" wrap="nowrap">
{linkIndex === 0 && <Icon name={locationInfo.icon} />}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/constants.ts
new file mode 100644
index 00000000000..45d559e788d
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/constants.ts
@@ -0,0 +1 @@
+export const PAGE_SIZE = 25;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
index 35e13c0475b..a412b96055a 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
@@ -12,9 +12,12 @@ const BROKEN_GROUP_TYPES: DependencyGroupType[] = [
];
const UNREFERENCED_GROUP_TYPES: DependencyGroupType[] = [
+ "table",
+ "question",
"model",
"metric",
"segment",
+ "measure",
"snippet",
];
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts
index 4f190b6519b..701bad52de1 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts
@@ -1,7 +1,6 @@
export type DependencyListQueryParams = {
- query?: unknown;
- groupTypes?: unknown;
- selectedId?: unknown;
- selectedType?: unknown;
- includePersonalCollections?: unknown;
+ page?: string;
+ query?: string;
+ groupTypes?: string | string[];
+ includePersonalCollections?: string;
};
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
index 3472cd6e060..4229234b92b 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
@@ -1,7 +1,13 @@
import type * as Urls from "metabase/lib/urls";
import { DEPENDENCY_GROUP_TYPES } from "metabase-types/api";
-import { parseBoolean, parseEnum, parseList, parseString } from "../../utils";
+import {
+ parseBoolean,
+ parseEnum,
+ parseList,
+ parseNumber,
+ parseString,
+} from "../../utils";
import type { DependencyListQueryParams } from "./types";
@@ -9,6 +15,7 @@ export function parseParams(
params: DependencyListQueryParams,
): Urls.DependencyListParams {
return {
+ page: parseNumber(params.page),
query: parseString(params.query),
groupTypes: parseList(params.groupTypes, (item) =>
parseEnum(item, DEPENDENCY_GROUP_TYPES),
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
index f8b627126f4..a6639721164 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
@@ -732,6 +732,13 @@ export function parseString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
+export function parseNumber(value: unknown): number | undefined {
+ if (typeof value === "string") {
+ const number = Number(value);
+ return Number.isFinite(number) ? number : undefined;
+ }
+}
+
export function parseBoolean(value: unknown): boolean | undefined {
switch (value) {
case "true":
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index 9f9bfee5c57..29a8e91fa1b 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -7,6 +7,7 @@ import type { Card, CardType } from "./card";
import type { Dashboard } from "./dashboard";
import type { Document } from "./document";
import type { Measure } from "./measure";
+import type { PaginationRequest, PaginationResponse } from "./pagination";
import type { Segment } from "./segment";
import type { NativeQuerySnippet } from "./snippets";
import type { Table, TableId } from "./table";
@@ -279,16 +280,24 @@ export type CheckSnippetDependenciesRequest = Pick<NativeQuerySnippet, "id"> &
export type CheckTransformDependenciesRequest = Pick<Transform, "id"> &
Partial<Pick<Transform, "source">>;
-export type ListBrokenGraphNodesRequest = {
+export type ListBrokenGraphNodesRequest = PaginationRequest & {
types?: DependencyType[];
card_types?: CardType[];
query?: string;
include_personal_collections?: boolean;
};
-export type ListUnreferencedGraphNodesRequest = {
+export type ListBrokenGraphNodesResponse = PaginationResponse & {
+ data: DependencyNode[];
+};
+
+export type ListUnreferencedGraphNodesRequest = PaginationRequest & {
types?: DependencyType[];
card_types?: CardType[];
query?: string;
include_personal_collections?: boolean;
};
+
+export type ListUnreferencedGraphNodesResponse = PaginationResponse & {
+ data: DependencyNode[];
+};
diff --git a/frontend/src/metabase/lib/urls/dependencies.ts b/frontend/src/metabase/lib/urls/dependencies.ts
index 4e4b785ad88..41cb8dcf3e7 100644
--- a/frontend/src/metabase/lib/urls/dependencies.ts
+++ b/frontend/src/metabase/lib/urls/dependencies.ts
@@ -27,17 +27,22 @@ export function dependencyTasks() {
}
export type DependencyListParams = {
+ page?: number;
query?: string;
groupTypes?: DependencyGroupType[];
includePersonalCollections?: boolean;
};
function dependencyListQueryString({
+ page,
query,
groupTypes,
includePersonalCollections,
}: DependencyListParams = {}) {
const searchParams = new URLSearchParams();
+ if (page != null) {
+ searchParams.set("page", String(page));
+ }
if (query != null) {
searchParams.set("query", query);
}
diff --git a/frontend/src/metabase/metadata/components/UserInput.tsx b/frontend/src/metabase/metadata/components/UserInput.tsx
index ff54b401680..66f3b348453 100644
--- a/frontend/src/metabase/metadata/components/UserInput.tsx
+++ b/frontend/src/metabase/metadata/components/UserInput.tsx
@@ -81,8 +81,8 @@ export const UserInput = ({
<Icon name="mail" />
</Avatar>
) : userId === "unknown" ? (
- <Avatar color="bg-light" name="unknown">
- <Icon name="person" c="text-medium" />
+ <Avatar color="background-secondary" name="unknown">
+ <Icon name="person" c="text-secondary" />
</Avatar>
) : null
}
@@ -97,7 +97,7 @@ export const UserInput = ({
{option.type === "user" && <Avatar name={item.option.label} />}
{option.type === "unknown" && (
<Avatar>
- <Icon name="person" c="text-medium" />
+ <Icon name="person" c="text-secondary" />
</Avatar>
)}
{option.type === "email" && (