Skip to content

Commit 5380fee

Browse files
committed
fix: DnD corner cases in allDay move/resize
1 parent f670719 commit 5380fee

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/addons/dragAndDrop/WeekWrapper.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ import Selection, {
88
import * as dates from '../../utils/dates'
99
import { eventSegments } from '../../utils/eventLevels'
1010
import { getSlotAtX, pointInBox } from '../../utils/selection'
11-
import { dragAccessors, eventTimes } from './common'
11+
import { dragAccessors } from './common'
1212
import { DnDContext } from './DnDContext'
1313

14+
const eventTimes = (event, accessors) => {
15+
let start = accessors.start(event)
16+
let end = accessors.end(event)
17+
18+
const isZeroDuration =
19+
dates.eq(start, end, 'minutes') && start.getMinutes() === 0
20+
// make zero duration midnight events at least one day long
21+
if (isZeroDuration) end = dates.add(end, 1, 'day')
22+
const duration = dates.diff(end, start, 'milliseconds')
23+
return { start, end, duration }
24+
}
25+
1426
class WeekWrapper extends React.Component {
1527
static propTypes = {
1628
isAllDay: PropTypes.bool,
@@ -102,33 +114,30 @@ class WeekWrapper extends React.Component {
102114
this.handleMove(point, node, this.context.draggable.dragFromOutsideItem())
103115
}
104116

105-
// TODO: when resizing RIGHT, the mouse has to make it all the way to the
106-
// very end of the slot before it jumps...
107117
handleResize(point, bounds) {
108118
const { event, direction } = this.context.draggable.dragAndDropAction
109119
const { accessors, slotMetrics, rtl } = this.props
110120

111-
let { start, end, allDay } = eventTimes(event, accessors)
112-
let originalStart = start
113-
let originalEnd = end
121+
let { start, end } = eventTimes(event, accessors)
114122

115123
const slot = getSlotAtX(bounds, point.x, rtl, slotMetrics.slots)
116124
const date = slotMetrics.getDateForSlot(slot)
117-
let cursorInRow = pointInBox(bounds, point)
125+
const cursorInRow = pointInBox(bounds, point)
118126

119127
if (direction === 'RIGHT') {
120128
if (cursorInRow) {
121129
if (slotMetrics.last < start) return this.reset()
122-
end = date
130+
end = dates.add(date, 1, 'day')
123131
} else if (
124132
dates.inRange(start, slotMetrics.first, slotMetrics.last) ||
125-
(bounds.bottom < point.y && dates.gt(slotMetrics.first, start))
133+
(bounds.bottom < point.y && +slotMetrics.first > +start)
126134
) {
127135
end = dates.add(slotMetrics.last, 1, 'milliseconds')
128136
} else {
129137
this.setState({ segment: null })
130138
return
131139
}
140+
const originalEnd = accessors.end(event)
132141
end = dates.merge(end, originalEnd)
133142
if (dates.lt(end, start)) {
134143
end = originalEnd
@@ -146,20 +155,19 @@ class WeekWrapper extends React.Component {
146155
this.reset()
147156
return
148157
}
158+
const originalStart = accessors.start(event)
149159
start = dates.merge(start, originalStart)
150160
if (dates.gt(start, end)) {
151161
start = originalStart
152162
}
153163
}
154164

155-
if (allDay) end = dates.add(end, 1, 'day')
156165
this.update(event, start, end)
157166
}
158167

159168
_selectable = () => {
160-
let wrapper = this.ref.current
161-
let node = wrapper.closest('.rbc-month-row, .rbc-allday-cell')
162-
let container = wrapper.closest('.rbc-month-view, .rbc-time-view')
169+
let node = this.ref.current.closest('.rbc-month-row, .rbc-allday-cell')
170+
let container = node.closest('.rbc-month-view, .rbc-time-view')
163171

164172
let selector = (this._selector = new Selection(() => container))
165173

src/addons/dragAndDrop/common.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { wrapAccessor } from '../../utils/accessors'
22
import { createFactory } from 'react'
3-
import * as dates from '../../utils/dates'
43

54
export const dragAccessors = {
65
start: wrapAccessor(e => e.start),
@@ -32,22 +31,3 @@ export function pointInColumn(bounds, point) {
3231
const { x, y } = point
3332
return x < right + 10 && x > left && y > top
3433
}
35-
36-
/**
37-
* Get start, end, allDay and duration of an event using the provided accessors.
38-
* Fixes up problematic case of malformed allDay events (those missing
39-
* allDay=true or allDay events where the end date isn't exclusive)
40-
*/
41-
export function eventTimes(event, accessors) {
42-
const start = accessors.start(event)
43-
let end = accessors.end(event)
44-
let allDay = accessors.allDay(event)
45-
const duration = dates.diff(start, end, 'milliseconds')
46-
47-
// make zero duration midnight events at least one day long
48-
if (duration === 0 && start.getMinutes() === 0) {
49-
end = dates.add(end, 1, 'day')
50-
allDay = true
51-
}
52-
return { start, end, allDay, duration }
53-
}

0 commit comments

Comments
 (0)