Goal: We want to round a drop to the nearest quarter-day increment, excluding our lunch hour, non-working time, and non-working days.
Expectation: On drop, the task(s) will round to the nearest quarter-day working time
Actuals: If you drag and drop any child task that is not the starting child task, it reverts to its original position. The event store correctly batches the changes and syncs with our server, but the UI will briefly render the correct date before jumping the task back to its original position. There is also a jittering when you drop a parent task as well (it's not as noticeable in this example, but in our large data-set with custom JSX rendering, it is very apparent).
For our attempt at the quarter-day rounding, we manually set the start date for the dropped tasks in our onBeforeEventDropFinalize
handler after calling context.finalize(false)
.
// Round drop date to quarter day
onBeforeEventDropFinalize({ source, context }: BeforeEventDropEvent) {
context.async = true;
if (!context.valid) {
context.finalize(false);
} else {
const { events: drops, assignments } = context.dropData;
const dropAssignments = Object.fromEntries(
assignments.map(({ assignmentRecord, resourceRecord }) => [
assignmentRecord.eventId,
resourceRecord.id,
])
);
const calendar = source.project.calendar as CalendarModel;
source.suspendRefresh();
context.finalize(false);
source.eventStore.beginBatch();
for (const { eventRecord: task, startDate } of drops) {
const adjustedStart = roundDatetimeToQuarterDay(startDate);
const adjustedEnd = calendar.calculateEndDate(
adjustedStart,
task.durationMS
);
const stageUnit = dropAssignments[task.id];
task.set({
startDate: adjustedStart,
endDate: adjustedEnd,
resourceId: stageUnit,
});
if (task.isParent) {
for (const child of task.children as SchedulerEventModel[]) {
child.set({ resourceId: stageUnit });
}
}
}
source.eventStore.endBatch();
source.resumeRefresh(true);
}
}
I can reproduce this your examples/frameworks/react-vite/nested-events-lazy-load
example and attached that here:
I modified it by:
- Changing the data set to have the parent tasks constrained by its children
- Adding a working time calendar
- Adding the
onBeforeEventDropFinalize
handler