Skip to content

Commit 7e50caf

Browse files
committed
feat(calendar-web): yearDayClickView to standart and custom
1 parent b90df10 commit 7e50caf

7 files changed

Lines changed: 56 additions & 14 deletions

File tree

packages/pluggableWidgets/calendar-web/openspec/changes/add-calendar-year-view/proposal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Users need a year-at-a-glance view to see events across all 12 months simultaneo
2727

2828
**Code Changes:**
2929

30-
- **XML Configuration** (`Calendar.xml`): Add "year" enum value to `defaultViewStandard`, `defaultViewCustom`, and toolbar `itemType` properties; add top-level `yearDayClickView` enum (day/week/work_week/month/agenda) controlling the day-click target
30+
- **XML Configuration** (`Calendar.xml`): Add "year" enum value to `defaultViewStandard`, `defaultViewCustom`, and toolbar `itemType` properties; add per-mode day-click target enums `yearDayClickViewStandard` (day/week/month) and `yearDayClickViewCustom` (day/week/work_week/month/agenda), each shown only in its matching view mode via `Calendar.editorConfig.ts`
3131
- **Type Definitions** (`CalendarProps.d.ts`): Auto-generated types will include "year" in view enums
3232
- **View Registration** (`CalendarPropsBuilder.ts`): Update `buildVisibleViews()` to include year view component, update type unions
3333
- **Toolbar** (`Toolbar.tsx`): Add "year" to `ResolvedToolbarItem` type and render logic

packages/pluggableWidgets/calendar-web/openspec/changes/add-calendar-year-view/specs/calendar-year-view/spec.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ Days with events SHALL display a single dot indicator, regardless of the number
7474

7575
### Requirement: Day click navigates to the configured target view
7676

77-
Clicking a day cell SHALL navigate the calendar to the author-configured day-click target view (via the `yearDayClickView` property) for the selected date, PROVIDED that target view is enabled. The target choices are day, week, work_week, month, and agenda; the default is day. If the configured target view is not among the calendar's enabled views, day-click SHALL be disabled: day cells are rendered as non-interactive (no button role, tab stop, click, or keyboard handler) while retaining their aria-label, and no navigation occurs.
77+
Clicking a day cell SHALL navigate the calendar to the author-configured day-click target view for the selected date, PROVIDED that target view is enabled. The target is configured per view mode via two properties, so the available choices always match the mode's available views:
78+
79+
- **Standard mode**`yearDayClickViewStandard`, choices: day, week, month (default day). All are always enabled in Standard mode, so the target is always honored.
80+
- **Custom mode**`yearDayClickViewCustom`, choices: day, week, work_week, month, agenda (default day). Only honored if that view is enabled via a toolbar item.
81+
82+
The builder collapses the mode-specific property into a single effective target early (mirroring `defaultView`), so downstream logic is mode-agnostic. If the configured target view is not among the calendar's enabled views (only reachable in Custom mode), day-click SHALL be disabled: day cells are rendered as non-interactive (no button role, tab stop, click, or keyboard handler) while retaining their aria-label, and no navigation occurs.
7883

