Skip to content

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

Make GET /api/ee/library return null instead of message (#66440)

Ryan Laurie4d0695b9da26
diff --git a/enterprise/backend/src/metabase_enterprise/library/api.clj b/enterprise/backend/src/metabase_enterprise/library/api.clj
index a436b7ffb48..d37ad2820ac 100644
--- a/enterprise/backend/src/metabase_enterprise/library/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/library/api.clj
@@ -42,8 +42,9 @@
(t2/hydrate
:can_write
:effective_children)
- (add-here-and-below))
- {:message "Library does not exist"}))
+ (add-here-and-below)
+ (assoc :model "collection"))
+ {:data nil}))
(defn- select-collections
[]
diff --git a/enterprise/backend/test/metabase_enterprise/library/api_test.clj b/enterprise/backend/test/metabase_enterprise/library/api_test.clj
index 78aec161195..f2f9a19ec34 100644
--- a/enterprise/backend/test/metabase_enterprise/library/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/library/api_test.clj
@@ -12,7 +12,7 @@
(without-library
(testing "When there is no library, returns a message but still 200"
(let [response (mt/user-http-request :crowberto :get 200 "ee/library")]
- (is (= {:message "Library does not exist"} response))))
+ (is (= {:data nil} response))))
(let [_ (collection/create-library-collection!)
models-id (t2/select-one-pk :model/Collection :type collection/library-models-collection-type)
metrics-id (t2/select-one-pk :model/Collection :type collection/library-metrics-collection-type)
diff --git a/enterprise/frontend/src/metabase-enterprise/api/library.ts b/enterprise/frontend/src/metabase-enterprise/api/library.ts
index 82d5a5212f8..8cbcd90d97f 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/library.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/library.ts
@@ -12,7 +12,7 @@ export const libraryApi = EnterpriseApi.injectEndpoints({
}),
invalidatesTags: [listTag("collection")],
}),
- getLibraryCollection: builder.query<CollectionItem, void>({
+ getLibraryCollection: builder.query<CollectionItem | { data: null }, void>({
query: () => ({
url: `/api/ee/library`,
method: "GET",
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/utils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/utils.ts
index 88bf64fdcb1..cc644b64c31 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/utils.ts
@@ -78,15 +78,26 @@ export function canPlaceEntityInCollectionOrDescendants(
return false;
}
+const isLibrary = (
+ collection: CollectionItem | { data: null } | undefined,
+): collection is CollectionItem => !!collection && "name" in collection;
+
export const useGetLibraryCollection = ({
skip = false,
}: { skip?: boolean } = {}) => {
- const { data: libraryCollection, isLoading: isLoadingCollection } =
- useGetLibraryCollectionQuery(undefined, { skip });
+ const { data, isLoading: isLoadingCollection } = useGetLibraryCollectionQuery(
+ undefined,
+ { skip },
+ );
+
+ const maybeLibrary = useMemo(
+ () => (isLibrary(data) ? data : undefined),
+ [data],
+ );
return {
isLoading: isLoadingCollection,
- data: libraryCollection,
+ data: maybeLibrary,
};
};
@@ -97,10 +108,7 @@ export const useGetLibraryChildCollectionByType = ({
skip?: boolean;
type: CollectionType;
}) => {
- const { data: rootLibraryCollection } = useGetLibraryCollectionQuery(
- undefined,
- { skip },
- );
+ const { data: rootLibraryCollection } = useGetLibraryCollection({ skip });
const { data: libraryCollections } = useListCollectionItemsQuery(
rootLibraryCollection ? { id: rootLibraryCollection.id } : skipToken,
);
@@ -120,7 +128,7 @@ export const useGetResolvedLibraryCollection = ({
skip = false,
}: { skip?: boolean } = {}) => {
const { data: libraryCollection, isLoading: isLoadingCollection } =
- useGetLibraryCollectionQuery(undefined, { skip });
+ useGetLibraryCollection({ skip });
const hasStuff = Boolean(
libraryCollection &&