support
support copied to clipboard
WBS value is calculated incorrectly when applying changeset with removed record
Steps to reproduce on advanced demo:
- Modify Task model to persist
orderedParentIndex
field
{ name : 'orderedParentIndex', persist : true }
- add function to apply a changeset
window.foo = () => {
gantt.project.applyProjectChanges({
tasks : {
added : [
{
id : '1-10',
name : 'test',
parentId : 1,
duration : 1,
orderedParentIndex : 1
}
],
removed : [{ id : 13 }],
updated : [
{
id : 14,
name : 'foo'
}
]
}
});
};
- Run demo, execute
foo
from the console
Expected result:
task test
to have WBS of 1.1.3 (or 1.1.2 even)
Got result:
task test
has WBS of 1.1.5 as it is added last to the ordered tree
WIthout removed
key WBS calculates correctly
Problem: code which works with ordered tree is low level and does not have enough information.
Problem occurs when we actually put records to the children array. If we don't provide information on beforeNode
we put record to the end of children array and hope to sort nodes after changeset is applied completely. Sorting uses existing orderedParentIndex
property. We cannot use this property to put record to the correct place right away because this code also works for node reordering, indent, outdent and copy paste. We would need to clean orderedParentIndex
beforehand and there are quite a few places.
Instead, the solution is to patch remove
method on the tree node and sort ordered children by orderedParentIndex
.