7984
#### Scenario: User clicks a day in the current month
8085

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function getProperties(values: CalendarPreviewProps, defaultProperties: P
3434
if (values.view === "standard") {
3535
hidePropertiesIn(defaultProperties, values, [
3636
"defaultViewCustom",
37+
"yearDayClickViewCustom",
3738
"toolbarItems",
3839
"customViewShowMonday",
3940
"customViewShowTuesday",
@@ -44,7 +45,12 @@ export function getProperties(values: CalendarPreviewProps, defaultProperties: P
4445
"customViewShowSunday"
4546
]);
4647
} else {
47-
hidePropertiesIn(defaultProperties, values, ["defaultViewStandard", "topBarDateFormat", "timeFormat"]);
48+
hidePropertiesIn(defaultProperties, values, [
49+
"defaultViewStandard",
50+
"yearDayClickViewStandard",
51+
"topBarDateFormat",
52+
"timeFormat"
53+
]);
4854
}
4955

5056
values.toolbarItems?.forEach((item, index) => {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,18 @@
101101
<enumerationValue key="year">Year</enumerationValue>
102102
</enumerationValues>
103103
</property>
104-
<property key="yearDayClickView" type="enumeration" defaultValue="day">
104+
<property key="yearDayClickViewStandard" type="enumeration" defaultValue="day">
105105
<caption>Year view: day click opens</caption>
106-
<description>Which view opens when a day is clicked in the Year view. Only applies if that view is enabled; otherwise clicking a day does nothing.</description>
106+
<description>Which view opens when a day is clicked in the Year view.</description>
107+
<enumerationValues>
108+
<enumerationValue key="day">Day</enumerationValue>
109+
<enumerationValue key="week">Week</enumerationValue>
110+
<enumerationValue key="month">Month</enumerationValue>
111+
</enumerationValues>
112+
</property>
113+
<property key="yearDayClickViewCustom" type="enumeration" defaultValue="day">
114+
<caption>Year view: day click opens</caption>
115+
<description>Which view opens when a day is clicked in the Year view. Only applies if that view is enabled via a toolbar item; otherwise clicking a day does nothing.</description>
107116
<enumerationValues>
108117
<enumerationValue key="day">Day</enumerationValue>
109118
<enumerationValue key="week">Week</enumerationValue>

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ const customViewProps: CalendarContainerProps = {
7272
view: "custom",
7373
defaultViewStandard: "month",
7474
defaultViewCustom: "work_week",
75-
yearDayClickView: "day",
75+
yearDayClickViewStandard: "day",
76+
yearDayClickViewCustom: "day",
7677
editable: dynamic.available(true),
7778
showEventDate: dynamic.available(true),
7879
widthUnit: "percentage",
@@ -259,11 +260,11 @@ describe("CalendarPropsBuilder validation", () => {
259260

260261
const buildWithToolbarItems = (
261262
itemTypes: string[],
262-
yearDayClickView: CalendarContainerProps["yearDayClickView"] = "day"
263+
yearDayClickView: CalendarContainerProps["yearDayClickViewCustom"] = "day"
263264
): ReturnType<typeof CalendarPropsBuilder.prototype.build> => {
264265
const props = {
265266
...customViewProps,
266-
yearDayClickView,
267+
yearDayClickViewCustom: yearDayClickView,
267268
toolbarItems: itemTypes.map(itemType => ({
268269
itemType,
269270
position: "right",
@@ -300,4 +301,19 @@ describe("CalendarPropsBuilder validation", () => {
300301
const views = buildWithToolbarItems(["year", "week"], "month").views as Record<string, unknown>;
301302
expect(views.month).toBe(false);
302303
});
304+
305+
const buildStandard = (
306+
yearDayClickViewStandard: CalendarContainerProps["yearDayClickViewStandard"]
307+
): ReturnType<typeof CalendarPropsBuilder.prototype.build> => {
308+
const props = { ...customViewProps, view: "standard", yearDayClickViewStandard } as any;
309+
return new CalendarPropsBuilder(props).build(mockLocalizer, "en");
310+
};
311+
312+
it("resolves the standard-mode day-click view against the fixed day/week/month set", () => {
313+
// Standard mode always enables day/week/month/year, so a standard target of "month"
314+
// is honored: month is a registered view and the year view is available to drill from.
315+
const views = buildStandard("month").views as Record<string, unknown>;
316+
expect(views.month).toBe(true);
317+
expect(views.year).toBeTruthy();
318+
});
303319
});

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { ObjectItem } from "mendix";
22
import { DateLocalizer, Formats, ViewsProps } from "react-big-calendar";
33
import { CustomWeekController } from "./CustomWeekController";
44
import { YearViewController } from "./YearViewController";
5-
import { CalendarContainerProps, YearDayClickViewEnum } from "../../typings/CalendarProps";
5+
import { CalendarContainerProps, YearDayClickViewCustomEnum } from "../../typings/CalendarProps";
66
import { createConfigurableToolbar, CustomToolbar, ResolvedToolbarItem } from "../components/Toolbar";
77
import { eventPropGetter, getTextValue } from "../utils/calendar-utils";
88
import { CalendarEvent, DragAndDropCalendarProps } from "../utils/typings";
99

1010
export class CalendarPropsBuilder {
1111
private visibleDays: Set<number>;
1212
private defaultView: "month" | "week" | "work_week" | "day" | "agenda" | "year";
13-
private yearDayClickView: YearDayClickViewEnum;
13+
private yearDayClickView: YearDayClickViewCustomEnum;
1414
private isCustomView: boolean;
1515
private events: CalendarEvent[];
1616
private minTime: Date;
@@ -23,7 +23,9 @@ export class CalendarPropsBuilder {
2323
constructor(private props: CalendarContainerProps) {
2424
this.isCustomView = props.view === "custom";
2525
this.defaultView = this.isCustomView ? props.defaultViewCustom : props.defaultViewStandard;
26-
this.yearDayClickView = props.yearDayClickView;
26+
// Collapse the mode-specific day-click view into one field early, mirroring how
27+
// `defaultView` is chosen above — the rest of the builder stays mode-agnostic.
28+
this.yearDayClickView = this.isCustomView ? props.yearDayClickViewCustom : props.yearDayClickViewStandard;
2729
this.visibleDays = this.buildVisibleDays();
2830
this.events = this.buildEvents(props.databaseDataSource?.items ?? []);
2931
this.minTime = this.buildTime(props.minHour ?? 0);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export type DefaultViewStandardEnum = "day" | "week" | "month" | "year";
1414

1515
export type DefaultViewCustomEnum = "day" | "week" | "month" | "work_week" | "agenda" | "year";
1616

17-
export type YearDayClickViewEnum = "day" | "week" | "work_week" | "month" | "agenda";
17+
export type YearDayClickViewStandardEnum = "day" | "week" | "month";
18+
19+
export type YearDayClickViewCustomEnum = "day" | "week" | "work_week" | "month" | "agenda";
1820

1921
export type ItemTypeEnum = "day" | "month" | "agenda" | "week" | "work_week" | "year" | "title" | "previous" | "next" | "today";
2022

@@ -85,7 +87,8 @@ export interface CalendarContainerProps {
8587
view: ViewEnum;
8688
defaultViewStandard: DefaultViewStandardEnum;
8789
defaultViewCustom: DefaultViewCustomEnum;
88-
yearDayClickView: YearDayClickViewEnum;
90+
yearDayClickViewStandard: YearDayClickViewStandardEnum;
91+
yearDayClickViewCustom: YearDayClickViewCustomEnum;
8992
showEventDate: DynamicValue<boolean>;
9093
timeFormat?: DynamicValue<string>;
9194
topBarDateFormat?: DynamicValue<string>;
@@ -141,7 +144,8 @@ export interface CalendarPreviewProps {
141144
view: ViewEnum;
142145
defaultViewStandard: DefaultViewStandardEnum;
143146
defaultViewCustom: DefaultViewCustomEnum;
144-
yearDayClickView: YearDayClickViewEnum;
147+
yearDayClickViewStandard: YearDayClickViewStandardEnum;
148+
yearDayClickViewCustom: YearDayClickViewCustomEnum;
145149
showEventDate: string;
146150
timeFormat: string;
147151
topBarDateFormat: string;

0 commit comments

Comments
 (0)