Our state of the art Gantt chart


Post by galb@control.site »

Hi,

We are experiencing issues with the redo-undo functionality. When the project loads, the undo count is set to 1, even though no changes have been made.

Additionally, after making several changes, the redo functionality shows the correct number of changes. However, after redoing all changes, it still indicates 1 change remaining.

Attached are a runnable test and a video demonstrating the issue.

Thank you for your assistance.

Attachments
screen-capture.webm
(1.08 MiB) Downloaded 4 times
runnable-test-undoredo.zip
(112.9 KiB) Downloaded 6 times

Post by alex.l »

Hi,

It fixed when I commented this code

    this.gantt.project.on({
      load: "updateStartDateField",
      refresh: "updateStartDateField",
      thisObj: this,
    });

This happened because you update startDate of the projectModel after load. You subscribed on load that set data to dateField. That change initiates onStartDateChange call that change projectModel's startDate. I updated the code with this:

  onStartDateChange({ value, oldValue, userAction }) {
    if (!userAction) {
      return;
    }

and it worked now.

All the best,
Alex


Post by galb@control.site »

Hi,

Thank you for your response.

We are unsure about the steps we need to take. Should we:

Comment out the following code:

this.gantt.project.on({
  load: "updateStartDateField",
  refresh: "updateStartDateField",
  thisObj: this,
});

and update the onStartDateChange function as follows:

onStartDateChange({ value, oldValue, userAction }) {
  if (!userAction) {
    return;
  }
}

or

Simply update the onStartDateChange function:

onStartDateChange({ value, oldValue, userAction }) {
  if (!userAction) {
    return;
  }
}

We have tried both options, but neither seems to resolve the issue. The first option results in no changes being tracked at all, while the second does not fix the issue we raised. Could you please provide further guidance?

Thank you.


Post by alex.l »

Hi

Sorry for confusing, that's my mistake. After double-check I found that I tested in not valid code state with commented refresh handler. I've spent more time on it, but was not able to fix this right away. I opened a ticket to fix this https://github.com/bryntum/support/issues/9559
You can subscribe on ticket updates to be notified when it's done.

All the best,
Alex


Post by nickolay »

Hi,

Regarding the 1st issue you are experiencing:

When the project loads, the undo count is set to 1, even though no changes have been made.

To avoid this, one should enable the stm mechanism only after the initial data loading is fully complete. Otherwise, if stm is enabled, but data is still being loaded/mutated - that will be picked up as a undo/redo transaction. This is what happens in this case.

Unfortunately, there's some issue in the loadCrudManagerData method and it requires an additional await project.commitAsync() call after, to process the data. Stm should be enabled only after that call.

A workaround looks like this:

  • remove this.gantt.project.stm.enable(); call from updateStartDateField
  • change initGantt in src/app/components/gantt.component.tsx to:
      const initGantt = async () => {
        await ganttRef.current.instance.crudManager.loadCrudManagerData(ganttData);
        const ganttInstance = ganttRef.current.instance;
    
        await ganttInstance.project.commitAsync()
    
        if (ganttInstance.isDestroyed) return;
    
        ganttInstance.eventStore.syncDataOnLoad = false;
        ganttInstance.project.stm.resetQueue();
        // enable stm and start recording changes only after all initial data loading/processing is completed
        ganttInstance.project.stm.enable();
    
        ganttInstance.taskStore.wbsMode = "auto";
      };

It seems gantt chart is actually re-created during data loading, thus the ganttInstance.isDestroyed check - but this is something related to react effects system and you'll need to debug it yourself.

After fixing the initial issue, it seems the 2nd issue you mention is not reproducible, please verify.

I'll also investigate why loadCrudManagerData method requires an extra commitAsync() call after, so hopefully this will be fixed in the next release.

Hope that helps,

Regards, Nickolay


Post by galb@control.site »

Hi,
thank you for you response.

we tried your solution and it works good for the first project we upload - for the first ganttData.
But this issue appear again if we replace/change it with another data(ganttData is changed).

Best regards,


Post by nickolay »

Glad it works, yw. Please provide detailed steps to reproduce and test case for new issue?


Post by galb@control.site »

HI,

adding a new runnable test with the old logic + your new solution.

to reproduce it click on the button "Change Project" and the issue will appear again.(if i change project it should be reset again to 0).

Thank you!

Attachments
runnable-test-undoredo.zip
(114.74 KiB) Downloaded 1 time

Post by nickolay »

This issue is caused by the fact that https://bryntum.com/products/gantt/docs/api/Core/data/stm/StateTrackingManager#function-resetQueue call of the stm does not stop the ongoing transaction. It does, however, clear all previous transactions in the queue. But the ongoing transaction that includes loading of the new data will still be recorded.

To fix, need to make sure that data loading will not be ever recorded as a transaction. For that, you can disable stm before loading the data:

  const initGantt = async () => {
    ganttRef.current.instance.project.stm.disable()

    await ganttRef.current.instance.crudManager.loadCrudManagerData(ganttData);
    const ganttInstance = ganttRef.current.instance;
    await ganttInstance.project.commitAsync();

    if (ganttInstance.isDestroyed) return;

    ganttInstance.eventStore.syncDataOnLoad = false;

    ganttInstance?.project?.stm.resetQueue();
    ganttInstance.project.stm.enable();

    ganttInstance.taskStore.wbsMode = "auto";
  };

The initial stm.disable() call will disable stm and stop any ongoing transaction. Then, after data loading the queue will be reset and stm will be re-enabled.

Hope that helps,

Regards, Nickolay


Post by galb@control.site »

Thank you!!!!:)


Post Reply