@@ -121,6 +121,11 @@ interface TimeTableRowsProps<
121
121
* Callback for when rendered groups change, return the group indices that were rendered (parameter is a set of group indices)
122
122
*/
123
123
onRenderedGroupsChanged : ( ( groups : Set < number > ) => void ) | undefined
124
+
125
+ /**
126
+ * Callback for when a time slot is clicked.
127
+ */
128
+ onTimeSlotClick ?: ( s : { groupId : string ; startDate : Dayjs ; endDate : Dayjs } ) => void
124
129
}
125
130
126
131
const intersectionStackDelay = 1
@@ -147,6 +152,7 @@ function renderGroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>(
147
152
viewType : TimeTableViewType ,
148
153
timeStepMinutesHoursView : number ,
149
154
onRenderedGroupsChanged : ( ( groups : Set < number > ) => void ) | undefined ,
155
+ onTimeSlotClick ?: ( s : { groupId : string ; startDate : Dayjs ; endDate : Dayjs } ) => void ,
150
156
) {
151
157
if ( g < 0 ) {
152
158
throw new Error ( "TimeTable - group number is negative" )
@@ -234,6 +240,7 @@ function renderGroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>(
234
240
renderedGroupsRef = { renderedGroupsRef }
235
241
changedGroupRowsRef = { changedGroupRowsRef }
236
242
timeStepMinutesHoursView = { timeStepMinutesHoursView }
243
+ onTimeSlotClick = { onTimeSlotClick }
237
244
//
238
245
/>
239
246
)
@@ -260,6 +267,7 @@ export default function TimeTableRows<
260
267
viewType,
261
268
timeStepMinutesHoursView,
262
269
onRenderedGroupsChanged,
270
+ onTimeSlotClick,
263
271
} : TimeTableRowsProps < G , I > ) : JSX . Element [ ] {
264
272
const storeIdent = useTimeTableIdent ( )
265
273
const { rowHeight, columnWidth, placeHolderHeight } =
@@ -674,6 +682,7 @@ export default function TimeTableRows<
674
682
viewType ,
675
683
timeStepMinutesHoursView ,
676
684
onRenderedGroupsChanged ,
685
+ onTimeSlotClick ,
677
686
)
678
687
counter ++
679
688
if ( counter > timeTableGroupRenderBatchSize ) {
@@ -711,6 +720,7 @@ export default function TimeTableRows<
711
720
viewType ,
712
721
timeStepMinutesHoursView ,
713
722
onRenderedGroupsChanged ,
723
+ onTimeSlotClick ,
714
724
)
715
725
counter ++
716
726
if ( counter > timeTableGroupRenderBatchSize ) {
@@ -744,6 +754,7 @@ export default function TimeTableRows<
744
754
viewType ,
745
755
timeStepMinutesHoursView ,
746
756
onRenderedGroupsChanged ,
757
+ onTimeSlotClick ,
747
758
)
748
759
++ counter
749
760
}
@@ -769,6 +780,7 @@ export default function TimeTableRows<
769
780
onRenderedGroupsChanged ,
770
781
groupRowKeys ,
771
782
groupRows ,
783
+ onTimeSlotClick ,
772
784
] )
773
785
774
786
// Ensure rendering is triggered - handle edge cases where renderGroupRangeRef might be [-1, -1]
@@ -851,6 +863,7 @@ function TableCell<G extends TimeTableGroup, I extends TimeSlotBooking>({
851
863
viewType,
852
864
timeStepMinutesHoursView,
853
865
groupItemRows,
866
+ onTimeSlotClick,
854
867
} : {
855
868
timeSlotNumber : number
856
869
group : G
@@ -867,6 +880,7 @@ function TableCell<G extends TimeTableGroup, I extends TimeSlotBooking>({
867
880
viewType : TimeTableViewType
868
881
timeStepMinutesHoursView : number
869
882
groupItemRows : ItemRowEntry < I > [ ] [ ] | null
883
+ onTimeSlotClick ?: ( s : { groupId : string ; startDate : Dayjs ; endDate : Dayjs } ) => void
870
884
} ) {
871
885
const storeIdent = useTimeTableIdent ( )
872
886
const disableWeekendInteractions =
@@ -912,6 +926,8 @@ function TableCell<G extends TimeTableGroup, I extends TimeSlotBooking>({
912
926
disableWeekendInteractions ,
913
927
)
914
928
929
+ const timeSlotEnd = timeSlot . add ( timeSlotMinutes , "minutes" )
930
+
915
931
const handleKeyUp = useKeyboardHandlers (
916
932
timeSlotNumber ,
917
933
group . id ,
@@ -1087,6 +1103,11 @@ function TableCell<G extends TimeTableGroup, I extends TimeSlotBooking>({
1087
1103
< td
1088
1104
key = { timeSlotNumber }
1089
1105
{ ...mouseHandlersUsed }
1106
+ onClick = { onTimeSlotClick ? ( ) => {
1107
+ onTimeSlotClick ( { groupId : group . id , startDate : timeSlot , endDate : timeSlotEnd } )
1108
+ }
1109
+ : undefined
1110
+ }
1090
1111
onKeyUp = { handleKeyUp }
1091
1112
onBlur = { ( e ) => {
1092
1113
// Only handle blur for the first cell
@@ -1200,6 +1221,7 @@ function PlaceholderTableCell<
1200
1221
slotsArray,
1201
1222
selectedTimeSlots, // this will be only with value when the current time slot is selected
1202
1223
placeHolderHeight,
1224
+ onTimeSlotClick,
1203
1225
} : {
1204
1226
group : G
1205
1227
groupNumber : number
@@ -1212,6 +1234,7 @@ function PlaceholderTableCell<
1212
1234
slotsArray : readonly Dayjs [ ]
1213
1235
selectedTimeSlots : readonly number [ ] | undefined
1214
1236
placeHolderHeight : number
1237
+ onTimeSlotClick ?: ( s : { groupId : string ; startDate : Dayjs ; endDate : Dayjs } ) => void
1215
1238
} ) {
1216
1239
const storeIdent = useTimeTableIdent ( )
1217
1240
const focusedCell = useFocusedCell ( storeIdent )
@@ -1279,14 +1302,16 @@ function PlaceholderTableCell<
1279
1302
disableWeekendInteractions ,
1280
1303
)
1281
1304
1305
+ const timeSlotEnd = timeSlot . add ( timeSlotMinutes , "minutes" )
1306
+
1282
1307
const handleKeyUp = useKeyboardHandlers (
1283
1308
timeSlotNumber ,
1284
1309
group . id ,
1285
1310
nextGroupId ,
1286
1311
previousGroupId ,
1287
1312
slotsArray ,
1288
1313
storeIdent ,
1289
- groupItemRows ,
1314
+ groupItemRows
1290
1315
)
1291
1316
1292
1317
const isFocused =
@@ -1340,6 +1365,14 @@ function PlaceholderTableCell<
1340
1365
} }
1341
1366
tabIndex = { - 1 }
1342
1367
onKeyUp = { handleKeyUp }
1368
+ onKeyDown = { onTimeSlotClick ? ( e ) => {
1369
+ if ( e . key === "Enter" ) {
1370
+ onTimeSlotClick ?.( { groupId : group . id , startDate : timeSlot , endDate : timeSlotEnd } )
1371
+ }
1372
+ } : undefined }
1373
+ onClick = { ( ) => {
1374
+ onTimeSlotClick ?.( { groupId : group . id , startDate : timeSlot , endDate : timeSlotEnd } )
1375
+ } }
1343
1376
>
1344
1377
{ isFocused && (
1345
1378
< div
@@ -1382,6 +1415,7 @@ type GroupRowsProps<G extends TimeTableGroup, I extends TimeSlotBooking> = {
1382
1415
renderedGroupsRef : React . MutableRefObject < Set < number > >
1383
1416
changedGroupRowsRef : React . MutableRefObject < Set < number > >
1384
1417
timeStepMinutesHoursView : number
1418
+ onTimeSlotClick ?: ( s : { groupId : string ; startDate : Dayjs ; endDate : Dayjs } ) => void
1385
1419
}
1386
1420
1387
1421
function GroupRows < G extends TimeTableGroup , I extends TimeSlotBooking > ( {
@@ -1406,6 +1440,7 @@ function GroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>({
1406
1440
renderedGroupsRef,
1407
1441
changedGroupRowsRef,
1408
1442
//
1443
+ onTimeSlotClick,
1409
1444
} : GroupRowsProps < G , I > ) {
1410
1445
// ugly SIDE EFFECTs for now to make sure the rendered groups are set
1411
1446
changedGroupRowsRef . current . delete ( groupNumber )
@@ -1541,6 +1576,7 @@ function GroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>({
1541
1576
placeHolderHeight = { placeHolderHeight }
1542
1577
timeSlotMinutes = { timeSlotMinutes }
1543
1578
groupItemRows = { groupItemRows }
1579
+ onTimeSlotClick = { onTimeSlotClick }
1544
1580
/> ,
1545
1581
)
1546
1582
}
@@ -1600,6 +1636,7 @@ function GroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>({
1600
1636
timeFrameDay = { timeFrameDay }
1601
1637
viewType = { viewType }
1602
1638
timeStepMinutesHoursView = { timeStepMinutesHoursView }
1639
+ onTimeSlotClick = { onTimeSlotClick }
1603
1640
/> ,
1604
1641
)
1605
1642
}
@@ -1621,6 +1658,7 @@ function GroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>({
1621
1658
timeStepMinutesHoursView ,
1622
1659
nextGroupId ,
1623
1660
previousGroupId ,
1661
+ onTimeSlotClick ,
1624
1662
] )
1625
1663
1626
1664
if ( ! renderCells ) {
0 commit comments