Skip to content

Commit

Permalink
Fix comment/branchpoint removal for last node of a tree (#2897)
Browse files Browse the repository at this point in the history
* fix comment/branchpoint removal for first node of a tree

* Update CHANGELOG.md
  • Loading branch information
daniel-wer authored Jul 16, 2018
1 parent 1acf357 commit 9ec19d9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
### Fixed

- Fixed a bug which caused segmentation data to be requested as four-bit when four-bit-mode was enabled. [#2828](https://github.com/scalableminds/webknossos/pull/2828)
- Fixed a bug where possible comments or branchpoints sometimes were not properly deleted when deleting a node. [2897](https://github.com/scalableminds/webknossos/pull/2897)
- Fixed a bug which caused projects to be unpaused when the project priority was changed. [#2795](https://github.com/scalableminds/webknossos/pull/2795)
- Fixed an unnecessary warning when deleting a tree in a task, that warned about deleting the initial node although the initial node was not contained in the deleted tree. [#2812](https://github.com/scalableminds/webknossos/pull/2812)
- Fixed a bug where the comment tab was scrolled into view horizontally if a node with a comment was activated. [#2805](https://github.com/scalableminds/webknossos/pull/2805)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ export function deleteNode(
const { allowUpdate } = skeletonTracing.restrictions;

if (allowUpdate) {
// Delete Node
// Delete node and possible branchpoints/comments
const activeTree = update(tree, {
nodes: { $apply: nodes => nodes.delete(node.id) },
comments: { $apply: comments => comments.filter(comment => comment.nodeId !== node.id) },
branchPoints: {
$apply: branchPoints =>
branchPoints.filter(branchPoint => branchPoint.nodeId !== node.id),
},
});

// Do we need to split trees? Are there edges leading to/from it?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@ test("SkeletonTracing should delete a node from a tree", t => {
t.deepEqual(newStateB, newState);
});

test("SkeletonTracing should delete respective comments and branchpoints when deleting a node from a tree", t => {
const createNodeAction = SkeletonTracingActions.createNodeAction(
position,
rotation,
viewport,
resolution,
);
const deleteNodeAction = SkeletonTracingActions.deleteNodeAction();
const createCommentAction = SkeletonTracingActions.createCommentAction("foo");
const createBranchPointAction = SkeletonTracingActions.createBranchPointAction();

// Add a node, comment, and branchpoint, then delete the node again
const newState = SkeletonTracingReducer(initialState, createNodeAction);
const newStateA = SkeletonTracingReducer(newState, createCommentAction);
const newStateB = SkeletonTracingReducer(newStateA, createBranchPointAction);
const newStateC = SkeletonTracingReducer(newStateB, deleteNodeAction);

// Workaround, because the diffable map creates a new chunk but doesn't delete it again
const nodes = newStateC.tracing.trees[1].nodes;
t.is(nodes.chunks.length, 1);
t.is(nodes.chunks[0].size, 0);
nodes.chunks = [];
t.deepEqual(newStateC, initialState);
});

test("SkeletonTracing should not delete tree when last node is deleted from the tree", t => {
const createNodeAction = SkeletonTracingActions.createNodeAction(
position,
Expand Down

0 comments on commit 9ec19d9

Please sign in to comment.