forked from jquense/react-big-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed DnD with Resource Columns + Added Example of it (jquense#873)
* Fixed DnD with Resource Columns + Added Example of it * Update DayColumn.js * Update TimeSlotGroup.js
- Loading branch information
1 parent
a13951c
commit 7411386
Showing
5 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react' | ||
import HTML5Backend from 'react-dnd-html5-backend' | ||
import { DragDropContext } from 'react-dnd' | ||
import BigCalendar from 'react-big-calendar' | ||
import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop' | ||
|
||
import 'react-big-calendar/lib/addons/dragAndDrop/styles.less' | ||
|
||
const DragAndDropCalendar = withDragAndDrop(BigCalendar) | ||
|
||
let allViews = Object.keys(BigCalendar.Views).map(k => BigCalendar.Views[k]) | ||
const events = [ | ||
{ | ||
id: 0, | ||
title: 'Board meeting', | ||
start: new Date(2018, 0, 29, 9, 0, 0), | ||
end: new Date(2018, 0, 29, 13, 0, 0), | ||
resourceId: 1, | ||
}, | ||
{ | ||
id: 1, | ||
title: 'MS training', | ||
start: new Date(2018, 0, 29, 14, 0, 0), | ||
end: new Date(2018, 0, 29, 16, 30, 0), | ||
resourceId: 2, | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Team lead meeting', | ||
start: new Date(2018, 0, 29, 8, 30, 0), | ||
end: new Date(2018, 0, 29, 12, 30, 0), | ||
resourceId: 3, | ||
}, | ||
{ | ||
id: 11, | ||
title: 'Birthday Party', | ||
start: new Date(2018, 0, 30, 7, 0, 0), | ||
end: new Date(2018, 0, 30, 10, 30, 0), | ||
resourceId: 4, | ||
}, | ||
] | ||
|
||
const resourceMap = [ | ||
{ resourceId: 1, resourceTitle: 'Board room' }, | ||
{ resourceId: 2, resourceTitle: 'Training room' }, | ||
{ resourceId: 3, resourceTitle: 'Meeting room 1' }, | ||
{ resourceId: 4, resourceTitle: 'Meeting room 2' }, | ||
] | ||
|
||
class Dnd extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
events: events, | ||
} | ||
|
||
this.moveEvent = this.moveEvent.bind(this) | ||
} | ||
|
||
moveEvent({ event, start, end, resourceId }) { | ||
console.log('moveEvent.args=', { event, start, end, resourceId }) | ||
const { events } = this.state | ||
|
||
const idx = events.indexOf(event) | ||
const updatedEvent = { ...event, start, end, resourceId } | ||
console.log('events', events) | ||
const nextEvents = [...events] | ||
nextEvents.splice(idx, 1, updatedEvent) | ||
console.log('nextEvents', nextEvents) | ||
this.setState({ | ||
events: nextEvents, | ||
}) | ||
} | ||
|
||
resizeEvent = (resizeType, { event, start, end }) => { | ||
const { events } = this.state | ||
|
||
const nextEvents = events.map(existingEvent => { | ||
return existingEvent.id == event.id | ||
? { ...existingEvent, start, end } | ||
: existingEvent | ||
}) | ||
|
||
this.setState({ | ||
events: nextEvents, | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<DragAndDropCalendar | ||
selectable | ||
events={this.state.events} | ||
onEventDrop={this.moveEvent} | ||
resizable | ||
resources={resourceMap} | ||
resourceIdAccessor="resourceId" | ||
resourceTitleAccessor="resourceTitle" | ||
onEventResize={this.resizeEvent} | ||
defaultView="day" | ||
defaultDate={new Date(2018, 0, 29)} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default DragDropContext(HTML5Backend)(Dnd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters