Move document improvements (#927)

* Show all collections in UI

* Introduce command pattern

* Actually remove from previous collection

* Stash

* Fixes: Promises resolved outside of response lifecycle

* 💚

* 💚

* documentMover tests

* Transaction

* Perf. More in transactions
This commit is contained in:
Tom Moor
2019-04-08 21:25:13 -07:00
committed by GitHub
parent 16066c0b24
commit 763f57a3dc
16 changed files with 313 additions and 146 deletions

View File

@@ -294,17 +294,20 @@ export default class DocumentsStore extends BaseStore<Document> {
};
@action
move = async (document: Document, parentDocumentId: ?string) => {
move = async (
document: Document,
collectionId: string,
parentDocumentId: ?string
) => {
const res = await client.post('/documents.move', {
id: document.id,
parentDocument: parentDocumentId,
collectionId,
parentDocumentId,
});
invariant(res && res.data, 'Data not available');
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
return this.add(res.data);
res.data.documents.forEach(this.add);
res.data.collections.forEach(this.rootStore.collections.add);
};
@action