Skip to content

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

use new library icon for remote-synced collections (#65251)

Aleksandr Lesnenkoa5db416a8a71
diff --git a/enterprise/frontend/src/metabase-enterprise/collections/utils.ts b/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
index 7964dab909a..a890146bc69 100644
--- a/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
@@ -31,11 +31,15 @@ export function isRegularCollection({
export function getCollectionType({
authority_level,
type,
+ location,
}: Partial<Collection>):
| CollectionAuthorityLevelConfig
| CollectionInstanceAnaltyicsConfig {
+ const virtualType =
+ type === "remote-synced" && location !== "/" ? null : type;
return (
- COLLECTION_TYPES?.[String(type || authority_level)] ?? REGULAR_COLLECTION
+ COLLECTION_TYPES?.[String(virtualType || authority_level)] ??
+ REGULAR_COLLECTION
);
}
@@ -54,7 +58,10 @@ export function isSyncedCollection(
}
export const getIcon = (item: ObjectWithModel): IconData => {
- const collectionType = getCollectionType({ type: item.type }).type;
+ const collectionType = getCollectionType({
+ type: item.type || item.collection_type,
+ location: item.location || item.effective_location,
+ }).type;
if (collectionType === "instance-analytics") {
return {
name: INSTANCE_ANALYTICS_COLLECTION.icon,
diff --git a/frontend/src/metabase/lib/icon.ts b/frontend/src/metabase/lib/icon.ts
index 7e878269bca..48004736b26 100644
--- a/frontend/src/metabase/lib/icon.ts
+++ b/frontend/src/metabase/lib/icon.ts
@@ -27,6 +27,9 @@ export type ObjectWithModel = {
moderated_status?: "verified" | string | null;
display?: CardDisplayType | null;
type?: Collection["type"];
+ collection_type?: Collection["type"];
+ location?: Collection["location"];
+ effective_location?: Collection["location"];
is_personal?: boolean;
};
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/repository.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/repository.svg
index 6e217f64f98..65d670571b5 100644
--- a/frontend/src/metabase/ui/components/icons/Icon/icons/repository.svg
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/repository.svg
@@ -1 +1,3 @@
-<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.21 1.25c.313 0 .615.109.855.306l.1.09.09.1c.196.24.305.542.305.855v10.813a1.352 1.352 0 0 1-1.35 1.352H4.702a2.255 2.255 0 0 1-2.241-2.03l-.012-.222V3.502A2.254 2.254 0 0 1 4.702 1.25h7.508zM4.702 11.762a.753.753 0 0 0-.752.752l.015.147a.754.754 0 0 0 .737.605h7.358v-1.504H4.702zm0-9.012a.753.753 0 0 0-.752.752v6.89c.24-.084.494-.13.752-.13h7.358V2.75h-1.152v4.056a.501.501 0 0 1-.853.353l-1.45-1.448-1.448 1.448a.5.5 0 0 1-.853-.353V2.75H4.702zm2.602 2.849l.948-.949.079-.064a.501.501 0 0 1 .629.064l.948.949V2.75H7.304v2.849z" fill="#071722" fill-opacity=".84"/></svg>
\ No newline at end of file
+<svg viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <path d="M12.21 1.25c.313 0 .615.109.855.306l.1.09.09.1c.196.24.305.542.305.855v10.813a1.352 1.352 0 0 1-1.35 1.352H4.702a2.255 2.255 0 0 1-2.241-2.03l-.012-.222V3.502A2.254 2.254 0 0 1 4.702 1.25h7.508zM4.702 11.762a.753.753 0 0 0-.752.752l.015.147a.754.754 0 0 0 .737.605h7.358v-1.504H4.702zm0-9.012a.753.753 0 0 0-.752.752v6.89c.24-.084.494-.13.752-.13h7.358V2.75h-1.152v4.056a.501.501 0 0 1-.853.353l-1.45-1.448-1.448 1.448a.5.5 0 0 1-.853-.353V2.75H4.702zm2.602 2.849l.948-.949.079-.064a.501.501 0 0 1 .629.064l.948.949V2.75H7.304v2.849z" />
+</svg>
diff --git a/src/metabase/collections/api.clj b/src/metabase/collections/api.clj
index 8643cf92148..3a6e9b805ce 100644
--- a/src/metabase/collections/api.clj
+++ b/src/metabase/collections/api.clj
@@ -653,7 +653,7 @@
:personal_owner_id
:location
:archived_directly
- [:type :collection_type]
+ :type
[(h2x/literal "collection") :model]
:authority_level])
;; the nil indicates that collections are never pinned.
@@ -729,13 +729,15 @@
(assoc row :name (collection/user->personal-collection-name (:personal_owner_id row) :user))
(dissoc row :personal_owner_id)))]
(for [row (annotate-collections parent-collection rows options)]
- (-> (t2/instance :model/Collection row)
- collection/maybe-localize-trash-name
- (update :archived api/bit->boolean)
- (t2/hydrate :can_write :effective_location :can_restore :can_delete)
- (dissoc :collection_position :display :moderated_status :icon
- :collection_preview :dataset_query :table_id :query_type :is_upload)
- update-personal-collection))))
+ (let [type-value (:type row)]
+ (-> (t2/instance :model/Collection row)
+ collection/maybe-localize-trash-name
+ (update :archived api/bit->boolean)
+ (t2/hydrate :can_write :effective_location :can_restore :can_delete)
+ (dissoc :collection_position :display :moderated_status :icon
+ :collection_preview :dataset_query :table_id :query_type :is_upload)
+ (assoc :type type-value)
+ update-personal-collection)))))
;;; TODO -- consider whether this function belongs here or in [[metabase.revisions.models.revision.last-edit]]
(mu/defn- coalesce-edit-info :- revisions/MaybeAnnotated
@@ -757,7 +759,7 @@
(defn- remove-unwanted-keys [{:keys [model] :as row}]
(cond-> (dissoc row :model_ranking :archived_directly :total_count)
- (not= model :collection) (dissoc :collection_type)))
+ (not= model "collection") (dissoc :type)))
(defn- model-name->toucan-model [model-name]
(case (keyword model-name)
@@ -810,7 +812,7 @@
:model :collection_position :authority_level [:personal_owner_id :integer] :location
:last_edit_email :last_edit_first_name :last_edit_last_name :moderated_status :icon
[:last_edit_user :integer] [:last_edit_timestamp :timestamp] [:database_id :integer]
- :collection_type [:archived :boolean] [:last_used_at :timestamp]
+ :type [:archived :boolean] [:last_used_at :timestamp]
;; for determining whether a model is based on a csv-uploaded table
[:table_id :integer] [:is_upload :boolean] :query_type])
@@ -850,7 +852,7 @@
[:authority_level :asc :nulls-last]))
(def ^:private normal-collections-first-sort-clause
- [:collection_type :asc :nulls-first])
+ [:type :asc :nulls-first])
(defn children-sort-clause
"Given the client side sort-info, return sort clause to effect this. `db-type` is necessary due to complications from
diff --git a/test/metabase/collections/api_test.clj b/test/metabase/collections/api_test.clj
index 2f732f78ad7..a340d8f2e56 100644
--- a/test/metabase/collections/api_test.clj
+++ b/test/metabase/collections/api_test.clj
@@ -1182,7 +1182,7 @@
(testing "Default sort"
(doseq [app-db [:mysql :h2 :postgres]]
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:%lower.name :asc]
[:id :asc]]
(api.collection/children-sort-clause {:official-collections-first? true} app-db))))))
@@ -1190,7 +1190,7 @@
(deftest ^:parallel children-sort-clause-test-2
(testing "Sorting by last-edited-at"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:%isnull.last_edit_timestamp]
[:last_edit_timestamp :asc]
[:%lower.name :asc]
@@ -1202,7 +1202,7 @@
(deftest ^:parallel children-sort-clause-test-2b
(testing "Sorting by last-edited-at"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:last_edit_timestamp :nulls-last]
[:last_edit_timestamp :asc]
[:%lower.name :asc]
@@ -1214,7 +1214,7 @@
(deftest ^:parallel children-sort-clause-test-2c
(testing "Sorting by last-edited-by"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:last_edit_last_name :nulls-last]
[:last_edit_last_name :asc]
[:last_edit_first_name :nulls-last]
@@ -1228,7 +1228,7 @@
(deftest ^:parallel children-sort-clause-test-2d
(testing "Sorting by last-edited-by"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:%isnull.last_edit_last_name]
[:last_edit_last_name :asc]
[:%isnull.last_edit_first_name]
@@ -1242,7 +1242,7 @@
(deftest ^:parallel children-sort-clause-test-3
(testing "Sorting by model"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:model_ranking :asc]
[:%lower.name :asc]
[:id :asc]]
@@ -1253,7 +1253,7 @@
(deftest ^:parallel children-sort-clause-test-3b
(testing "Sorting by model"
(is (= [[:authority_level :asc :nulls-last]
- [:collection_type :asc :nulls-first]
+ [:type :asc :nulls-first]
[:model_ranking :desc]
[:%lower.name :asc]
[:id :asc]]
@@ -2272,16 +2272,19 @@
:model/Collection _ {:name "Second Normal Collection"}]
(let [response (mt/user-http-request :crowberto :get 200 "collection/root/items"
:collection_type "remote-synced")
- collection-names (->> (:data response)
- (filter #(= (:model %) "collection"))
- (map :name)
- set)]
+ collections (->> (:data response)
+ (filter #(= (:model %) "collection")))
+ collection-names (set (map :name collections))]
(testing "should include remote-synced collections"
(is (contains? collection-names "Remote Synced Collection"))
(is (contains? collection-names "Another Remote Collection")))
(testing "should not include normal collections"
(is (not (contains? collection-names "Normal Collection")))
- (is (not (contains? collection-names "Second Normal Collection")))))))
+ (is (not (contains? collection-names "Second Normal Collection"))))
+ (testing "should include type field in response"
+ (doseq [coll collections]
+ (is (= "remote-synced" (:type coll))
+ (str "Collection " (:name coll) " should have type=remote-synced")))))))
(testing "without collection_type parameter, all collections are returned"
(mt/with-temp [:model/Collection _ {:name "Normal Collection Test"}