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

Added dragging ability from the monthly Popup component #1554

Merged
merged 2 commits into from
May 29, 2020
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
42 changes: 36 additions & 6 deletions examples/demos/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,39 @@ class Dnd extends React.Component {
super(props)
this.state = {
events: events,
displayDragItemInCell: true,
}

this.moveEvent = this.moveEvent.bind(this)
this.newEvent = this.newEvent.bind(this)
}

moveEvent({ event, start, end, isAllDay: droppedOnAllDaySlot }) {
handleDragStart = event => {
this.setState({ draggedEvent: event })
}

dragFromOutsideItem = () => {
return this.state.draggedEvent
}

onDropFromOutside = ({ start, end, allDay }) => {
const { draggedEvent } = this.state

const event = {
id: draggedEvent.id,
title: draggedEvent.title,
start,
end,
allDay: allDay,
}

this.setState({ draggedEvent: null })
this.moveEvent({ event, start, end })
}

moveEvent = ({ event, start, end, isAllDay: droppedOnAllDaySlot }) => {
const { events } = this.state

const idx = events.indexOf(event)
let allDay = event.allDay

if (!event.allDay && droppedOnAllDaySlot) {
Expand All @@ -30,10 +53,11 @@ class Dnd extends React.Component {
allDay = false
}

const updatedEvent = { ...event, start, end, allDay }

const nextEvents = [...events]
nextEvents.splice(idx, 1, updatedEvent)
const nextEvents = events.map(existingEvent => {
return existingEvent.id == event.id
? { ...existingEvent, start, end }
: existingEvent
})

this.setState({
events: nextEvents,
Expand Down Expand Up @@ -86,6 +110,12 @@ class Dnd extends React.Component {
onDragStart={console.log}
defaultView={Views.MONTH}
defaultDate={new Date(2015, 3, 12)}
popup={true}
dragFromOutsideItem={
this.state.displayDragItemInCell ? this.dragFromOutsideItem : null
}
onDropFromOutside={this.onDropFromOutside}
handleDragStart={this.handleDragStart}
/>
)
}
Expand Down
9 changes: 9 additions & 0 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ class MonthView extends React.Component {
components={components}
localizer={localizer}
position={overlay.position}
show={this.overlayDisplay}
events={overlay.events}
slotStart={overlay.date}
slotEnd={overlay.end}
onSelect={this.handleSelectEvent}
onDoubleClick={this.handleDoubleClickEvent}
handleDragStart={this.props.handleDragStart}
/>
)}
</Overlay>
Expand Down Expand Up @@ -273,6 +275,12 @@ class MonthView extends React.Component {
notify(onShowMore, [events, date, slot])
}

overlayDisplay = () => {
this.setState({
overlay: null,
})
}

selectDates(slotInfo) {
let slots = this._pendingSelection.slice()

Expand Down Expand Up @@ -328,6 +336,7 @@ MonthView.propTypes = {
getDrilldownView: PropTypes.func.isRequired,

popup: PropTypes.bool,
handleDragStart: PropTypes.func,

popupOffset: PropTypes.oneOfType([
PropTypes.number,
Expand Down
5 changes: 5 additions & 0 deletions src/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Popup extends React.Component {
slotStart={slotStart}
slotEnd={slotEnd}
selected={isSelected(event, selected)}
draggable={true}
onDragStart={() => this.props.handleDragStart(event)}
onDragEnd={() => this.props.show()}
/>
))}
</div>
Expand All @@ -103,6 +106,8 @@ Popup.propTypes = {
localizer: PropTypes.object.isRequired,
onSelect: PropTypes.func,
onDoubleClick: PropTypes.func,
handleDragStart: PropTypes.func,
show: PropTypes.func,
slotStart: PropTypes.instanceOf(Date),
slotEnd: PropTypes.number,
popperRef: PropTypes.oneOfType([
Expand Down