// @flow import * as React from 'react'; import { observer } from 'mobx-react'; import styled from 'styled-components'; import { GoToIcon, CollectionIcon, PrivateCollectionIcon } from 'outline-icons'; import Flex from 'shared/components/Flex'; import Document from 'models/Document'; import Collection from 'models/Collection'; import type { DocumentPath } from 'stores/CollectionsStore'; type Props = { result: DocumentPath, document?: ?Document, collection: ?Collection, onSuccess?: () => void, ref?: *, }; @observer class PathToDocument extends React.Component { handleClick = async (ev: SyntheticEvent<*>) => { ev.preventDefault(); const { document, result, onSuccess } = this.props; if (!document) return; if (result.type === 'document') { await document.move(result.collectionId, result.id); } else { await document.move(result.collectionId, null); } if (onSuccess) onSuccess(); }; render() { const { result, collection, document, ref } = this.props; const Component = document ? ResultWrapperLink : ResultWrapper; if (!result) return
; return ( {collection && (collection.private ? ( ) : ( ))} {result.path .map(doc => {doc.title}) .reduce((prev, curr) => [prev, , curr])} {document && ( {' '} {document.title} )} ); } } const Title = styled.span` white-space: nowrap; overflow: hidden; text-overflow: ellipsis; `; const StyledGoToIcon = styled(GoToIcon)` opacity: 0.25; `; const ResultWrapper = styled.div` display: flex; margin-bottom: 10px; color: ${props => props.theme.text}; cursor: default; `; const ResultWrapperLink = styled(ResultWrapper.withComponent('a'))` height: 32px; padding-top: 3px; padding-left: 5px; &:hover, &:active, &:focus { margin-left: 0px; border-radius: 2px; background: ${props => props.theme.black}; color: ${props => props.theme.smokeLight}; outline: none; cursor: pointer; ${StyledGoToIcon} { fill: ${props => props.theme.white}; } } `; export default PathToDocument;