Fix new document creation. Add collection name to DocumentPreview in search results

This commit is contained in:
Tom Moor
2017-07-14 22:15:56 -07:00
parent 2fea9fafd0
commit 2a9efaba8f
5 changed files with 15 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import PublishingInfo from 'components/PublishingInfo';
type Props = { type Props = {
document: Document, document: Document,
highlight?: ?string, highlight?: ?string,
showCollection?: boolean,
innerRef?: Function, innerRef?: Function,
}; };
@ -43,7 +44,7 @@ class DocumentPreview extends Component {
props: Props; props: Props;
render() { render() {
const { document, innerRef, ...rest } = this.props; const { document, showCollection, innerRef, ...rest } = this.props;
return ( return (
<DocumentLink to={document.url} innerRef={innerRef} {...rest}> <DocumentLink to={document.url} innerRef={innerRef} {...rest}>
@ -53,6 +54,7 @@ class DocumentPreview extends Component {
createdBy={document.createdBy} createdBy={document.createdBy}
updatedAt={document.updatedAt} updatedAt={document.updatedAt}
updatedBy={document.updatedBy} updatedBy={document.updatedBy}
collection={showCollection ? document.collection : undefined}
/> />
</DocumentLink> </DocumentLink>
); );

View File

@ -2,11 +2,11 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import moment from 'moment'; import moment from 'moment';
import styled from 'styled-components'; import styled from 'styled-components';
import Collection from 'models/Collection';
import type { User } from 'types'; import type { User } from 'types';
import Flex from 'components/Flex'; import Flex from 'components/Flex';
const Container = styled(Flex)` const Container = styled(Flex)`
justify-content: space-between;
color: #bbb; color: #bbb;
font-size: 13px; font-size: 13px;
`; `;
@ -32,6 +32,7 @@ const Avatar = styled.img`
class PublishingInfo extends Component { class PublishingInfo extends Component {
props: { props: {
collaborators?: Array<User>, collaborators?: Array<User>,
collection?: Collection,
createdAt: string, createdAt: string,
createdBy: User, createdBy: User,
updatedAt: string, updatedAt: string,
@ -42,6 +43,7 @@ class PublishingInfo extends Component {
render() { render() {
const { const {
collaborators, collaborators,
collection,
createdAt, createdAt,
updatedAt, updatedAt,
createdBy, createdBy,
@ -71,6 +73,7 @@ class PublishingInfo extends Component {
{' '} {' '}
{moment(updatedAt).fromNow()} {moment(updatedAt).fromNow()}
</span>} </span>}
{collection && <span>&nbsp;in <strong>{collection.name}</strong></span>}
</Container> </Container>
); );
} }

View File

@ -151,6 +151,8 @@ type Props = {
renderHeading(isEditing: boolean) { renderHeading(isEditing: boolean) {
invariant(this.document, 'document not available'); invariant(this.document, 'document not available');
if (this.props.newDocument) return;
return ( return (
<InfoWrapper visible={!isEditing}> <InfoWrapper visible={!isEditing}>
<PublishingInfo <PublishingInfo

View File

@ -125,6 +125,7 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
key={document.id} key={document.id}
document={document} document={document}
highlight={this.store.searchTerm} highlight={this.store.searchTerm}
showCollection
/> />
))} ))}
</StyledArrowKeyNavigation> </StyledArrowKeyNavigation>

View File

@ -193,12 +193,15 @@ router.post('documents.create', auth(), async ctx => {
text, text,
}); });
// reload to get all of the data needed to present (user, collection etc)
const document = await Document.findById(newDocument.id);
if (ownerCollection.type === 'atlas') { if (ownerCollection.type === 'atlas') {
await ownerCollection.addDocumentToStructure(newDocument, index); await ownerCollection.addDocumentToStructure(document, index);
} }
ctx.body = { ctx.body = {
data: await presentDocument(ctx, newDocument), data: await presentDocument(ctx, document),
}; };
}); });