Skip to content

Commit 9689b7d

Browse files
NathanBPjquense
authored andcommitted
fix: bug where appointments can appear outside the calendar (jquense#1204)
* Fixed bug where appointments can appear outside the calendar * Modfied change to stop moving all appointments up by 2% * Updated code to get top of appointment * Added range tests, to ensure appointments don't appear outside calendar
1 parent f3ea6f8 commit 9689b7d

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

examples/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const EXAMPLES = {
4444
customView: 'Custom Calendar Views',
4545
resource: 'Resource Scheduling',
4646
dnd: 'Addon: Drag and drop',
47+
dndresource: 'Resource Drag and drop',
4748
dndOutsideSource: 'Addon: Drag and drop (from outside calendar)',
4849
}
4950

examples/demos/dndresource.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,41 @@ const events = [
2828
end: new Date(2018, 0, 29, 12, 30, 0),
2929
resourceId: 3,
3030
},
31+
{
32+
id: 10,
33+
title: 'Board meeting',
34+
start: new Date(2018, 0, 30, 23, 0, 0),
35+
end: new Date(2018, 0, 30, 23, 59, 0),
36+
resourceId: 1,
37+
},
3138
{
3239
id: 11,
3340
title: 'Birthday Party',
3441
start: new Date(2018, 0, 30, 7, 0, 0),
3542
end: new Date(2018, 0, 30, 10, 30, 0),
3643
resourceId: 4,
3744
},
45+
{
46+
id: 12,
47+
title: 'Board meeting',
48+
start: new Date(2018, 0, 29, 23, 59, 0),
49+
end: new Date(2018, 0, 30, 13, 0, 0),
50+
resourceId: 1,
51+
},
52+
{
53+
id: 13,
54+
title: 'Board meeting',
55+
start: new Date(2018, 0, 29, 23, 50, 0),
56+
end: new Date(2018, 0, 30, 13, 0, 0),
57+
resourceId: 2,
58+
},
59+
{
60+
id: 14,
61+
title: 'Board meeting',
62+
start: new Date(2018, 0, 29, 23, 40, 0),
63+
end: new Date(2018, 0, 30, 13, 0, 0),
64+
resourceId: 4,
65+
},
3866
]
3967

4068
const resourceMap = [
@@ -103,6 +131,8 @@ class Dnd extends React.Component {
103131
resourceTitleAccessor="resourceTitle"
104132
onEventResize={this.resizeEvent}
105133
defaultView="day"
134+
step={15}
135+
showMultiDayTimes={true}
106136
defaultDate={new Date(2018, 0, 29)}
107137
/>
108138
)

src/utils/TimeSlots.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) {
130130

131131
const rangeStartMin = positionFromDate(rangeStart)
132132
const rangeEndMin = positionFromDate(rangeEnd)
133-
const top = (rangeStartMin / (step * numSlots)) * 100
133+
const top =
134+
rangeEndMin - rangeStartMin < step
135+
? ((rangeStartMin - step) / (step * numSlots)) * 100
136+
: (rangeStartMin / (step * numSlots)) * 100
134137

135138
return {
136139
top,

test/utils/TimeSlots.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,81 @@ describe('getSlotMetrics', () => {
2222
expect(diff).toBe(60)
2323
})
2424
})
25+
26+
describe('getRange', () => {
27+
const min = dates.startOf(new Date(), 'day')
28+
const max = dates.endOf(new Date(), 'day')
29+
const slotMetrics = getSlotMetrics({ min, max, step: 60, timeslots: 1 })
30+
31+
test('getRange: 15 minute start of day appointment stays within calendar', () => {
32+
let range = slotMetrics.getRange(
33+
new Date(2018, 0, 29, 0, 0, 0),
34+
new Date(2018, 0, 29, 0, 15, 0)
35+
)
36+
expect(range.top + range.height).toBeLessThan(100)
37+
expect(range.height).toBeGreaterThan(0)
38+
})
39+
40+
test('getRange: 1 hour start of day appointment stays within calendar', () => {
41+
let range = slotMetrics.getRange(
42+
new Date(2018, 0, 29, 0, 0, 0),
43+
new Date(2018, 0, 29, 1, 0, 0)
44+
)
45+
expect(range.top + range.height).toBeLessThan(100)
46+
expect(range.height).toBeGreaterThan(0)
47+
})
48+
49+
test('getRange: 1 hour mid range appointment stays within calendar', () => {
50+
let range = slotMetrics.getRange(
51+
new Date(2018, 0, 29, 14, 0, 0),
52+
new Date(2018, 0, 29, 15, 0, 0)
53+
)
54+
expect(range.top + range.height).toBeLessThan(100)
55+
expect(range.height).toBeGreaterThan(0)
56+
})
57+
58+
test('getRange: 3 hour mid range appointment stays within calendar', () => {
59+
let range = slotMetrics.getRange(
60+
new Date(2018, 0, 29, 14, 0, 0),
61+
new Date(2018, 0, 29, 17, 0, 0)
62+
)
63+
expect(range.top + range.height).toBeLessThan(100)
64+
expect(range.height).toBeGreaterThan(0)
65+
})
66+
67+
test('getRange: full day appointment stays within calendar', () => {
68+
let range = slotMetrics.getRange(
69+
new Date(2018, 0, 29, 0, 0, 0),
70+
new Date(2018, 0, 29, 23, 59, 0)
71+
)
72+
expect(range.top + range.height).toBeLessThan(100)
73+
expect(range.height).toBeGreaterThan(0)
74+
})
75+
76+
test('getRange: 1 hour end of day appointment stays within calendar', () => {
77+
let range = slotMetrics.getRange(
78+
new Date(2018, 0, 29, 23, 0, 0),
79+
new Date(2018, 0, 29, 23, 59, 0)
80+
)
81+
expect(range.top + range.height).toBeLessThan(100)
82+
expect(range.height).toBeGreaterThan(0)
83+
})
84+
85+
test('getRange: 15 minute end of day appointment stays within calendar', () => {
86+
let range = slotMetrics.getRange(
87+
new Date(2018, 0, 29, 23, 45, 0),
88+
new Date(2018, 0, 29, 23, 59, 0)
89+
)
90+
expect(range.top + range.height).toBeLessThan(100)
91+
expect(range.height).toBeGreaterThan(0)
92+
})
93+
94+
test('getRange: multi day appointment stays within calendar', () => {
95+
let range = slotMetrics.getRange(
96+
new Date(2018, 0, 29, 0, 0, 0),
97+
new Date(2018, 0, 30, 4, 0, 0)
98+
)
99+
expect(range.top + range.height).toBeLessThan(100)
100+
expect(range.height).toBeGreaterThan(0)
101+
})
102+
})

0 commit comments

Comments
 (0)