draft
This commit is contained in:
@ -90,6 +90,26 @@ type Props = {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { document, documents } = this.props;
|
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 (
|
return (
|
||||||
<Modal isOpen onRequestClose={this.handleClose} title="Move document">
|
<Modal isOpen onRequestClose={this.handleClose} title="Move document">
|
||||||
@ -115,18 +135,13 @@ type Props = {
|
|||||||
mode={ArrowKeyNavigation.mode.VERTICAL}
|
mode={ArrowKeyNavigation.mode.VERTICAL}
|
||||||
defaultActiveChildIndex={0}
|
defaultActiveChildIndex={0}
|
||||||
>
|
>
|
||||||
<PathToDocument
|
{resultSet.map((documentId, index) => (
|
||||||
document={document}
|
|
||||||
documents={documents}
|
|
||||||
ref={ref => this.setFirstDocumentRef(ref)}
|
|
||||||
onSuccess={this.handleClose}
|
|
||||||
/>
|
|
||||||
{this.resultIds.map((documentId, index) => (
|
|
||||||
<PathToDocument
|
<PathToDocument
|
||||||
key={documentId}
|
key={documentId || document.id}
|
||||||
documentId={documentId}
|
documentId={documentId}
|
||||||
documents={documents}
|
documents={documents}
|
||||||
document={document}
|
document={document}
|
||||||
|
ref={ref => index === 0 && this.setFirstDocumentRef(ref)}
|
||||||
onSuccess={this.handleClose}
|
onSuccess={this.handleClose}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
@ -74,16 +74,17 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { document, onSuccess, ref } = this.props;
|
const { document, documentId, onSuccess, ref } = this.props;
|
||||||
// $FlowIssue we'll always have a document
|
// $FlowIssue we'll always have a document
|
||||||
const { collection } = document || this.resultDocument;
|
const { collection } = documentId ? this.resultDocument : document;
|
||||||
const Component = onSuccess ? ResultWrapperLink : ResultWrapper;
|
const Component = onSuccess ? ResultWrapperLink : ResultWrapper;
|
||||||
|
|
||||||
|
// Exclude document when it's part of the path and not the preview
|
||||||
return (
|
return (
|
||||||
<Component
|
<Component
|
||||||
innerRef={ref}
|
innerRef={ref}
|
||||||
selectable
|
selectable
|
||||||
href={!!onSuccess}
|
href
|
||||||
onClick={onSuccess && this.handleSelect}
|
onClick={onSuccess && this.handleSelect}
|
||||||
>
|
>
|
||||||
{collection.name}
|
{collection.name}
|
||||||
|
@ -5,7 +5,6 @@ import {
|
|||||||
action,
|
action,
|
||||||
runInAction,
|
runInAction,
|
||||||
ObservableArray,
|
ObservableArray,
|
||||||
autorunAsync,
|
|
||||||
} from 'mobx';
|
} from 'mobx';
|
||||||
import ApiClient, { client } from 'utils/ApiClient';
|
import ApiClient, { client } from 'utils/ApiClient';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@ -17,8 +16,6 @@ import ErrorsStore from 'stores/ErrorsStore';
|
|||||||
import CacheStore from 'stores/CacheStore';
|
import CacheStore from 'stores/CacheStore';
|
||||||
import UiStore from 'stores/UiStore';
|
import UiStore from 'stores/UiStore';
|
||||||
|
|
||||||
const COLLECTION_CACHE_KEY = 'COLLECTION_CACHE_KEY';
|
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
teamId: string,
|
teamId: string,
|
||||||
cache: CacheStore,
|
cache: CacheStore,
|
||||||
@ -41,6 +38,30 @@ class CollectionsStore {
|
|||||||
: undefined;
|
: 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 */
|
/* Actions */
|
||||||
|
|
||||||
@action fetchAll = async (): Promise<*> => {
|
@action fetchAll = async (): Promise<*> => {
|
||||||
@ -99,21 +120,6 @@ class CollectionsStore {
|
|||||||
this.teamId = options.teamId;
|
this.teamId = options.teamId;
|
||||||
this.cache = options.cache;
|
this.cache = options.cache;
|
||||||
this.ui = options.ui;
|
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