Skip to content

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

722 B
Raw Blame
import { useMemo } from "react";

import { useGetLibraryCollectionQuery } from "metabase-enterprise/api";
import type { CollectionItem } from "metabase-types/api";

const isLibrary = (
  collection: CollectionItem | { data: null } | undefined,
): collection is CollectionItem => !!collection && "name" in collection;

export const useGetLibraryCollection = ({
  skip = false,
}: { skip?: boolean } = {}) => {
  const {
    data,
    isLoading: isLoadingCollection,
    error,
  } = useGetLibraryCollectionQuery(undefined, { skip });

  const maybeLibrary = useMemo(
    () => (isLibrary(data) ? data : undefined),
    [data],
  );

  return {
    isLoading: isLoadingCollection,
    data: maybeLibrary,
    error,
  };
};