import { observer } from "mobx-react"; import { GlobeIcon, PadlockIcon, TeamIcon } from "outline-icons"; import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; import { breakpoint } from "@shared/styles/breakpoint"; import { flattenTree } from "@shared/utils/tree"; import type Collection from "~/models/Collection"; import Flex from "~/components/Flex"; import { HeaderMeta, Separator } from "~/components/HeaderMeta"; import Tooltip from "~/components/Tooltip"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useStores from "~/hooks/useStores"; type Props = { /** The collection to display meta information for */ collection: Collection; }; /** * A line of meta information about a collection, rendered directly beneath its * title to match the equivalent display for documents. */ export const CollectionMeta = observer(function CollectionMeta_({ collection, }: Props) { const { t } = useTranslation(); const { shares } = useStores(); const team = useCurrentTeam(); const share = shares.getByCollectionId(collection.id); const isPubliclyShared = team.sharing !== false && collection.sharing !== false && !!share?.isActive; // The document structure is cached on the collection once loaded, so this is // a no-op when the sidebar or another tab has already requested it. useEffect(() => { void collection.fetchDocuments(); }, [collection]); const documentCount = collection.documents ? flattenTree(collection.asNavigationNode).length - 1 : undefined; return ( {collection.isPrivate ? ( ) : ( )} {collection.isPrivate ? t("Private") : t("Workspace")} {isPubliclyShared && ( <> {t("Publicly shared")} )} {documentCount !== undefined && ( {t("{{ count }} document", { count: documentCount })} )} ); }); const IconLabel = styled(Flex)` gap: 2px; cursor: default; `; const Meta = styled(HeaderMeta)` // Aligns with the collection title, which is indented on mobile. margin-inline-start: 16px; ${breakpoint("tablet")` margin-inline-start: 0; `} `;