-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
EventEndingRow.js
107 lines (86 loc) · 2.48 KB
/
EventEndingRow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import PropTypes from 'prop-types'
import React from 'react'
import EventRowMixin from './EventRowMixin'
import { eventLevels } from './utils/eventLevels'
import range from 'lodash/range'
let isSegmentInSlot = (seg, slot) => seg.left <= slot && seg.right >= slot
let eventsInSlot = (segments, slot) =>
segments.filter(seg => isSegmentInSlot(seg, slot)).length
class EventEndingRow extends React.Component {
static propTypes = {
segments: PropTypes.array,
slots: PropTypes.number,
onShowMore: PropTypes.func,
...EventRowMixin.propTypes,
}
static defaultProps = {
...EventRowMixin.defaultProps,
}
render() {
let { segments, slotMetrics: { slots } } = this.props
let rowSegments = eventLevels(segments).levels[0]
let current = 1,
lastEnd = 1,
row = []
while (current <= slots) {
let key = '_lvl_' + current
let { event, left, right, span } =
rowSegments.filter(seg => isSegmentInSlot(seg, current))[0] || {} //eslint-disable-line
if (!event) {
current++
continue
}
let gap = Math.max(0, left - lastEnd)
if (this.canRenderSlotEvent(left, span)) {
let content = EventRowMixin.renderEvent(this.props, event)
if (gap) {
row.push(EventRowMixin.renderSpan(slots, gap, key + '_gap'))
}
row.push(EventRowMixin.renderSpan(slots, span, key, content))
lastEnd = current = right + 1
} else {
if (gap) {
row.push(EventRowMixin.renderSpan(slots, gap, key + '_gap'))
}
row.push(
EventRowMixin.renderSpan(
slots,
1,
key,
this.renderShowMore(segments, current)
)
)
lastEnd = current = current + 1
}
}
return <div className="rbc-row">{row}</div>
}
canRenderSlotEvent(slot, span) {
let { segments } = this.props
return range(slot, slot + span).every(s => {
let count = eventsInSlot(segments, s)
return count === 1
})
}
renderShowMore(segments, slot) {
let { localizer } = this.props
let count = eventsInSlot(segments, slot)
return count ? (
<a
key={'sm_' + slot}
href="#"
className={'rbc-show-more'}
onClick={e => this.showMore(slot, e)}
>
{localizer.messages.showMore(count)}
</a>
) : (
false
)
}
showMore(slot, e) {
e.preventDefault()
this.props.onShowMore(slot)
}
}
export default EventEndingRow