Add Event feature to BitCalendar (#12261)#12262
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe pull request introduces an event feature to the BitCalendar component, allowing users to display custom events for each calendar day via a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cs (1)
1006-1011: Index events once instead of filtering them per cell render.
GetDayEventswalks the fullEventssequence for every visible day button, so each rerender becomes ~42 full enumerations plus list allocations. Precomputing aDictionary<DateOnly, List<BitCalendarEvent>>whenEventschanges will keep the render path flat and avoid scaling cost with larger event sets.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cs` around lines 1006 - 1011, GetDayEvents currently scans the entire Events sequence for each day button causing O(n*m) cost; instead, build a Dictionary<DateOnly, List<BitCalendarEvent>> when Events changes and have GetDayEvents simply look up the date key. Add a private field (e.g. _eventsByDate) and populate it in the component's parameter-set/update path (e.g. in the Events setter or OnParametersSet/OnParametersSetAsync) by grouping Events by DateOnly.FromDateTime(e.Date) or e.Date if already DateOnly; ensure null/empty Events clears the dictionary; then change GetDayEvents to return the list from _eventsByDate.TryGetValue(dateOnly, out var list) ? list : an empty list to avoid per-cell enumeration and allocations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor`:
- Around line 589-616: Replace hard-coded date/time formats and English labels
in the modal and the tooltip formatter with a single culture-aware
formatter/localizer: change the _eventModalDate.ToString("MMMM d, yyyy") and the
time renderings for evt.StartTime/evt.EndTime to call a shared method (e.g.,
Create a FormatEventDate(DateTime) and FormatEventTime(TimeSpan?/DateTime?) or a
single FormatEventRange(start,end)) that uses CultureInfo.CurrentCulture (and
the BitTimeFormat setting to choose 12/24-hour patterns) and returns localized
"From"/"Until" text via resources; also update the tooltip formatter in the
BitCalendar class to call the same formatter so all date/time displays use
consistent, culture-aware formatting.
- Around line 579-625: The event popup markup controlled by _showEventModal
should be turned into an accessible dialog: add role="dialog" and
aria-modal="true" on the modal container and set aria-labelledby to the header
span (give the header span a unique id, e.g., eventModalTitle) which should
reference `@_eventModalDate` display; make the container focusable (tabindex="0")
and capture an ElementReference (e.g., _eventModalRef) so when _showEventModal
becomes true you call FocusAsync on that ref and save/restore the previously
focused element; wire an `@onkeydown` handler on the dialog container to close via
Escape (call CloseEventModal) and to trap Tab/Shift+Tab (or call a small JS
focus-trap helper via IJSRuntime) so keyboard users cannot tab out; ensure
CloseEventModal returns focus to the saved element when closing and keep
references to _eventModalEvents and CloseEventModal in these changes to locate
the code.
---
Nitpick comments:
In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cs`:
- Around line 1006-1011: GetDayEvents currently scans the entire Events sequence
for each day button causing O(n*m) cost; instead, build a Dictionary<DateOnly,
List<BitCalendarEvent>> when Events changes and have GetDayEvents simply look up
the date key. Add a private field (e.g. _eventsByDate) and populate it in the
component's parameter-set/update path (e.g. in the Events setter or
OnParametersSet/OnParametersSetAsync) by grouping Events by
DateOnly.FromDateTime(e.Date) or e.Date if already DateOnly; ensure null/empty
Events clears the dictionary; then change GetDayEvents to return the list from
_eventsByDate.TryGetValue(dateOnly, out var list) ? list : an empty list to
avoid per-cell enumeration and allocations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 646fab1c-3a88-44be-8c98-a33934be6383
📒 Files selected for processing (8)
src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razorsrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.scsssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendarClassStyles.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendarEvent.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razorsrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razor.samples.cs
There was a problem hiding this comment.
Pull request overview
Adds an “Events” feature to BitCalendar, enabling days to display an event indicator and show event details via tooltip + modal, and updates the demo/docs accordingly.
Changes:
- Introduces
BitCalendarEventmodel and a newEventsparameter onBitCalendar. - Renders an event indicator dot on days with events and shows an overlay modal with event details on click.
- Updates the Calendar demo page, sample snippets, and parameter/class-style documentation to include the new feature.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razor.samples.cs | Adds sample snippet/code for Events and shifts example numbering. |
| src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razor.cs | Documents new Events parameter, event-related class/style hooks, and BitCalendarEvent metadata. |
| src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Calendar/BitCalendarDemo.razor | Adds an “Events” demo section and updates subsequent example references/IDs. |
| src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendarEvent.cs | Introduces the new event DTO used by the calendar. |
| src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendarClassStyles.cs | Adds class/style extension points for the new indicator and modal UI. |
| src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.scss | Adds styles for the event indicator and modal overlay/container/items. |
| src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cs | Adds Events parameter and supporting logic to retrieve events, build tooltips, and manage modal state. |
| src/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor | Renders event indicator dot per day, sets tooltip, and adds the event details modal markup. |
closes #12261
Summary by CodeRabbit