2018-07-01 16:16:38 +00:00
|
|
|
// @flow
|
2020-11-30 04:04:58 +00:00
|
|
|
import { observer } from "mobx-react";
|
2020-08-08 22:18:37 +00:00
|
|
|
import {
|
2020-09-07 18:51:09 +00:00
|
|
|
ArchiveIcon,
|
|
|
|
EditIcon,
|
2020-08-08 22:18:37 +00:00
|
|
|
GoToIcon,
|
|
|
|
MoreIcon,
|
2020-09-07 18:51:09 +00:00
|
|
|
PadlockIcon,
|
2020-08-08 22:18:37 +00:00
|
|
|
ShapesIcon,
|
2020-09-07 18:51:09 +00:00
|
|
|
TrashIcon,
|
2020-08-08 22:18:37 +00:00
|
|
|
} from "outline-icons";
|
2020-08-09 05:53:59 +00:00
|
|
|
import * as React from "react";
|
2020-11-30 04:04:58 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-08-09 05:53:59 +00:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import breakpoint from "styled-components-breakpoint";
|
2020-06-23 04:29:21 +00:00
|
|
|
|
|
|
|
import CollectionsStore from "stores/CollectionsStore";
|
2020-08-09 05:53:59 +00:00
|
|
|
import Document from "models/Document";
|
|
|
|
import CollectionIcon from "components/CollectionIcon";
|
2020-07-10 05:33:07 +00:00
|
|
|
import Flex from "components/Flex";
|
2020-06-23 04:29:21 +00:00
|
|
|
import BreadcrumbMenu from "./BreadcrumbMenu";
|
2020-11-30 04:04:58 +00:00
|
|
|
import useStores from "hooks/useStores";
|
2020-08-09 05:53:59 +00:00
|
|
|
import { collectionUrl } from "utils/routeHelpers";
|
2018-07-01 16:16:38 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
document: Document,
|
2018-07-01 18:54:24 +00:00
|
|
|
collections: CollectionsStore,
|
2019-04-06 23:45:08 +00:00
|
|
|
onlyText: boolean,
|
2018-07-01 16:16:38 +00:00
|
|
|
};
|
|
|
|
|
2020-09-07 18:51:09 +00:00
|
|
|
function Icon({ document }) {
|
2020-11-30 04:04:58 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2020-09-07 18:51:09 +00:00
|
|
|
if (document.isDeleted) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<CollectionName to="/trash">
|
|
|
|
<TrashIcon color="currentColor" />
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
<span>{t("Trash")}</span>
|
2020-09-07 18:51:09 +00:00
|
|
|
</CollectionName>
|
|
|
|
<Slash />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (document.isArchived) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<CollectionName to="/archive">
|
|
|
|
<ArchiveIcon color="currentColor" />
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
<span>{t("Archive")}</span>
|
2020-09-07 18:51:09 +00:00
|
|
|
</CollectionName>
|
|
|
|
<Slash />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (document.isDraft) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<CollectionName to="/drafts">
|
|
|
|
<EditIcon color="currentColor" />
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
<span>{t("Drafts")}</span>
|
2020-09-07 18:51:09 +00:00
|
|
|
</CollectionName>
|
|
|
|
<Slash />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (document.isTemplate) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<CollectionName to="/templates">
|
|
|
|
<ShapesIcon color="currentColor" />
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
<span>{t("Templates")}</span>
|
2020-09-07 18:51:09 +00:00
|
|
|
</CollectionName>
|
|
|
|
<Slash />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
const Breadcrumb = ({ document, onlyText }: Props) => {
|
|
|
|
const { collections } = useStores();
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2020-09-07 18:51:09 +00:00
|
|
|
let collection = collections.get(document.collectionId);
|
|
|
|
if (!collection) {
|
|
|
|
if (!document.deletedAt) return <div />;
|
2018-11-14 04:54:18 +00:00
|
|
|
|
2020-09-07 18:51:09 +00:00
|
|
|
collection = {
|
|
|
|
id: document.collectionId,
|
2020-11-30 04:04:58 +00:00
|
|
|
name: t("Deleted Collection"),
|
2020-09-07 18:51:09 +00:00
|
|
|
color: "currentColor",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = collection.pathToDocument
|
2020-12-16 03:07:29 +00:00
|
|
|
? collection.pathToDocument(document.id).slice(0, -1)
|
2020-09-07 18:51:09 +00:00
|
|
|
: [];
|
2018-07-01 16:16:38 +00:00
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
if (onlyText === true) {
|
|
|
|
return (
|
2020-08-09 16:48:04 +00:00
|
|
|
<>
|
2019-08-29 04:41:40 +00:00
|
|
|
{collection.private && (
|
2020-08-09 16:48:04 +00:00
|
|
|
<>
|
2020-06-23 04:29:21 +00:00
|
|
|
<SmallPadlockIcon color="currentColor" size={16} />{" "}
|
2020-08-09 16:48:04 +00:00
|
|
|
</>
|
2019-08-29 04:41:40 +00:00
|
|
|
)}
|
2019-04-06 23:45:08 +00:00
|
|
|
{collection.name}
|
2020-08-09 01:53:11 +00:00
|
|
|
{path.map((n) => (
|
2019-04-06 23:45:08 +00:00
|
|
|
<React.Fragment key={n.id}>
|
|
|
|
<SmallSlash />
|
|
|
|
{n.title}
|
|
|
|
</React.Fragment>
|
|
|
|
))}
|
2020-08-09 16:48:04 +00:00
|
|
|
</>
|
2019-04-06 23:45:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-26 06:21:04 +00:00
|
|
|
const isNestedDocument = path.length > 1;
|
|
|
|
const lastPath = path.length ? path[path.length - 1] : undefined;
|
|
|
|
const menuPath = isNestedDocument ? path.slice(0, -1) : [];
|
|
|
|
|
2018-07-01 16:16:38 +00:00
|
|
|
return (
|
|
|
|
<Wrapper justify="flex-start" align="center">
|
2020-09-07 18:51:09 +00:00
|
|
|
<Icon document={document} />
|
2018-07-01 18:54:24 +00:00
|
|
|
<CollectionName to={collectionUrl(collection.id)}>
|
2020-08-09 01:53:11 +00:00
|
|
|
<CollectionIcon collection={collection} expanded />
|
|
|
|
|
2018-07-01 18:54:24 +00:00
|
|
|
<span>{collection.name}</span>
|
2018-07-01 16:16:38 +00:00
|
|
|
</CollectionName>
|
2019-06-26 06:21:04 +00:00
|
|
|
{isNestedDocument && (
|
2020-08-09 16:48:04 +00:00
|
|
|
<>
|
2019-06-26 06:21:04 +00:00
|
|
|
<Slash /> <BreadcrumbMenu label={<Overflow />} path={menuPath} />
|
2020-08-09 16:48:04 +00:00
|
|
|
</>
|
2019-06-26 06:21:04 +00:00
|
|
|
)}
|
|
|
|
{lastPath && (
|
2020-08-09 16:48:04 +00:00
|
|
|
<>
|
2020-06-23 04:29:21 +00:00
|
|
|
<Slash />{" "}
|
2019-06-26 06:21:04 +00:00
|
|
|
<Crumb to={lastPath.url} title={lastPath.title}>
|
|
|
|
{lastPath.title}
|
2019-01-07 00:12:07 +00:00
|
|
|
</Crumb>
|
2020-08-09 16:48:04 +00:00
|
|
|
</>
|
2019-06-26 06:21:04 +00:00
|
|
|
)}
|
2018-07-01 16:16:38 +00:00
|
|
|
</Wrapper>
|
|
|
|
);
|
2020-11-30 04:04:58 +00:00
|
|
|
};
|
2018-07-01 16:16:38 +00:00
|
|
|
|
|
|
|
const Wrapper = styled(Flex)`
|
2018-07-01 17:20:57 +00:00
|
|
|
display: none;
|
|
|
|
|
2020-06-23 04:29:21 +00:00
|
|
|
${breakpoint("tablet")`
|
2018-07-01 17:20:57 +00:00
|
|
|
display: flex;
|
|
|
|
`};
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2019-08-29 04:41:40 +00:00
|
|
|
const SmallPadlockIcon = styled(PadlockIcon)`
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: sub;
|
|
|
|
`;
|
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
const SmallSlash = styled(GoToIcon)`
|
|
|
|
width: 15px;
|
|
|
|
height: 10px;
|
|
|
|
flex-shrink: 0;
|
|
|
|
opacity: 0.25;
|
|
|
|
`;
|
|
|
|
|
2020-04-05 19:22:26 +00:00
|
|
|
export const Slash = styled(GoToIcon)`
|
2018-07-01 18:54:24 +00:00
|
|
|
flex-shrink: 0;
|
2020-08-09 01:53:11 +00:00
|
|
|
fill: ${(props) => props.theme.divider};
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2019-06-26 06:21:04 +00:00
|
|
|
const Overflow = styled(MoreIcon)`
|
|
|
|
flex-shrink: 0;
|
|
|
|
transition: opacity 100ms ease-in-out;
|
2020-09-04 19:49:20 +00:00
|
|
|
fill: ${(props) => props.theme.divider};
|
2019-06-26 06:21:04 +00:00
|
|
|
|
2020-09-04 19:49:20 +00:00
|
|
|
&:active,
|
|
|
|
&:hover {
|
|
|
|
fill: ${(props) => props.theme.text};
|
2019-06-26 06:21:04 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-07-01 16:16:38 +00:00
|
|
|
const Crumb = styled(Link)`
|
2020-08-09 01:53:11 +00:00
|
|
|
color: ${(props) => props.theme.text};
|
2018-07-01 16:16:38 +00:00
|
|
|
font-size: 15px;
|
|
|
|
height: 24px;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CollectionName = styled(Link)`
|
2018-07-01 18:54:24 +00:00
|
|
|
display: flex;
|
|
|
|
flex-shrink: 0;
|
2020-08-09 01:53:11 +00:00
|
|
|
color: ${(props) => props.theme.text};
|
2018-07-01 16:16:38 +00:00
|
|
|
font-size: 15px;
|
|
|
|
font-weight: 500;
|
2018-07-01 18:54:24 +00:00
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
export default observer(Breadcrumb);
|