Skip to content

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

populate `here` and `below` for transforms (#68614)

John Swansonf8d4a239b370
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj
index c346cae39e7..a7c33051e5e 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj
@@ -1185,6 +1185,42 @@
(format "collection/%d/items" collection-id)))]
(is (empty? items))))))))
+(deftest transforms-appear-in-here-test
+ (testing "GET /api/collection/:id/items"
+ (testing "Transforms in a collection appear in its :here field"
+ (mt/with-premium-features #{:transforms}
+ (mt/with-temp [:model/Collection {parent-id :id} {:name "Parent"
+ :namespace :transforms}
+ :model/Collection {child-id :id} {:name "Child"
+ :location (format "/%d/" parent-id)
+ :namespace :transforms}
+ :model/Transform _ {:name "Test Transform"
+ :collection_id child-id}]
+ ;; Check child collection shows transform in :here
+ (let [child-coll (first (:data (mt/user-http-request :crowberto :get 200
+ (format "collection/%d/items" parent-id))))]
+ (is (= ["transform"] (:here child-coll)))))))))
+
+(deftest transforms-appear-in-below-test
+ (testing "GET /api/collection/:id/items"
+ (testing "Transforms in descendant collections appear in :below field"
+ (mt/with-premium-features #{:transforms}
+ (mt/with-temp [:model/Collection {parent-id :id} {:name "Parent"
+ :namespace :transforms}
+ :model/Collection {child-id :id} {:name "Child"
+ :location (format "/%d/" parent-id)
+ :namespace :transforms}
+ :model/Collection {grandchild-id :id} {:name "Grandchild"
+ :location (format "/%d/%d/" parent-id child-id)
+ :namespace :transforms}
+ :model/Transform _ {:name "Nested Transform"
+ :collection_id grandchild-id}]
+ ;; Check child collection shows transform in :below
+ (let [child-coll (first (:data (mt/user-http-request :crowberto :get 200
+ (format "collection/%d/items" parent-id))))]
+ (is (= ["collection"] (:here child-coll)))
+ (is (= ["transform"] (:below child-coll)))))))))
+
(deftest native-incremental-column-type-validated-on-create-test
(testing "POST /api/ee/transform column type validation"
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table ::extract-columns-from-query)
diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.clj
index 311c640720a..3641eac6ddc 100644
--- a/src/metabase/collections_rest/api.clj
+++ b/src/metabase/collections_rest/api.clj
@@ -824,6 +824,16 @@
(into #{}))
#{})
+ collections-containing-transforms
+ (if (premium-features/has-feature? :transforms)
+ (->> (when (seq descendant-collection-ids)
+ (t2/query {:select-distinct [:collection_id]
+ :from :transform
+ :where [:in :collection_id descendant-collection-ids]}))
+ (map :collection_id)
+ (into #{}))
+ #{})
+
collections-containing-dashboards
(->> (when (seq descendant-collection-ids)
(t2/query {:select-distinct [:collection_id]
@@ -846,7 +856,8 @@
(merge child-type->coll-id-set
{:table collections-containing-tables
:collection collections-containing-collections
- :dashboard collections-containing-dashboards})
+ :dashboard collections-containing-dashboards
+ :transform collections-containing-transforms})
;; why are we calling `annotate-collections` on all descendants, when we only need the collections in `colls`
;; to be annotated? Because `annotate-collections` works by looping through the collections it's passed and