draft
This commit is contained in:
@ -90,6 +90,26 @@ type Props = {
|
||||
|
||||
render() {
|
||||
const { document, documents } = this.props;
|
||||
let resultSet;
|
||||
|
||||
resultSet = this.resultIds.filter(docId => {
|
||||
const resultDoc = documents.getById(docId);
|
||||
|
||||
if (document && resultDoc) {
|
||||
return (
|
||||
// Exclude the document if it's on the path to a potential new path
|
||||
!resultDoc.pathToDocument.map(doc => doc.id).includes(document.id) &&
|
||||
// Exclude if the same path, e.g the last one before the current
|
||||
_.last(resultDoc.pathToDocument).id !== document.parentDocumentId
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Prepend root if document does have a parent document
|
||||
resultSet = document.parentDocumentId
|
||||
? _.concat(null, resultSet)
|
||||
: this.resultIds;
|
||||
|
||||
return (
|
||||
<Modal isOpen onRequestClose={this.handleClose} title="Move document">
|
||||
@ -115,18 +135,13 @@ type Props = {
|
||||
mode={ArrowKeyNavigation.mode.VERTICAL}
|
||||
defaultActiveChildIndex={0}
|
||||
>
|
||||
{resultSet.map((documentId, index) => (
|
||||
<PathToDocument
|
||||
document={document}
|
||||
documents={documents}
|
||||
ref={ref => this.setFirstDocumentRef(ref)}
|
||||
onSuccess={this.handleClose}
|
||||
/>
|
||||
{this.resultIds.map((documentId, index) => (
|
||||
<PathToDocument
|
||||
key={documentId}
|
||||
key={documentId || document.id}
|
||||
documentId={documentId}
|
||||
documents={documents}
|
||||
document={document}
|
||||
ref={ref => index === 0 && this.setFirstDocumentRef(ref)}
|
||||
onSuccess={this.handleClose}
|
||||
/>
|
||||
))}
|
||||
|
@ -74,16 +74,17 @@ type Props = {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { document, onSuccess, ref } = this.props;
|
||||
const { document, documentId, onSuccess, ref } = this.props;
|
||||
// $FlowIssue we'll always have a document
|
||||
const { collection } = document || this.resultDocument;
|
||||
const { collection } = documentId ? this.resultDocument : document;
|
||||
const Component = onSuccess ? ResultWrapperLink : ResultWrapper;
|
||||
|
||||
// Exclude document when it's part of the path and not the preview
|
||||
return (
|
||||
<Component
|
||||
innerRef={ref}
|
||||
selectable
|
||||
href={!!onSuccess}
|
||||
href
|
||||
onClick={onSuccess && this.handleSelect}
|
||||
>
|
||||
{collection.name}
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
action,
|
||||
runInAction,
|
||||
ObservableArray,
|
||||
autorunAsync,
|
||||
} from 'mobx';
|
||||
import ApiClient, { client } from 'utils/ApiClient';
|
||||
import _ from 'lodash';
|
||||
@ -17,8 +16,6 @@ import ErrorsStore from 'stores/ErrorsStore';
|
||||
import CacheStore from 'stores/CacheStore';
|
||||
import UiStore from 'stores/UiStore';
|
||||
|
||||
const COLLECTION_CACHE_KEY = 'COLLECTION_CACHE_KEY';
|
||||
|
||||
type Options = {
|
||||
teamId: string,
|
||||
cache: CacheStore,
|
||||
@ -41,6 +38,30 @@ class CollectionsStore {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of paths to each of the documents, where paths are composed of id and title/name pairs
|
||||
*/
|
||||
@computed get pathsToDocuments(): ?[[{ id: string, title: string }]] {
|
||||
let results = [];
|
||||
const travelDocuments = (documentList, path) =>
|
||||
documentList.forEach(document => {
|
||||
const { id, title } = document;
|
||||
const node = { id, title };
|
||||
results.push(_.concat(path, node));
|
||||
travelDocuments(document.children, _.concat(path, [node]));
|
||||
});
|
||||
|
||||
if (this.isLoaded) {
|
||||
this.data.forEach(collection => {
|
||||
const { id, name } = collection;
|
||||
const node = { id, title: name };
|
||||
travelDocuments(collection.documents, [node]);
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
|
||||
@action fetchAll = async (): Promise<*> => {
|
||||
@ -99,21 +120,6 @@ class CollectionsStore {
|
||||
this.teamId = options.teamId;
|
||||
this.cache = options.cache;
|
||||
this.ui = options.ui;
|
||||
//
|
||||
// this.cache.getItem(COLLECTION_CACHE_KEY).then(data => {
|
||||
// if (data) {
|
||||
// this.data.replace(data.map(collection => new Collection(collection)));
|
||||
// this.isLoaded = true;
|
||||
// }
|
||||
// });
|
||||
|
||||
autorunAsync('CollectionsStore.persists', () => {
|
||||
if (this.data.length > 0)
|
||||
this.cache.setItem(
|
||||
COLLECTION_CACHE_KEY,
|
||||
this.data.map(collection => collection.data)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user