Clarify available options in document move

closes #852
This commit is contained in:
Tom Moor
2019-04-08 22:27:10 -07:00
parent a3ca3447d1
commit 57e051d62b
2 changed files with 38 additions and 41 deletions

View File

@ -1,6 +1,7 @@
// @flow // @flow
import * as React from 'react'; import * as React from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { darken } from 'polished';
import styled from 'styled-components'; import styled from 'styled-components';
import { GoToIcon, CollectionIcon, PrivateCollectionIcon } from 'outline-icons'; import { GoToIcon, CollectionIcon, PrivateCollectionIcon } from 'outline-icons';
import Flex from 'shared/components/Flex'; import Flex from 'shared/components/Flex';
@ -74,29 +75,29 @@ const StyledGoToIcon = styled(GoToIcon)`
const ResultWrapper = styled.div` const ResultWrapper = styled.div`
display: flex; display: flex;
margin-bottom: 10px; margin-bottom: 10px;
margin-left: -4px;
user-select: none;
color: ${props => props.theme.text}; color: ${props => props.theme.text};
cursor: default; cursor: default;
`; `;
const ResultWrapperLink = styled(ResultWrapper.withComponent('a'))` const ResultWrapperLink = styled(ResultWrapper.withComponent('a'))`
height: 32px; margin: 0 -10px;
padding-top: 3px; padding: 8px 4px;
padding-left: 5px; border-radius: 8px;
border: 2px solid transparent;
&:hover, &:hover,
&:active, &:active,
&:focus { &:focus {
margin-left: 0px; background: ${props => props.theme.listItemHoverBackground};
border-radius: 2px; border: 2px solid ${props => props.theme.listItemHoverBorder};
background: ${props => props.theme.black};
color: ${props => props.theme.smokeLight};
outline: none; outline: none;
cursor: pointer;
${StyledGoToIcon} {
fill: ${props => props.theme.white};
} }
&:focus {
border: 2px solid ${props => darken(0.5, props.theme.listItemHoverBorder)};
} }
`; `;

View File

@ -16,12 +16,16 @@ import Flex from 'shared/components/Flex';
import Document from 'models/Document'; import Document from 'models/Document';
import DocumentsStore from 'stores/DocumentsStore'; import DocumentsStore from 'stores/DocumentsStore';
import UiStore from 'stores/UiStore';
import CollectionsStore, { type DocumentPath } from 'stores/CollectionsStore'; import CollectionsStore, { type DocumentPath } from 'stores/CollectionsStore';
const MAX_RESULTS = 8;
type Props = { type Props = {
document: Document, document: Document,
documents: DocumentsStore, documents: DocumentsStore,
collections: CollectionsStore, collections: CollectionsStore,
ui: UiStore,
onRequestClose: *, onRequestClose: *,
}; };
@ -53,24 +57,9 @@ class DocumentMove extends React.Component<Props> {
let results = []; let results = [];
if (collections.isLoaded) { if (collections.isLoaded) {
if (this.searchTerm) { if (this.searchTerm) {
// Search by the keyword
results = this.searchIndex.search(this.searchTerm); results = this.searchIndex.search(this.searchTerm);
} else { } else {
// Default results, root of the current collection results = this.searchIndex._documents;
results = [];
collections.orderedData.forEach(collection => {
collection.documents.forEach(doc => {
const path = collections.getPathForDocument(doc.id);
if (doc && path) {
results.push(path);
}
});
const rootPath = collections.getPathForDocument(collection.id);
if (rootPath) {
results = [rootPath, ...results];
}
});
} }
} }
@ -100,6 +89,11 @@ class DocumentMove extends React.Component<Props> {
} }
}; };
handleSuccess = () => {
this.props.ui.showToast('Document moved');
this.props.onRequestClose();
};
handleFilter = (ev: SyntheticInputEvent<*>) => { handleFilter = (ev: SyntheticInputEvent<*>) => {
this.searchTerm = ev.target.value; this.searchTerm = ev.target.value;
}; };
@ -140,7 +134,7 @@ class DocumentMove extends React.Component<Props> {
<Labeled label="Choose a new location"> <Labeled label="Choose a new location">
<Input <Input
type="text" type="text"
placeholder="Filter…" placeholder="Search collections & documents…"
onKeyDown={this.handleKeyDown} onKeyDown={this.handleKeyDown}
onChange={this.handleFilter} onChange={this.handleFilter}
required required
@ -152,7 +146,9 @@ class DocumentMove extends React.Component<Props> {
mode={ArrowKeyNavigation.mode.VERTICAL} mode={ArrowKeyNavigation.mode.VERTICAL}
defaultActiveChildIndex={0} defaultActiveChildIndex={0}
> >
{this.results.map((result, index) => ( {this.results
.slice(0, MAX_RESULTS)
.map((result, index) => (
<PathToDocument <PathToDocument
key={result.id} key={result.id}
result={result} result={result}
@ -161,7 +157,7 @@ class DocumentMove extends React.Component<Props> {
ref={ref => ref={ref =>
index === 0 && this.setFirstDocumentRef(ref) index === 0 && this.setFirstDocumentRef(ref)
} }
onSuccess={onRequestClose} onSuccess={this.handleSuccess}
/> />
))} ))}
</StyledArrowKeyNavigation> </StyledArrowKeyNavigation>
@ -184,4 +180,4 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
flex: 1; flex: 1;
`; `;
export default inject('documents', 'collections')(DocumentMove); export default inject('documents', 'collections', 'ui')(DocumentMove);