support icon indicating copy to clipboard operation
support copied to clipboard

CRUD manager loses changes when applying sync response

Open bmblb opened this issue 1 year ago • 7 comments

Reproducible on scheduler pro using this source:

import '../_shared/shared.js'; // not required, our example styling etc.
import '../../lib/Scheduler/column/ResourceInfoColumn.js';
import SchedulerPro from '../../lib/SchedulerPro/view/SchedulerPro.js';

import AjaxHelper from '../../lib/Core/helper/AjaxHelper.js';

const resources = [
    { id : 'r6', name : 'Gloria', company : 'Small rocket co' }
];

AjaxHelper.mockUrl('load', {
    responseText : JSON.stringify({
        success   : true,
        resources : { rows : resources }
    })
});

let count = 1000;

AjaxHelper.mockUrl('sync', function(url, params, options) {
    const body = JSON.parse(options.body);

    console.log(body);

    if (body.events.added) {
        body.events.added.forEach(added => {
            added.id = count++;
        });
    }

    return {
        responseText : JSON.stringify({
            success : true,
            events  : {
                rows : [
                    ...(body.events?.added || []),
                    ...(body.events?.updated || [])
                ],
                removed : [...(body.events?.removed || [])]
            }
        }),
        delay : 200
    };
});

const schedulerPro = new SchedulerPro({
    appendTo          : 'container',
    resourceImagePath : '../_shared/images/users/',

    features : {
        eventTooltip : true
    },

    columns : [
        { type : 'resourceInfo', text : 'L{Name}', width : 150 },
        { text : 'L{Company}', field : 'company', width : 150 }
    ],

    project : {
        loadUrl  : 'load',
        syncUrl  : 'sync',
        autoLoad : true,
        autoSync : true
    },

    startDate  : new Date(2017, 0, 1, 6),
    endDate    : new Date(2017, 0, 1, 20),
    viewPreset : 'hourAndDay'
});

window.run = function() {
    let counter = 1;

    const interval = setInterval(() => {
        schedulerPro.eventStore.add({ name : `Child ${counter++}`, duration : 1, startDate : '2017-01-01', resourceId : 'r6' });

        console.log('added event ' + counter);

        if (counter > 10) {
            clearInterval(interval);
        }
    }, 100);
};

Open the demo and launch run() method. You will see sync requests logged to the console and you could notice they only contain 6 changes combined. There should be 10 records.

image

Changes are likely lost when applying sync response to a modified project. We should either postponse sync until there are none made within an autoSyncTimeout interval, or preserve changes when applying a changeset,

bmblb avatar Jan 15 '24 14:01 bmblb