Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

Commit 9bf1f70

Browse files
authored
fix(react-scheduler): fix deleting first oppointment (#3582)
1 parent 458174a commit 9bf1f70

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ describe('EditingState', () => {
7171
const changes = deleteCurrent(appointmentData);
7272
expect(changes).toEqual({ deleted: 0 });
7373
});
74+
75+
it('should remove first appointment for never ending sequence', () => {
76+
const appointmentData = {
77+
id: 0,
78+
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
79+
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
80+
rRule: 'FREQ=DAILY',
81+
parentData: {
82+
rRule: 'FREQ=DAILY',
83+
startDate: new Date(Date.UTC(2019, 6, 15, 14, 20)),
84+
endDate: new Date(Date.UTC(2019, 6, 15, 16)),
85+
},
86+
};
87+
88+
const changes = deleteCurrent(appointmentData);
89+
expect(changes).toEqual({ changed: { 0: { exDate: '20190715T142000Z' } } });
90+
});
7491
});
7592

7693
describe('#deleteCurrentAndFollowing', () => {

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,20 @@ const configureDateSequence: MakeDateSequenceFn = (rRule, exDate, prevStartDate,
5252
dtstart: prevStartDateUTC,
5353
}));
5454
if (currentOptions.count || currentOptions.until) {
55-
return rruleSet.all()
55+
return {
56+
options: currentOptions,
57+
dates: rruleSet.all()
5658
// we shouldn't use `new Date(string)` because this function has different results in Safari
57-
.map(nextDate => moment(formatDateToString(nextDate)).toDate());
59+
.map(nextDate => moment(formatDateToString(nextDate)).toDate()),
60+
};
5861
}
5962
const leftBound = prevStartDateUTC;
6063
const rightBound = moment(getUTCDate(nextStartDate!)).toDate();
61-
return rruleSet.between(leftBound, rightBound, true)
62-
.map(nextDate => moment(formatDateToString(nextDate)).toDate());
64+
return {
65+
options: currentOptions,
66+
dates: rruleSet.between(leftBound, rightBound, true)
67+
.map(nextDate => moment(formatDateToString(nextDate)).toDate()),
68+
};
6369
};
6470

6571
const configureICalendarRules = (rRule: string | undefined, options: object) => {
@@ -100,22 +106,22 @@ const changeCurrentAndFollowing: ChangeFn = (appointmentData, changes, changeAll
100106
const getAppointmentSequenceData = (
101107
prevStartDate: Date, startDate: Date, exDate: string, rRule: string | undefined,
102108
) => {
103-
const initialSequence: Date[] = configureDateSequence(rRule, exDate,
109+
const initialSequence = configureDateSequence(rRule, exDate,
104110
moment.utc(prevStartDate).toDate(), moment.utc(startDate).toDate(),
105-
);
111+
).dates;
106112
const currentChildIndex = initialSequence
107113
.findIndex(date => moment(date).isSame(startDate as Date));
108114
return { initialSequence, currentChildIndex };
109115
};
110116

111117
export const deleteCurrent: DeleteFn = (appointmentData) => {
112-
const currentSequence: Date[] = configureDateSequence(
118+
const { options, dates } = configureDateSequence(
113119
appointmentData.rRule, appointmentData.exDate,
114120
moment.utc(appointmentData.parentData.startDate).toDate(),
115121
moment.utc(appointmentData.startDate).toDate(),
116122
);
117123

118-
if (currentSequence.length === 1) {
124+
if ((options.count || options.until) && dates.length === 1) {
119125
return deleteAll(appointmentData);
120126
}
121127

packages/dx-scheduler-core/src/types/editing-state.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Options } from 'rrule';
12
import { AppointmentModel, AppointmentId } from './scheduler-core.types';
23

34
export type AppointmentChanges = { [key: string]: object };
@@ -13,7 +14,7 @@ export type PreCommitChangesFn = (
1314
/** @internal */
1415
export type MakeDateSequenceFn = (
1516
rRule: string | undefined, exDate: string | undefined, prevStartDate: Date, date: Date,
16-
) => Array<Date>;
17+
) => { options: Partial<Options>, dates: Array<Date> };
1718

1819
/** @internal */
1920
export type EditFn = (appointmentData: Partial<AppointmentModel>, changes: Changes) => ChangeSet;

0 commit comments

Comments
 (0)