fix flow issues introduced in documents reordering feature

This commit is contained in:
Ante Primorac committed 2020-05-24 23:12:33 +02:00
1 parent 8911020f34
commit 5d2be0a199
4 files changed
+35 -29

No files matched your search

@@ -3,12 +3,8 @@ import * as React from 'react';
import { observer, Observer } from 'mobx-react';
import { observable } from 'mobx';
import { CollectionIcon, PrivateCollectionIcon } from 'outline-icons';
import {
DragDropContext,
Droppable,
Draggable,
DropResult,
} from 'react-beautiful-dnd';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import type { DropResult } from 'react-beautiful-dnd';
import Collection from 'models/Collection';
import Document from 'models/Document';
import CollectionMenu from 'menus/CollectionMenu';
@@ -3,12 +3,8 @@ import * as React from 'react';
import { observer, Observer } from 'mobx-react';
import { observable } from 'mobx';
import styled from 'styled-components';
import {
DragDropContext,
Droppable,
Draggable,
DropResult,
} from 'react-beautiful-dnd';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import type { DropResult } from 'react-beautiful-dnd';
import Document from 'models/Document';
import DocumentMenu from 'menus/DocumentMenu';
import SidebarLink from './SidebarLink';
+5 -3
View File
@@ -108,16 +108,18 @@ export default class Collection extends BaseModel {
) {
if (!parentDocumentId) {
this.documents.splice(
index !== undefined ? index : this.documents.length,
index !== undefined && index !== null ? index : this.documents.length,
0,
document
);
} else {
const recursivelyAddDocument = nodes => {
const recursivelyAddDocument = (nodes: NavigationNode[]) => {
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].id === parentDocumentId) {
nodes[i].children.splice(
index !== undefined ? index : nodes[i].children.length,
index !== undefined && index !== null
? index
: nodes[i].children.length,
0,
document
);
+26 -14
View File
@@ -367,22 +367,34 @@ export default class DocumentsStore extends BaseStore<Document> {
index: ?number
) => {
const oldCollection = this.rootStore.collections.get(document.collectionId);
// Retrive all children documents
const childDocuments = oldCollection.getDocumentChildren(document.id);
// Remove document from old collection
oldCollection.removeDocumentInStructure(document.id);
let newCollection = oldCollection;
// Recreate navigation node object
const navigationNode: NavigationNode = {
id: document.id,
title: document.title,
url: document.url,
children: childDocuments,
};
if (document.collectionId !== collectionId) {
newCollection = this.rootStore.collections.get(collectionId);
}
const collection = this.rootStore.collections.get(collectionId);
// Move document to new location on the client side
collection.addDocumentToStructure(navigationNode, parentDocumentId, index);
// Update UI
if (oldCollection && newCollection) {
// Retrive all children documents
const childDocuments = oldCollection.getDocumentChildren(document.id);
// Remove document from old collection
oldCollection.removeDocumentInStructure(document.id);
// Recreate navigation node object
const navigationNode: NavigationNode = {
id: document.id,
title: document.title,
url: document.url,
children: childDocuments,
};
// Move document to new location
newCollection.addDocumentToStructure(
navigationNode,
parentDocumentId,
index
);
}
// Send data to server
const res = await client.post('/documents.move', {