Skip to content

Commit 2ea4619

Browse files
fix(calendar-web): update startDateAttribute to use EditableValue and handle null cases
1 parent 00208d2 commit 2ea4619

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "./ui/Calendar.scss";
88
import { useCalendarEvents } from "./helpers/useCalendarEvents";
99
import { useLocalizer } from "./helpers/useLocalizer";
1010

11-
export default function MxCalendar(props: CalendarContainerProps): ReactElement {
11+
export default function MxCalendar(props: CalendarContainerProps): ReactElement | null {
1212
// useMemo with empty dependency array is used
1313
// because style and calendar controller needs to be created only once
1414
// and not on every re-render
@@ -26,6 +26,11 @@ export default function MxCalendar(props: CalendarContainerProps): ReactElement
2626
}, [props, calendarController, localizer, culture]);
2727

2828
const calendarEvents = useCalendarEvents(props);
29+
30+
if (props.startDateAttribute && props.startDateAttribute.status !== "available") {
31+
return null;
32+
}
33+
2934
return (
3035
<div className={classNames("widget-calendar", props.class)} style={wrapperStyle}>
3136
<DnDCalendar {...calendarProps} {...calendarEvents} />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
<attributeType name="String" />
6363
</attributeTypes>
6464
</property>
65-
<property key="startDateAttribute" type="attribute" dataSource="databaseDataSource" required="false">
65+
<property key="startDateAttribute" type="attribute" required="false">
6666
<caption>Start date attribute</caption>
67-
<description>The start date that should be shown in the view</description>
67+
<description>The DateTime attribute used on initial load</description>
6868
<attributeTypes>
6969
<attributeType name="DateTime" />
7070
</attributeTypes>

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

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

1819
constructor(private props: CalendarContainerProps) {
1920
this.isCustomView = props.view === "custom";
@@ -23,13 +24,15 @@ export class CalendarPropsBuilder {
2324
this.minTime = this.buildTime(props.minHour ?? 0);
2425
this.maxTime = this.buildTime(props.maxHour ?? 24);
2526
this.toolbarItems = this.buildToolbarItems();
27+
this.defaultDate = props.startDateAttribute?.value;
2628
}
2729

2830
updateProps(props: CalendarContainerProps): void {
2931
// Update the props object, skipping props that are static (on construction only)
3032
this.props = props;
3133
this.events = this.buildEvents(props.databaseDataSource?.items ?? []);
3234
this.toolbarItems = this.buildToolbarItems();
35+
this.defaultDate = props.startDateAttribute?.value;
3336
}
3437

3538
build(localizer: DateLocalizer, culture: string): DragAndDropCalendarProps<CalendarEvent> {
@@ -71,7 +74,8 @@ export class CalendarPropsBuilder {
7174
titleAccessor: (event: CalendarEvent) => event.title,
7275
showAllEvents: this.props.showAllEvents,
7376
min: this.minTime,
74-
max: this.maxTime
77+
max: this.maxTime,
78+
...(this.defaultDate ? { defaultDate: this.defaultDate } : {})
7579
};
7680
}
7781

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Mendix Widgets Framework Team
55
*/
66
import { CSSProperties } from "react";
7-
import { ActionValue, DynamicValue, ListValue, Option, ListActionValue, ListAttributeValue, ListExpressionValue } from "mendix";
7+
import { ActionValue, DynamicValue, EditableValue, ListValue, Option, ListActionValue, ListAttributeValue, ListExpressionValue } from "mendix";
88

99
export type TitleTypeEnum = "attribute" | "expression";
1010

@@ -79,7 +79,7 @@ export interface CalendarContainerProps {
7979
startAttribute?: ListAttributeValue<Date>;
8080
endAttribute?: ListAttributeValue<Date>;
8181
eventColor?: ListAttributeValue<string>;
82-
startDateAttribute?: ListAttributeValue<Date>;
82+
startDateAttribute?: EditableValue<Date>;
8383
editable: DynamicValue<boolean>;
8484
view: ViewEnum;
8585
defaultViewStandard: DefaultViewStandardEnum;

0 commit comments

Comments
 (0)