From 081a4efbca8379e2c998ebcdbc38897e170ce5cf Mon Sep 17 00:00:00 2001 From: Thibault Vigouroux Date: Sat, 23 Sep 2017 13:04:40 +0200 Subject: [PATCH] Code review --- src/Calendar.js | 1 + src/TimeGrid.js | 39 +++++---------------------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/Calendar.js b/src/Calendar.js index 97da14418..f6090f4ea 100644 --- a/src/Calendar.js +++ b/src/Calendar.js @@ -512,6 +512,7 @@ class Calendar extends React.Component { allDayAccessor: 'allDay', startAccessor: 'start', endAccessor: 'end', + resourceIdAccessor: 'resourceId', longPressThreshold: 250, }; diff --git a/src/TimeGrid.js b/src/TimeGrid.js index a0b2fdbda..8d3cdc688 100644 --- a/src/TimeGrid.js +++ b/src/TimeGrid.js @@ -49,6 +49,7 @@ export default class TimeGrid extends Component { allDayAccessor: accessor.isRequired, startAccessor: accessor.isRequired, endAccessor: accessor.isRequired, + resourceIdAccessor: accessor.isRequired, selected: PropTypes.object, selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), @@ -177,9 +178,7 @@ export default class TimeGrid extends Component { let gutterRef = ref => this._gutters[1] = ref && findDOMNode(ref); - let eventsRendered = resources ? - this.renderEventsWithResource(range, rangeEvents, this.props.now, resources) : - this.renderEvents(range, rangeEvents, this.props.now); + let eventsRendered = this.renderEvents(range, rangeEvents, this.props.now, resources || [{}]); return (
@@ -202,8 +201,8 @@ export default class TimeGrid extends Component {
); } - renderEventsWithResource(range, events, today, resources) { - let { min, max, endAccessor, startAccessor, components } = this.props; + renderEvents(range, events, today, resources) { + let { min, max, endAccessor, startAccessor, resourceIdAccessor, components } = this.props; return range.map((date, idx) => { let daysEvents = events.filter( @@ -215,7 +214,7 @@ export default class TimeGrid extends Component { return resources.map((resource, id) => { let eventsToDisplay = daysEvents.filter( - event => event.resourceId === resource.id + event => get(event, resourceIdAccessor) === resource.id ) return ( @@ -238,34 +237,6 @@ export default class TimeGrid extends Component { }) } - renderEvents(range, events, today, id){ - let { min, max, endAccessor, startAccessor, components } = this.props; - - return range.map((date, idx) => { - let daysEvents = events.filter( - event => dates.inRange(date, - get(event, startAccessor), - get(event, endAccessor), 'day') && event.resourceId === id - ) - - return ( - - ) - }) - } - renderHeader(range, events, width, resources) { let { messages, rtl, selectable, components, now } = this.props; let { isOverflowing } = this.state || {};