Skip to content

Commit b0f29d6

Browse files
committed
fixed that bookings had no key to identify them
1 parent 59ed228 commit b0f29d6

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

library/src/components/timetable/TimeTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { useRateLimitHelper } from "../../utils/rateLimit"
3939
import useResizeObserver from "use-resize-observer"
4040

4141
export interface TimeSlotBooking {
42+
key: React.Key
4243
title: string
4344
startDate: Dayjs
4445
endDate: Dayjs
@@ -614,6 +615,7 @@ function moveNowBar(
614615
}
615616

616617
const nowItem: TimeSlotBooking = {
618+
key: "nowbar",
617619
title: "nowBar",
618620
startDate: now,
619621
endDate: now,

library/src/components/timetable/TimeTableRows.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ function TableCell<G extends TimeTableGroup, I extends TimeSlotBooking>({
763763

764764
return (
765765
<ItemWrapper
766-
key={it.item.title}
766+
key={it.item.key}
767767
group={group}
768768
item={it.item}
769769
width={itemWidthInColumn}

library/src/components/timetable/timeTableUtils.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ function calculateTimeSlotsHoursView(
6565
slotsArray[i * timeSlotsPerDay + ts] = timeSlot
6666
}
6767
}
68-
6968
return slotsArray
7069
}
7170

@@ -145,17 +144,22 @@ function calculateTimeSlotPropertiesForHoursView(
145144
return { timeFrameDay, slotsArray: [], timeSlotMinutes: 0 }
146145
}
147146

148-
let timeDiff = dayjs()
147+
let endOfDay = dayjs()
149148
.startOf("day")
150149
.add(endDate.hour(), "hours")
151150
.add(endDate.minute(), "minutes")
152-
.diff(
153-
dayjs()
154-
.startOf("day")
155-
.add(startDate.hour(), "hours")
156-
.add(startDate.minute(), "minutes"),
157-
"minutes",
158-
)
151+
152+
const startOfDay = endOfDay
153+
.startOf("day")
154+
.add(startDate.hour(), "hours")
155+
.add(startDate.minute(), "minutes")
156+
157+
if (endOfDay.isBefore(startOfDay)) {
158+
endOfDay = endOfDay.add(1, "day")
159+
}
160+
161+
let timeDiff = endOfDay.diff(startOfDay, "minutes")
162+
159163
if (timeDiff === 0) {
160164
timeDiff = 24 * 60
161165
}
@@ -293,29 +297,22 @@ export function calculateTimeSlotPropertiesForView(
293297
slotsArray.push(ret)
294298
}
295299

296-
let oneDayMinutes = dayjs()
300+
let endOfDay = dayjs()
297301
.startOf("day")
298302
.add(endHour, "hours")
299303
.add(endMinute, "minutes")
300-
.diff(
301-
dayjs()
302-
.startOf("day")
303-
.add(startHour, "hours")
304-
.add(startMinute, "minutes"),
305-
"minutes",
306-
)
304+
305+
const startOfDay = endOfDay
306+
.startOf("day")
307+
.add(startHour, "hours")
308+
.add(startMinute, "minutes")
309+
310+
if (endOfDay.isBefore(startOfDay)) {
311+
endOfDay = endOfDay.add(1, "day")
312+
}
313+
314+
let oneDayMinutes = endOfDay.diff(startOfDay, "minutes")
307315
if (oneDayMinutes === 0) {
308-
// I set it on purpose to 23h 59min
309-
/*const endOfDay = dayjs().endOf("day")
310-
endHour = endOfDay.hour()
311-
endMinute = endOfDay.minute()
312-
oneDayMinutes = endOfDay.diff(
313-
dayjs()
314-
.startOf("day")
315-
.add(startHour, "hours")
316-
.add(endHour, "minutes"),
317-
"minutes",
318-
)*/
319316
oneDayMinutes = 24 * 60
320317
}
321318

@@ -614,7 +611,10 @@ export function getStartAndEndSlot(
614611
.add(timeFrameDay.startMinute, "minutes")
615612
}
616613

617-
if (item.endDate.isBefore(startSlotStart)) {
614+
if (
615+
item.endDate.isBefore(startSlotStart) ||
616+
item.endDate.isSame(startSlotStart)
617+
) {
618618
return { startSlot: startSlot, endSlot: startSlot, status: "before" }
619619
}
620620

showcase/src/components/showcase/wrapper/TimeTableShowcase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ function createMoreTestGroups(
420420
return newGroups
421421
}
422422

423-
const startDateInitial = dayjs().startOf("day").add(-1, "day")
423+
const startDateInitial = dayjs().startOf("day").add(-1, "day").add(8, "hours")
424424
const endDateInitial = dayjs().startOf("day").add(6, "days")
425425

426426
function TestCustomHeaderRowTimeSlot<

0 commit comments

Comments
 (0)