Skip to content

Commit

Permalink
fix: preserve time on horizontal resizing (#1795)
Browse files Browse the repository at this point in the history
When an event is resized horizontally (e.g. on the Month
View), keep the time of the event the same and only change
the date.

This also fixes the bug where you cannot resize an event to
a single day because the `dates.max` or `dates.min` would
force the event to occur at least 1 day after the
`start` or `end` respectively.

Co-authored-by: Jackson Hoang <jhoang@atlassian.com>
  • Loading branch information
jkhoang313 and jhoangatl authored Nov 6, 2020
1 parent a3aebe9 commit 1b186da
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/addons/dragAndDrop/WeekWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,17 @@ class WeekWrapper extends React.Component {
const { accessors, slotMetrics: metrics } = this.props

let { start, end } = eventTimes(event, accessors)
let originalStart = start
let originalEnd = end

let rowBox = getBoundsForNode(node)
let cursorInRow = pointInBox(rowBox, point)

if (direction === 'RIGHT') {
if (cursorInRow) {
if (metrics.last < start) return this.reset()
// add min
end = dates.add(
metrics.getDateForSlot(
getSlotAtX(rowBox, point.x, false, metrics.slots)
),
1,
'day'
end = metrics.getDateForSlot(
getSlotAtX(rowBox, point.x, false, metrics.slots)
)
} else if (
dates.inRange(start, metrics.first, metrics.last) ||
Expand All @@ -162,8 +159,10 @@ class WeekWrapper extends React.Component {
this.setState({ segment: null })
return
}

end = dates.max(end, dates.add(start, 1, 'day'))
end = dates.merge(end, accessors.end(event))
if (dates.lt(end, start)) {
end = originalEnd
}
} else if (direction === 'LEFT') {
// inbetween Row
if (cursorInRow) {
Expand All @@ -181,8 +180,10 @@ class WeekWrapper extends React.Component {
this.reset()
return
}

start = dates.min(dates.add(end, -1, 'day'), start)
start = dates.merge(start, accessors.start(event))
if (dates.gt(start, end)) {
start = originalStart
}
}

this.update(event, start, end)
Expand Down

0 comments on commit 1b186da

Please sign in to comment.