Skip to content

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Oct 16, 2025

Description

This PR fixes calendar startofweek alignment and code refactoring.

Type of Change

  • Bug fix
  • Code refactoring

Media

Before After
before after

Summary by CodeRabbit

  • Bug Fixes

    • Calendar now automatically updates when you change your start-of-week preference.
  • Refactor

    • Improved calendar view architecture for better preference handling and responsiveness.

@anmolsinghbhatia anmolsinghbhatia self-assigned this Oct 16, 2025
@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 11:13
@makeplane
Copy link

makeplane bot commented Oct 16, 2025

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

The changes introduce configurable week-start day support to the calendar system. CalendarStore now accepts a root store reference, establishes a reactive watch on the user's start_of_the_week preference, and triggers calendar regeneration when this preference changes. The generateCalendarData utility function is extended to accept and apply the start-of-week setting during calendar computation.

Changes

Cohort / File(s) Summary
Calendar Store Root Wiring
apps/web/core/store/issue/issue_calendar_view.store.ts
Adds _rootStore parameter to CalendarStore constructor; stores root store reference in new rootStore property; enables access to user preferences.
Calendar Regeneration Logic
apps/web/core/store/issue/issue_calendar_view.store.ts
Introduces new regenerateCalendar() method; sets up MobX reaction to monitor start_of_the_week preference changes; triggers full calendar regeneration on preference updates; passes start_of_the_week to generateCalendarData during initialization and updates.
Interface Updates
apps/web/core/store/issue/issue_calendar_view.store.ts
Extends ICalendarStore interface to include regenerateCalendar: () => void; method signature.
Root Store Integration
apps/web/core/store/issue/root.store.ts
Updates CalendarStore instantiation to pass root store context via CalendarStore(this).
Calendar Generation Utility
packages/utils/src/calendar.ts
Adds optional startOfWeek: EStartOfTheWeek parameter to generateCalendarData function (defaults to Sunday); adjusts firstDayOfMonth computation based on start-of-week setting; refactors week key generation from ISO-based to sequential (w-{week}) for consistent grouping.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant Calendar as CalendarStore
    participant RootStore as RootStore
    participant Reaction as MobX Reaction
    participant Utils as generateCalendarData

    User->>Calendar: User changes start_of_the_week preference
    activate Calendar
    Calendar->>RootStore: Preference update propagates
    activate RootStore
    RootStore->>Reaction: start_of_the_week changed
    deactivate RootStore
    activate Reaction
    Reaction->>Calendar: Trigger regenerateCalendar()
    activate Calendar
    Calendar->>Calendar: Clear cached calendar data
    Calendar->>Utils: Call generateCalendarData(activeMonthDate, newStartOfWeek)
    activate Utils
    Utils->>Utils: Compute firstDayOfMonth with new alignment
    Utils->>Utils: Generate weeks with new grouping
    Utils-->>Calendar: Return updated ICalendarPayload
    deactivate Utils
    Calendar->>Calendar: Update calendar state
    Calendar-->>User: Calendar UI refreshes
    deactivate Calendar
    deactivate Reaction
    deactivate Calendar
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes span three distinct files with cohesive logic focused on one feature. The CalendarStore modifications introduce reactive patterns and dependency injection that warrant careful review. The utility function extends calendar alignment logic with week-start computation. While not trivial, the changes follow a clear architectural pattern and avoid high-density complexity.

Poem

🐰 A calendar reborn, week by week anew,
When Monday calls or Sunday's due,
The rabbit tends each shifting day,
Regenerating calendars in nature's way! 🗓️✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description follows the template for the Description, Type of Change, and Media sections but omits the required Test Scenarios and References headings, which are necessary for completeness and traceability. Please add the Test Scenarios section to describe how the changes were verified and include a References section linking related issues or tickets to fully comply with the repository’s PR description template.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title concisely and accurately summarizes the principal change, namely fixing the calendar start-of-week alignment and performing related code refactoring, without extraneous details or unrelated content.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-calendar-startofweek-alignment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fix calendar start-of-week alignment and refactor calendar generation to respect user preference.

  • Add startOfWeek support to calendar generation and adjust first-day offset calculations.
  • Regenerate calendar on user preference changes; wire CalendarStore to IssueRootStore.
  • Switch week keys to sequential indices within the month for consistency across start-of-week settings.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/utils/src/calendar.ts Add startOfWeek param, adjust first-day offset, reset month data, and use sequential week keys.
apps/web/core/store/issue/root.store.ts Pass IssueRootStore into CalendarStore constructor.
apps/web/core/store/issue/issue_calendar_view.store.ts Inject root store, use startOfWeek from user profile, add reaction to regenerate calendar, and add regenerateCalendar method.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/core/store/issue/issue_calendar_view.store.ts (1)

115-123: Potential bug: activeWeekNumber calculation may not align with sequential week keys.

The allDaysOfActiveWeek getter uses this.activeWeekNumber - 1 to access the week data, but the week keys in the calendar payload are now sequential indices (w-0, w-1, etc.) rather than calculated week numbers. This could cause a mismatch.

For example:

  • If activeWeekNumber (from getWeekNumberOfDate) is 42, the code tries to access w-41
  • But the actual keys are w-0, w-1, w-2, etc.

To verify this issue, check how week keys are used elsewhere:

