Don't allow dragging into itself (Fixes #583)

This commit is contained in:
Gregory Schier 2017-11-10 00:36:09 +01:00
parent d48d396aa2
commit a5ce4d8f05

View File

@ -937,11 +937,20 @@ function mapDispatchToProps (dispatch) {
} }
async function _moveDoc (docToMove, parentId, targetId, targetOffset) { async function _moveDoc (docToMove, parentId, targetId, targetOffset) {
// Nothing to do. We are in the same spot as we started
if (docToMove._id === targetId) { if (docToMove._id === targetId) {
// Nothing to do. We are in the same spot as we started
return; return;
} }
// Don't allow dragging things into itself or children. This will disconnect
// the node from the tree and cause the item to no longer show in the UI.
const descendents = await db.withDescendants(docToMove);
for (const doc of descendents) {
if (doc._id === parentId) {
return;
}
}
function __updateDoc (doc, patch) { function __updateDoc (doc, patch) {
models.getModel(docToMove.type).update(doc, patch); models.getModel(docToMove.type).update(doc, patch);
} }