Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dnd): added check for null dragFromOutsideItem, updated example #2651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/addons/dragAndDrop/EventContainerWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ class EventContainerWrapper extends React.Component {
})
}

handleDragOverFromOutside = (point, bounds) => {
const { slotMetrics } = this.props

const start = slotMetrics.closestSlotFromPoint(
{ y: point.y, x: point.x },
bounds
)
const end = slotMetrics.nextSlot(start)
const event = this.context.draggable.dragFromOutsideItem()
this.update(event, slotMetrics.getRange(start, end, false, true))
}

updateParentScroll = (parent, node) => {
setTimeout(() => {
const draggedEl = qsa(node, '.rbc-addons-dnd-drag-preview')[0]
Expand Down Expand Up @@ -200,10 +212,12 @@ class EventContainerWrapper extends React.Component {
this.handleDropFromOutside(point, bounds)
})

selector.on('dragOver', (point) => {
if (!this.context.draggable.dragFromOutsideItem) return
selector.on('dragOverFromOutside', (point) => {
const item = this.context.draggable.dragFromOutsideItem ? this.context.draggable.dragFromOutsideItem() : null
if (!item) return
const bounds = getBoundsForNode(node)
this.handleDropFromOutside(point, bounds)
if (!pointInColumn(bounds, point)) return this.reset()
this.handleDragOverFromOutside(point, bounds)
})

selector.on('selectStart', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/addons/dragAndDrop/WeekWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ class WeekWrapper extends React.Component {
}

handleDragOverFromOutside = (point, node) => {
if (!this.context.draggable.dragFromOutsideItem) return
this.handleMove(point, node, this.context.draggable.dragFromOutsideItem())
const item = this.context.draggable.dragFromOutsideItem ? this.context.draggable.dragFromOutsideItem() : null
if (!item) return
this.handleMove(point, node, item)
}

handleResize(point, bounds) {
Expand Down
6 changes: 3 additions & 3 deletions stories/demos/exampleCode/dndOutsideSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export default function DnDOutsideResource({ localizer }) {
//,
const handleDragStart = useCallback((event) => setDraggedEvent(event), [])

const dragFromOutsideItem = useCallback(() => draggedEvent, [draggedEvent])
const dragFromOutsideItem = useCallback(() => draggedEvent === 'undroppable' ? null : draggedEvent, [draggedEvent])

const customOnDragOver = useCallback(
const customOnDragOverFromOutside = useCallback(
(dragEvent) => {
// check for undroppable is specific to this example
// and not part of API. This just demonstrates that
Expand Down Expand Up @@ -177,7 +177,7 @@ export default function DnDOutsideResource({ localizer }) {
events={myEvents}
localizer={localizer}
onDropFromOutside={onDropFromOutside}
onDragOver={customOnDragOver}
onDragOverFromOutside={customOnDragOverFromOutside}
onEventDrop={moveEvent}
onEventResize={resizeEvent}
onSelectSlot={newEvent}
Expand Down
Loading