#!/bin/bash
# Search for week key access patterns in the codebase
ast-grep --pattern $'calendarPayload[$$$][`w-${$_}`]'

# Also check getWeekNumberOfDate usage
rg -nP --type=ts 'getWeekNumberOfDate' -A 2 -B 2

The fix should align the week key access with the sequential indexing used in generateCalendarData. Consider either:

  1. Calculating the week index from the date and active month start, or
  2. Storing a mapping from week numbers to sequential indices
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f266cd8 and fd14644.

📒 Files selected for processing (3)
  • apps/web/core/store/issue/issue_calendar_view.store.ts (5 hunks)
  • apps/web/core/store/issue/root.store.ts (1 hunks)
  • packages/utils/src/calendar.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/web/core/store/issue/root.store.ts (1)
apps/web/core/store/issue/issue_calendar_view.store.ts (1)
  • CalendarStore (34-189)
apps/web/core/store/issue/issue_calendar_view.store.ts (2)
apps/web/core/store/issue/root.store.ts (1)
  • IIssueRootStore (48-114)
packages/utils/src/calendar.ts (1)
  • generateCalendarData (13-69)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (11)
packages/utils/src/calendar.ts (4)

13-17: LGTM! Function signature correctly extended.

The addition of the startOfWeek parameter with a sensible default value of EStartOfTheWeek.SUNDAY maintains backward compatibility while enabling the new functionality.


27-31: Verify the firstDayOfMonth calculation logic.

The calculation (firstDayOfMonthRaw - startOfWeek + 7) % 7 determines the number of empty cells needed at the start of the calendar. This formula should correctly handle all combinations of firstDayOfMonthRaw (0-6) and startOfWeek (0-6).

Let me verify the calculation logic is correct for all possible inputs:

#!/usr/bin/env python3
# Verify the firstDayOfMonth calculation for all possible combinations
print("Verifying firstDayOfMonth calculation:")
print("Format: firstDayOfMonthRaw | startOfWeek | Result | Expected")
print("-" * 60)

for raw in range(7):  # Sunday(0) to Saturday(6)
    for start in range(7):  # All possible start days
        result = (raw - start + 7) % 7
        # Expected: number of empty cells before the first day
        # If raw == start, we expect 0 empty cells
        # If raw > start, we expect raw - start empty cells
        # If raw < start, we expect (7 - start + raw) empty cells
        expected = (raw - start + 7) % 7
        status = "✓" if result == expected else "✗"
        print(f"{status} {raw:19} | {start:11} | {result:6} | {expected:8}")

print("\nTest scenarios:")
# Sunday start, Sunday first day (no offset)
print(f"Sunday(0) start, Sunday(0) first: {(0 - 0 + 7) % 7} empty cells (expect 0)")
# Monday start, Sunday first day (6 offset)
print(f"Monday(1) start, Sunday(0) first: {(0 - 1 + 7) % 7} empty cells (expect 6)")
# Sunday start, Monday first day (1 offset)
print(f"Sunday(0) start, Monday(1) first: {(1 - 0 + 7) % 7} empty cells (expect 1)")

34-35: Month data reset ensures clean regeneration.

Resetting the month data on each call to generateCalendarData ensures that any change in startOfWeek is properly reflected without stale data from previous calculations. This is the correct approach for the regeneration workflow.


63-65: Week key normalization improves consistency.

Using sequential week indices (w-${week}) instead of calculated week numbers (w-${weekNumber}) ensures consistent week grouping regardless of the startOfWeek preference. This is a good improvement that prevents potential key collisions or ordering issues.

apps/web/core/store/issue/root.store.ts (1)

269-269: LGTM! Root store reference correctly passed.

The change from new CalendarStore() to new CalendarStore(this) correctly provides the CalendarStore with access to the root store, enabling it to read user preferences like start_of_the_week.

apps/web/core/store/issue/issue_calendar_view.store.ts (6)

1-1: LGTM! Necessary imports added.

The imports for reaction, EStartOfTheWeek, and IIssueRootStore are correctly added to support the new functionality.

Also applies to: 6-6, 9-9


21-21: Interface correctly extended.

The ICalendarStore interface is properly updated to include the new regenerateCalendar method.


45-46: Root store wiring implemented correctly.

The root store reference is properly stored and the constructor signature is updated to accept it. This enables access to user preferences throughout the calendar store.

Also applies to: 48-48, 68-68


158-158: Consistent null fallback for start_of_the_week.

The code correctly falls back to EStartOfTheWeek.SUNDAY when the user preference is not available. This ensures the calendar always has a valid start-of-week value.

Also applies to: 166-166


161-161: LGTM! startOfWeek parameter correctly passed.

The startOfWeek value is correctly passed to generateCalendarData in both updateCalendarPayload and initCalendar methods, ensuring calendar data respects user preferences.

Also applies to: 167-167


174-188: Regeneration logic is correct.

The regenerateCalendar method correctly:

  1. Reads the current startOfWeek preference
  2. Uses the current activeMonthDate to maintain the user's view
  3. Passes null to generateCalendarData to force complete regeneration
  4. Updates the calendar payload in a MobX action

@pushya22 pushya22 merged commit 38cdf75 into preview Oct 23, 2025
7 checks passed
@pushya22 pushya22 deleted the fix-calendar-startofweek-alignment branch October 23, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Не верное отображение календаря

3 participants