Skip to content

Commit 301a3c3

Browse files
committed
feat(calendar-web): add hour scope for the day view
1 parent 4c040b2 commit 301a3c3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
<attributeType name="DateTime" />
102102
</attributeTypes>
103103
</property>
104+
<property key="minHour" type="integer" defaultValue="0">
105+
<caption>Day start hour</caption>
106+
<description>The hour at which the day view starts (0-23)</description>
107+
</property>
108+
<property key="maxHour" type="integer" defaultValue="24">
109+
<caption>Day end hour</caption>
110+
<description>The hour at which the day view ends (1-24)</description>
111+
</property>
104112
</propertyGroup>
105113
</propertyGroup>
106114
<propertyGroup caption="Events">

packages/pluggableWidgets/calendar-web/src/utils/calendar-utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export function extractCalendarProps(props: CalendarContainerProps): DragAndDrop
8181
const viewsOption: ViewsProps<CalEvent, object> =
8282
props.view === "standard" ? ["day", "week", "month"] : ["month", "week", "work_week", "day", "agenda"];
8383

84+
// Compute minimum and maximum times for the day based on configured hours
85+
const minTime = new Date();
86+
minTime.setHours(props.minHour ?? 0, 0, 0, 0);
87+
const maxTime = new Date();
88+
maxTime.setHours(props.maxHour ?? 24, 0, 0, 0);
89+
8490
const handleSelectEvent = (event: CalEvent): void => {
8591
if (props.onClickEvent?.canExecute) {
8692
props.onClickEvent.execute({
@@ -143,6 +149,8 @@ export function extractCalendarProps(props: CalendarContainerProps): DragAndDrop
143149
onSelectEvent: handleSelectEvent,
144150
onSelectSlot: handleSelectSlot,
145151
startAccessor: (event: CalEvent) => event.start,
146-
titleAccessor: (event: CalEvent) => event.title
152+
titleAccessor: (event: CalEvent) => event.title,
153+
min: minTime,
154+
max: maxTime
147155
};
148156
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface CalendarContainerProps {
4242
enableCreate: boolean;
4343
defaultView: DefaultViewEnum;
4444
startDateAttribute?: EditableValue<Date>;
45+
minHour: number;
46+
maxHour: number;
4547
eventDataAttribute?: EditableValue<string>;
4648
onClickEvent?: ActionValue<{ startDate: Option<Date>; endDate: Option<Date>; allDay: Option<boolean>; title: Option<string> }>;
4749
onCreateEvent?: ActionValue<{ startDate: Option<Date>; endDate: Option<Date>; allDay: Option<boolean> }>;
@@ -82,6 +84,8 @@ export interface CalendarPreviewProps {
8284
enableCreate: boolean;
8385
defaultView: DefaultViewEnum;
8486
startDateAttribute: string;
87+
minHour: number | null;
88+
maxHour: number | null;
8589
eventDataAttribute: string;
8690
onClickEvent: {} | null;
8791
onCreateEvent: {} | null;

0 commit comments

Comments
 (0)