Skip to content

Commit 9852d0a

Browse files
StefanKellerSiemensrahmanunver
authored andcommitted
feat(calendar-web): new props step and timeslots and fix for day/week/month view change
1 parent 27969d9 commit 9852d0a

6 files changed

Lines changed: 52 additions & 5 deletions

File tree

packages/pluggableWidgets/calendar-web/src/Calendar.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@
131131
<caption>Show all events</caption>
132132
<description>Auto-adjust calendar height to display all events without "more" links</description>
133133
</property>
134+
<property key="step" type="integer" defaultValue="60">
135+
<caption>Step</caption>
136+
<description>Determines the selectable time increments in week and day views</description>
137+
</property>
138+
<property key="timeslots" type="integer" defaultValue="2">
139+
<caption>Time slots</caption>
140+
<description>The number of slots per "section" in the time grid views. Adjust with step to change the default of 1 hour long groups, with 30 minute slots.</description>
141+
</property>
134142
</propertyGroup>
135143
</propertyGroup>
136144
<propertyGroup caption="Custom view">

packages/pluggableWidgets/calendar-web/src/__tests__/Calendar.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ const customViewProps: CalendarContainerProps = {
8686
customViewShowFriday: true,
8787
customViewShowSaturday: false,
8888
showAllEvents: true,
89+
step: 60,
90+
timeslots: 2,
8991
toolbarItems: [],
9092
topBarDateFormat: undefined
9193
};

packages/pluggableWidgets/calendar-web/src/__tests__/__snapshots__/Calendar.spec.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ exports[`Calendar renders correctly with basic props 1`] = `
1919
formats="[object Object]"
2020
localizer="[object Object]"
2121
messages="[object Object]"
22+
step="60"
23+
timeslots="2"
2224
views="[object Object]"
2325
/>
2426
</div>

packages/pluggableWidgets/calendar-web/src/helpers/CalendarPropsBuilder.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export class CalendarPropsBuilder {
1414
private minTime: Date;
1515
private maxTime: Date;
1616
private toolbarItems?: ResolvedToolbarItem[];
17+
private step: number;
18+
private timeSlots: number;
1719

1820
constructor(private props: CalendarContainerProps) {
1921
this.isCustomView = props.view === "custom";
@@ -23,6 +25,8 @@ export class CalendarPropsBuilder {
2325
this.minTime = this.buildTime(props.minHour ?? 0);
2426
this.maxTime = this.buildTime(props.maxHour ?? 24);
2527
this.toolbarItems = this.buildToolbarItems();
28+
this.step = props.step;
29+
this.timeSlots = props.timeslots;
2630
}
2731

2832
updateProps(props: CalendarContainerProps): void {
@@ -71,7 +75,9 @@ export class CalendarPropsBuilder {
7175
titleAccessor: (event: CalendarEvent) => event.title,
7276
showAllEvents: this.props.showAllEvents,
7377
min: this.minTime,
74-
max: this.maxTime
78+
max: this.maxTime,
79+
step: this.step,
80+
timeslots: this.timeSlots
7581
};
7682
}
7783

packages/pluggableWidgets/calendar-web/src/helpers/useCalendarEvents.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
22
import { CalendarEvent, EventDropOrResize } from "../utils/typings";
33
import { CalendarContainerProps } from "../../typings/CalendarProps";
4-
import { CalendarProps, NavigateAction } from "react-big-calendar";
4+
import { CalendarProps, NavigateAction, View } from "react-big-calendar";
55
import { getViewRange } from "../utils/calendar-utils";
66

77
type CalendarEventHandlers = Pick<
88
CalendarProps<CalendarEvent>,
9-
"onSelectEvent" | "onDoubleClickEvent" | "onKeyPressEvent" | "onSelectSlot" | "onNavigate" | "selected"
9+
| "onSelectEvent"
10+
| "onDoubleClickEvent"
11+
| "onKeyPressEvent"
12+
| "onSelectSlot"
13+
| "onNavigate"
14+
| "selected"
15+
| "onRangeChange"
1016
> & {
1117
onEventDrop: (event: EventDropOrResize) => void;
1218
onEventResize: (event: EventDropOrResize) => void;
@@ -116,7 +122,7 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
116122
[onDragDropResize]
117123
);
118124

119-
const handleRangeChange = useCallback(
125+
const handleNavigate = useCallback(
120126
(date: Date, view: string, _action: NavigateAction) => {
121127
const action = onViewRangeChange;
122128

@@ -132,6 +138,24 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
132138
[onViewRangeChange]
133139
);
134140

141+
const handleRangeChange = useCallback(
142+
(range: Date[] | { start: Date; end: Date }, view?: View) => {
143+
const action = onViewRangeChange;
144+
145+
if (action?.canExecute) {
146+
const start = Array.isArray(range) ? range[0] : range.start;
147+
const end = Array.isArray(range) ? range[range.length - 1] : range.end;
148+
149+
action.execute({
150+
rangeStart: start,
151+
rangeEnd: end,
152+
currentView: view
153+
});
154+
}
155+
},
156+
[onViewRangeChange]
157+
);
158+
135159
useEffect(() => {
136160
/**
137161
* What Is This?
@@ -152,7 +176,8 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
152176
onSelectSlot: handleCreateEvent,
153177
onEventDrop: handleEventDropOrResize,
154178
onEventResize: handleEventDropOrResize,
155-
onNavigate: handleRangeChange,
179+
onNavigate: handleNavigate,
180+
onRangeChange: handleRangeChange,
156181
selected
157182
};
158183
}

packages/pluggableWidgets/calendar-web/typings/CalendarProps.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export interface CalendarContainerProps {
9090
minHour: number;
9191
maxHour: number;
9292
showAllEvents: boolean;
93+
step: number;
94+
timeslots: number;
9395
toolbarItems: ToolbarItemsType[];
9496
customViewShowMonday: boolean;
9597
customViewShowTuesday: boolean;
@@ -143,6 +145,8 @@ export interface CalendarPreviewProps {
143145
minHour: number | null;
144146
maxHour: number | null;
145147
showAllEvents: boolean;
148+
step: number | null;
149+
timeslots: number | null;
146150
toolbarItems: ToolbarItemsPreviewType[];
147151
customViewShowMonday: boolean;
148152
customViewShowTuesday: boolean;

0 commit comments

Comments
 (0)