Skip to content

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

1.5 KB
Raw Blame
import { t } from "ttag";

import { useListUsersQuery } from "metabase/api";
import { ROOT_COLLECTION } from "metabase/common/collections/constants";
import { CollectionListView } from "metabase/common/components/CollectionListView";
import { useParams } from "metabase/router";
import * as Urls from "metabase/urls";
import { checkNotNull } from "metabase/utils/types";
import { useGetTenantQuery } from "metabase-enterprise/api";
import type { IconName } from "metabase-types/api";

export const TenantUsersPersonalCollectionList = () => {
  const { tenantId: tenantIdParam } = useParams();
  const tenantId = parseInt(checkNotNull(tenantIdParam), 10);

  const { data: tenant } = useGetTenantQuery(tenantId);
  const { data, isLoading } = useListUsersQuery({ tenant_id: tenantId });

  const users = data?.data ?? [];

  const crumbs = [
    {
      title: ROOT_COLLECTION.name,
      to: Urls.collection({ id: "root", name: "" }),
    },
    {
      title: t`Tenant users' personal collections`,
      to: Urls.tenantUsersPersonalCollections(),
    },
    { title: tenant?.name ?? "" },
  ];

  const items = users
    .filter((user) => user.personal_collection_id)
    .map((user) => ({
      key: user.id,
      name: user.common_name,
      icon: "person" as const satisfies IconName,
      link: Urls.collection({
        id: user.personal_collection_id,
        name: user.common_name,
      }),
    }));

  return (
    <CollectionListView crumbs={crumbs} loading={isLoading} items={items} />
  );
};