Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Commit bb203d3

Browse files
fix: editing time of secondary recurring appointment (#3691)
* fix editing time of secondary recurring appointment * lint * update tests * fix tests again * prettify code * lint
1 parent 5438eda commit bb203d3

File tree

2 files changed

+112
-13
lines changed

2 files changed

+112
-13
lines changed

packages/dx-scheduler-core/src/plugins/editing-state/helpers.test.ts

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ describe('EditingState', () => {
168168
});
169169

170170
describe('editing helpers', () => {
171+
const firstAppointmentInSeries = {
172+
id: 4,
173+
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
174+
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
175+
rRule: 'FREQ=DAILY;COUNT=5',
176+
exDate: '20190716T142000Z',
177+
parentData: {
178+
id: 4,
179+
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
180+
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
181+
},
182+
};
171183
const appointmentDataBase = {
172184
id: 4,
173185
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
@@ -183,39 +195,81 @@ describe('EditingState', () => {
183195
describe('#editAll', () => {
184196
it('should edit simple recurrence', () => {
185197
const changes = {
186-
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
187-
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
198+
startDate: new Date(Date.UTC(2019, 6, 15, 15, 20)),
199+
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
200+
rRule: 'FREQ=DAILY;COUNT=5',
201+
};
202+
203+
expect(editAll(firstAppointmentInSeries, changes)).toEqual({
204+
changed: {
205+
4: {
206+
startDate: new Date(Date.UTC(2019, 6, 15, 15, 20)),
207+
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
208+
rRule: 'FREQ=DAILY;COUNT=5',
209+
},
210+
},
211+
});
212+
});
213+
it('should update all appointments using deltas', () => {
214+
const changes = {
215+
startDate: new Date(Date.UTC(2019, 6, 17, 8)),
216+
endDate: new Date(Date.UTC(2019, 6, 17, 19)),
188217
rRule: 'FREQ=DAILY;COUNT=5',
189218
};
190219

191220
expect(editAll(appointmentDataBase, changes)).toEqual({
192221
changed: {
193222
4: {
194-
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
195-
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
223+
startDate: new Date(Date.UTC(2019, 6, 15, 8)),
224+
endDate: new Date(Date.UTC(2019, 6, 15, 19)),
196225
rRule: 'FREQ=DAILY;COUNT=5',
197226
},
198227
},
199228
});
200229
});
230+
it('should edit only one date in recurrent appointment', () => {
231+
const changes = {
232+
startDate: new Date(Date.UTC(2019, 6, 17, 14, 10)),
233+
};
234+
235+
expect(editAll(appointmentDataBase, changes)).toEqual({
236+
changed: {
237+
4: {
238+
startDate: new Date(Date.UTC(2019, 6, 15, 14, 10)),
239+
},
240+
},
241+
});
242+
243+
const otherChanges = {
244+
endDate: new Date(Date.UTC(2019, 6, 17, 17)),
245+
};
246+
247+
expect(editAll(appointmentDataBase, otherChanges)).toEqual({
248+
changed: {
249+
4: {
250+
endDate: new Date(Date.UTC(2019, 6, 15, 17)),
251+
},
252+
},
253+
});
254+
});
201255
it('should edit if the item is moved after until', () => {
202256
const appointmentData = {
203-
...appointmentDataBase,
257+
...firstAppointmentInSeries,
204258
startDate: new Date(Date.UTC(2019, 6, 17, 14, 20)),
205259
endDate: new Date(Date.UTC(2019, 6, 17, 16)),
206260
rRule: 'FREQ=DAILY;UNTIL=20190717T142000Z',
207261
exDate: '20190716T142000Z',
208262
};
209263
const changes = {
210-
startDate: new Date(Date.UTC(2019, 6, 18, 14, 20)),
211-
endDate: new Date(Date.UTC(2019, 6, 18, 16)),
264+
startDate: new Date(Date.UTC(2019, 8, 18, 14, 20)),
265+
endDate: new Date(Date.UTC(2019, 8, 18, 16)),
212266
};
213267

214268
expect(editAll(appointmentData, changes)).toEqual({
215269
changed: {
216270
4: {
217-
startDate: new Date(Date.UTC(2019, 6, 18, 14, 20)),
218-
endDate: new Date(Date.UTC(2019, 6, 18, 16)),
271+
startDate: new Date(Date.UTC(2019, 8, 18, 14, 20)),
272+
endDate: new Date(Date.UTC(2019, 8, 18, 16)),
219273
rRule: 'FREQ=DAILY;COUNT=1',
220274
exDate: '',
221275
},
@@ -224,7 +278,7 @@ describe('EditingState', () => {
224278
});
225279
it('should edit if changes\' startDate is undefined', () => {
226280
const appointmentData = {
227-
...appointmentDataBase,
281+
...firstAppointmentInSeries,
228282
rRule: 'FREQ=DAILY;UNTIL=20190717T142000Z',
229283
};
230284
const changes = {
@@ -360,8 +414,8 @@ describe('EditingState', () => {
360414
},
361415
};
362416
const changes = {
363-
startDate: new Date(Date.UTC(2019, 6, 15, 11, 20)),
364-
endDate: new Date(Date.UTC(2019, 6, 15, 14)),
417+
startDate: new Date(Date.UTC(2019, 6, 16, 11, 20)),
418+
endDate: new Date(Date.UTC(2019, 6, 16, 14)),
365419
};
366420

367421
expect(editCurrentAndFollowing(appointmentData, changes)).toEqual({

packages/dx-scheduler-core/src/plugins/editing-state/helpers.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,44 @@ export const deleteCurrentAndFollowing: DeleteFn = appointmentData => changeCurr
137137
appointmentData, {}, deleteAll,
138138
);
139139

140+
const getParentChanges = (
141+
appointmentData: Partial<AppointmentModel>, changes: Changes,
142+
): Partial<AppointmentModel> => {
143+
let parentChanges: Changes = {};
144+
145+
const convert = (
146+
date: Date, prevDate: Date, parentDate: Date,
147+
): Date => {
148+
const diff = moment.utc(date).diff(prevDate);
149+
150+
return moment(parentDate).add(diff).toDate();
151+
};
152+
153+
if (changes.startDate) {
154+
parentChanges = {
155+
...parentChanges,
156+
startDate: convert(
157+
changes.startDate as Date,
158+
appointmentData.startDate as Date,
159+
appointmentData.parentData.startDate as Date,
160+
),
161+
};
162+
}
163+
164+
if (changes.endDate) {
165+
parentChanges = {
166+
...parentChanges,
167+
endDate: convert(
168+
changes.endDate as Date,
169+
appointmentData.endDate as Date,
170+
appointmentData.parentData.endDate as Date,
171+
),
172+
};
173+
}
174+
175+
return parentChanges;
176+
};
177+
140178
export const editAll: EditFn = (appointmentData, changes) => {
141179
const { rRule, id } = appointmentData;
142180

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

157-
return { changed: { [appointmentData.id!]: changes } };
195+
return {
196+
changed: {
197+
[appointmentData.id!]: {
198+
...changes,
199+
...getParentChanges(appointmentData, changes),
200+
},
201+
},
202+
};
158203
};
159204

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

0 commit comments

Comments
 (0)