Skip to content

Commit e30529c

Browse files
committed
feat(calendar-web): split standard and custom config
1 parent 2a80103 commit e30529c

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

packages/pluggableWidgets/calendar-web/src/Calendar.editorConfig.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ export function getProperties(values: CalendarPreviewProps, defaultProperties: P
3535
// Hide custom week range properties when view is set to 'standard'
3636
if (values.view === "standard") {
3737
hidePropertiesIn(defaultProperties, values, [
38+
"defaultViewCustom",
3839
"showSunday",
3940
"showMonday",
4041
"showTuesday",
4142
"showWednesday",
4243
"showThursday",
4344
"showFriday",
44-
"showSaturday"
45+
"showSaturday",
46+
"customViewCaption"
4547
]);
48+
} else {
49+
hidePropertyIn(defaultProperties, values, "defaultViewStandard");
4650
}
4751

4852
// Show/hide title properties based on selection

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<caption>Enable create</caption>
8484
<description />
8585
</property>
86-
<property key="defaultView" type="enumeration" defaultValue="month">
86+
<property key="defaultViewCustom" type="enumeration" defaultValue="month">
8787
<caption>Initial selected view</caption>
8888
<description>Work week and agenda are only available in custom views</description>
8989
<enumerationValues>
@@ -94,6 +94,15 @@
9494
<enumerationValue key="agenda">Agenda</enumerationValue>
9595
</enumerationValues>
9696
</property>
97+
<property key="defaultViewStandard" type="enumeration" defaultValue="month">
98+
<caption>Default view</caption>
99+
<description>The default view to show when the calendar is loaded</description>
100+
<enumerationValues>
101+
<enumerationValue key="day">Day</enumerationValue>
102+
<enumerationValue key="week">Week</enumerationValue>
103+
<enumerationValue key="month">Month</enumerationValue>
104+
</enumerationValues>
105+
</property>
97106
<property key="startDateAttribute" type="attribute" required="false">
98107
<caption>Start date attribute</caption>
99108
<description>The start date that should be shown in the view</description>

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ interface DragAndDropCalendarProps<TEvent extends object = Event, TResource exte
6767
withDragAndDropProps<TEvent, TResource> {}
6868

6969
export function extractCalendarProps(props: CalendarContainerProps): DragAndDropCalendarProps<CalEvent, object> {
70-
const visibleSet = new Set<number>();
71-
// Caption for custom work week button / title
72-
70+
const isCustomView = props.view === "custom";
71+
const defaultView = isCustomView ? props.defaultViewCustom : props.defaultViewStandard;
7372
const customCaption: string = props.customViewCaption ?? "Custom";
73+
const visibleSet = new Set<number>();
7474
const dayProps = [
7575
{ prop: props.showSunday, day: 0 },
7676
{ prop: props.showMonday, day: 1 },
@@ -158,16 +158,9 @@ export function extractCalendarProps(props: CalendarContainerProps): DragAndDrop
158158
return { title, start, end, allDay, color, item };
159159
});
160160

161-
// Update button label inside localizer messages
162-
(localizer as any).messages = {
163-
...localizer.messages,
164-
work_week: customCaption
165-
};
166-
167-
const viewsOption: ViewsProps<CalEvent, object> =
168-
props.view === "standard"
169-
? { day: true, week: true, month: true }
170-
: { day: true, week: true, month: true, work_week: CustomWeek, agenda: true };
161+
const viewsOption: ViewsProps<CalEvent, object> = isCustomView
162+
? { day: true, week: true, month: true, work_week: CustomWeek, agenda: true }
163+
: { day: true, week: true, month: true };
171164

172165
// Compute minimum and maximum times for the day based on configured hours
173166
const minTime = new Date();
@@ -222,7 +215,7 @@ export function extractCalendarProps(props: CalendarContainerProps): DragAndDrop
222215
components: {
223216
toolbar: CustomToolbar
224217
},
225-
defaultView: props.defaultView,
218+
defaultView,
226219
messages: {
227220
work_week: customCaption
228221
},

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export type ViewEnum = "standard" | "custom";
1212

1313
export type EditableEnum = "default" | "never";
1414

15-
export type DefaultViewEnum = "day" | "week" | "month" | "work_week" | "agenda";
15+
export type DefaultViewCustomEnum = "day" | "week" | "month" | "work_week" | "agenda";
16+
17+
export type DefaultViewStandardEnum = "day" | "week" | "month";
1618

1719
export type WidthUnitEnum = "pixels" | "percentage";
1820

@@ -40,7 +42,8 @@ export interface CalendarContainerProps {
4042
view: ViewEnum;
4143
editable: EditableEnum;
4244
enableCreate: boolean;
43-
defaultView: DefaultViewEnum;
45+
defaultViewCustom: DefaultViewCustomEnum;
46+
defaultViewStandard: DefaultViewStandardEnum;
4447
startDateAttribute?: EditableValue<Date>;
4548
minHour: number;
4649
maxHour: number;
@@ -91,7 +94,8 @@ export interface CalendarPreviewProps {
9194
view: ViewEnum;
9295
editable: EditableEnum;
9396
enableCreate: boolean;
94-
defaultView: DefaultViewEnum;
97+
defaultViewCustom: DefaultViewCustomEnum;
98+
defaultViewStandard: DefaultViewStandardEnum;
9599
startDateAttribute: string;
96100
minHour: number | null;
97101
maxHour: number | null;

0 commit comments

Comments
 (0)