Skip to content

Commit abb5421

Browse files
author
Dohyung Ahn
authored
Merge pull request #1352 from blacktoast/fix/#1327
fix: afterRenderEvent doesn't work in readonly mode ( fix #1327 )
2 parents 7fb2f20 + 0385829 commit abb5421

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

apps/calendar/src/components/events/horizontalEvent.spec.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ describe(`Firing 'afterRenderEvent'`, () => {
141141
// Then
142142
expect(handler).not.toBeCalled();
143143
});
144+
145+
it(`should fire 'afterRenderEvent' when it is in readonly mode`, () => {
146+
// Given
147+
const { eventBus, handler } = setup();
148+
const uiModel = new EventUIModel(
149+
new EventModel({
150+
id: '1',
151+
start: new Date(2020, 0, 1, 10, 0),
152+
end: new Date(2020, 0, 1, 12, 0),
153+
isReadOnly: true,
154+
})
155+
);
156+
157+
const props = {
158+
uiModel,
159+
eventHeight: 30,
160+
headerHeight: 0,
161+
};
162+
163+
// When
164+
render(<HorizontalEvent {...props} />, { eventBus });
165+
166+
// Then
167+
expect(handler).toHaveBeenCalledTimes(1);
168+
});
144169
});
145170

146171
describe('Apply customStyle', () => {
@@ -307,11 +332,35 @@ describe('Color values', () => {
307332
});
308333

309334
describe('isReadOnly', () => {
335+
function setup() {
336+
const eventName = 'readonly-event';
337+
const uiModel = new EventUIModel(
338+
new EventModel({
339+
id: '1',
340+
title: eventName,
341+
start: new Date(2020, 0, 1, 10, 0),
342+
end: new Date(2020, 0, 1, 12, 0),
343+
isReadOnly: true,
344+
})
345+
);
346+
347+
const props = {
348+
uiModel,
349+
eventHeight: 30,
350+
headerHeight: 0,
351+
};
352+
353+
return {
354+
props,
355+
};
356+
}
357+
310358
it("should be able to show detail popup even if the model's `isReadOnly` property is `true`", () => {
311359
// Given
312360
const store = initCalendarStore({
313361
useDetailPopup: true,
314362
});
363+
315364
const eventName = 'readonly-event';
316365
const uiModel = new EventUIModel(
317366
new EventModel({
@@ -322,6 +371,7 @@ describe('isReadOnly', () => {
322371
isReadOnly: true,
323372
})
324373
);
374+
325375
const props = {
326376
uiModel,
327377
eventHeight: 30,

apps/calendar/src/components/events/horizontalEvent.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { dndSelector, optionsSelector, viewSelector } from '@src/selectors';
1616
import { DraggingState } from '@src/slices/dnd';
1717
import { isSameDate } from '@src/time/datetime';
1818
import { passConditionalProp } from '@src/utils/preact';
19-
import { isNil } from '@src/utils/type';
19+
import { isPresent } from '@src/utils/type';
2020

2121
import type { CalendarColor } from '@t/options';
2222

@@ -144,8 +144,9 @@ export function HorizontalEvent({
144144
const eventContainerRef = useRef<HTMLDivElement>(null);
145145

146146
const { isReadOnly, id, calendarId } = uiModel.model;
147-
const isDraggableEvent =
148-
!isReadOnlyCalendar && !isReadOnly && isNil(resizingWidth) && isNil(movingLeft);
147+
148+
const isDraggingGuideEvent = isPresent(resizingWidth) || isPresent(movingLeft);
149+
const isDraggableEvent = !isReadOnlyCalendar && !isReadOnly && !isDraggingGuideEvent;
149150

150151
const startDragEvent = (className: string) => {
151152
setDraggingEventUIModel(uiModel);
@@ -160,8 +161,7 @@ export function HorizontalEvent({
160161
if (
161162
draggingState === DraggingState.DRAGGING &&
162163
draggingEventUIModel?.cid() === uiModel.cid() &&
163-
isNil(resizingWidth) &&
164-
isNil(movingLeft)
164+
!isDraggingGuideEvent
165165
) {
166166
setIsDraggingTarget(true);
167167
} else {
@@ -170,7 +170,7 @@ export function HorizontalEvent({
170170
});
171171

172172
useEffect(() => {
173-
if (isDraggableEvent) {
173+
if (!isDraggingGuideEvent) {
174174
eventBus.fire('afterRenderEvent', uiModel.model.toEventObject());
175175
}
176176
// This effect is only for the first render.

0 commit comments

Comments
 (0)