support icon indicating copy to clipboard operation
support copied to clipboard

WBS value is calculated incorrectly when applying changeset with removed record

Open bmblb opened this issue 9 months ago • 1 comments

Steps to reproduce on advanced demo:

  1. Modify Task model to persist orderedParentIndex field
{ name : 'orderedParentIndex', persist : true }
  1. 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'
                }
            ]
        }
    });
};
  1. 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

bmblb avatar May 13 '24 15:05 bmblb

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.

bmblb avatar May 14 '24 07:05 bmblb