The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add Data Apps to the Dependencies Graph (#85075)
Timofey Kachalove7b35c9ced56
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 04bc7b4cecf..8d327a7244f 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -2532,6 +2532,7 @@appearanceaudit-appcollections+ data-appseventshealth-inspectorlib@@ -2554,6 +2555,7 @@:model-imports #{:model/Card:model/Collection:model/Dashboard+ :model/DataApp:model/Database:model/Table:model/User}}@@ -3839,8 +3841,8 @@premium-featuresremote-syncrequest+ searchsettings- usersutilutil.graphwarehouse-schema-overlay@@ -3901,6 +3903,7 @@app-dbbatch-processingcollections+ data-appsdatabase-routingdocumentsdriver@@ -3936,6 +3939,7 @@:model/DashboardCard:model/DashboardCardSeries:model/DashboardTab+ :model/DataApp:model/Database:model/Dimension:model/Documentdiff --git a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj b/enterprise/backend/src/metabase_enterprise/data_apps/api.cljindex ab634b12e2a..0ca0c51ee4b 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/api.clj@@ -99,6 +99,7 @@(def ^:private PublicDataAppResponse[:map {:closed true}+ [:id ms/PositiveInt][:name ms/NonBlankString][:display_name ms/NonBlankString]])@@ -164,7 +165,7 @@[app](if api/*is-superuser?*(assoc app :outdated (data-app.config/outdated? app))- (select-keys app [:name :display_name])))+ (select-keys app [:id :name :display_name])))(defn- read-check-data-app"Check whether the current user can access a data app. Viewing requires read access to the app'sdiff --git a/enterprise/backend/src/metabase_enterprise/data_apps/core.clj b/enterprise/backend/src/metabase_enterprise/data_apps/core.cljindex 1d2f78b4a3b..df0d77f6712 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/core.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/core.clj@@ -1,5 +1,5 @@(ns metabase-enterprise.data-apps.core- "What other modules may ask the data-apps module: whether a user can open an app."+ "What other modules may ask the data-apps module: whether a user can open an app, and which apps a user may read."(:require[metabase-enterprise.data-apps.db :as data-apps.db][metabase.api.common :as api]@@ -12,3 +12,9 @@[request](let [app (api/check-404 (data-apps.db/data-app-by-slug (get-in request [:route-params :name])))](api/check-403 (mi/can-read? app))))++(defenterprise visible-data-app-filter-select+ "A HoneySQL query of the ids of the data apps that the user with `:user-id` and `:is-superuser?` can read."+ :feature :data-apps+ [{:keys [user-id is-superuser?]}]+ (data-apps.db/readable-data-app-ids-select user-id (boolean is-superuser?)))diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj b/enterprise/backend/src/metabase_enterprise/data_apps/db.cljindex b3dfadf02fd..6f857dbc464 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/db.clj@@ -136,6 +136,36 @@(t2/select :model/DataAppGroupAssignment :data_app_id [:in app-ids])[]))+(mu/defn readable-data-app-ids-select+ "A HoneySQL query of the ids of the DataApps that the User with `user-id` can read: every app for a superuser, else+ the enabled apps assigned to one of their groups, and none for a tenant user."+ [user-id :- [:maybe ms/PositiveInt]+ superuser? :- :boolean]+ (if superuser?+ ^:allow-subquery {:select [:id] :from [(t2/table-name :model/DataApp)]}+ ^:allow-subquery {:select [:assignment.data_app_id]+ :from [[(t2/table-name :model/DataAppGroupAssignment) :assignment]]+ :join [[(t2/table-name :model/DataApp) :app]+ [:= :app.id :assignment.data_app_id]+ [:permissions_group_membership :membership]+ [:= :membership.group_id :assignment.permission_group_id]+ [:core_user :member]+ [:= :member.id :membership.user_id]]+ ;; No `[:auto/param]` marker: this query also runs inside queries compiled outside Toucan, such+ ;; as the search index's, which reject it. Both compilers bind the integer id as a parameter.+ :where [:and+ [:= :app.enabled true]+ [:= :membership.user_id user-id]+ [:= :member.tenant_id nil]]}))++(mu/defn readable-data-app?+ "Whether the non-superuser User with `user-id` can read the DataApp with `app-id`."+ [user-id :- ms/PositiveInt+ app-id :- ms/PositiveInt]+ (t2/exists? :model/DataApp {:where [:and+ [:= :id [:auto/param app-id]]+ [:in :id (readable-data-app-ids-select user-id false)]]}))+(defn insert-assignments!"Assign groups to an app. The unique constraint rejects concurrent duplicates."[app-id group-ids]diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj b/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.cljindex 71a509bae6c..ec4a608662e 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj@@ -9,8 +9,8 @@[metabase.lib.core :as lib][metabase.models.interface :as mi][metabase.models.serialization :as serdes]- [metabase.premium-features.core :refer [defenterprise]]- [metabase.users.models.user :as user]+ [metabase.premium-features.core :as premium-features :refer [defenterprise]]+ [metabase.search.core :as search][metabase.util.i18n :refer [tru]][metabase.util.malli :as mu][methodical.core :as methodical]@@ -45,7 +45,8 @@(doto :model/DataApp(derive :metabase/model)(derive :hook/entity-id)- (derive :hook/timestamped?))+ (derive :hook/timestamped?)+ (derive :hook/dependencies))(t2.default-fields/define-default-fields :model/DataAppdata-apps.db/non-blob-columns)@@ -121,18 +122,12 @@(contains? app :allowed_hosts) (update :allowed_hosts #(or % []))))(defmethod mi/can-read? :model/DataApp- ([app]- (or api/*is-superuser?*- (boolean- (and (:enabled app)- api/*current-user-id*- (nil? (:tenant_id @api/*current-user*))- (let [group-ids (user/group-ids api/*current-user-id*)]- (some (comp group-ids :permission_group_id)- (data-apps.db/app-assignments [(:id app)])))))))+ ([app] (mi/can-read? :model/DataApp (:id app)))([_model pk]- (or api/*is-superuser?*- (boolean (some-> (data-apps.db/data-app pk) mi/can-read?)))))+ (and (premium-features/has-feature? :data-apps)+ (or api/*is-superuser?*+ (and (some? api/*current-user-id*)+ (data-apps.db/readable-data-app? api/*current-user-id* pk))))))(defmethod mi/can-write? :model/DataApp([_instance] api/*is-superuser?*)@@ -150,7 +145,18 @@;; it, and the collection's own hooks delete what it holds and the grants on it.(t2/define-before-delete :model/DataApp[app]- (data-app.resources/delete-resources! app))+ (data-app.resources/delete-resources! app)+ (search/delete! :model/DataApp [(str (:id app))]))++(search/define-spec "data-app"+ {:model :model/DataApp+ :attrs {:archived false+ :collection-id false+ :created-at true+ :updated-at true}+ :search-terms [:name :display_name :description]+ ;; A result's `name` can be its display name, and the app's URL needs its slug.+ :render-terms {:data-app-slug :name}})(methodical/defmethod mi/to-json :model/DataApp"Never include the raw bundle bytes in JSON."diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.cljindex e66aab0255d..89ccaad347b 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj@@ -52,7 +52,8 @@:sandbox [:table :table_id]:segment [:name :description :created_at :creator :creator_id :table :table_id]:measure [:name :description :created_at :creator :creator_id :table :table_id]- :action [:name :description :type :model_id :parameters :created_at :creator :creator_id :collection :collection_id]})+ :action [:name :description :type :model_id :parameters :created_at :creator :creator_id :collection :collection_id]+ :data-app [:name :display_name :description :created_at]})(mr/def ::data-value[:schema {::mr/deliberately-open true, :description "any column or hydrated value of a dependency-tracked entity"}@@ -69,7 +70,8 @@(mr/def ::usages[:map-of- [:enum :table :snippet :transform :dashboard :document :sandbox :segment :question :model :metric :measure :action]+ [:enum :table :snippet :transform :dashboard :document :sandbox :segment :question :model :metric :measure :action+ :data-app]::deps.dependency-types/entity-id])(mr/def ::normalized-finding-error@@ -184,6 +186,13 @@[:type [:= :action]][:data (fields-for :action)]]])+(mr/def ::data-app-entity+ [:merge ::base-entity+ [:map+ [:id ms/PositiveInt]+ [:type [:= :data-app]]+ [:data (fields-for :data-app)]]])+(mr/def ::entity[:multi {:dispatch :type}[:table [:ref ::table-entity]]@@ -195,7 +204,8 @@[:sandbox [:ref ::sandbox-entity]][:segment [:ref ::segment-entity]][:measure [:ref ::measure-entity]]- [:action [:ref ::action-entity]]])+ [:action [:ref ::action-entity]]+ [:data-app [:ref ::data-app-entity]]])(mr/def ::entity-data"The `:data` of an `::entity` as the helpers that filter and sort entities read it: the keys of `entity-keys`, each@@ -229,7 +239,8 @@:metabase-enterprise.sandbox.schema/sandbox:metabase.segments.schema/segment:metabase.measures.schema/measure- ::actions.schema/action])+ ::actions.schema/action+ :metabase-enterprise.data-apps.schema/data-app])(mu/defn- entity-value :- ::entity[entity-type :- ::deps.dependency-types/dependency-types@@ -270,7 +281,8 @@:sandbox [:id :table_id]:segment [:id :name :description :created_at :creator_id :table_id]:measure [:id :name :description :created_at :creator_id :table_id]- :action [:id :name :description :type :model_id :parameters :created_at :creator_id :collection_id]})+ :action [:id :name :description :type :model_id :parameters :created_at :creator_id :collection_id]+ :data-app [:id :name :display_name :description :created_at]})(mr/def ::include-archived-items[:enum :exclude :all :only])@@ -406,7 +418,10 @@(map #(collection.root/hydrate-root-collection%(collection.root/root-collection-with-ui-details- (dependencies.db/action-root-namespace (nil? (:model_id %)))))))))+ (dependencies.db/action-root-namespace (nil? (:model_id %)))))))+ ;; Like the data-app API, which gives a non-admin only an app's names.+ :data-app (cond->> entities+ (not api/*is-superuser?*) (map #(select-keys % [:id :name :display_name])))))(mu/defn- fetch-and-hydrate-nodes :- [:map-of ::deps.schema/node Entity]"Fetches and hydrates entities for the given nodes.@@ -459,7 +474,7 @@{:keys [id type]} :- [:map {:closed true}[:id {:optional true} ms/PositiveInt][:type {:optional true} ::deps.dependency-types/dependency-types]]]- (api/read-check (deps.dependency-types/dependency-type->model type) id)+ (api/read-check (dependencies.db/entity type id))(let [starting-nodes [[type id]]upstream-graph (readable-graph-dependencies {:include-archived-items :all})downstream-graph (graph/cached-graph (readable-graph-dependents))@@ -483,8 +498,8 @@[entity :- ::entity-node](let [data (:data entity)](case (:type entity)- :table (:display_name data)- :sandbox nil+ (:table :data-app) (:display_name data)+ :sandbox nil(:name data))))(mu/defn- entity-location :- [:maybe :string]@@ -575,7 +590,7 @@:or {include-personal-collections falsesort-column :namesort-direction :asc}} :- dependents-args]- (api/read-check (deps.dependency-types/dependency-type->model type) id)+ (api/read-check (dependencies.db/entity type id))(let [downstream-graph (graph/cached-graph (readable-graph-dependents {:broken broken}))nodes (vec (-> (graph/children-of downstream-graph [[type id]])(get [type id])))@@ -835,7 +850,7 @@:or {include-personal-collections falsesort-column :namesort-direction :asc}} :- broken-dependents-args]- (api/read-check (deps.dependency-types/dependency-type->model entity-type) id)+ (api/read-check (dependencies.db/entity entity-type id))(let [normalize-types (fn normalize-types [types](if (keyword? types)[(name types)]diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.cljindex ce1e9ab49cd..7d22eca30ec 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj@@ -12,6 +12,7 @@[metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.schema :as lib.schema]+ [metabase.lib.schema.id :as lib.schema.id][metabase.measures.schema][metabase.native-query-snippets.schema][metabase.queries.schema :as queries.schema]@@ -25,7 +26,8 @@(def ^:private Entity"Any dependency-tracked entity `calculate-deps` accepts. A `:dashboard` entity arrives hydrated with `:dashcards`,each of those in turn hydrated with `:series`; a query `:action` arrives with the `:dataset_query` of its- QueryAction; every other entity is a plain row of its model."+ QueryAction; a `:data-app` arrives with the `:card_ids` and `:action_ids` of its resource collection; every other+ entity is a plain row of its model."[:or::queries.schema/card:metabase.warehouse-schema.schema/table@@ -36,7 +38,12 @@:metabase-enterprise.sandbox.schema/sandbox:metabase.segments.schema/segment:metabase.measures.schema/measure- ::actions.schema/action])+ ::actions.schema/action+ [:merge+ :metabase-enterprise.data-apps.schema/data-app+ [:map+ [:card_ids [:set ::lib.schema.id/card]]+ [:action_ids [:set ::lib.schema.id/action]]]]])(defmulti calculate-deps*"Implementation multimethod for [[calculate-deps]]. Dispatches on entity-type keyword.@@ -208,3 +215,8 @@(case action-type:implicit {:card #{model-id}}:query (upstream-deps:query (lib-be/normalize-query query))))++(defmethod calculate-deps* :data-app+ [_ {card-ids :card_ids, action-ids :action_ids}]+ {:card card-ids+ :action action-ids})diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj b/enterprise/backend/src/metabase_enterprise/dependencies/db.cljindex 65df475f10b..82fb568ddf7 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/db.clj@@ -9,6 +9,7 @@[metabase.app-db.core :as mdb][metabase.collections.models.collection :as collection][metabase.collections.models.collection.root :as collection.root]+ [metabase.data-apps.core :as data-apps][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata][metabase.models.interface :as mi]@@ -51,7 +52,8 @@sandboxed users.- Table: filters by table visibility permissions. Tables are NOT filtered by active/visibility_type regardlessof `include-archived-items`, so dependencies broken by dropped or hidden tables stay visible.- - Transform: analysts can view any transform they have source view permission to."+ - Transform: analysts can view any transform they have source view permission to.+ - Data app: the apps the user can read, none without the data apps feature."[entity-type-field :- Columnentity-id-field :- Column{:keys [user-id is-superuser? is-data-analyst? include-archived-items]@@ -157,7 +159,14 @@(case include-archived-items:exclude [:= archived-column false]:only [:= archived-column true]- :all nil)]}]])))))+ :all nil)]}]])++ :model/DataApp+ (when-let [visible-ids (data-apps/visible-data-app-filter-select {:user-id user-id+ :is-superuser? is-superuser?})]+ [:and+ [:= entity-type-field (name entity-type)]+ [:in entity-id-field visible-ids]])))))deps.dependency-types/dependency-type->model))(mu/defn- broken-entities-expr :- ::h2x/honeysql-expr@@ -341,9 +350,10 @@:sandbox :sandboxes:segment :segment:measure :measure- :action :action)+ :action :action+ :data-app :data_app):name-column (case entity-type- :table :entity.display_name+ (:table :data-app) :entity.display_name:sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]:entity.name):location-column (case entity-type@@ -361,7 +371,8 @@:else(:name (collection.root/root-collection-with-ui-details (action-root-namespace false)))]]:sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]- (:segment :measure) :table.display_name)}))+ (:segment :measure) :table.display_name+ :data-app nil)}))(mu/defn- item-query-join :- [:map {:closed true}[:join [:sequential HoneySQLForm]]@@ -609,11 +620,24 @@;;; ---------------------------------------------------- Entities ----------------------------------------------------+(def ^:private narrow-columns+ "The columns read for the entity types whose rows hold much more than dependency code needs: a data app's bundle+ can be megabytes."+ {:data-app [:id :resource_collection_id]})+(mu/defn entities- "The entities of the entity type `entity-type` with `ids`."+ "The entities of the entity type `entity-type` with `ids`: whole rows, except for the types in [[narrow-columns]],+ whose rows hold only those columns."[entity-type :- ::deps.dependency-types/dependency-typesids :- [:set ::deps.dependency-types/entity-id]]- (t2/select (deps.dependency-types/dependency-type->model entity-type) :id [:in ids]))+ (let [model (deps.dependency-types/dependency-type->model entity-type)]+ (t2/select (if-let [columns (narrow-columns entity-type)] (into [model] columns) model) :id [:in ids])))++(mu/defn entity+ "The entity of the entity type `entity-type` with `id`, or nil, with the columns of [[entities]]."+ [entity-type :- ::deps.dependency-types/dependency-types+ id :- ::deps.dependency-types/entity-id]+ (first (entities entity-type #{id})))(mu/defn- entity-source :- [:map {:closed true}[:from {:optional true} [:sequential HoneySQLForm]]]@@ -644,6 +668,12 @@[action-ids :- [:sequential ::lib.schema.id/action]](t2/select-fn->fn :action_id :dataset_query :model/QueryAction :action_id [:in action-ids]))+(mu/defn ids-in-collections+ "The `:id` and `:collection_id` of the `model` rows in the Collections with `collection-ids`."+ [model :- [:enum :model/Card :model/Action]+ collection-ids :- [:sequential ::lib.schema.id/collection]]+ (t2/select [model :id :collection_id] :collection_id [:in collection-ids]))+(mu/defn card"The Card with `card-id`, or nil."[card-id :- ::lib.schema.id/card]@@ -846,6 +876,18 @@[type->ids :- ::dependencies.schema/type->ids](mark-stale! :model/DependencyStatus type->ids))+(mu/defn mark-data-app-dependency-statuses-stale!+ "Mark the DependencyStatuses of the DataApps whose resource collection is one of the Collections with+ `collection-ids` stale, in one UPDATE."+ [collection-ids :- [:sequential ::lib.schema.id/collection]]+ (t2/query {:update (t2/table-name :model/DependencyStatus)+ :set (assoc fresh-attempts :stale one-more-write)+ :where [:and+ [:= :entity_type (name :data-app)]+ [:in :entity_id ^:allow-subquery {:select [:id]+ :from [(t2/table-name :model/DataApp)]+ :where [:in :resource_collection_id collection-ids]}]]}))+(mu/defn mark-result-metadata-statuses-stale!"Mark the ResultMetadataStatuses of the entities `type->ids` stale, so the result metadata job re-derives them."[type->ids :- ::dependencies.schema/type->ids]diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.clj b/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.cljindex d0129ed652d..586699ed39a 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.clj@@ -15,7 +15,8 @@:model/Sandbox :sandbox:model/Segment :segment:model/Measure :measure- :model/Action :action})+ :model/Action :action+ :model/DataApp :data-app})(def dependency-type->model"A map relating dependency types to their corresponding model."diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj b/enterprise/backend/src/metabase_enterprise/dependencies/hooks.cljindex d2453f9d283..2b02bbb45ae 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj@@ -76,6 +76,7 @@{:model/Action #{:model_id :type}:model/Card #{:type :dataset_query :dimension_mappings :parameters}:model/Dashboard #{:parameters}+ :model/DataApp #{:resource_collection_id}:model/Document #{:content_type :document}:model/Measure #{:definition :table_id}:model/NativeQuerySnippet #{:content :template_tags}@@ -218,6 +219,21 @@(changed? row (disj columns :result_metadata))(not (deps.result-metadata/same-output? (:result_metadata (t2/original row)) (:result_metadata row)))))))+(mu/defn- data-apps-changed? :- :boolean+ "Whether the update of `row` of `model` moves a Card or an Action to another collection, which changes what the data+ apps whose resource collection it leaves or enters depend on."+ [model :- :keyword+ row :- Row]+ (and (contains? #{:model/Action :model/Card} model)+ (changed? row #{:collection_id})))++(mu/defn- mark-data-apps!+ "Mark the dependencies of the data apps whose resource collection is one of `collection-ids` stale, querying nothing+ when every one is nil."+ [collection-ids :- [:sequential [:maybe ms/PositiveInt]]]+ (when-let [collection-ids (not-empty (into [] (comp (remove nil?) (distinct)) collection-ids))]+ (dependencies.db/mark-data-app-dependency-statuses-stale! collection-ids)))+(mu/defn- mark-update! :- :boolean"Mark the statuses an update of `row` of `model` makes stale: the entity's own, by the columns each jobreads, and what reads its output when that changes, returning whether a column some job reads changed."@@ -228,7 +244,8 @@dependency? (changed? row (dependency-columns model))analysis? (changed? row (analysis-columns model))output? (output-changed? model row)- part? (changed? row (part-columns model))]+ part? (changed? row (part-columns model))+ data-apps? (data-apps-changed? model row)](when dependency?(dependencies.db/mark-dependency-statuses-stale! own))(when analysis?@@ -242,7 +259,9 @@:model/Field (mark-remap-targets! #{(:id row)}):model/FieldUserSettings (mark-remap-targets! #{(:field_id row)})nil))- (or dependency? analysis? output? part?+ (when data-apps?+ (mark-data-apps! [(:collection_id (t2/original row)) (:collection_id row)]))+ (or dependency? analysis? output? part? data-apps?(case model:model/Dimension (do (run! mark-dimension! (distinct [(t2/original row) row])) true):model/FieldValues (mark-field-values! (t2/original row) row)@@ -277,9 +296,10 @@(when (contains? part-columns model)(mark-part-owner! (part-owner model row)))(case model- :model/Dimension (mark-dimension! row)- :model/FieldValues (mark-field-values! nil row)- :model/FieldUserSettings (mark-remap-targets! #{(:field_id row)})+ (:model/Action :model/Card) (mark-data-apps! [(:collection_id row)])+ :model/Dimension (mark-dimension! row)+ :model/FieldValues (mark-field-values! nil row)+ :model/FieldUserSettings (mark-remap-targets! #{(:field_id row)})nil)(trigger-jobs!))@@ -298,10 +318,11 @@(when (contains? part-columns model)(mark-part-owner! (part-owner model row)))(case model- :model/Dimension (mark-dimension! row)- :model/FieldValues (mark-field-values! row nil)- :model/Field (mark-remap-targets! #{(:id row)})- :model/FieldUserSettings (mark-remap-targets! #{(:field_id row)})+ (:model/Action :model/Card) (mark-data-apps! [(:collection_id row)])+ :model/Dimension (mark-dimension! row)+ :model/FieldValues (mark-field-values! row nil)+ :model/Field (mark-remap-targets! #{(:id row)})+ :model/FieldUserSettings (mark-remap-targets! #{(:field_id row)})nil)(when-let [entity-type (deps.dependency-types/model->dependency-type model)](mark-output-changed! entity-type row))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.cljindex de66599e3ab..cf4bccfa9ef 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj@@ -255,6 +255,9 @@(defmethod add-override :action [^OverridingMetadataProvider mp _entity-type _id _updates]mp)+(defmethod add-override :data-app [^OverridingMetadataProvider mp _entity-type _id _updates]+ mp)+(defmethod add-override :segment [^OverridingMetadataProvider mp _entity-type id updates]{[:metadata/segment id] (delay (merge (when id(lib.metadata/segment (inner-mp mp) id))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.cljindex da302e456f7..def1b780a68 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj@@ -262,7 +262,8 @@:metabase-enterprise.sandbox.schema/sandbox:metabase.segments.schema/segment:metabase.measures.schema/measure- ::actions.schema/action]]]]+ ::actions.schema/action+ :metabase-enterprise.data-apps.schema/data-app]]]](boolean(case entity-type:card (some-> entitydiff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency_status.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency_status.cljindex 47c19f712d1..7462b47f9a9 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency_status.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency_status.clj@@ -5,6 +5,7 @@[metabase-enterprise.dependencies.models.dependency :as models.dependency][metabase-enterprise.dependencies.schema :as dependencies.schema][metabase.models.interface :as mi]+ [metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][methodical.core :as methodical]@@ -36,6 +37,20 @@(contains? queries id) (assoc :dataset_query (queries id))))entities)))+(defmethod hydrate-for-deps :data-app [_ entities]+ (let [collection-ids (into [] (keep :resource_collection_id) entities)+ ids-by-collection (fn [rows]+ (u/group-by :collection_id :id conj #{} rows))+ card-ids (when (seq collection-ids)+ (ids-by-collection (dependencies.db/ids-in-collections :model/Card collection-ids)))+ action-ids (when (seq collection-ids)+ (ids-by-collection (dependencies.db/ids-in-collections :model/Action collection-ids)))]+ (mapv (fn [{collection-id :resource_collection_id :as app}]+ (assoc app+ :card_ids (get card-ids collection-id #{})+ :action_ids (get action-ids collection-id #{})))+ entities)))+(mu/defn take-pending-statuses! :- [:sequential ::dependencies.schema/pending-status]"Up to `batch-size` entities of `entity-type` whose dependencies a write changed, are not computed yet, or werecomputed by an older analysis, those last, with the `stale` count the job clears afterwards."diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj b/enterprise/backend/src/metabase_enterprise/dependencies/schema.cljindex 71a29b23408..736d322086f 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj@@ -66,7 +66,8 @@[:dashboard {:optional true} [:set ::lib.schema.id/dashboard]][:document {:optional true} [:set ::documents.schema/document.id]][:sandbox {:optional true} [:set ::lib.schema.id/sandbox]]- [:segment {:optional true} [:set ::lib.schema.id/segment]]])+ [:segment {:optional true} [:set ::lib.schema.id/segment]]+ [:action {:optional true} [:set ::lib.schema.id/action]]])(mr/def ::analysis-finding-error"A AnalysisFindingError as selected from the app DB: every column of `:analysis_finding_error`."diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.cljindex ea0a877862a..f0519ce3383 100644--- a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj@@ -175,7 +175,7 @@(with-redefs [data-app.config/supported-app-version 2](testing "a regular user is never told about the outdated app in a list"(doseq [url ["ee/apps" "ee/apps?available=true"]]- (is (= [{:name "current" :display_name "Current"}]+ (is (= [{:id (t2/select-one-pk :model/DataApp :name "current") :name "current" :display_name "Current"}](mt/user-http-request :rasta :get 200 url)))))(testing "for a regular user, opening an outdated app is a 409 that says what to do"(doseq [url ["ee/apps/old" "ee/apps/old/bundle"]]@@ -183,7 +183,7 @@:message #"This app was built for version 1 of data apps.*"}(mt/user-http-request :rasta :get 409 url)))))(testing "the current app still opens"- (is (= {:name "current" :display_name "Current"}+ (is (= {:id (t2/select-one-pk :model/DataApp :name "current") :name "current" :display_name "Current"}(mt/user-http-request :rasta :get 200 "ee/apps/current")))(is (str/includes?(str (mt/user-real-request :crowberto :get 200 "ee/apps/current/bundle"))diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.cljindex f705f2b3cfd..b00171fabad 100644--- a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj+++ b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj@@ -4,6 +4,7 @@[metabase-enterprise.data-apps.group-access :as group-access][metabase-enterprise.data-apps.resources :as resources][metabase.api.macros :as api.macros]+ [metabase.app-db.core :as mdb][metabase.collections.core :as collection][metabase.data-apps.core :as data-apps][metabase.models.interface :as mi]@@ -14,39 +15,58 @@(set! *warn-on-reflection* true)+(deftest visible-data-app-filter-select-outside-toucan-test+ (testing "the read rule query works in an app-DB query compiled outside Toucan, as the search index's queries are"+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/DataApp _ {:name "owls" :display_name "Owls" :bundle_path "owls.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}]+ (is (= [app-id]+ (map :id (mdb/query {:select [:id]+ :from [:data_app]+ :where [:in :id (data-apps/visible-data-app-filter-select+ {:user-id (mt/user->id :rasta) :is-superuser? false})]}))))))))+(deftest assignments-authorize-access-test- (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}- :model/PermissionsGroup group {}]- (resources/ensure-resources! app)- (mt/with-current-user (mt/user->id :rasta)- (is (not (mi/can-read? app))))- (group-access/add-groups! app [(:id group)])- (perms/add-user-to-group! (mt/user->id :rasta) (:id group))- (mt/with-current-user (mt/user->id :rasta)- (is (mi/can-read? app)))- (group-access/remove-group! app (:id group))- (mt/with-current-user (mt/user->id :rasta)- (is (not (mi/can-read? app))))- (mt/with-current-user (mt/user->id :crowberto)- (is (mi/can-read? app)))))+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/PermissionsGroup group {}]+ (resources/ensure-resources! app)+ (mt/with-current-user (mt/user->id :rasta)+ (is (not (mi/can-read? app))))+ (group-access/add-groups! app [(:id group)])+ (perms/add-user-to-group! (mt/user->id :rasta) (:id group))+ (mt/with-current-user (mt/user->id :rasta)+ (is (mi/can-read? app)))+ (group-access/remove-group! app (:id group))+ (mt/with-current-user (mt/user->id :rasta)+ (is (not (mi/can-read? app))))+ (mt/with-current-user (mt/user->id :crowberto)+ (is (mi/can-read? app))+ (testing "without the data apps feature nobody can read an app, admins included"+ (mt/with-premium-features #{}+ (is (not (mi/can-read? app)))))))))(deftest app-list-filters-readable-apps-test- (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}- :model/DataApp disabled {:name "disabled" :display_name "Disabled" :bundle_path "disabled.js"- :enabled false}- :model/DataApp _ {:name "hidden" :display_name "Hidden" :bundle_path "hidden.js"}- :model/PermissionsGroup finches {}- :model/PermissionsGroup owls {}]- (group-access/add-groups! app [(:id finches) (:id owls)])- (group-access/add-groups! disabled [(:id finches)])- (perms/add-user-to-group! (mt/user->id :rasta) (:id finches))- (perms/add-user-to-group! (mt/user->id :rasta) (:id owls))- (let [list-apps (api.macros/find-route-fn 'metabase-enterprise.data-apps.api :get "/")]- (mt/with-current-user (mt/user->id :rasta)- (list-apps {} {})- (testing "a disabled app isn't listed to a non-superuser, available or not"- (doseq [query [{} {:available true}]]- (is (= [{:name "birds" :display_name "Birds"}] (list-apps {} query)))))))))+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/DataApp disabled {:name "disabled" :display_name "Disabled" :bundle_path "disabled.js"+ :enabled false}+ :model/DataApp _ {:name "hidden" :display_name "Hidden" :bundle_path "hidden.js"}+ :model/PermissionsGroup finches {}+ :model/PermissionsGroup owls {}]+ (group-access/add-groups! app [(:id finches) (:id owls)])+ (group-access/add-groups! disabled [(:id finches)])+ (perms/add-user-to-group! (mt/user->id :rasta) (:id finches))+ (perms/add-user-to-group! (mt/user->id :rasta) (:id owls))+ (let [list-apps (api.macros/find-route-fn 'metabase-enterprise.data-apps.api :get "/")]+ (mt/with-current-user (mt/user->id :rasta)+ (list-apps {} {})+ (testing "a disabled app isn't listed to a non-superuser, available or not"+ (doseq [query [{} {:available true}]]+ (is (= [{:id (:id app) :name "birds" :display_name "Birds"}] (list-apps {} query))))))))))(deftest read-access-agrees-across-entry-points-test(mt/with-premium-features #{:data-apps :tenants}@@ -75,6 +95,10 @@(mt/user-http-request user-id :get (if allowed? 200 403) "ee/apps/birds/bundle")(mt/with-current-user user-id(is (= allowed? (boolean (mi/can-read? app)))))+ (is (= allowed? (contains? (t2/select-pks-set :model/DataApp+ {:where [:in :id (data-apps/visible-data-app-filter-select+ {:user-id user-id :is-superuser? admin?})]})+ (:id app))))(mt/with-current-user user-id(let [request {:route-params {:name "birds"} :metabase-user-id user-id :is-superuser? admin?}](if allowed?@@ -306,11 +330,11 @@(perms/revoke-collection-permissions! group-id collection-id)(mt/user-http-request :rasta :get 403 "ee/apps/birds")(resources/ensure-resources! app)- (is (= {:name "birds" :display_name "Birds"}+ (is (= {:id (:id app) :name "birds" :display_name "Birds"}(mt/user-http-request :rasta :get 200 "ee/apps/birds"))))))))(deftest tenant-users-cannot-inherit-app-access-test- (mt/with-premium-features #{:tenants}+ (mt/with-premium-features #{:data-apps :tenants}(mt/with-temp [:model/Tenant tenant {:name "Tenant"}:model/User user {:tenant_id (:id tenant)}:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}]@@ -319,13 +343,14 @@(is (not (mi/can-read? app)))))))(deftest sso-membership-controls-assigned-app-access-test- (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}- :model/PermissionsGroup group {}- :model/User user {}]- (group-access/add-groups! app [(:id group)])- (sso/sync-group-memberships! (:id user) [(:id group)])- (mt/with-current-user (:id user)- (is (mi/can-read? app)))- (sso/sync-group-memberships! (:id user) [])- (mt/with-current-user (:id user)- (is (not (mi/can-read? app))))))+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp app {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/PermissionsGroup group {}+ :model/User user {}]+ (group-access/add-groups! app [(:id group)])+ (sso/sync-group-memberships! (:id user) [(:id group)])+ (mt/with-current-user (:id user)+ (is (mi/can-read? app)))+ (sso/sync-group-memberships! (:id user) [])+ (mt/with-current-user (:id user)+ (is (not (mi/can-read? app)))))))diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.cljindex a2b1e7ba78a..1cc609c3a6d 100644--- a/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj+++ b/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj@@ -143,10 +143,15 @@(deftest permissions-test(testing "a superuser can read, write, and create"- (binding [api/*is-superuser?* true]- (is (mi/can-read? :model/DataApp 1))- (is (mi/can-write? :model/DataApp 1))- (is (mi/can-create? :model/DataApp {}))))+ (mt/with-premium-features #{:data-apps}+ (binding [api/*is-superuser?* true]+ (is (mi/can-read? :model/DataApp 1))+ (is (mi/can-write? :model/DataApp 1))+ (is (mi/can-create? :model/DataApp {})))))+ (testing "without the data apps feature, a superuser cannot read"+ (mt/with-premium-features #{}+ (binding [api/*is-superuser?* true]+ (is (not (mi/can-read? :model/DataApp 1))))))(testing "an unassigned user cannot read, write, or create"(binding [api/*is-superuser?* false](is (not (mi/can-read? :model/DataApp 1)))diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/search_test.cljnew file mode 100644index 00000000000..978520248dd--- /dev/null+++ b/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj@@ -0,0 +1,227 @@+(ns metabase-enterprise.data-apps.search-test+ (:require+ [clojure.test :refer :all]+ [metabase-enterprise.data-apps.config :as data-apps.config]+ [metabase.api.common :as api]+ [metabase.permissions.core :as perms]+ [metabase.search.appdb.index :as search.index]+ [metabase.search.core :as search]+ [metabase.search.test-util :as search.tu]+ [metabase.test :as mt]+ [metabase.test.fixtures :as fixtures]+ [toucan2.core :as t2]))++(set! *warn-on-reflection* true)++(use-fixtures :once (fixtures/initialize :db :test-users))++;; The index table is created here, outside the tests' rollback-only `with-temp`: creating it is DDL, which commits.+(use-fixtures :each (fn [thunk] (search.tu/with-appdb-search-if-available-otherwise-legacy (thunk))))++(def ^:private search-term "sandpiper")++(defn- found-data-apps+ "The name and slug of the data apps that `user` finds searching for [[search-term]] with `params`, by id."+ [user & params]+ (->> (apply mt/user-http-request user :get 200 "search" :q search-term params)+ :data+ (filter (comp #{"data-app"} :model))+ (into {} (map (juxt :id #(select-keys % [:name :data_app_slug]))))))++(defn- offers-data-app-type?+ "Whether the search page's type filter offers data apps to `user` searching for [[search-term]]."+ [user]+ (-> (mt/user-http-request user :get 200 "search" :q search-term :calculate_available_models true)+ :available_models+ set+ (contains? "data-app")))++(defn- semantic-engine-offers-data-app-type?+ "Whether the semantic search engine's type filter offers data apps to `user` searching for [[search-term]]."+ [user]+ (mt/with-current-user (mt/user->id user)+ (-> (search/search-context {:current-user-id api/*current-user-id*+ :current-user-perms @api/*current-user-permissions-set*+ :is-superuser? api/*is-superuser?*+ :is-impersonated-user? false+ :is-sandboxed-user? false+ :is-routed-user? false+ :models nil+ :search-string search-term})+ (assoc :search-engine :search.engine/semantic)+ search/model-set+ (contains? "data-app"))))++(defn- with-each-engine+ "Run `check!` with the index engine when the app DB supports it, then with the legacy engine."+ [check!]+ (check!)+ (search.tu/with-legacy-search (check!)))++(deftest search-finds-the-data-apps-the-user-can-read-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {slug-match-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "sightings.js"}+ :model/DataApp {assigned-id :id} {:name "plovers" :display_name "Sandpiper counts"+ :bundle_path "counts.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id assigned-id :permission_group_id group-id}]+ (with-each-engine+ (fn []+ (testing "an admin finds every app, by its slug or its display name"+ (is (= #{slug-match-id assigned-id}+ (set (keys (found-data-apps :crowberto :models "data-app"))))))+ (testing "another user finds the apps assigned to one of their groups, with display name and slug"+ (is (= {assigned-id {:name "Sandpiper counts" :data_app_slug "plovers"}}+ (found-data-apps :rasta :models "data-app"))))+ (testing "a user in no assigned group finds none"+ (is (= {} (found-data-apps :lucky :models "data-app"))))+ (testing "a search that names no models, as global search does, finds them too"+ (is (= #{slug-match-id assigned-id}+ (set (keys (found-data-apps :crowberto)))))))))))++(deftest search-finds-disabled-and-outdated-data-apps-the-user-can-read-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {current-id :id} {:name "sandpiper-dunlin" :display_name "Dunlin"+ :bundle_path "dunlin.js" :version 2}+ :model/DataApp {outdated-id :id} {:name "sandpiper-knot" :display_name "Knot"+ :bundle_path "knot.js" :version 1}+ :model/DataApp {disabled-id :id} {:name "sandpiper-sanderling" :display_name "Sanderling"+ :bundle_path "sanderling.js" :version 2 :enabled false}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id current-id :permission_group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id outdated-id :permission_group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id disabled-id :permission_group_id group-id}]+ (with-redefs [data-apps.config/supported-app-version 2]+ (with-each-engine+ (fn []+ (doseq [params [[] [:models "data-app"]]]+ (testing (str "an admin searching with " (pr-str params) " finds disabled and outdated apps too")+ (is (= #{current-id outdated-id disabled-id}+ (set (keys (apply found-data-apps :crowberto params))))))+ (testing (str "another user searching with " (pr-str params) " finds outdated apps, but no disabled one")+ (is (= #{current-id outdated-id}+ (set (keys (apply found-data-apps :rasta params)))))))))))))++(deftest search-without-models-finds-only-the-data-apps-the-user-can-read-test+ (mt/with-premium-features #{:data-apps :tenants}+ (mt/with-temporary-setting-values [use-tenants true]+ (mt/with-temp [:model/Tenant tenant {:name "Tenant"}+ :model/User tenant-user {:tenant_id (:id tenant)}+ :model/DataApp {enabled-id :id} {:name "plovers" :display_name "Sandpiper counts"+ :bundle_path "counts.js"}+ :model/DataApp {disabled-id :id} {:name "sandpiper-drafts" :display_name "Drafts"+ :enabled false :bundle_path "drafts.js"}+ :model/DataApp {unassigned-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "sightings.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroup {tenant-group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id enabled-id :permission_group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id disabled-id :permission_group_id group-id}]+ ;; Assigned before the group becomes a tenant group.+ (t2/insert! :model/DataAppGroupAssignment {:data_app_id enabled-id :permission_group_id tenant-group-id})+ (t2/update! :model/PermissionsGroup tenant-group-id {:is_tenant_group true})+ (perms/add-user-to-group! (:id tenant-user) tenant-group-id)+ (with-each-engine+ (fn []+ (testing "an admin finds every app"+ (is (= #{enabled-id disabled-id unassigned-id} (set (keys (found-data-apps :crowberto))))))+ (testing "another user finds only the enabled apps assigned to one of their groups"+ (is (= #{enabled-id} (set (keys (found-data-apps :rasta))))))+ (testing "a user in no assigned group finds none"+ (is (= {} (found-data-apps :lucky))))+ (testing "a tenant user finds none, even through an assigned tenant group"+ (is (= {} (found-data-apps (:id tenant-user)))))))))))++(deftest type-filter-offers-data-apps-only-to-users-who-can-read-one-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {enabled-id :id} {:name "plovers" :display_name "Sandpiper counts"+ :bundle_path "counts.js"}+ :model/DataApp {disabled-id :id} {:name "sandpiper-drafts" :display_name "Drafts"+ :enabled false :bundle_path "drafts.js"}+ :model/PermissionsGroup {other-group-id :id} {}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id enabled-id :permission_group_id other-group-id}+ :model/DataAppGroupAssignment _ {:data_app_id disabled-id :permission_group_id group-id}]+ (with-each-engine+ (fn []+ (testing "an admin is offered data apps"+ (is (offers-data-app-type? :crowberto)))+ (testing "a user in no assigned group is not offered data apps"+ (is (not (offers-data-app-type? :lucky))))+ (testing "a user whose groups are assigned only a disabled app is not offered data apps"+ (is (not (offers-data-app-type? :rasta)))))))))++(deftest type-filter-offers-no-data-apps-without-the-feature-test+ (mt/with-premium-features #{}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "s.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}]+ (with-each-engine+ (fn []+ (doseq [user [:crowberto :rasta :lucky]]+ (testing (str user " is not offered data apps")+ (is (not (offers-data-app-type? user))))))))))++(defn- without-app-db-index+ "Run `thunk` as on an app DB that cannot hold the search index, such as MySQL and MariaDB."+ [thunk]+ (search.tu/with-legacy-search+ (mt/with-dynamic-fn-redefs [search.index/active-table (constantly nil)]+ (thunk))))++(deftest semantic-type-filter-offers-data-apps-only-to-users-who-can-read-one-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "s.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}]+ (doseq [[app-db with-app-db] [["this app DB" (fn [thunk] (thunk))]+ ["an app DB without the search index" without-app-db-index]]]+ (with-app-db+ (fn []+ (testing app-db+ (testing "an admin is offered data apps"+ (is (semantic-engine-offers-data-app-type? :crowberto)))+ (testing "a user in an assigned group is offered data apps"+ (is (semantic-engine-offers-data-app-type? :rasta)))+ (testing "a user in no assigned group is not offered data apps"+ (is (not (semantic-engine-offers-data-app-type? :lucky)))))))))))++(deftest search-by-ids-finds-the-requested-data-app-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "sightings.js"}+ :model/DataApp {other-id :id} {:name "plovers" :display_name "Sandpiper counts"+ :bundle_path "counts.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id other-id :permission_group_id group-id}]+ (with-each-engine+ (fn []+ (doseq [user [:crowberto :rasta]]+ (testing (str user " finds only the data app with the requested id")+ (is (= #{app-id}+ (set (keys (found-data-apps user :models "data-app" :ids app-id))))))))))))++(deftest search-finds-no-data-apps-without-the-feature-test+ (mt/with-premium-features #{}+ (mt/with-temp [:model/DataApp _ {:name "sandpiper-sightings" :display_name "Shorebirds" :bundle_path "s.js"}]+ (with-each-engine+ #(is (= {} (found-data-apps :crowberto :models "data-app")))))))++(deftest deleting-a-data-app-removes-it-from-the-index-test+ (mt/with-premium-features #{:data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"+ :bundle_path "s.js"}]+ (is (contains? (found-data-apps :crowberto :models "data-app") app-id))+ (t2/delete! :model/DataApp app-id)+ (is (= {} (found-data-apps :crowberto :models "data-app"))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.cljindex 629f62654db..91a39a2a31f 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj@@ -2,6 +2,7 @@(:require[clojure.test :refer :all][medley.core :as m]+ [metabase-enterprise.data-apps.test-util :as data-apps.tu][metabase-enterprise.dependencies.analysis-finding :as deps.analysis-finding][metabase-enterprise.dependencies.api :as deps.api][metabase-enterprise.dependencies.hooks :as deps.hooks]@@ -3119,3 +3120,128 @@(mt/user-http-request :rasta :get 403 "ee/dependencies/backfill-status")))(is (=? {:complete boolean?}(mt/user-http-request :crowberto :get 200 "ee/dependencies/backfill-status"))))))++(defn- data-app-card+ "A question on venues in the data app resource collection with `collection-id`."+ [collection-id]+ (assoc (basic-card "Bird sightings" :venues) :collection_id collection-id))++(deftest ^:synchronized graph-data-app-test+ (testing "GET /api/ee/dependencies/graph shows what a data app depends on, and counts the app as a card's dependent"+ (mt/with-premium-features #{:dependencies :data-apps}+ (data-apps.tu/with-published-tables! [(mt/id :venues)]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id}+ {:name "birds" :display_name "Birds" :description "Sightings" :bundle_path "birds.js"}+ :model/Card {card-id :id} (data-app-card collection-id)]+ (mt/with-model-cleanup [:model/Dependency :model/DependencyStatus]+ (deps.test/synchronously-run-dependency-job!)+ (let [{:keys [nodes edges]} (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph"+ :id app-id+ :type "data-app")+ node (fn [node-type node-id]+ (m/find-first #(= [node-type node-id] ((juxt :type :id) %)) nodes))]+ (is (=? {:data {:name "birds" :display_name "Birds" :description "Sightings"}}+ (node "data-app" app-id)))+ (is (=? {:dependents_count {:data-app 1}}+ (node "card" card-id)))+ (is (some? (node "table" (mt/id :venues))))+ (is (contains? (into #{}+ (map (juxt :from_entity_type :from_entity_id :to_entity_type :to_entity_id))+ edges)+ ["data-app" app-id "card" card-id])))))))))++(deftest ^:synchronized graph-data-app-dependents-test+ (testing "GET /api/ee/dependencies/graph/dependents lists the data apps a user can read"+ (data-apps.tu/with-published-tables! [(mt/id :venues)]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id}+ {:name "birds" :display_name "Birds" :bundle_path "birds.js" :enabled false}+ :model/Card {card-id :id} (data-app-card collection-id)+ :model/PermissionsGroup {group-id :id} {}]+ (mt/with-model-cleanup [:model/Dependency :model/DependencyStatus]+ (deps.test/synchronously-run-dependency-job!)+ (perms/grant-collection-read-permissions! (perms/all-users-group) collection-id)+ (let [dependent-ids (fn [user]+ (->> (mt/user-http-request user :get 200 "ee/dependencies/graph/dependents"+ :id card-id+ :type "card"+ :dependent-types "data-app")+ (into #{} (map :id))))]+ (mt/with-premium-features #{:dependencies :data-apps}+ (testing "an admin sees every app, disabled ones too"+ (is (= #{app-id} (dependent-ids :crowberto))))+ (testing "a user sees the enabled apps assigned to one of their groups, not the apps whose collection they+ can read"+ (is (= #{} (dependent-ids :rasta)))+ (perms/add-user-to-group! (mt/user->id :rasta) group-id)+ (t2/insert! :model/DataAppGroupAssignment {:data_app_id app-id :permission_group_id group-id})+ (is (= #{} (dependent-ids :rasta)))+ (t2/update! :model/DataApp app-id {:enabled true})+ (is (= #{app-id} (dependent-ids :rasta)))))+ (mt/with-premium-features #{:dependencies}+ (testing "without the data apps feature, the dependents list has no data apps, even for an admin"+ (is (= #{} (dependent-ids :crowberto)))))))))))++(deftest graph-data-app-names-only-for-non-admins-test+ (testing "GET /api/ee/dependencies/graph gives a non-admin only a data app's names, as the data-app API does"+ (mt/with-premium-features #{:dependencies :data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds" :display_name "Birds" :description "Sightings"+ :bundle_path "birds.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}]+ (let [app-data (fn [user]+ (->> (mt/user-http-request user :get 200 "ee/dependencies/graph" :id app-id :type "data-app")+ :nodes+ (m/find-first #(= ["data-app" app-id] ((juxt :type :id) %)))+ :data))]+ (is (= {:name "birds" :display_name "Birds"}+ (app-data :rasta)))+ (testing "an admin also gets the description and creation time"+ (is (=? {:description "Sightings" :created_at some?}+ (app-data :crowberto)))))))))++(deftest graph-data-app-without-data-apps-feature-test+ (testing "GET /api/ee/dependencies/graph refuses a data app start node without the data apps feature"+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/PermissionsGroup {group-id :id} {}+ :model/PermissionsGroupMembership _ {:user_id (mt/user->id :rasta) :group_id group-id}+ :model/DataAppGroupAssignment _ {:data_app_id app-id :permission_group_id group-id}]+ (doseq [[description user] [["to an admin" :crowberto]+ ["to a user in a group assigned the app" :rasta]]]+ (testing description+ (is (= "You don't have permissions to do that."+ (mt/user-http-request user :get 403 "ee/dependencies/graph" :id app-id :type "data-app")))))))))++(deftest ^:synchronized unreferenced-data-app-test+ (testing "GET /api/ee/dependencies/graph/unreferenced lists data apps, finds them by their display name, and sorts them+ by location"+ (mt/with-premium-features #{:dependencies :data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds" :display_name "Bird sightings unreftest" :bundle_path "birds.js"}]+ (mt/with-model-cleanup [:model/Dependency :model/DependencyStatus]+ (deps.test/synchronously-run-dependency-job!)+ (let [unreferenced (fn [& params]+ (->> (apply mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced"+ :query "unreftest"+ params)+ :data+ (into #{} (map (juxt :type :id (comp :display_name :data))))))]+ (is (= #{["data-app" app-id "Bird sightings unreftest"]}+ (unreferenced :types "data-app" :sort-column "location")))+ (testing "without a types filter"+ (is (= #{["data-app" app-id "Bird sightings unreftest"]}+ (unreferenced))))))))))++(deftest graph-data-app-read-check-skips-the-bundle-test+ (testing "the graph endpoints check a data app start node without reading its bundle"+ (mt/with-premium-features #{:dependencies :data-apps}+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds"+ :display_name "Birds"+ :bundle_path "birds.js"+ :bundle (byte-array [1 2 3])}]+ (testing "a full row read counts"+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))+ (doseq [endpoint ["ee/dependencies/graph" "ee/dependencies/graph/dependents" "ee/dependencies/graph/broken"]]+ (testing endpoint+ (is (= [] (deps.test/data-app-bundle-reads+ #(mt/user-http-request :crowberto :get 200 endpoint :id app-id :type "data-app"))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.cljindex 776153a69df..f57c94c5f12 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj@@ -198,6 +198,18 @@:base-provider provider:graph graph))))))+(deftest ^:parallel card-edit-with-data-app-dependent-test+ (testing "editing a card that a data app depends on reports no errors"+ (let [{:keys [provider mbql-base]} (testbed)+ graph (graph/in-memory {[:card 101] #{[:data-app 900]}})+ card' (-> mbql-base+ (update :dataset-query lib/filter (lib/> (lib.metadata/field (mt/metadata-provider) (mt/id :orders :quantity))+ 100))+ (dissoc :result-metadata))]+ (is (= {} (dependencies/errors-from-proposed-edits {:card [card']}+ :base-provider provider+ :graph graph))))))+(deftest ^:parallel sql-snippet->card->transform->cards-test(testing "changing a snippet correctly finds downstream errors when asked"(let [{:keys [provider graph snippet-inner]diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.cljindex c731c2d78fb..0def4bf8e25 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj@@ -2,6 +2,7 @@(:require[clojure.test :refer :all][java-time.api :as t]+ [metabase-enterprise.data-apps.test-util :as data-apps.tu][metabase-enterprise.dependencies.db :as dependencies.db][metabase-enterprise.dependencies.hooks][metabase-enterprise.dependencies.test-util :as deps.test]@@ -278,6 +279,36 @@:type :internal}))))(is (changes? #(t2/delete! :model/Dimension :id @dimension-id))))))))))+(deftest card-writes-mark-resource-collection-apps-in-one-statement-test+ (testing "a card write in a data app's resource collection marks the app's dependencies stale in one statement,+ without looking the app up first"+ (mt/with-premium-features #{:dependencies}+ (data-apps.tu/with-published-tables! [(mt/id :products)]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id} {:name "birds"+ :display_name "Birds"+ :bundle_path "birds.js"}+ :model/Collection {other-collection-id :id} {}+ :model/Card card {:dataset_query (table-query :products) :collection_id collection-id}]+ (let [marks (fn [hook!]+ (computed! :data-app app-id)+ {:statements (filterv (partial re-find #"(?i)\b(?:data_app|dependency_status)\b")+ (deps.test/app-db-statements hook!))+ :pending? (pending? :data-app app-id)})+ moved-to (fn [from-collection-id to-collection-id]+ (assoc (t2/instance :model/Card (assoc (into {} card) :collection_id from-collection-id))+ :collection_id to-collection-id))+ one-update? {:statements [#"(?is)UPDATE\b.*"] :pending? true}]+ (testing "inserting a card"+ (is (=? one-update? (marks #(dependencies.hooks/before-insert :model/Card card)))))+ (testing "moving a card out"+ (is (=? one-update? (marks #(dependencies.hooks/before-update+ :model/Card (moved-to collection-id other-collection-id))))))+ (testing "moving a card in"+ (is (=? one-update? (marks #(dependencies.hooks/before-update+ :model/Card (moved-to other-collection-id collection-id))))))+ (testing "deleting a card"+ (is (=? one-update? (marks #(dependencies.hooks/before-delete :model/Card card)))))))))))+(deftest entity-delete-test(testing "the dependency job drops the dependencies and status of a deleted entity"(mt/with-premium-features #{:dependencies}diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.cljindex d190b2488c1..f0f686b6d65 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj@@ -4,6 +4,7 @@[clojure.string :as str][clojure.test :refer :all][environ.core :as env]+ [metabase-enterprise.data-apps.test-util :as data-apps.tu][metabase-enterprise.dependencies.calculation :as deps.calculation][metabase-enterprise.dependencies.db :as dependencies.db][metabase-enterprise.dependencies.hooks :as deps.hooks]@@ -1197,3 +1198,107 @@(deps.test/record-analysis-finding-processed! :card card-id)(deps.test/synchronously-run-dependency-job!)(is (deps.test/analysis-finding-pending? :card card-id)))))))++(defn- data-app-deps+ "The entities the data app with `app-id` depends on, as `[entity-type entity-id]` pairs."+ [app-id]+ (t2/select-fn-set (juxt :to_entity_type :to_entity_id)+ :model/Dependency :from_entity_type :data-app :from_entity_id app-id))++(deftest ^:synchronized data-app-depends-on-its-resource-collection-test+ (data-apps.tu/with-published-tables! [(mt/id :venues)]+ (deps.test/run-with-dependencies-setup!+ (fn [mp]+ (let [venues-query (lib/query mp (lib.metadata/table mp (mt/id :venues)))]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id}+ {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/Collection {other-collection-id :id} {}+ :model/Card {card-id :id} {:dataset_query venues-query :collection_id collection-id}+ :model/Action {action-id :id} {:type :query :name "Delete venue" :collection_id collection-id}+ :model/QueryAction _ {:action_id action-id+ :database_id (mt/id)+ :dataset_query (lib/native-query mp "DELETE FROM venues WHERE id = 1")}]+ (testing "an app depends on the cards and actions in its resource collection"+ (assert-pending :data-app app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (= #{[:card card-id] [:action action-id]} (data-app-deps app-id))))+ (mt/with-temp [:model/Card {added-id :id} {:dataset_query venues-query :collection_id collection-id}]+ (testing "a card added to the collection becomes a dependency"+ (assert-pending :data-app app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (= #{[:card card-id] [:card added-id] [:action action-id]} (data-app-deps app-id))))+ (testing "a card moved out of the collection stops being one"+ (t2/update! :model/Card added-id {:collection_id other-collection-id})+ (assert-pending :data-app app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (= #{[:card card-id] [:action action-id]} (data-app-deps app-id)))))+ (testing "a deleted action stops being one"+ (t2/delete! :model/Action action-id)+ (assert-pending :data-app app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (= #{[:card card-id]} (data-app-deps app-id))))+ (testing "the app is an MBQL dependent of its card"+ (is (= {:data-app #{app-id}}+ (dependencies.model/transitive-mbql-dependents {:card [{:id card-id}]}))))+ (testing "deleting the app removes its dependencies and status"+ (t2/delete! :model/DataApp app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (empty? (data-app-deps app-id)))+ (is (not (t2/exists? :model/DependencyStatus :entity_type :data-app :entity_id app-id))))))))))++(deftest ^:synchronized data-app-given-a-collection-depends-on-its-cards-test+ (testing "an app that lost its collection, given one that already holds a card, depends on that card"+ (data-apps.tu/with-published-tables! [(mt/id :venues)]+ (deps.test/run-with-dependencies-setup!+ (fn [mp]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id}+ {:name "birds" :display_name "Birds" :bundle_path "birds.js"}+ :model/Collection {given-collection-id :id} {:namespace "data-apps"}+ :model/Card {card-id :id} {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :venues)))+ :collection_id given-collection-id}]+ (t2/delete! :model/Collection collection-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (empty? (data-app-deps app-id)))+ (t2/update! :model/DataApp app-id {:resource_collection_id given-collection-id})+ (assert-pending :data-app app-id)+ (deps.test/synchronously-run-dependency-job!)+ (is (= #{[:card card-id]} (data-app-deps app-id)))))))))++(deftest ^:synchronized data-app-dependency-job-skips-the-bundle-test+ (testing "the dependency job computes an app's dependencies without reading its bundle"+ (deps.test/run-with-dependencies-setup!+ (fn [_mp]+ (mt/with-temp [:model/DataApp {app-id :id} {:name "birds"+ :display_name "Birds"+ :bundle_path "birds.js"+ :bundle (byte-array [1 2 3])}]+ (testing "a full row read counts"+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))+ (is (= [] (deps.test/data-app-bundle-reads deps.test/synchronously-run-dependency-job!)))+ (assert-processed :data-app app-id))))))++(deftest ^:synchronized data-app-resource-hooks-skip-the-bundle-test+ (testing "a card write in a resource collection does not read the app's bundle"+ (data-apps.tu/with-published-tables! [(mt/id :venues)]+ (deps.test/run-with-dependencies-setup!+ (fn [mp]+ (mt/with-temp [:model/DataApp {app-id :id collection-id :resource_collection_id}+ {:name "birds" :display_name "Birds" :bundle_path "birds.js" :bundle (byte-array [1 2 3])}+ :model/Collection {other-collection-id :id} {}]+ (mt/with-model-cleanup [:model/Card]+ (testing "a full row read counts"+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))+ (testing "adding a card"+ (let [card (assoc (mt/with-temp-defaults :model/Card)+ :collection_id collection-id+ :dataset_query (lib/query mp (lib.metadata/table mp (mt/id :venues))))]+ (is (= [] (deps.test/data-app-bundle-reads #(t2/insert! :model/Card card))))))+ (let [card-id (t2/select-one-pk :model/Card :collection_id collection-id)]+ (testing "moving a card out"+ (is (= [] (deps.test/data-app-bundle-reads+ #(t2/update! :model/Card card-id {:collection_id other-collection-id})))))+ (testing "moving a card in"+ (is (= [] (deps.test/data-app-bundle-reads+ #(t2/update! :model/Card card-id {:collection_id collection-id})))))+ (testing "deleting a card"+ (is (= [] (deps.test/data-app-bundle-reads #(t2/delete! :model/Card card-id)))))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj b/enterprise/backend/test/metabase_enterprise/dependencies/test_util.cljindex 03119603223..5baa0575f31 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj@@ -13,7 +13,8 @@[metabase.lib.metadata :as lib.metadata][metabase.lib.test-util.metadata-providers.mock :as providers.mock][metabase.test :as mt]- [toucan2.core :as t2]))+ [toucan2.core :as t2]+ [toucan2.jdbc.query :as t2.jdbc.query]))(defn run-with-dependencies-setup!"Run `thunk` with the metadata provider of the test database, as Rasta and with the dependencies feature, each write@@ -117,6 +118,25 @@(mt/with-dynamic-fn-redefs [mdb/do-after-commit (fn [f] (f))](thunk)))+(defn app-db-statements+ "The SQL statements that `thunk` sends to the app DB, in order."+ [thunk]+ (let [sqls (atom [])+ run-query (mt/original-fn #'t2.jdbc.query/reduce-jdbc-query)]+ (mt/with-dynamic-fn-redefs [t2.jdbc.query/reduce-jdbc-query (fn [rf init conn model [sql :as sql-args] opts]+ (swap! sqls conj sql)+ (run-query rf init conn model sql-args opts))]+ (thunk))+ @sqls))++(defn data-app-bundle-reads+ "The SQL statements that `thunk` sends to the app DB and that read the `bundle` column of `data_app`: a `SELECT *`,+ or a select that names the column."+ [thunk]+ ;; app DB quoting differs: "..." on Postgres and H2, `...` on MySQL+ (filterv #(re-find #"(?i)^SELECT\s+(?:(?:[\"`]?data_app[\"`]?\.)?\*|.*\bbundle\b.*)\s+FROM\s+[\"`]?data_app[\"`]?(?:\s|$)" %)+ (app-db-statements thunk)))+(defn mock-card [metadata-provider {:keys [id query details]}](merge {:lib/type :metadata/card:id iddiff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.tsindex 7cdf5d79b29..8d6fbe52157 100644--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts@@ -14,6 +14,7 @@ import {type CardDependencyNode,DEPENDENCY_TYPES,type DashboardDependencyNode,+ type DataAppDependencyNode,type DependencyGraph,type DependencyNode,type DocumentDependencyNode,@@ -210,6 +211,13 @@ function provideActionDependencyNodeTags(];}+function provideDataAppDependencyNodeTags(+ node: DataAppDependencyNode,+): TagDescription<EnterpriseTagType>[] {+ // the data app endpoints tag apps by their slug, not their id+ return [idTag("data-app", node.data.name)];+}+export function provideDependencyNodeTags(node: DependencyNode,): TagDescription<EnterpriseTagType>[] {@@ -234,6 +242,8 @@ export function provideDependencyNodeTags(return provideMeasureDependencyNodeTags(node);case "action":return provideActionDependencyNodeTags(node);+ case "data-app":+ return provideDataAppDependencyNodeTags(node);}}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.tsindex 11ad1e64329..f5cbabd6ad7 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@@ -37,5 +37,7 @@ export function getHeaderLabel(return t`Measures that use ${nodeLabel}`;case "action":return t`Data actions that use ${nodeLabel}`;+ case "data-app":+ return t`Data apps that use ${nodeLabel}`;}}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.tsxindex 3a410512332..385f31b1f5e 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@@ -2,11 +2,15 @@ import { useMemo } from "react";import { t } from "ttag";import {+ type EntityPickerCustomFolder,EntityPickerModal,type OmniPickerItem,} from "metabase/common/components/Pickers";+import { useDataApps } from "metabase-enterprise/dependencies/hooks/use-data-apps";import type { DependencyEntry, DependencyNode } from "metabase-types/api";+import { getNodeIconWithType } from "../../../../utils";+import {ENTITY_PICKER_OPTIONS,ENTRY_PICKER_MODELS,@@ -28,6 +32,30 @@ export function EntryPickerModal({return value != null ? getEntryPickerItem(value) : undefined;}, [value]);+ const { data: dataApps = [], isLoading: isLoadingDataApps } = useDataApps();++ // data apps aren't collection items, so the picker can't list them itself+ const customFolders = useMemo(+ (): EntityPickerCustomFolder[] =>+ dataApps.length > 0+ ? [+ {+ id: "data-apps",+ name: t`Data apps`,+ items: dataApps.map((dataApp) => ({+ id: dataApp.id,+ name: dataApp.display_name,+ icon: getNodeIconWithType("data-app"),+ isSelected:+ value?.type === "data-app" && value.id === dataApp.id,+ onSelect: () => onChange({ id: dataApp.id, type: "data-app" }),+ })),+ },+ ]+ : [],+ [dataApps, value, onChange],+ );+const handleItemSelect = (item: OmniPickerItem) => {const value = getEntryPickerValue(item);if (value != null) {@@ -39,6 +67,8 @@ export function EntryPickerModal({<EntityPickerModaltitle={t`Pick an item to see its dependencies`}models={ENTRY_PICKER_MODELS}+ customFolders={customFolders}+ isLoadingCustomFolders={isLoadingDataApps}value={selectedItem}options={ENTITY_PICKER_OPTIONS}recentsContext={RECENTS_CONTEXT}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.unit.spec.tsxnew file mode 100644index 00000000000..44100d80fb0--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/EntryPickerModal.unit.spec.tsx@@ -0,0 +1,200 @@+import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";++import {+ setupCollectionByIdEndpoint,+ setupCollectionItemsEndpoint,+ setupCollectionsEndpoints,+ setupDatabasesEndpoints,+ setupListDataAppsEndpoint,+ setupRecentViewsAndSelectionsEndpoints,+ setupRootCollectionItemsEndpoint,+} from "__support__/server-mocks";+import { mockSettings } from "__support__/settings";+import { createMockState } from "__support__/state";+import {+ act,+ mockGetBoundingClientRect,+ renderWithProviders,+ screen,+ waitFor,+} from "__support__/ui";+import { defer } from "metabase/utils/promise";+import { EnterpriseApi } from "metabase-enterprise/api";+import { listTag } from "metabase-enterprise/api/tags";+import type {+ DataApp,+ DependencyEntry,+ DependencyNode,+} from "metabase-types/api";+import {+ createMockCollection,+ createMockDataApp,+ createMockDataAppDependencyNode,+ createMockTokenFeatures,+} from "metabase-types/api/mocks";++import { EntryPickerModal } from "./EntryPickerModal";++const OWLS = createMockDataApp({ id: 8, name: "owls", display_name: "Owls" });++// The current user's personal collection, which the picker fetches for its root list.+const PERSONAL_COLLECTION = createMockCollection({+ id: 1,+ name: "Bobby Tables's Personal Collection",+ personal_owner_id: 1,+});++type SetupOpts = {+ dataApps?: DataApp[];+ hasDataApps?: boolean;+ value?: DependencyNode | null;+};++function setup({+ dataApps = [OWLS],+ hasDataApps = true,+ value = null,+}: SetupOpts = {}) {+ mockGetBoundingClientRect();+ setupListDataAppsEndpoint(dataApps);+ setupDatabasesEndpoints([]);+ setupRecentViewsAndSelectionsEndpoints([], ["selections"]);+ setupCollectionsEndpoints({+ collections: [],+ rootCollection: createMockCollection({ id: "root", name: "Our analytics" }),+ });+ setupRootCollectionItemsEndpoint({ rootCollectionItems: [] });+ setupCollectionByIdEndpoint({ collections: [PERSONAL_COLLECTION] });+ setupCollectionItemsEndpoint({+ collection: PERSONAL_COLLECTION,+ collectionItems: [],+ });++ const onChange = jest.fn<void, [DependencyEntry]>();+ const { store } = renderWithProviders(+ <EntryPickerModal value={value} onChange={onChange} onClose={jest.fn()} />,+ {+ storeInitialState: createMockState({+ settings: mockSettings({+ "token-features": createMockTokenFeatures({+ "data-apps": hasDataApps,+ }),+ }),+ }),+ },+ );+ return { onChange, store };+}++describe("EntryPickerModal", () => {+ it("picks a data app from the Data apps folder as the entry", async () => {+ const { onChange } = setup();++ await userEvent.click(await screen.findByText("Data apps"));+ await userEvent.click(await screen.findByText("Owls"));++ expect(onChange).toHaveBeenCalledWith({ id: 8, type: "data-app" });+ });++ it("opens on the data app whose graph is shown, selected", async () => {+ const HERONS = createMockDataApp({+ id: 9,+ name: "herons",+ display_name: "Herons",+ });+ setup({+ dataApps: [OWLS, HERONS],+ value: createMockDataAppDependencyNode({ id: OWLS.id }),+ });++ await waitFor(() => {+ expect(screen.getByRole("link", { name: /Owls/ })).toHaveAttribute(+ "data-active",+ "true",+ );+ });+ expect(screen.getByRole("link", { name: /Data apps/ })).toHaveAttribute(+ "data-active",+ "true",+ );+ expect(screen.getByRole("link", { name: /Herons/ })).not.toHaveAttribute(+ "data-active",+ );+ });++ it("shows no folder until the app list loads, then opens on the data app", async () => {+ const appsResponse = defer<DataApp[]>();+ fetchMock.get("path:/api/ee/apps", () => appsResponse.promise);+ setup({ value: createMockDataAppDependencyNode({ id: OWLS.id }) });++ // The root collection is the last thing the root list asks for besides the app list.+ await waitFor(() => {+ expect(fetchMock.callHistory.called("path:/api/collection/root")).toBe(+ true,+ );+ });+ await expect(+ screen.findByRole("link", { name: /Our analytics/ }, { timeout: 500 }),+ ).rejects.toThrow();++ appsResponse.resolve([OWLS]);++ await waitFor(() => {+ expect(screen.getByRole("link", { name: /Owls/ })).toHaveAttribute(+ "data-active",+ "true",+ );+ });+ });++ it("keeps the folder the user opened when the app list changes", async () => {+ let dataApps = [OWLS];+ fetchMock.get("path:/api/ee/apps", () => dataApps);+ const { store } = setup({+ value: createMockDataAppDependencyNode({ id: OWLS.id }),+ });++ await waitFor(() => {+ expect(screen.getByRole("link", { name: /Owls/ })).toHaveAttribute(+ "data-active",+ "true",+ );+ });+ await userEvent.click(screen.getByRole("link", { name: /Our analytics/ }));+ dataApps = [];+ act(() => {+ store.dispatch(EnterpriseApi.util.invalidateTags([listTag("data-app")]));+ });++ await waitFor(() => {+ expect(screen.queryByText("Data apps")).not.toBeInTheDocument();+ });+ expect(screen.getByRole("link", { name: /Our analytics/ })).toHaveAttribute(+ "data-active",+ "true",+ );+ });++ it("has no Data apps folder when the user has no data apps", async () => {+ setup({ dataApps: [] });++ await screen.findByText("Our analytics");+ await waitFor(() => {+ expect(+ fetchMock.callHistory.called("path:/api/ee/apps", { method: "GET" }),+ ).toBe(true);+ });+ expect(screen.queryByText("Data apps")).not.toBeInTheDocument();+ });++ it("has no Data apps folder without the data apps feature", async () => {+ setup({ hasDataApps: false });++ await screen.findByText("Our analytics");+ expect(screen.queryByText("Data apps")).not.toBeInTheDocument();+ expect(+ fetchMock.callHistory.called("path:/api/ee/apps", { method: "GET" }),+ ).toBe(false);+ });+});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/EntrySearchInput.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/EntrySearchInput.unit.spec.tsxnew file mode 100644index 00000000000..bfeaccd231c--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/EntrySearchInput.unit.spec.tsx@@ -0,0 +1,92 @@+import userEvent from "@testing-library/user-event";++import {+ setupRecentViewsEndpoints,+ setupSearchEndpoints,+} from "__support__/server-mocks";+import { renderWithProviders, screen } from "__support__/ui";+import type { DependencyEntry, SearchResult } from "metabase-types/api";+import { createMockSearchResult } from "metabase-types/api/mocks";++import { SEARCH_MODELS } from "../constants";++import { EntrySearchInput } from "./EntrySearchInput";++const BIRD_CARD = createMockSearchResult({+ id: 3,+ name: "Bird counts",+ model: "card",+});++const BIRD_APP = createMockSearchResult({+ id: 7,+ name: "Bird sightings",+ model: "data-app",+});++type SetupOpts = {+ searchResults?: SearchResult[];+};++function setup({ searchResults = [BIRD_CARD, BIRD_APP] }: SetupOpts = {}) {+ setupRecentViewsEndpoints([]);+ setupSearchEndpoints(searchResults);+ const onEntryChange = jest.fn<void, [DependencyEntry]>();++ renderWithProviders(+ <EntrySearchInput+ searchModels={SEARCH_MODELS}+ isGraphFetching={false}+ onEntryChange={onEntryChange}+ onSearchModelsChange={jest.fn()}+ onPickerOpen={jest.fn<void, []>()}+ />,+ );++ return { onEntryChange };+}++describe("EntrySearchInput", () => {+ it("finds data apps in the search index, and picks one as the entry", async () => {+ const { onEntryChange } = setup();++ await userEvent.type(+ screen.getByPlaceholderText("Pick an item to see its dependencies"),+ "bird",+ );++ await screen.findByRole("option", { name: /Bird sightings/ });+ expect(+ screen.getAllByRole("option").map((option) => option.textContent?.trim()),+ ).toEqual(["Bird counts", "Bird sightings", "Browse all"]);++ await userEvent.click(+ screen.getByRole("option", { name: /Bird sightings/ }),+ );+ expect(onEntryChange).toHaveBeenCalledTimes(1);+ expect(onEntryChange).toHaveBeenCalledWith({ id: 7, type: "data-app" });+ });++ it("offers a data apps filter when the search finds data apps", async () => {+ setup();++ await userEvent.click(screen.getByRole("button", { name: "Filter" }));++ expect(+ await screen.findByRole("checkbox", { name: "Data apps" }),+ ).toBeInTheDocument();+ });++ it("offers no data apps filter when the search finds none", async () => {+ setup({ searchResults: [BIRD_CARD] });++ await userEvent.click(screen.getByRole("button", { name: "Filter" }));++ expect(+ await screen.findByRole("checkbox", { name: "Questions" }),+ ).toBeInTheDocument();+ expect(+ screen.queryByRole("checkbox", { name: "Data apps" }),+ ).not.toBeInTheDocument();+ });+});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.tsindex 5f5cbe56c9d..520b8e54c93 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@@ -19,6 +19,7 @@ export function getSearchModelItems(data: SearchResponse): SearchModelItem[] {dashboard: t`Dashboards`,document: t`Documents`,segment: t`Segments`,+ "data-app": t`Data apps`,};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.tsindex e8860e86ea2..8a7fdb89df7 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@@ -12,6 +12,7 @@ export const ENABLED_SEARCH_MODELS = ["dashboard","document","segment",+ "data-app",] as const satisfies SearchModel[];export const ENABLED_SEARCH_MODEL_TO_GROUP_TYPE: Record<@@ -26,6 +27,7 @@ export const ENABLED_SEARCH_MODEL_TO_GROUP_TYPE: Record<dashboard: "dashboard",document: "document",segment: "segment",+ "data-app": "data-app",};export const SEARCH_MODELS: SearchModel[] = ENABLED_SEARCH_MODELS;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.tsdeleted file mode 100644index e60b79cd92c..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts+++ /dev/null@@ -1,107 +0,0 @@-import { c, msgid, ngettext, t } from "ttag";--import type { DependencyNode } from "metabase-types/api";--import type { DependentGroup } from "../../../types";--export function getDependentGroups(node: DependencyNode): DependentGroup[] {- const {- question = 0,- model = 0,- metric = 0,- table = 0,- transform = 0,- snippet = 0,- dashboard = 0,- document = 0,- sandbox = 0,- segment = 0,- measure = 0,- action = 0,- } = node.dependents_count ?? {};-- const groups: DependentGroup[] = [- { type: "question", count: question },- { type: "model", count: model },- { type: "metric", count: metric },- { type: "table", count: table },- { type: "transform", count: transform },- { type: "snippet", count: snippet },- { type: "dashboard", count: dashboard },- { type: "document", count: document },- { type: "sandbox", count: sandbox },- { type: "segment", count: segment },- { type: "measure", count: measure },- { type: "action", count: action },- ];-- return groups.filter(({ count }) => count !== 0);-}--export function getDependencyGroupTitle(- node: DependencyNode,- groups: DependentGroup[],-) {- if (node.type === "sandbox") {- return t`Restricts table data`;- }- if (groups.length === 0) {- return t`Nothing uses this`;- }- if (node.type === "transform") {- return t`Generates`;- }- return t`Used by`;-}--export function getDependentGroupLabel({- type,- count,-}: DependentGroup): string {- switch (type) {- case "question":- return ngettext(msgid`${count} question`, `${count} questions`, count);- case "model":- return ngettext(msgid`${count} model`, `${count} models`, count);- case "metric":- return ngettext(msgid`${count} metric`, `${count} metrics`, count);- case "table":- return ngettext(msgid`${count} table`, `${count} tables`, count);- case "transform":- return ngettext(msgid`${count} transform`, `${count} transforms`, count);- case "snippet":- return ngettext(- msgid`${count} SQL snippet`,- `${count} SQL snippets`,- 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,- );- case "segment":- return c("{0} is the number of segments").ngettext(- msgid`${count} segment`,- `${count} segments`,- count,- );- case "measure":- return c("{0} is the number of measures").ngettext(- msgid`${count} measure`,- `${count} measures`,- count,- );- case "action":- return c("{0} is the number of data actions").ngettext(- msgid`${count} data action`,- `${count} data actions`,- count,- );- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/index.tsnew file mode 100644index 00000000000..0fb4ac66ae3--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/index.ts@@ -0,0 +1 @@+export { useDataApps } from "./use-data-apps";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/use-data-apps.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/use-data-apps.tsnew file mode 100644index 00000000000..8f59b4e0572--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-data-apps/use-data-apps.ts@@ -0,0 +1,12 @@+import { useHasTokenFeature } from "metabase/common/hooks";+import { useListDataAppsQuery } from "metabase-enterprise/api";++/**+ * The data apps the user can read. Without the data apps feature, or with `skip`, it sends no+ * request; `hasDataApps` says whether the instance has the feature.+ */+export function useDataApps({ skip = false }: { skip?: boolean } = {}) {+ const hasDataApps = useHasTokenFeature("data-apps");+ const query = useListDataAppsQuery(undefined, { skip: skip || !hasDataApps });+ return { ...query, hasDataApps };+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.tsindex eb352808ec1..f04d7a28509 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts@@ -2,6 +2,7 @@ import { c, msgid, ngettext, t } from "ttag";import {getCollectionPathAsArray,+ isDataAppCollection,isRootCollection,} from "metabase/common/collections/utils";import * as Urls from "metabase/urls";@@ -56,6 +57,7 @@ export function getNodeId(export function getNodeLabel(node: DependencyNode): string {switch (node.type) {case "table":+ case "data-app":return node.data.display_name;case "sandbox":return node.data.table?.display_name ?? t`Row and column security rule`;@@ -124,6 +126,8 @@ export function getNodeIconWithType(return "ruler";case "action":return "bolt";+ case "data-app":+ return "app";}}@@ -138,9 +142,20 @@ function getCardLinkLabel(cardType: CardType): string {}}+function isInDataAppCollection(collection: Collection | null | undefined) {+ return (+ collection !== null &&+ collection !== undefined &&+ isDataAppCollection(collection)+ );+}+export function getNodeLink(node: DependencyNode): NodeLink | null {switch (node.type) {case "card":+ if (isInDataAppCollection(node.data.collection)) {+ return null;+ }return {label: getCardLinkLabel(node.data.type),url: Urls.card({@@ -217,9 +232,15 @@ export function getNodeLink(node: DependencyNode): NodeLink | null {url: Urls.dataStudioSnippet(node.id),};case "action":- return node.data.model_id == null+ return node.data.model_id == null &&+ !isInDataAppCollection(node.data.collection)? { label: t`View this action`, url: Urls.dataStudioAction(node.id) }: null;+ case "data-app":+ return {+ label: t`View this data app`,+ url: Urls.dataApp(node.data.name),+ };}}@@ -351,6 +372,7 @@ export function getNodeLocationInfo(: null;case "transform":case "sandbox":+ case "data-app":return null;}}@@ -420,6 +442,8 @@ export function getNodeCreatedAt(node: DependencyNode): string | null {case "transform":case "action":return node.data.created_at;+ case "data-app":+ return node.data.created_at ?? null;default:return null;}@@ -615,6 +639,8 @@ export function getDependencyGroupType(return "snippet";case "action":return "action";+ case "data-app":+ return "data-app";}}@@ -649,6 +675,8 @@ export function getDependencyGroupTypeInfo(return { label: t`Measure`, color: "core-summarize" };case "action":return { label: t`Data action`, color: "text-secondary" };+ case "data-app":+ return { label: t`Data app`, color: "accent4" };}}@@ -701,6 +729,7 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {segment = 0,measure = 0,action = 0,+ "data-app": dataApp = 0,} = node.dependents_count ?? {};const groups: DependentGroup[] = [@@ -716,6 +745,7 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {{ type: "segment", count: segment },{ type: "measure", count: measure },{ type: "action", count: action },+ { type: "data-app", count: dataApp },];return groups.filter(({ count }) => count !== 0);@@ -796,6 +826,12 @@ export function getDependentGroupLabel({`${count} data actions`,count,);+ case "data-app":+ return c("{0} is the number of data apps").ngettext(+ msgid`${count} data app`,+ `${count} data apps`,+ count,+ );default:return ngettext(msgid`${count} entity`, `${count} entities`, count);}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.tsindex 3001d102282..0b928a29b2d 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts@@ -18,6 +18,8 @@ import {createMockCollection,createMockDashboardDependencyNode,createMockDashboardDependencyNodeData,+ createMockDataAppDependencyNode,+ createMockDataAppDependencyNodeData,createMockDatabase,createMockDocumentDependencyNode,createMockDocumentDependencyNodeData,@@ -140,6 +142,10 @@ describe("getNodeIcon", () => {node: createMockActionDependencyNode(),expectedIcon: "bolt",},+ {+ node: createMockDataAppDependencyNode(),+ expectedIcon: "app",+ },])("should get the $node.type node icon", ({ node, expectedIcon }) => {expect(getNodeIcon(node)).toBe(expectedIcon);});@@ -227,6 +233,15 @@ describe("getNodeLink", () => {url: "/data-studio/actions/1",},},+ {+ node: createMockDataAppDependencyNode({+ data: createMockDataAppDependencyNodeData({ name: "bird-sightings" }),+ }),+ expectedLink: {+ label: "View this data app",+ url: "/apps/bird-sightings",+ },+ },])("should get the $node.type node link", ({ node, expectedLink }) => {expect(getNodeLink(node)).toEqual(expectedLink);});@@ -237,6 +252,22 @@ describe("getNodeLink", () => {});expect(getNodeLink(node)).toBeNull();});++ it.each<DependencyNode>([+ createMockCardDependencyNode({+ data: createMockCardDependencyNodeData({+ collection: createMockCollection({ namespace: "data-apps" }),+ }),+ }),+ createMockActionDependencyNode({+ data: createMockActionDependencyNodeData({+ model_id: null,+ collection: createMockCollection({ namespace: "data-apps" }),+ }),+ }),+ ])("should not link the $type node in a data app's collection", (node) => {+ expect(getNodeLink(node)).toBeNull();+ });});describe("getNodeTypeInfo", () => {@@ -357,6 +388,15 @@ describe("getNodeLabel", () => {node: createMockSandboxDependencyNode({ data: { table_id: 1 } }),expected: "Row and column security rule",},+ {+ node: createMockDataAppDependencyNode({+ data: createMockDataAppDependencyNodeData({+ name: "bird-sightings",+ display_name: "Bird sightings",+ }),+ }),+ expected: "Bird sightings",+ },])("should get label for $node.type", ({ node, expected }) => {expect(getNodeLabel(node)).toBe(expected);});@@ -570,6 +610,11 @@ describe("getNodeLocationInfo", () => {const node = createMockTransformDependencyNode();expect(getNodeLocationInfo(node)).toBeNull();});++ it("should return null for data app", () => {+ const node = createMockDataAppDependencyNode();+ expect(getNodeLocationInfo(node)).toBeNull();+ });});describe("getNodeCreatedAt", () => {@@ -590,6 +635,14 @@ describe("getNodeCreatedAt", () => {node: createMockSandboxDependencyNode(),expected: null,},+ {+ node: createMockDataAppDependencyNode({+ data: createMockDataAppDependencyNodeData({+ created_at: "2021-02-03T00:00:00Z",+ }),+ }),+ expected: "2021-02-03T00:00:00Z",+ },])("should get created_at for $node.type", ({ node, expected }) => {expect(getNodeCreatedAt(node)).toBe(expected);});@@ -771,6 +824,10 @@ describe("getDependencyGroupType", () => {node: createMockActionDependencyNode(),expected: "action",},+ {+ node: createMockDataAppDependencyNode(),+ expected: "data-app",+ },])("should get group type for $node.type", ({ node, expected }) => {expect(getDependencyGroupType(node)).toBe(expected);});@@ -790,6 +847,10 @@ describe("getDependencyGroupTypeInfo", () => {groupType: "action",expected: { label: "Data action", color: "text-secondary" },},+ {+ groupType: "data-app",+ expected: { label: "Data app", color: "accent4" },+ },{groupType: "metric",expected: { label: "Metric", color: "core-summarize" },@@ -864,6 +925,13 @@ describe("getDependentGroups", () => {const node = createMockCardDependencyNode({ dependents_count: {} });expect(getDependentGroups(node)).toEqual([]);});++ it("should return the data apps that depend on the node", () => {+ const node = createMockCardDependencyNode({+ dependents_count: { "data-app": 2 },+ });+ expect(getDependentGroups(node)).toEqual([{ type: "data-app", count: 2 }]);+ });});describe("getDependencyGroupTitle", () => {@@ -898,6 +966,8 @@ describe("getDependentGroupLabel", () => {{ type: "model", count: 3, expected: "3 models" },{ type: "dashboard", count: 1, expected: "1 dashboard" },{ type: "dashboard", count: 2, expected: "2 dashboards" },+ { type: "data-app", count: 1, expected: "1 data app" },+ { type: "data-app", count: 2, expected: "2 data apps" },])("should format $count $type", ({ type, count, expected }) => {expect(getDependentGroupLabel({ type, count })).toBe(expected);});diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.tsindex 1589b02cd88..f824f0fb2d6 100644--- a/frontend/src/metabase-types/api/dependencies.ts+++ b/frontend/src/metabase-types/api/dependencies.ts@@ -7,6 +7,7 @@ import type { WritebackActionBase, WritebackActionType } from "./actions";import type { Card, CardType } from "./card";import type { Collection } from "./collection";import type { Dashboard } from "./dashboard";+import type { DataApp } from "./data-app";import type { Document } from "./document";import type { Measure } from "./measure";import type { PaginationRequest, PaginationResponse } from "./pagination";@@ -43,6 +44,7 @@ export const DEPENDENCY_TYPES = ["segment","measure","action",+ "data-app",] as const;export type DependencyType = (typeof DEPENDENCY_TYPES)[number];@@ -59,6 +61,7 @@ export const DEPENDENCY_GROUP_TYPES = ["segment","measure","action",+ "data-app",] as const;export type DependencyGroupType = (typeof DEPENDENCY_GROUP_TYPES)[number];@@ -235,6 +238,15 @@ export type ActionDependencyNode = BaseDependencyNode<ActionDependencyNodeData>;+// The API sends `description` and `created_at` to admins only.+export type DataAppDependencyNodeData = Pick<DataApp, "name" | "display_name"> &+ Partial<Pick<DataApp, "description" | "created_at">>;++export type DataAppDependencyNode = BaseDependencyNode<+ "data-app",+ DataAppDependencyNodeData+>;+export type DependencyNode =| TableDependencyNode| TransformDependencyNode@@ -245,7 +257,8 @@ export type DependencyNode =| SandboxDependencyNode| SegmentDependencyNode| MeasureDependencyNode- | ActionDependencyNode;+ | ActionDependencyNode+ | DataAppDependencyNode;export type AnalysisFindingErrorId = number;diff --git a/frontend/src/metabase-types/api/mocks/dependencies.ts b/frontend/src/metabase-types/api/mocks/dependencies.tsindex 48b90194345..1133f069939 100644--- a/frontend/src/metabase-types/api/mocks/dependencies.ts+++ b/frontend/src/metabase-types/api/mocks/dependencies.ts@@ -6,6 +6,8 @@ import type {CardDependencyNodeData,DashboardDependencyNode,DashboardDependencyNodeData,+ DataAppDependencyNode,+ DataAppDependencyNodeData,DependencyEdge,DependencyEntry,DependencyGraph,@@ -327,6 +329,30 @@ export function createMockActionDependencyNode(};}+export function createMockDataAppDependencyNodeData(+ opts?: Partial<DataAppDependencyNodeData>,+): DataAppDependencyNodeData {+ return {+ name: "data-app",+ display_name: "Data app",+ description: null,+ created_at: "2020-01-01T00:00:00Z",+ ...opts,+ };+}++export function createMockDataAppDependencyNode(+ opts?: Partial<DataAppDependencyNode>,+): DataAppDependencyNode {+ return {+ id: 1,+ type: "data-app",+ data: createMockDataAppDependencyNodeData(),+ dependents_count: {},+ ...opts,+ };+}+export function createMockListBrokenGraphNodesRequest(opts?: Partial<ListBreakingGraphNodesRequest>,): ListBreakingGraphNodesRequest {diff --git a/frontend/src/metabase-types/api/search.ts b/frontend/src/metabase-types/api/search.tsindex 5e17894df9c..367f75fca98 100644--- a/frontend/src/metabase-types/api/search.ts+++ b/frontend/src/metabase-types/api/search.ts@@ -32,6 +32,7 @@ const ENABLED_SEARCH_MODELS = ["document","exploration","transform",+ "data-app",] as const;export const SEARCH_MODELS = [...ENABLED_SEARCH_MODELS, "segment"] as const;@@ -123,6 +124,7 @@ export interface SearchResult<"last-edit-info"?: LastEditInfo;result_metadata?: Field[];collection_id?: CollectionId;+ data_app_slug?: string | null;}/**diff --git a/frontend/src/metabase/api/tags/constants.ts b/frontend/src/metabase/api/tags/constants.tsindex f0c3822574f..9474b94021c 100644--- a/frontend/src/metabase/api/tags/constants.ts+++ b/frontend/src/metabase/api/tags/constants.ts@@ -102,4 +102,5 @@ export const TAG_TYPE_MAPPING = {pulse: "subscription",transform: "transform",exploration: "exploration",+ "data-app": "data-app",} as const;diff --git a/frontend/src/metabase/common/components/InfoText/InfoText.unit.spec.tsx b/frontend/src/metabase/common/components/InfoText/InfoText.unit.spec.tsxindex 24f97598c47..f1816e8a28c 100644--- a/frontend/src/metabase/common/components/InfoText/InfoText.unit.spec.tsx+++ b/frontend/src/metabase/common/components/InfoText/InfoText.unit.spec.tsx@@ -135,6 +135,13 @@ describe("InfoText", () => {);});+ it("shows Data app for data apps", async () => {+ await setup({+ model: "data-app",+ });+ expect(screen.getByText("Data app")).toBeInTheDocument();+ });+it("shows segment's table name", async () => {await setup({model: "segment",diff --git a/frontend/src/metabase/common/components/InfoText/get-info-text.tsx b/frontend/src/metabase/common/components/InfoText/get-info-text.tsxindex 77e1ebb9600..e242aed9f3b 100644--- a/frontend/src/metabase/common/components/InfoText/get-info-text.tsx+++ b/frontend/src/metabase/common/components/InfoText/get-info-text.tsx@@ -25,6 +25,8 @@ export const getInfoText = (result: SearchResult): InfoTextData => {return getCollectionInfoText(result);case "database":return getDatabaseInfoText();+ case "data-app":+ return { label: t`Data app` };case "action":case "indexed-entity":return getActionInfoText(result);diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/CustomFolderItemList.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/CustomFolderItemList.tsxnew file mode 100644index 00000000000..2bcbdccb333--- /dev/null+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/CustomFolderItemList.tsx@@ -0,0 +1,38 @@+import { VirtualizedList } from "metabase/common/components/VirtualizedList";+import { useTranslateContent } from "metabase/content-translation/hooks";++import type { EntityPickerCustomFolder } from "../../types";++import { PickerColumn, PickerItemRow } from "./PickerItemRow";++export const CustomFolderItemList = ({+ folder,+}: {+ folder: EntityPickerCustomFolder;+}) => {+ const tc = useTranslateContent();++ return (+ <VirtualizedList+ Wrapper={PickerColumn}+ scrollTo={folder.items.findIndex((item) => item.isSelected)}+ estimatedItemSize={37}+ >+ {folder.items.map((item) => (+ <PickerItemRow+ key={item.id}+ label={tc(item.name)}+ icon={{+ name: item.icon,+ c: item.isSelected ? "text-primary-inverse" : "core-brand",+ }}+ isSelected={Boolean(item.isSelected)}+ // a custom folder is a root folder, so its items are the last column+ isCurrentLevel+ containerProps={{ pb: "xxs" }}+ onClick={item.onSelect}+ />+ ))}+ </VirtualizedList>+ );+};diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsxindex 75dbad191ea..7084c55a2b6 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx@@ -1,38 +1,23 @@-import type React from "react";import { useMemo } from "react";-import { EntityIcon } from "metabase/common/components/EntityIcon";import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";import { VirtualizedList } from "metabase/common/components/VirtualizedList";import { useTranslateContent } from "metabase/content-translation/hooks";import { getIsTenantUser } from "metabase/current-user";import { PLUGIN_MODERATION } from "metabase/plugins";import { useSelector } from "metabase/redux";-import {- Box,- type BoxProps,- Flex,- Icon,- NavLink,- type NavLinkProps,- Tooltip,-} from "metabase/ui";+import { type BoxProps, Flex, type NavLinkProps } from "metabase/ui";import { useOmniPickerContext } from "../../context";import type { OmniPickerItem } from "../../types";-import { isSelectedItem, useGetEntityPickerIcon } from "../../utils";+import {+ findCustomFolder,+ isSelectedItem,+ useGetEntityPickerIcon,+} from "../../utils";import { ItemListLoader } from "../ItemListLoader";-const PickerColumn = ({- children,- ...props-}: {- children: React.ReactNode;-}) => (- <Box p="1rem" {...props}>- {children}- </Box>-);+import { PickerColumn, PickerItemRow } from "./PickerItemRow";interface ItemListProps {pathIndex: number;@@ -55,6 +40,7 @@ export function ItemList({const {path,setPath,+ customFolders,isHiddenItem,isDisabledItem,isFolderItem,@@ -66,7 +52,13 @@ export function ItemList({const filteredItems = useMemo(() => {return items ? items.filter((i) => !isHiddenItem(i)) : items;}, [items, isHiddenItem]);- const isCurrentLevel = path.length - 2 === pathIndex;+ // A custom folder's selected item isn't in the path, so the folder's own column is a parent level.+ const selectedCustomFolder = selectedItem+ ? findCustomFolder(customFolders, selectedItem)+ : undefined;+ const isCurrentLevel =+ path.length - 2 === pathIndex &&+ !selectedCustomFolder?.items.some((item) => item.isSelected);const isTenantUser = useSelector(getIsTenantUser);const getEntityPickerIcon = useGetEntityPickerIcon();@@ -100,69 +92,43 @@ export function ItemList({>{filteredItems.map((item: OmniPickerItem, index) => {const isSelected = index === activeItemIndex;- const icon = getEntityPickerIcon(item, {- isSelected: isSelected && isCurrentLevel,- isTenantUser,- });- const isDisabled = isDisabledItem(item);- const tooltip = options.getItemTooltip?.(item);return (- <Box- data-testid="picker-item"+ <PickerItemRowkey={`${item.model}-${item.id}`}- {...containerProps}- >- <Tooltip label={tooltip} disabled={!tooltip} position="right">- <NavLink- w={"auto"}- disabled={isDisabled}- style={- isDisabled && tooltip ? { pointerEvents: "all" } : undefined- }- rightSection={- isFolderItem(item) ? (- <Icon name="chevronright" size={10} />- ) : null- }- mb={0}- label={- <Flex align="center">- {tc(item.name)}{" "}- <PLUGIN_MODERATION.ModerationStatusIcon- status={- "moderated_status" in item && item.moderated_status- }- filled- size={14}- ml="0.5rem"- />- </Flex>- }- active={isSelected}- leftSection={<EntityIcon {...icon} />}- onClick={(e: React.MouseEvent) => {- e.preventDefault(); // prevent form submission- e.stopPropagation(); // prevent parent onClick-- if (isDisabled) {- return;- }-- setPath((prevPath) => [- ...prevPath.slice(0, pathIndex + 1),- item,- ]);+ label={+ <Flex align="center">+ {tc(item.name)}{" "}+ <PLUGIN_MODERATION.ModerationStatusIcon+ status={"moderated_status" in item && item.moderated_status}+ filled+ size={14}+ ml="0.5rem"+ />+ </Flex>+ }+ icon={getEntityPickerIcon(item, {+ isSelected: isSelected && isCurrentLevel,+ isTenantUser,+ })}+ isSelected={isSelected}+ isCurrentLevel={isCurrentLevel}+ isFolder={isFolderItem(item)}+ isDisabled={isDisabledItem(item)}+ tooltip={options.getItemTooltip?.(item)}+ containerProps={containerProps}+ navLinkProps={navLinkProps?.(isSelected)}+ onClick={() => {+ setPath((prevPath) => [+ ...prevPath.slice(0, pathIndex + 1),+ item,+ ]);- if (!options?.hasConfirmButtons && isSelectableItem(item)) {- onChange(item);- }- }}- variant={isCurrentLevel ? "primary" : "secondary"}- {...navLinkProps?.(isSelected)}- />- </Tooltip>- </Box>+ if (!options?.hasConfirmButtons && isSelectableItem(item)) {+ onChange(item);+ }+ }}+ />);})}</VirtualizedList>diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemListRouter.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemListRouter.tsxindex 792e36d9e64..1139dfaf81e 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemListRouter.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemListRouter.tsx@@ -6,7 +6,11 @@ import {} from "metabase/common/components/Pickers";import { PLUGIN_TENANTS } from "metabase/plugins";+import { useOmniPickerContext } from "../../context";+import { findCustomFolder } from "../../utils";+import { CollectionItemList } from "./CollectionItemList";+import { CustomFolderItemList } from "./CustomFolderItemList";import { DashboardItemList } from "./DashboardItemList";import { DbItemList } from "./DbItemList";import { PersonalCollectionsItemList } from "./PersonalCollectionItemList";@@ -31,6 +35,8 @@ export const ItemListRouter = ({pathIndex: number;isLoading?: boolean;}) => {+ const { customFolders } = useOmniPickerContext();+if (isLoading) {return <ItemListLoader />;}@@ -40,6 +46,11 @@ export const ItemListRouter = ({return null;}+ const customFolder = findCustomFolder(customFolders, parentItem);+ if (customFolder) {+ return <CustomFolderItemList folder={customFolder} />;+ }+if (parentItem.model === "collection") {if (parentItem.id === PERSONAL_COLLECTIONS.id) {return <PersonalCollectionsItemList pathIndex={pathIndex} />;diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/PickerItemRow.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/PickerItemRow.tsxnew file mode 100644index 00000000000..f96926704e3--- /dev/null+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/PickerItemRow.tsx@@ -0,0 +1,79 @@+import type React from "react";++import { EntityIcon } from "metabase/common/components/EntityIcon";+import type { IconData } from "metabase/common/utils/icon";+import {+ Box,+ type BoxProps,+ Icon,+ NavLink,+ type NavLinkProps,+ Tooltip,+} from "metabase/ui";+import type { ColorName } from "metabase/ui/colors/types";++export const PickerColumn = ({+ children,+ ...props+}: {+ children: React.ReactNode;+}) => (+ <Box p="1rem" {...props}>+ {children}+ </Box>+);++type PickerItemRowProps = {+ label: React.ReactNode;+ icon: IconData & { c?: ColorName };+ isSelected: boolean;+ isCurrentLevel: boolean;+ isFolder?: boolean;+ isDisabled?: boolean;+ tooltip?: string;+ containerProps?: BoxProps;+ navLinkProps?: NavLinkProps;+ onClick: () => void;+};++export function PickerItemRow({+ label,+ icon,+ isSelected,+ isCurrentLevel,+ isFolder = false,+ isDisabled = false,+ tooltip,+ containerProps,+ navLinkProps,+ onClick,+}: PickerItemRowProps) {+ return (+ <Box data-testid="picker-item" {...containerProps}>+ <Tooltip label={tooltip} disabled={!tooltip} position="right">+ <NavLink+ w={"auto"}+ disabled={isDisabled}+ style={isDisabled && tooltip ? { pointerEvents: "all" } : undefined}+ rightSection={+ isFolder ? <Icon name="chevronright" size={10} /> : null+ }+ mb={0}+ label={label}+ active={isSelected}+ leftSection={<EntityIcon {...icon} />}+ onClick={(e: React.MouseEvent) => {+ e.preventDefault(); // prevent form submission+ e.stopPropagation(); // prevent parent onClick++ if (!isDisabled) {+ onClick();+ }+ }}+ variant={isCurrentLevel ? "primary" : "secondary"}+ {...navLinkProps}+ />+ </Tooltip>+ </Box>+ );+}diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResults.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResults.tsxindex 361b1e1245d..d6d33cd830b 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResults.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResults.tsx@@ -6,6 +6,7 @@ import { EntityIcon } from "metabase/common/components/EntityIcon";import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";import { VirtualizedList } from "metabase/common/components/VirtualizedList";import { NoObjectError } from "metabase/common/components/errors/NoObjectError";+import type { IconData } from "metabase/common/utils/icon";import { useGetIcon } from "metabase/hooks/use-icon";import { PLUGIN_LIBRARY, PLUGIN_MODERATION } from "metabase/plugins";import {@@ -19,6 +20,8 @@ import {} from "metabase/ui";import type {+ EntityPickerCustomFolder,+ EntityPickerCustomItem,OmniPickerItem,OmniPickerMeasureItem,OmniPickerTableItem,@@ -31,13 +34,20 @@ import {} from "../../hooks/use-current-search-scope";import { isSelectedItem, useGetEntityPickerIcon } from "../../utils";+export type CustomSearchResult = {+ folder: EntityPickerCustomFolder;+ item: EntityPickerCustomItem;+};+export const SearchResults = ({searchResults,+ customResults = [],isLoading,error,onClick,}: {searchResults: OmniPickerItem[];+ customResults?: CustomSearchResult[];isLoading?: boolean;error?: unknown;onClick?: (item: OmniPickerItem, index: number) => void;@@ -63,7 +73,7 @@ export const SearchResults = ({);}- if (searchResults.length === 0) {+ if (searchResults.length === 0 && customResults.length === 0) {return (<EmptyStatetitle={t`We didn't find anything`}@@ -72,6 +82,42 @@ export const SearchResults = ({);}+ const customRows = customResults.map(({ folder, item }) => (+ <Box+ key={`custom-${folder.id}-${item.id}`}+ pb="xxs"+ px="sm"+ data-testid="result-item"+ >+ <NavLink+ w={"auto"}+ mb={0}+ label={<Ellipsified maw="21rem">{item.name}</Ellipsified>}+ rightSection={+ <LocationLabel+ icon={{ name: "folder" }}+ text={folder.name}+ isSelected={Boolean(item.isSelected)}+ />+ }+ active={item.isSelected}+ leftSection={+ <EntityIcon+ name={item.icon}+ c={item.isSelected ? "text-primary-inverse" : "core-brand"}+ size="1rem"+ />+ }+ onClick={(e: React.MouseEvent) => {+ e.preventDefault(); // prevent form submission+ e.stopPropagation(); // prevent parent onClick+ item.onSelect();+ }}+ variant="primary"+ />+ </Box>+ ));+return (<VirtualizedListWrapper={({ children, ...props }) => (@@ -81,64 +127,68 @@ export const SearchResults = ({)}estimatedItemSize={66}>- {searchResults?.map((item, index) => {- const isSelected = isSelectedItem(item, selectedItem);- const isSelectable = isSelectableItem(item);-- return (- <Box- key={`${item.model}-${item.id}`}- pb="xxs"- px="sm"- data-testid="result-item"- data-model-type={item.model}- >- <NavLink- w={"auto"}- disabled={isDisabledItem(item) || !isSelectable}- rightSection={- <LocationInfo item={item} isSelected={isSelected} />- }- mb={0}- label={- <Flex align="center">- <Ellipsified maw="21rem">{item.name} </Ellipsified>- <PLUGIN_MODERATION.ModerationStatusIcon- status={"moderated_status" in item && item.moderated_status}- filled- size={14}- ml="0.5rem"+ {customRows.concat(+ searchResults.map((item, index) => {+ const isSelected = isSelectedItem(item, selectedItem);+ const isSelectable = isSelectableItem(item);++ return (+ <Box+ key={`${item.model}-${item.id}`}+ pb="xxs"+ px="sm"+ data-testid="result-item"+ data-model-type={item.model}+ >+ <NavLink+ w={"auto"}+ disabled={isDisabledItem(item) || !isSelectable}+ rightSection={+ <LocationInfo item={item} isSelected={isSelected} />+ }+ mb={0}+ label={+ <Flex align="center">+ <Ellipsified maw="21rem">{item.name} </Ellipsified>+ <PLUGIN_MODERATION.ModerationStatusIcon+ status={+ "moderated_status" in item && item.moderated_status+ }+ filled+ size={14}+ ml="0.5rem"+ />+ </Flex>+ }+ active={isSelected}+ leftSection={+ <EntityIcon+ {...getEntityPickerIcon(item, { isSelected })}+ size="1rem"/>- </Flex>- }- active={isSelected}- leftSection={- <EntityIcon- {...getEntityPickerIcon(item, { isSelected })}- size="1rem"- />- }- onClick={(e: React.MouseEvent) => {- e.preventDefault(); // prevent form submission- e.stopPropagation(); // prevent parent onClick-- if (onClick) {- onClick(item, index);}+ onClick={(e: React.MouseEvent) => {+ e.preventDefault(); // prevent form submission+ e.stopPropagation(); // prevent parent onClick- if (isSelectable) {- setPath((prevPath) => [...prevPath.slice(0, 1), item]);+ if (onClick) {+ onClick(item, index);+ }- if (!options?.hasConfirmButtons) {- onChange(item);+ if (isSelectable) {+ setPath((prevPath) => [...prevPath.slice(0, 1), item]);++ if (!options?.hasConfirmButtons) {+ onChange(item);+ }}- }- }}- variant="primary"- />- </Box>- );- })}+ }}+ variant="primary"+ />+ </Box>+ );+ }),+ )}</VirtualizedList>);};@@ -210,20 +260,32 @@ const LocationInfo = ({}return (- <Flex gap="xxs" align="center">- {iconProps && <Icon {...iconProps} size={12} />}- <Text- size="sm"- c={isSelected ? "text-secondary-inverse" : "text-secondary"}- >- <Ellipsified maw="12rem" data-testid="picker-item-location">- {itemText}- </Ellipsified>- </Text>- </Flex>+ <LocationLabel icon={iconProps} text={itemText} isSelected={isSelected} />);};+const LocationLabel = ({+ icon,+ text,+ isSelected,+}: {+ icon: IconData | null;+ text: string;+ isSelected: boolean;+}) => (+ <Flex gap="xxs" align="center">+ {icon && <Icon {...icon} size={12} />}+ <Text+ size="sm"+ c={isSelected ? "text-secondary-inverse" : "text-secondary"}+ >+ <Ellipsified maw="12rem" data-testid="picker-item-location">+ {text}+ </Ellipsified>+ </Text>+ </Flex>+);+export function SearchScopeSelector() {const { setSearchScope, options: pickerOptions } = useOmniPickerContext();const searchScope = useCurrentSearchScope();diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResultsItemList.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResultsItemList.tsxindex ee438b0fc21..aeafb18b962 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResultsItemList.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/SearchResultsItemList.tsx@@ -16,7 +16,11 @@ import { useOmniPickerContext } from "../../context";import { useCurrentSearchScope } from "../../hooks/use-current-search-scope";import type { OmniPickerItem } from "../../types";-import { SearchResults, SearchScopeSelector } from "./SearchResults";+import {+ type CustomSearchResult,+ SearchResults,+ SearchScopeSelector,+} from "./SearchResults";const makeIntoPickerItem = (item: SearchResult,@@ -104,11 +108,27 @@ export const SearchResultsItemList = () => {const {models,searchQuery,+ customFolders,isHiddenItem,isDisabledItem,isSelectableItem,searchParams,} = useOmniPickerContext();+ const searchScope = useCurrentSearchScope();++ const customResults = useMemo((): CustomSearchResult[] => {+ const query = searchQuery?.toLowerCase() ?? "";+ // Custom items are in no collection or database, so a search scoped to one leaves them out.+ const isUnscoped = searchScope === null || searchScope === "all";+ if (query.length === 0 || !isUnscoped) {+ return [];+ }+ return (customFolders ?? []).flatMap((folder) =>+ folder.items+ .filter((item) => item.name.toLowerCase().includes(query))+ .map((item) => ({ folder, item })),+ );+ }, [customFolders, searchQuery, searchScope]);const {data: results,@@ -154,6 +174,7 @@ export const SearchResultsItemList = () => {<SearchScopeSelector /><SearchResultssearchResults={filteredResults}+ customResults={customResults}isLoading={isFetching}error={error}onClick={onClick}diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsxindex d23491322cd..64577f7545d 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx@@ -1078,4 +1078,204 @@ describe("EntityPickerModal", () => {expect(within(searchList).getAllByRole("link")).toHaveLength(2);});});++ describe("Custom folders", () => {+ it("lists a caller's folder at the root and picks its items through their own handler", async () => {+ const onSelectOwls = jest.fn();+ const { onChange } = await setup({+ customFolders: [+ {+ id: "birds",+ name: "Birds",+ items: [+ { id: 1, name: "Owls", icon: "app", onSelect: onSelectOwls },+ { id: 2, name: "Herons", icon: "app", onSelect: jest.fn() },+ ],+ },+ ],+ });++ await userEvent.click(await screen.findByText("Birds"));+ await expectVisibleItem("Herons");+ await userEvent.click(await screen.findByText("Owls"));++ expect(onSelectOwls).toHaveBeenCalledTimes(1);+ expect(onChange).not.toHaveBeenCalled();+ });++ it("opens on the folder of a caller's selected item, with the item selected", async () => {+ await setup({+ customFolders: [+ {+ id: "birds",+ name: "Birds",+ items: [+ { id: 1, name: "Owls", icon: "app", onSelect: jest.fn() },+ {+ id: 2,+ name: "Herons",+ icon: "app",+ isSelected: true,+ onSelect: jest.fn(),+ },+ ],+ },+ ],+ });++ await expectActiveItem("Herons");+ await expectActiveItem("Birds");+ await expectInactiveItem("Owls");+ });++ it("lists a caller's folder above the personal collections", async () => {+ const personalCollection = createMockCollection({+ id: 1,+ name: "Bobby Tables's Personal Collection",+ personal_owner_id: 1,+ location: "/",+ });+ await setup({+ isAdmin: true,+ options: { hasRecents: false, hasDatabases: false },+ additionalCollections: [personalCollection],+ additionalCollectionItemEndpoints: [+ { collection: personalCollection, collectionItems: [] },+ ],+ customFolders: [{ id: "birds", name: "Birds", items: [] }],+ });++ const rootList = await screen.findByTestId("item-picker-level-0");+ await waitFor(() => {+ expect(+ within(rootList)+ .getAllByRole("link")+ .map((item) => item.textContent?.trim()),+ ).toEqual([+ "SQL Snippets",+ "Our analytics",+ "Birds",+ "Bobby Tables's Personal Collection",+ "All personal collections",+ ]);+ });+ });++ it("draws the folder of a caller's selected item as a parent of the selection", async () => {+ await setup({+ customFolders: [+ {+ id: "birds",+ name: "Birds",+ items: [+ { id: 1, name: "Owls", icon: "app", onSelect: jest.fn() },+ {+ id: 2,+ name: "Herons",+ icon: "app",+ isSelected: true,+ onSelect: jest.fn(),+ },+ ],+ },+ ],+ });++ await expectActiveItem("Herons");+ const activeItems = screen+ .getAllByRole("link")+ .filter((link) => link.getAttribute("data-active") === "true")+ .map((link) => ({+ name: link.textContent?.trim(),+ variant: link.getAttribute("data-variant"),+ }));+ expect(activeItems).toEqual([+ { name: "Birds", variant: "secondary" },+ { name: "Herons", variant: "primary" },+ ]);+ });++ it("keeps a built-in folder's own items when a caller's folder has the same id", async () => {+ await setup({+ customFolders: [+ {+ id: "root",+ name: "Birds",+ items: [{ id: 1, name: "Owls", icon: "app", onSelect: jest.fn() }],+ },+ ],+ });++ await userEvent.click(+ await screen.findByRole("link", { name: /Our analytics/ }),+ );++ await waitFor(() => {+ expect(+ within(screen.getByTestId("item-picker-level-1"))+ .getAllByRole("link")+ .map((item) => item.textContent?.trim()),+ ).toEqual(["First Collection", "Second Collection"]);+ });+ });++ it("finds a caller's item by its name in the search", async () => {+ await setup({+ customFolders: [+ {+ id: "birds",+ name: "Birds",+ items: [+ { id: 1, name: "Owls", icon: "app", onSelect: jest.fn() },+ { id: 2, name: "Herons", icon: "app", onSelect: jest.fn() },+ ],+ },+ ],+ });++ await userEvent.type(+ await screen.findByPlaceholderText("Search…"),+ "Owls",+ { delay: 50 },+ );+ await expectActiveItem('Search results for "Owls"');+ await expectVisibleItem("Search Result Card 3");++ const searchList = screen.getByTestId("item-picker-level-1");+ expect(+ within(searchList).getByRole("link", { name: /Owls/ }),+ ).toBeVisible();+ expect(+ within(searchList).queryByRole("link", { name: /Herons/ }),+ ).not.toBeInTheDocument();+ });++ it("leaves a caller's items out of a search scoped to a collection", async () => {+ await setup({+ customFolders: [+ {+ id: "birds",+ name: "Birds",+ items: [{ id: 1, name: "Owls", icon: "app", onSelect: jest.fn() }],+ },+ ],+ });++ await userEvent.click(await screen.findByText("Our analytics"));+ await userEvent.click(await screen.findByText("First Collection"));+ await userEvent.type(+ await screen.findByPlaceholderText("Search…"),+ "Owls",+ { delay: 50 },+ );+ await expectActiveItem('Search results for "Owls"');+ await expectVisibleItem("Search Result Card 3");++ expect(+ within(screen.getByTestId("item-picker-level-1")).queryByRole("link", {+ name: /Owls/,+ }),+ ).not.toBeInTheDocument();+ });+ });});diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/setup.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/setup.tsxindex 36a834de563..9fa50efd9a8 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/setup.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/setup.tsx@@ -35,6 +35,7 @@ import {createMockSearchResults,createMockTable,createMockTokenFeatures,+ createMockUser,} from "metabase-types/api/mocks";import {@@ -356,6 +357,7 @@ export type SetupOpts = Partial<EntityPickerModalProps> & {}>;libraryCollection?: Collection;libraryCollectionItems?: CollectionItem[];+ isAdmin?: boolean;};export const setup = async ({@@ -364,6 +366,7 @@ export const setup = async ({databases,libraryCollection,libraryCollectionItems,+ isAdmin = false,...rest}: SetupOpts = {}) => {process.env.OVERSCAN = "20"; // for VirtualizedList overscan@@ -379,13 +382,14 @@ export const setup = async ({? createMockLibraryCollectionItem(libraryCollection): undefined;- const state = libraryCollectionItem- ? createMockState({- settings: mockSettings({- "token-features": createMockTokenFeatures({ library: true }),- }),- })- : undefined;+ const state = createMockState({+ currentUser: createMockUser({ is_superuser: isAdmin }),+ ...(libraryCollectionItem && {+ settings: mockSettings({+ "token-features": createMockTokenFeatures({ library: true }),+ }),+ }),+ });if (libraryCollectionItem) {setupEnterpriseOnlyPlugin("library");diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/context.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/context.tsxindex 45283f3abf7..2f25b5ebf79 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/context.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/context.tsx@@ -29,6 +29,8 @@ export const EntityPickerProvider = ({const [path, setPath, { isLoadingPath }] = useGetPathFromValue({value: value.value,+ customFolders: value.customFolders,+ isLoadingCustomFolders: value.isLoadingCustomFolders,options: value.options,namespaces,models: getValidCollectionItemModels(value.models),@@ -42,6 +44,7 @@ export const EntityPickerProvider = ({() =>getItemFunctions({models: value.models,+ customFolders: value.customFolders,isFolderItem: value.isFolderItem,isHiddenItem: value.isHiddenItem,isDisabledItem: value.isDisabledItem,diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-path-from-value.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-path-from-value.tsindex 3f410ce3345..487f8966abc 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-path-from-value.ts+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-path-from-value.ts@@ -28,6 +28,7 @@ import type {} from "metabase-types/api";import type {+ EntityPickerCustomFolder,EntityPickerOptions,OmniPickerCollectionItem,OmniPickerCollectionItemValue,@@ -36,6 +37,7 @@ import type {OmniPickerTableValue,OmniPickerValue,} from "../types";+import { getCustomFolderItem } from "../utils";import { getRootCollectionItem, personalCollectionsRoot } from "./utils";@@ -92,11 +94,15 @@ const getDefaultPath = async ({export function useGetPathFromValue({value,+ customFolders,+ isLoadingCustomFolders = false,options,namespaces,models,}: {value?: OmniPickerValue;+ customFolders?: EntityPickerCustomFolder[];+ isLoadingCustomFolders?: boolean;options: EntityPickerOptions;namespaces: CollectionNamespace[];models: OmniPickerCollectionItem["model"][];@@ -113,12 +119,27 @@ export function useGetPathFromValue({useGetPersonalCollection();useDeepCompareEffect(() => {- if (isLoadingLibraryCollection || isLoadingPersonalCollection) {+ if (+ isLoadingLibraryCollection ||+ isLoadingPersonalCollection ||+ isLoadingCustomFolders+ ) {return;}setIsLoadingPath(true);+ // Not a dependency: once the picker has opened, a change to the custom folders must not replace+ // the folder the user is in.+ const selectedCustomFolder = customFolders?.find((folder) =>+ folder.items.some((item) => item.isSelected),+ );+ if (!value && selectedCustomFolder) {+ setPath([getCustomFolderItem(selectedCustomFolder)]);+ setIsLoadingPath(false);+ return;+ }+if (!value) {getDefaultPath({options,@@ -149,6 +170,7 @@ export function useGetPathFromValue({libraryCollection,isLoadingLibraryCollection,isLoadingPersonalCollection,+ isLoadingCustomFolders,]);return [path, setPath, { isLoadingPath }] as const;diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-root-items.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-root-items.tsindex d12c8192dd5..be97a48c7ee 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-root-items.ts+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/hooks/use-get-root-items.ts@@ -1,4 +1,4 @@-import { useState } from "react";+import { useMemo, useState } from "react";import { useDeepCompareEffect } from "react-use";import { t } from "ttag";@@ -31,6 +31,7 @@ import type {OmniPickerCollectionItem,OmniPickerItem,} from "../types";+import { getCustomFolderItem } from "../utils";import { getRootCollectionItem } from "./utils";@@ -49,7 +50,14 @@ const personalCollectionsRoot: OmniPickerCollectionItem = mergeLazily(* This will generate a list of the top level items for the entity picker*/export const useRootItems = () => {- const { options, models, searchQuery, namespaces } = useOmniPickerContext();+ const {+ options,+ models,+ searchQuery,+ namespaces,+ customFolders,+ isLoadingCustomFolders = false,+ } = useOmniPickerContext();const isAdmin = useSelector(getUserIsAdmin);const hasTenants = useSetting("use-tenants");const transformsEnabled = useHasTokenFeature("transforms-basic");@@ -83,6 +91,13 @@ export const useRootItems = () => {);const totalPersonalCollectionItems = personalCollectionItems?.total ?? 0;+ // Folders without their items: the effect below deep-compares its deps, and callers may pass new+ // item handlers on any render.+ const customRootItems = useMemo(+ () => (customFolders ?? []).map(getCustomFolderItem),+ [customFolders],+ );+useDeepCompareEffect(() => {const databases = databaseData?.data ?? [];setIsLoadingCollections(true);@@ -100,6 +115,7 @@ export const useRootItems = () => {transformsEnabled,currentUser,hasTenants,+ customRootItems,dispatch,}).then((rootItems) => {@@ -122,6 +138,7 @@ export const useRootItems = () => {transformsEnabled,currentUser,hasTenants,+ customRootItems,setIsLoadingCollections,dispatch,]);@@ -130,7 +147,8 @@ export const useRootItems = () => {isLoadingDatabases ||isLoadingCollections ||isLoadingPersonalCollection ||- isLoadingPersonalCollectionItems;+ isLoadingPersonalCollectionItems ||+ isLoadingCustomFolders;return { items: rootItems, isLoading };};@@ -149,6 +167,7 @@ async function getRootItems({transformsEnabled,currentUser,hasTenants,+ customRootItems,dispatch,}: {searchQuery?: string;@@ -164,6 +183,7 @@ async function getRootItems({transformsEnabled: boolean;currentUser: User | null;hasTenants: boolean;+ customRootItems: OmniPickerCollectionItem[];dispatch: DispatchFn;}): Promise<OmniPickerCollectionItem[]> {const collectionItems: OmniPickerCollectionItem[] = [];@@ -301,6 +321,8 @@ async function getRootItems({}}+ collectionItems.push(...customRootItems);+if (options?.hasPersonalCollections &&namespaces.includes(null) &&diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/types.tsindex 00c3e25bbca..3816735f7a4 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts@@ -9,6 +9,7 @@ import type {CollectionType,DashboardId,DatabaseId,+ IconName,Measure,MeasureId,NativeQuerySnippet,@@ -47,11 +48,38 @@ export type PickerItemFunctions = {isSelectableItem: (item: OmniPickerItem) => boolean;};+/**+ * A root folder a caller adds for things the picker doesn't know. Its `id` must be unique among the+ * caller's folders. A search that isn't scoped to a collection lists its matching items; recent+ * items never do. Picking one of its items calls that item's `onSelect` right away, instead of+ * `onChange`, also when the picker has confirm buttons.+ */+export type EntityPickerCustomFolder = {+ id: string;+ name: string;+ items: EntityPickerCustomItem[];+};++export type EntityPickerCustomItem = {+ id: string | number;+ name: string;+ icon: IconName;+ /**+ * Shows the item as selected. When the picker has no `value`, it opens on the first folder that+ * has a selected item.+ */+ isSelected?: boolean;+ onSelect: () => void;+};+export type EntityPickerProps = {onChange: (value: OmniPickerItem) => void;onClose: () => void;models: OmniPickerItem["model"][];namespaces?: CollectionNamespace[];+ customFolders?: EntityPickerCustomFolder[];+ /** While true, the picker waits for `customFolders` before it chooses the folder to open. */+ isLoadingCustomFolders?: boolean;options: EntityPickerOptions;searchParams?: Partial<SearchRequest>;value?: OmniPickerValue;diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/utils.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/utils.tsindex 441c31867a4..6b99a935ce2 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/utils.ts+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/utils.ts@@ -7,6 +7,7 @@ import type { CollectionNamespace, CollectionType } from "metabase-types/api";import { isObject } from "metabase-types/guards";import {+ type EntityPickerCustomFolder,type EntityPickerProps,type OmniPickerCollectionItem,type OmniPickerFolderItem,@@ -76,6 +77,28 @@ export const isSelectedItem = ();};+// Built-in root folders have ids such as "root" and "recents", which a caller's folder id must not+// take over.+const CUSTOM_FOLDER_ID_PREFIX = "custom-folder:";++export const getCustomFolderItem = (+ folder: EntityPickerCustomFolder,+): OmniPickerCollectionItem => ({+ id: `${CUSTOM_FOLDER_ID_PREFIX}${folder.id}`,+ model: "collection",+ name: folder.name,+ location: "/",+ can_write: false,+});++export const findCustomFolder = (+ customFolders: EntityPickerCustomFolder[] = [],+ item: OmniPickerItem,+): EntityPickerCustomFolder | undefined =>+ item.model === "collection"+ ? customFolders.find((folder) => getCustomFolderItem(folder).id === item.id)+ : undefined;+const isValidItem = (item: unknown): item is OmniPickerItem => {return (isObject(item) &&@@ -94,20 +117,28 @@ const isValidItem = (item: unknown): item is OmniPickerItem => {export function getItemFunctions({models,+ customFolders = [],isFolderItem,isHiddenItem,isDisabledItem,isSelectableItem,}: {models: EntityPickerProps["models"];+ customFolders?: EntityPickerProps["customFolders"];} & Partial<PickerItemFunctions>): PickerItemFunctions {const modelSet = new Set(models);+ const isCustomFolder = (item: OmniPickerItem) =>+ findCustomFolder(customFolders, item) !== undefined;const isFolderBase = (item: OmniPickerItem | unknown) => {if (!isValidItem(item)) {return false;}+ if (isCustomFolder(item)) {+ return true;+ }+if (item.model === OmniPickerFolderModel.Database ||item.model === OmniPickerFolderModel.Schema@@ -163,7 +194,7 @@ export function getItemFunctions({// selectable should be narrower than hidden or disabled because// intermediate items should not be disabled, but can't ultimately be selectedconst isSelectableBase = (item: OmniPickerItem) => {- if (!isValidItem(item)) {+ if (!isValidItem(item) || isCustomFolder(item)) {return false;}diff --git a/frontend/src/metabase/common/search/constants.ts b/frontend/src/metabase/common/search/constants.tsindex 7dd73430678..a7a3adf4450 100644--- a/frontend/src/metabase/common/search/constants.ts+++ b/frontend/src/metabase/common/search/constants.ts@@ -24,6 +24,7 @@ export const enabledSearchTypes: EnabledSearchModel[] = ["indexed-entity","document","exploration",+ "data-app",];export const SearchContextTypes = {diff --git a/frontend/src/metabase/common/utils/icon.ts b/frontend/src/metabase/common/utils/icon.tsindex 6f6927a7c06..6c81801f248 100644--- a/frontend/src/metabase/common/utils/icon.ts+++ b/frontend/src/metabase/common/utils/icon.ts@@ -65,6 +65,7 @@ export const modelIconMap: Record<IconModel, IconName> = {glossary: "glossary",exploration: "telescope",dataapp: "app",+ "data-app": "app",transformtest: "test_tube",};diff --git a/frontend/src/metabase/common/utils/model-names.ts b/frontend/src/metabase/common/utils/model-names.tsindex 783cf814833..f600715c49f 100644--- a/frontend/src/metabase/common/utils/model-names.ts+++ b/frontend/src/metabase/common/utils/model-names.ts@@ -47,6 +47,9 @@ const TRANSLATED_NAME_BY_MODEL_TYPE: Record<ModelNames, string> = {get transform() {return t`Transform`;},+ get "data-app"() {+ return t`Data app`;+ },get user() {return t`User`;},diff --git a/frontend/src/metabase/metabot/components/editor-extensions/MetabotMention/MetabotSuggestionNew.tsx b/frontend/src/metabase/metabot/components/editor-extensions/MetabotMention/MetabotSuggestionNew.tsxindex 7080b4fa8cf..215600559ee 100644--- a/frontend/src/metabase/metabot/components/editor-extensions/MetabotMention/MetabotSuggestionNew.tsx+++ b/frontend/src/metabase/metabot/components/editor-extensions/MetabotMention/MetabotSuggestionNew.tsx@@ -98,7 +98,8 @@ const MetabotMentionSuggestionComponent = forwardRef<model !== "action" &&model !== "segment" &&model !== "user" &&- model !== "measure",+ model !== "measure" &&+ model !== "data-app",);const shouldHide = useMemo(() => {diff --git a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsxindex d5de290ac0c..d3ed60aea93 100644--- a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx+++ b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx@@ -4,9 +4,11 @@ import fetchMock from "fetch-mock";import { screen, waitFor, within } from "__support__/ui";import * as Analytics from "metabase/analytics";import {+ createMockCollection,createMockDatabase,createMockRecentCollectionItem,createMockRecentTableItem,+ createMockSearchResult,} from "metabase-types/api/mocks";import { type CommonSetupProps, commonSetup } from "./setup";@@ -158,6 +160,43 @@ describe("PaletteResults", () => {).toBeInTheDocument();});+ it("should link a data app search result to its app", async () => {+ setup({+ query: "Link",+ searchItems: [+ createMockSearchResult({+ id: 7,+ model: "data-app",+ name: "Link Test",+ data_app_slug: "link-test",+ }),+ ],+ });++ expect(+ await screen.findByRole("link", { name: "Link Test" }),+ ).toHaveAttribute("href", "/apps/link-test");+ });++ it("should label a data app search result as a data app, not by a collection", async () => {+ setup({+ query: "Link",+ searchItems: [+ createMockSearchResult({+ id: 7,+ model: "data-app",+ name: "Link Test",+ collection: createMockCollection({ name: "Shorebirds" }),+ data_app_slug: "link-test",+ }),+ ],+ });++ const option = await screen.findByRole("option", { name: "Link Test" });+ expect(option).toHaveTextContent("Data app");+ expect(option).not.toHaveTextContent("Shorebirds");+ });+it("should display collections that search results are from", async () => {setup({query: "ques",diff --git a/frontend/src/metabase/palette/components/test/PaletteResults/setup.tsx b/frontend/src/metabase/palette/components/test/PaletteResults/setup.tsxindex e5d2ef21c85..99982823ffe 100644--- a/frontend/src/metabase/palette/components/test/PaletteResults/setup.tsx+++ b/frontend/src/metabase/palette/components/test/PaletteResults/setup.tsx@@ -24,6 +24,7 @@ import type {CollectionItem,Database,RecentItem,+ SearchResult,Settings,} from "metabase-types/api";import {@@ -136,7 +137,7 @@ export interface CommonSetupProps {query?: string;settings?: Partial<Settings>;recents?: RecentItem[];- searchItems?: CollectionItem[];+ searchItems?: (CollectionItem | SearchResult)[];isEE?: boolean;isAdmin?: boolean;databases?: Database[];diff --git a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx b/frontend/src/metabase/palette/hooks/useCommandPalette.tsxindex 465b6a4d5f3..a0442e5f32b 100644--- a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx+++ b/frontend/src/metabase/palette/hooks/useCommandPalette.tsx@@ -365,6 +365,9 @@ export const getSearchResultSubtext = (wrappedSearchResult: any) => {<SubtitleText>{wrappedSearchResult.dashboard.name}</SubtitleText></>);+ } else if (wrappedSearchResult.model === "data-app") {+ // A data app is in no collection, which getCollection would name as the root one.+ return <SubtitleText>{t`Data app`}</SubtitleText>;} else {return (<SubtitleText>{getCollection(wrappedSearchResult)?.name}</SubtitleText>diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-entity-data.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-entity-data.tsindex 6ad4f290a90..26092c02479 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-entity-data.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-entity-data.ts@@ -165,6 +165,7 @@ export const useEntityData = (}case "indexed-entity":case "exploration":+ case "data-app":case null:return { model, entity: null, isLoading: false, error: null };default:diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-smart-link-entity.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-smart-link-entity.tsindex 199bfcba969..00086a56957 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-smart-link-entity.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/use-smart-link-entity.ts@@ -117,6 +117,7 @@ const getLibraryEntity = ("user","indexed-entity","exploration",+ "data-app",null,),},diff --git a/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterContent.unit.spec.tsx b/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterContent.unit.spec.tsxindex d5915c0c667..5e90f2725da 100644--- a/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterContent.unit.spec.tsx+++ b/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterContent.unit.spec.tsx@@ -30,6 +30,7 @@ const MODEL_NAME: Record<EnabledSearchModel, string> = {document: "Document",exploration: "Research",transform: "Transform",+ "data-app": "Data app",};const TEST_TYPES: Array<EnabledSearchModel> = [diff --git a/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterDisplay.unit.spec.tsx b/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterDisplay.unit.spec.tsxindex 20db1530333..f4317812ca9 100644--- a/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterDisplay.unit.spec.tsx+++ b/frontend/src/metabase/search/components/filters/TypeFilter/TypeFilterDisplay.unit.spec.tsx@@ -18,6 +18,7 @@ const MODEL_TYPE_DISPLAY_NAMES: Record<EnabledSearchModel, string> = {document: "Document",exploration: "Research",transform: "Transform",+ "data-app": "Data app",};const setup = (value: TypeFilterProps) => {diff --git a/frontend/src/metabase/search/containers/SearchApp.unit.spec.tsx b/frontend/src/metabase/search/containers/SearchApp.unit.spec.tsxindex 91ced95c70d..a7446238aee 100644--- a/frontend/src/metabase/search/containers/SearchApp.unit.spec.tsx+++ b/frontend/src/metabase/search/containers/SearchApp.unit.spec.tsx@@ -45,6 +45,7 @@ const TYPE_FILTER_LABELS: Record<EnabledSearchModel, string> = {document: "Document",exploration: "Research",transform: "Transform",+ "data-app": "Data app",};const TEST_ITEMS: Partial<SearchResult>[] = [diff --git a/frontend/src/metabase/urls/modelToUrl.ts b/frontend/src/metabase/urls/modelToUrl.tsindex 9fdcfa871dc..9e3e13bcb52 100644--- a/frontend/src/metabase/urls/modelToUrl.ts+++ b/frontend/src/metabase/urls/modelToUrl.ts@@ -36,6 +36,7 @@ export type UrlableModel = {collection_id?: CollectionId | null;model_id?: CardId | null;table_id?: TableId;+ data_app_slug?: string | null;};const NOT_FOUND_URL = "/404";@@ -104,6 +105,11 @@ export function modelToUrl(item: UrlableModel): string {return dataStudioGlossary();case "dataapp":return dataApp(item.name);+ case "data-app":+ if (item.data_app_slug !== null && item.data_app_slug !== undefined) {+ return dataApp(item.data_app_slug);+ }+ return NOT_FOUND_URL;default:return NOT_FOUND_URL;}diff --git a/frontend/src/metabase/urls/modelToUrl.unit.spec.ts b/frontend/src/metabase/urls/modelToUrl.unit.spec.tsindex 8209f9bdaf0..d72cd133a1a 100644--- a/frontend/src/metabase/urls/modelToUrl.unit.spec.ts+++ b/frontend/src/metabase/urls/modelToUrl.unit.spec.ts@@ -116,4 +116,25 @@ describe("urls > modelToUrl", () => {}),).toBe("/404");});++ it("should return a data app URL for a data app search result, from its slug", () => {+ expect(+ modelToUrl({+ model: "data-app",+ name: "Bird Sightings",+ id: 7,+ data_app_slug: "bird-sightings",+ }),+ ).toBe("/apps/bird-sightings");+ });++ it("should return 404 for a data app without a slug", () => {+ expect(+ modelToUrl({+ model: "data-app",+ name: "Bird Sightings",+ id: 7,+ }),+ ).toBe("/404");+ });});diff --git a/src/metabase/data_apps/core.clj b/src/metabase/data_apps/core.cljindex 214e67d7ee5..c5be2fe7fdb 100644--- a/src/metabase/data_apps/core.clj+++ b/src/metabase/data_apps/core.clj@@ -7,3 +7,10 @@metabase-enterprise.data-apps.core[_request]nil)++(defenterprise visible-data-app-filter-select+ "A HoneySQL query of the ids of the data apps that the user described by `user-info` (`:user-id`, `:is-superuser?`)+ can read, or nil, meaning none, without the data apps feature."+ metabase-enterprise.data-apps.core+ [_user-info]+ nil)diff --git a/src/metabase/models/interface.clj b/src/metabase/models/interface.cljindex 9ec9ac31f52..bd05143615f 100644--- a/src/metabase/models/interface.clj+++ b/src/metabase/models/interface.clj@@ -623,6 +623,14 @@[](h2x/current-datetime-honeysql-form (mdb/db-type)))+(defn ->integer+ "Return a HoneySQL form casting `expr` to an integer in the app DB: `SIGNED` for MySQL/MariaDB, which have no+ `INTEGER` cast type."+ [expr]+ [:cast expr (case (mdb/db-type)+ :mysql :signed+ :integer)])+(defn current-timestamp"The current moment in UTC at the microsecond precision of the app DB's timestamp columns, so it reads back unchanged."[]diff --git a/src/metabase/search/appdb/query.clj b/src/metabase/search/appdb/query.cljindex 02b94a887f9..f2d2afca30b 100644--- a/src/metabase/search/appdb/query.clj+++ b/src/metabase/search/appdb/query.clj@@ -3,7 +3,7 @@`metabase.search.db` runs the queries, so this namespace must not require it (nor `metabase.search.appdb.index`)."(:require[honey.sql.helpers :as sql.helpers]- [metabase.app-db.core :as mdb]+ [metabase.models.interface :as mi][metabase.search.appdb.specialization.api :as specialization][metabase.search.filter :as search.filter][metabase.search.permissions :as search.permissions]))@@ -12,10 +12,8 @@"Add a `WHERE` clause to the query to only return tables the current user has access to.Also adds any CTEs required for permission filtering."[search-ctx qry]- (let [model-id-col [:cast :search_index.model_id (case (mdb/db-type)- :mysql :signed- :integer)]- {:keys [with clause]} (search.permissions/permitted-tables-clause search-ctx model-id-col)]+ (let [{:keys [with clause]} (search.permissions/permitted-tables-clause search-ctx+ (mi/->integer :search_index.model_id))](cond-> qry(seq with) (update :with (fnil into []) with)true (sql.helpers/where@@ -26,6 +24,15 @@[:= :search_index.model "table"]clause]]))))+(defn add-data-app-where-clauses+ "Add a `WHERE` clause to the query to only return data apps the current user can read."+ [search-ctx qry]+ (sql.helpers/where qry [:or+ [:= :search_index.model nil]+ [:!= :search_index.model "data-app"]+ (search.permissions/permitted-data-apps-clause search-ctx+ (mi/->integer :search_index.model_id))]))+(defn add-collection-join-and-where-clauses"Add a `WHERE` clause to the query to only return Collections the Current User has access to; join against Collection,so we can return its `:name`."@@ -52,6 +59,7 @@(concat[[:collection-permissions (partial add-collection-join-and-where-clauses search-ctx)][:table-permissions (partial add-table-where-clauses search-ctx)]+ [:data-app-permissions (partial add-data-app-where-clauses search-ctx)][:transform-source-type #(sql.helpers/where % (search.filter/transform-source-type-where-clausesearch-ctx:search_index.model@@ -80,13 +88,7 @@"The query returning the distinct `:model`s of the search index `index-table` with at least one visible result for`search-ctx`."[index-table search-ctx]- (->> (specialization/base-query index-table (:search-string search-ctx) search-ctx [[[:distinct :model] :model]])- (add-collection-join-and-where-clauses search-ctx)- (#(sql.helpers/where % (search.filter/transform-source-type-where-clause- search-ctx- :search_index.model- :search_index.source_type)))- (search.filter/with-filters search-ctx)))+ (base-filtered-query index-table search-ctx (:search-string search-ctx) [[[:distinct :model] :model]]))(defn- restrict-to-row[model id qry]diff --git a/src/metabase/search/config.clj b/src/metabase/search/config.cljindex 669e0834cbf..56492281f44 100644--- a/src/metabase/search/config.clj+++ b/src/metabase/search/config.clj@@ -1,6 +1,7 @@(ns metabase.search.config(:require[metabase.api.common :as api]+ [metabase.config.core :as config][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.permissions.core :as perms]@@ -43,7 +44,8 @@(def model->db-model"Mapping of model name to :db_model and :alias"- api/model->db-model)+ (cond-> api/model->db-model+ config/ee-available? (assoc "data-app" {:db-model :model/DataApp :alias :data-app})));; We won't need this once fully migrated to specs, but kept for now in case legacy cod falls out of sync(def excluded-models@@ -86,7 +88,10 @@(def models-search-order"The order of this list influences the order of the results: items earlier in thelist will be ranked higher."- ["dashboard" "metric" "segment" "measure" "indexed-entity" "card" "dataset" "collection" "table" "action" "document" "exploration" "transform" "database"])+ (cond-> ["dashboard" "metric" "segment" "measure" "indexed-entity" "card" "dataset" "collection" "table" "action"+ "document" "exploration" "transform"]+ config/ee-available? (conj "data-app")+ true (conj "database")))(assert (= all-models (set models-search-order)) "The models search order has to include all models")diff --git a/src/metabase/search/filter.clj b/src/metabase/search/filter.cljindex 27aa3dfeafe..07a14aa0f38 100644--- a/src/metabase/search/filter.clj+++ b/src/metabase/search/filter.clj@@ -200,7 +200,7 @@[:in :search_index.model_id (map str ids)];; NOTE: we limit id-based search to only a subset of the models;; TODO this should just become part of the model spec e.g. :search-by-id?- [:in :search_index.model ["card" "dataset" "metric" "dashboard" "action"]]]]])+ [:in :search_index.model ["card" "dataset" "metric" "dashboard" "action" "data-app"]]]]])[[:dashboard-questions [:and[:or;; leverage the fact that only card-related models populate this attributediff --git a/src/metabase/search/in_place/filter.clj b/src/metabase/search/in_place/filter.cljindex 97c5fa2b89b..f5a39239125 100644--- a/src/metabase/search/in_place/filter.clj+++ b/src/metabase/search/in_place/filter.clj@@ -72,8 +72,8 @@[model archived?][:= (search.config/column-with-model-alias model :archived) archived?])-;; Databases, transforms, and indexed-entities can't be archived-(doseq [model ["database" "transform" "indexed-entity"]]+;; Databases, transforms, indexed-entities, and data apps can't be archived+(doseq [model ["database" "transform" "indexed-entity" "data-app"]](defmethod archived-clause model[_model archived?](if archived?@@ -148,7 +148,7 @@[_filter model query creator-ids](sql.helpers/where query (default-created-by-filter-clause model creator-ids))))-(doseq [model ["card" "dataset" "metric" "dashboard" "action"]]+(doseq [model ["card" "dataset" "metric" "dashboard" "action" "data-app"]](defmethod build-optional-filter-query [:id model][_filter model query ids](sql.helpers/where query [:in (search.config/column-with-model-alias model :id) ids])))@@ -276,7 +276,7 @@[:and [:>= dt-col start] [:< dt-col end]])))(doseq [model ["collection" "database" "table" "dashboard" "card" "dataset" "metric" "action" "document"- "transform" "measure" "exploration"]]+ "transform" "measure" "exploration" "data-app"]](defmethod build-optional-filter-query [:created-at model][_filter model query created-at](sql.helpers/where query (date-range-filter-clausediff --git a/src/metabase/search/in_place/legacy.clj b/src/metabase/search/in_place/legacy.cljindex 068b3a569aa..3fbd7f109b6 100644--- a/src/metabase/search/in_place/legacy.clj+++ b/src/metabase/search/in_place/legacy.clj@@ -139,7 +139,9 @@;; returned for Table:is_published :boolean:data_authority :text- :data_layer :text))+ :data_layer :text+ ;; returned for DataApp+ :data_app_slug :text))(def ^:private SearchColumn"Enum of every key of [[all-search-columns]]."@@ -293,10 +295,11 @@(map first);; data_authority/data_layer are curation signals, not name/text fields —;; exclude them from exact-match ranking (and to keep in-place ordering stable).+ ;; data_app_slug repeats a data app's name.(remove #{:collection_authority_level :moderated_status:initial_sync_status :pk_ref :location:collection_location :data_authority- :data_layer :document}))+ :data_layer :document :data_app_slug}))case-clauses (as-> columns-to-search <>(map (fn [col] [:like [:lower col] match]) <>)(interleave <> (repeat [:inline 0]))@@ -454,6 +457,10 @@[_][:id :name :description :created_at :updated_at])+(defmethod columns-for-model "data-app"+ [_]+ [:id :name :display_name :description :created_at :updated_at [:name :data_app_slug]])+(mu/defn- select-clause-for-model :- [:sequential HoneySQLColumn]"The search query uses a `union-all` which requires that there be the same number of columns in each of the segmentsof the query. This function will take the columns for `model` and will inject constant `nil` values for any column@@ -562,6 +569,13 @@[_model search-ctx](base-query-for-model "transform" search-ctx))+(defmethod search-query-for-model "data-app"+ [model search-ctx]+ (-> (base-query-for-model model search-ctx)+ (sql.helpers/where (search.permissions/permitted-data-apps-clause+ search-ctx+ (search.config/column-with-model-alias model :id)))))+(defmethod search-query-for-model "database"[model search-ctx](-> (base-query-for-model model search-ctx)diff --git a/src/metabase/search/in_place/search_model.clj b/src/metabase/search/in_place/search_model.cljindex 4acb8619411..f66d82ca792 100644--- a/src/metabase/search/in_place/search_model.clj+++ b/src/metabase/search/in_place/search_model.clj@@ -71,6 +71,12 @@:display_name:description])+(defmethod searchable-columns "data-app"+ [_ _]+ [:name+ :display_name+ :description])+(defmethod searchable-columns "transform"[_ search-native-query](cond-> [:namediff --git a/src/metabase/search/permissions.clj b/src/metabase/search/permissions.cljindex d77ff1df2f5..5fa4efc467f 100644--- a/src/metabase/search/permissions.clj+++ b/src/metabase/search/permissions.clj@@ -1,6 +1,7 @@(ns metabase.search.permissions(:require[metabase.collections.models.collection :as collection]+ [metabase.data-apps.core :as data-apps][metabase.models.interface :as mi][metabase.permissions.core :as perms][metabase.search.config :refer [SearchContext]]@@ -48,3 +49,11 @@:perms/create-queries :query-builder}{:include-published-via-collection? true:active-only? true}))++(mu/defn permitted-data-apps-clause+ "Build the WHERE clause that keeps the data apps the given user can read: none without the data apps feature."+ [{:keys [current-user-id is-superuser?]} :- SearchContext data-app-id-col :- [:or :keyword [:vector :keyword]]]+ (if-let [readable-ids (data-apps/visible-data-app-filter-select {:user-id current-user-id+ :is-superuser? is-superuser?})]+ [:in data-app-id-col readable-ids]+ [:= [:inline 0] [:inline 1]]))diff --git a/src/metabase/search/semantic/core.clj b/src/metabase/search/semantic/core.cljindex 0a6eddfa265..849df683e71 100644--- a/src/metabase/search/semantic/core.clj+++ b/src/metabase/search/semantic/core.clj@@ -1,7 +1,6 @@(ns metabase.search.semantic.core(:require[metabase.premium-features.core :refer [defenterprise]]- [metabase.search.config :as search.config][metabase.search.engine :as search.engine][metabase.search.ingestion :as search.ingestion][metabase.util.log :as log]))@@ -75,8 +74,12 @@(results search-ctx))(defmethod search.engine/model-set :search.engine/semantic- [_search-ctx]- search.config/all-models)+ [search-ctx]+ ;; The fallback engine applies the permission filters: the app DB index, or in-place search on app DBs that cannot+ ;; hold the index. A semantic match does not need the search terms, so they must not narrow the types.+ (search.engine/model-set (assoc search-ctx+ :search-engine (search.engine/fallback-engine :search.engine/semantic)+ :search-string nil)))(defmethod search.engine/diagnose :search.engine/semantic[search-ctx expected-model expected-id]diff --git a/src/metabase/search/spec.clj b/src/metabase/search/spec.cljindex e21875d3cfd..cb4449580de 100644--- a/src/metabase/search/spec.clj+++ b/src/metabase/search/spec.clj@@ -18,24 +18,26 @@(def search-models"Search model string names, ordered by indexing priority.Important / cheaper models come first so partial index is usable as soon as possible during a full index."- ["collection"- "dashboard"- "segment"- "measure"- "database"- "action"- "document"- "exploration"- "transform"- ;; The following come last as they can be slow to index due to:- ;; - cardinality (table, indexed-entity),- ;; - cost (e.g. large text payloads and native-query parsing for cards)- "table"- "metric"- "card"- "dataset"- ;; These can easily dwarf the cardinality of other entities, hence being dead last.- "indexed-entity"])+ (-> ["collection"+ "dashboard"+ "segment"+ "measure"+ "database"+ "action"+ "document"+ "exploration"+ "transform"]+ ;; An OSS build has no model namespace to resolve data apps from.+ (cond-> config/ee-available? (conj "data-app"))+ (into [;; The following come last as they can be slow to index due to:+ ;; - cardinality (table, indexed-entity),+ ;; - cost (e.g. large text payloads and native-query parsing for cards)+ "table"+ "metric"+ "card"+ "dataset"+ ;; These can easily dwarf the cardinality of other entities, hence being dead last.+ "indexed-entity"])))(def raw-spec-forms"Stores the raw (unevaluated) spec forms captured at macro expansion time.diff --git a/test/metabase/models/interface_test.clj b/test/metabase/models/interface_test.cljindex fd5ceb66564..daf62241213 100644--- a/test/metabase/models/interface_test.clj+++ b/test/metabase/models/interface_test.clj@@ -322,3 +322,7 @@(let [hydrated (t2/hydrate card :can_query)](is (contains? hydrated :can_query))(is (boolean? (:can_query hydrated)))))))++(deftest ^:parallel ->integer-test+ (testing "casts to an integer on every app DB, though MySQL and MariaDB have no INTEGER cast type"+ (is (= 42 (:n (t2/query-one {:select [[(mi/->integer "42") :n]]}))))))diff --git a/test/metabase/search/filter_test.clj b/test/metabase/search/filter_test.cljindex 64b54d00cbf..e429b363f4b 100644--- a/test/metabase/search/filter_test.clj+++ b/test/metabase/search/filter_test.clj@@ -3,6 +3,7 @@[clojure.math.combinatorics :as math.combo][clojure.test :refer :all][metabase.collections.test-utils :as collections.tu]+ [metabase.config.core :as config][metabase.models.resolution][metabase.search.config :as search.config][metabase.search.filter :as search.filter]@@ -136,26 +137,27 @@[:not= :search_index.model "table"][:= :search_index.archived true][:= :search_index.curated true]- [:in :search_index.model ["card" "dataset" "metric" "dashboard" "action"]]+ [:in :search_index.model ["card" "dataset" "metric" "dashboard" "action" "data-app"]][:or[:= nil :search_index.dashboard_id][:not= [:inline 0] [:coalesce :search_index.dashboardcard_count [:inline 0]]]][:= nil :search_index.exploration_id][:in:search_index.model- #{"dashboard"- "table"- "segment"- "collection"- "measure"- "transform"- "document"- "exploration"- "database"- "action"- "indexed-entity"- "metric"- "card"}]+ (cond-> #{"dashboard"+ "table"+ "segment"+ "collection"+ "measure"+ "transform"+ "document"+ "exploration"+ "database"+ "action"+ "indexed-entity"+ "metric"+ "card"}+ config/ee-available? (conj "data-app"))][:< [:cast :search_index.model_created_at :date] #t "2024-10-02"][:in :search_index.model_id ["1" "2" "3" "4"]][:< [:cast :search_index.last_edited_at :date] #t "2024-10-03"]diff --git a/test/metabase/search/in_place/filter_test.clj b/test/metabase/search/in_place/filter_test.cljindex ec094f81142..95f7b674966 100644--- a/test/metabase/search/in_place/filter_test.clj+++ b/test/metabase/search/in_place/filter_test.clj@@ -2,6 +2,7 @@(:require[clojure.test :refer :all][metabase.audit-app.core :as audit]+ [metabase.config.core :as config][metabase.search.config :as search.config][metabase.search.in-place.filter :as search.filter][metabase.search.permissions :as search.permissions]@@ -54,7 +55,9 @@{:models #{"dashboard" "dataset" "table"}:created-by #{1}})))))(testing "created at"- (is (= #{"dashboard" "table" "dataset" "document" "exploration" "collection" "database" "action" "card" "metric" "transform" "measure"}+ (is (= (cond-> #{"dashboard" "table" "dataset" "document" "exploration" "collection" "database" "action" "card"+ "metric" "transform" "measure"}+ config/ee-available? (conj "data-app"))(search.filter/search-context->applicable-models(merge default-search-ctx{:created-at "past3days"}))))