Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ describe('EditingState', () => {
});

describe('editing helpers', () => {
const firstAppointmentInSeries = {
id: 4,
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
rRule: 'FREQ=DAILY;COUNT=5',
exDate: '20190716T142000Z',
parentData: {
id: 4,
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
},
};
const appointmentDataBase = {
id: 4,
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
Expand All @@ -183,39 +195,81 @@ describe('EditingState', () => {
describe('#editAll', () => {
it('should edit simple recurrence', () => {
const changes = {
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
startDate: new Date(Date.UTC(2019, 6, 15, 15, 20)),
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
rRule: 'FREQ=DAILY;COUNT=5',
};

expect(editAll(firstAppointmentInSeries, changes)).toEqual({
changed: {
4: {
startDate: new Date(Date.UTC(2019, 6, 15, 15, 20)),
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
rRule: 'FREQ=DAILY;COUNT=5',
},
},
});
});
it('should update all appointments using deltas', () => {
const changes = {
startDate: new Date(Date.UTC(2019, 6, 17, 8)),
endDate: new Date(Date.UTC(2019, 6, 17, 19)),
rRule: 'FREQ=DAILY;COUNT=5',
};

expect(editAll(appointmentDataBase, changes)).toEqual({
changed: {
4: {
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
startDate: new Date(Date.UTC(2019, 6, 15, 8)),
endDate: new Date(Date.UTC(2019, 6, 15, 19)),
rRule: 'FREQ=DAILY;COUNT=5',
},
},
});
});
it('should edit only one date in recurrent appointment', () => {
const changes = {
startDate: new Date(Date.UTC(2019, 6, 17, 14, 10)),
};

expect(editAll(appointmentDataBase, changes)).toEqual({
changed: {
4: {
startDate: new Date(Date.UTC(2019, 6, 15, 14, 10)),
},
},
});

const otherChanges = {
endDate: new Date(Date.UTC(2019, 6, 17, 17)),
};

expect(editAll(appointmentDataBase, otherChanges)).toEqual({
changed: {
4: {
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
},
},
});
});
it('should edit if the item is moved after until', () => {
const appointmentData = {
...appointmentDataBase,
...firstAppointmentInSeries,
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
rRule: 'FREQ=DAILY;UNTIL=20190717T142000Z',
exDate: '20190716T142000Z',
};
const changes = {
startDate: new Date(Date.UTC(2019, 6, 18, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 18, 16)),
startDate: new Date(Date.UTC(2019, 8, 18, 14, 20)),
endDate: new Date(Date.UTC(2019, 8, 18, 16)),
};

expect(editAll(appointmentData, changes)).toEqual({
changed: {
4: {
startDate: new Date(Date.UTC(2019, 6, 18, 14, 20)),
endDate: new Date(Date.UTC(2019, 6, 18, 16)),
startDate: new Date(Date.UTC(2019, 8, 18, 14, 20)),
endDate: new Date(Date.UTC(2019, 8, 18, 16)),
rRule: 'FREQ=DAILY;COUNT=1',
exDate: '',
},
Expand All @@ -224,7 +278,7 @@ describe('EditingState', () => {
});
it('should edit if changes\' startDate is undefined', () => {
const appointmentData = {
...appointmentDataBase,
...firstAppointmentInSeries,
rRule: 'FREQ=DAILY;UNTIL=20190717T142000Z',
};
const changes = {
Expand Down Expand Up @@ -360,8 +414,8 @@ describe('EditingState', () => {
},
};
const changes = {
startDate: new Date(Date.UTC(2019, 6, 15, 11, 20)),
endDate: new Date(Date.UTC(2019, 6, 15, 14)),
startDate: new Date(Date.UTC(2019, 6, 16, 11, 20)),
endDate: new Date(Date.UTC(2019, 6, 16, 14)),
};

expect(editCurrentAndFollowing(appointmentData, changes)).toEqual({
Expand Down
47 changes: 46 additions & 1 deletion packages/dx-scheduler-core/src/plugins/editing-state/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,44 @@ export const deleteCurrentAndFollowing: DeleteFn = appointmentData => changeCurr
appointmentData, {}, deleteAll,
);

const getParentChanges = (
appointmentData: Partial<AppointmentModel>, changes: Changes,
): Partial<AppointmentModel> => {
let parentChanges: Changes = {};

const convert = (
date: Date, prevDate: Date, parentDate: Date,
): Date => {
const diff = moment.utc(date).diff(prevDate);

return moment(parentDate).add(diff).toDate();
};

if (changes.startDate) {
parentChanges = {
...parentChanges,
startDate: convert(
changes.startDate as Date,
appointmentData.startDate as Date,
appointmentData.parentData.startDate as Date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have so much typecasting as Date? Could it be moved to type def?

),
};
}

if (changes.endDate) {
parentChanges = {
...parentChanges,
endDate: convert(
changes.endDate as Date,
appointmentData.endDate as Date,
appointmentData.parentData.endDate as Date,
),
};
}

return parentChanges;
};

export const editAll: EditFn = (appointmentData, changes) => {
const { rRule, id } = appointmentData;

Expand All @@ -154,7 +192,14 @@ export const editAll: EditFn = (appointmentData, changes) => {
};
}

return { changed: { [appointmentData.id!]: changes } };
return {
changed: {
[appointmentData.id!]: {
...changes,
...getParentChanges(appointmentData, changes),
},
},
};
};

export const editCurrent: EditFn = (appointmentData, changes) => ({
Expand Down