11import { ObjectItem } from "mendix" ;
2- import {
3- CalendarProps as ReactCalendarProps ,
4- DateLocalizer ,
5- Formats ,
6- NavigateAction ,
7- ViewsProps
8- } from "react-big-calendar" ;
9- import { withDragAndDropProps } from "react-big-calendar/lib/addons/dragAndDrop" ;
10-
2+ import { DateLocalizer , Formats , ViewsProps } from "react-big-calendar" ;
113import { CalendarContainerProps } from "../../typings/CalendarProps" ;
124import { CustomToolbar } from "../components/Toolbar" ;
13- import { eventPropGetter , getViewRange , localizer } from "../utils/calendar-utils" ;
5+ import { eventPropGetter , localizer } from "../utils/calendar-utils" ;
6+ import { CalendarEvent , DragAndDropCalendarProps } from "../utils/typings" ;
147import { CustomWeekController } from "./CustomWeekController" ;
158
16- export interface CalendarEvent {
17- title : string ;
18- start : Date ;
19- end : Date ;
20- allDay : boolean ;
21- color ?: string ;
22- item : ObjectItem ;
23- }
24-
25- type EventDropOrResize = {
26- event : CalendarEvent ;
27- start : Date ;
28- end : Date ;
29- } ;
30-
31- interface DragAndDropCalendarProps < TEvent extends object = Event , TResource extends object = object >
32- extends ReactCalendarProps < TEvent , TResource > ,
33- withDragAndDropProps < TEvent , TResource > { }
34-
359export class CalendarPropsBuilder {
36- private readonly visibleDays : Set < number > ;
37- private readonly defaultView : "month" | "week" | "work_week" | "day" | "agenda" ;
38- private readonly customCaption : string ;
39- private readonly isCustomView : boolean ;
40- private readonly events : CalendarEvent [ ] ;
41- private readonly minTime : Date ;
42- private readonly maxTime : Date ;
43-
44- // Keeps the currently focused/selected event. Updated on every selection.
45- private selectedEvent ?: CalendarEvent ;
46- /**
47- * Stores the event that should be ignored on the next onSelectEvent call.
48- * This is set when a double-click is detected so we can ignore the
49- * secondary click that React-Big-Calendar dispatches as part of the same
50- * interaction. After the click has been ignored, the field is cleared so
51- * that future selections are handled normally.
52- */
53- private ignoreNextClickFor ?: CalendarEvent ;
10+ private visibleDays : Set < number > ;
11+ private defaultView : "month" | "week" | "work_week" | "day" | "agenda" ;
12+ private customCaption : string ;
13+ private isCustomView : boolean ;
14+ private events : CalendarEvent [ ] ;
15+ private minTime : Date ;
16+ private maxTime : Date ;
5417
5518 constructor ( private props : CalendarContainerProps ) {
5619 this . isCustomView = props . view === "custom" ;
@@ -62,6 +25,17 @@ export class CalendarPropsBuilder {
6225 this . maxTime = this . buildTime ( props . maxHour ?? 24 ) ;
6326 }
6427
28+ updateProps ( props : CalendarContainerProps ) : void {
29+ this . props = props ;
30+ this . isCustomView = props . view === "custom" ;
31+ this . defaultView = this . isCustomView ? props . defaultViewCustom : props . defaultViewStandard ;
32+ this . customCaption = props . customViewCaption ?. value ?? "Custom" ;
33+ this . visibleDays = this . buildVisibleDays ( ) ;
34+ this . events = this . buildEvents ( props . databaseDataSource ?. items ?? [ ] ) ;
35+ this . minTime = this . buildTime ( props . minHour ?? 0 ) ;
36+ this . maxTime = this . buildTime ( props . maxHour ?? 24 ) ;
37+ }
38+
6539 build ( ) : DragAndDropCalendarProps < CalendarEvent > {
6640 const CustomWeek = CustomWeekController . getComponent ( this . visibleDays ) ;
6741 const formats = this . buildFormats ( ) ;
@@ -80,21 +54,14 @@ export class CalendarPropsBuilder {
8054 events : this . events ,
8155 formats,
8256 localizer,
83- resizable : this . props . editable !== "never" ,
84- selectable : this . props . enableCreate ,
57+ resizable : this . props . editable . value ?? true ,
58+ selectable : this . props . enableCreate . value ?? true ,
8559 views,
8660 allDayAccessor : ( event : CalendarEvent ) => event . allDay ,
8761 endAccessor : ( event : CalendarEvent ) => event . end ,
8862 eventPropGetter,
8963 // @ts -expect-error – navigatable prop not yet in typings but exists in runtime component
9064 navigatable : true ,
91- onEventDrop : this . handleEventDropOrResize ,
92- onEventResize : this . handleEventDropOrResize ,
93- onNavigate : this . handleRangeChange ,
94- onSelectEvent : this . handleSelectEvent ,
95- onDoubleClickEvent : this . handleDoubleClickEvent ,
96- onKeyPressEvent : this . handleKeyPressEvent ,
97- onSelectSlot : this . handleCreateEvent ,
9865 startAccessor : ( event : CalendarEvent ) => event . start ,
9966 titleAccessor : ( event : CalendarEvent ) => event . title ,
10067 showAllEvents : this . props . showAllEvents ,
@@ -186,87 +153,29 @@ export class CalendarPropsBuilder {
186153 return new Set ( visibleDays ) ;
187154 }
188155
189- private handleEventDropOrResize = ( { event, start, end } : EventDropOrResize ) : void => {
190- const action = this . props . onDragDropResize ?. get ( event . item ) ;
191-
192- if ( action ?. canExecute ) {
193- action . execute ( {
194- oldStart : event . start ,
195- oldEnd : event . end ,
196- newStart : start ,
197- newEnd : end
198- } ) ;
199- }
200- } ;
201-
202- private handleRangeChange = ( date : Date , view : string , _action : NavigateAction ) : void => {
203- const action = this . props . onViewRangeChange ;
204-
205- if ( action ?. canExecute ) {
206- const { start, end } = getViewRange ( view , date ) ;
207- action . execute ( {
208- rangeStart : start ,
209- rangeEnd : end ,
210- currentView : view
211- } ) ;
212- }
213- } ;
214-
215- /**
216- * Called when an event is single-clicked (selected).
217- * First click only stores the selection; a consecutive click on the same event triggers edit.
218- */
219- private handleSelectEvent = ( event : CalendarEvent ) : void => {
220- if ( this . ignoreNextClickFor === event ) {
221- // Skip this click – it belongs to a double-click we've already handled.
222- this . ignoreNextClickFor = undefined ;
223- return ;
224- }
225-
226- if ( this . selectedEvent === event ) {
227- // Second click on the already-selected event => open edit panel.
228- this . invokeEdit ( event ) ;
229- } else {
230- // Update current selection.
231- this . selectedEvent = event ;
232- }
233- } ;
234-
235- /**
236- * Fast double click should open edit immediately.
237- */
238- private handleDoubleClickEvent = ( event : CalendarEvent ) : void => {
239- // Open edit immediately & prevent the subsequent single-click handler from firing edit again.
240- this . invokeEdit ( event ) ;
241- this . ignoreNextClickFor = event ;
242- } ;
243-
244- /**
245- * When the event has focus, pressing Enter should open edit.
246- */
247- private handleKeyPressEvent = ( event : CalendarEvent , e : any ) : void => {
248- if ( e . key === "Enter" ) {
249- this . invokeEdit ( event ) ;
250- }
251- } ;
252-
253- private invokeEdit ( event : CalendarEvent ) : void {
254- const action = this . props . onEditEvent ?. get ( event . item ) ;
255-
256- if ( action ?. canExecute ) {
257- action . execute ( ) ;
258- }
259- }
260-
261- private handleCreateEvent = ( slotInfo : { start : Date ; end : Date ; action : string } ) : void => {
262- const action = this . props . onCreateEvent ;
263-
264- if ( action ?. canExecute && this . props . enableCreate ) {
265- action ?. execute ( {
266- startDate : slotInfo . start ,
267- endDate : slotInfo . end ,
268- allDay : slotInfo . action === "select"
269- } ) ;
270- }
271- } ;
156+ // private handleEventDropOrResize = ({ event, start, end }: EventDropOrResize): void => {
157+ // const action = this.props.onDragDropResize?.get(event.item);
158+
159+ // if (action?.canExecute) {
160+ // action.execute({
161+ // oldStart: event.start,
162+ // oldEnd: event.end,
163+ // newStart: start,
164+ // newEnd: end
165+ // });
166+ // }
167+ // };
168+
169+ // private handleRangeChange = (date: Date, view: string, _action: NavigateAction): void => {
170+ // const action = this.props.onViewRangeChange;
171+
172+ // if (action?.canExecute) {
173+ // const { start, end } = getViewRange(view, date);
174+ // action.execute({
175+ // rangeStart: start,
176+ // rangeEnd: end,
177+ // currentView: view
178+ // });
179+ // }
180+ // };
272181}
0 commit comments