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

View File

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

View File

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

View File

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

View File

@ -193,12 +193,15 @@ router.post('documents.create', auth(), async ctx => {
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') {
await ownerCollection.addDocumentToStructure(newDocument, index);
await ownerCollection.addDocumentToStructure(document, index);
}
ctx.body = {
data: await presentDocument(ctx, newDocument),
data: await presentDocument(ctx, document),
};
});