Skip to content

chore: date picker year range#6781

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
chore/day-picker-years
Mar 19, 2025
Merged

chore: date picker year range#6781
sriramveeraghanta merged 1 commit intopreviewfrom
chore/day-picker-years

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Mar 19, 2025

Description

This PR updates the year range of all date pickers to show +- 30 years from the current year.

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

Summary by CodeRabbit

  • New Features
    • Enhanced the calendar to now display a dynamic date range spanning from 30 years in the past to 30 years in the future, giving users an expanded view when selecting dates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request refactors the Calendar component in packages/ui/src/calendar.tsx to compute a range of months based on the current year. It introduces two new constants to determine the first day of the month thirty years ago and thirty years from now, then passes these values as the startMonth and endMonth props to the DayPicker component. The component has been refactored to a block body function to accommodate the new logic.

Changes

File Change Summary
packages/ui/src/calendar.tsx - Refactored the component from a single expression to a block body function.
- Added currentYear, thirtyYearsAgoFirstDay, and thirtyYearsFromNowFirstDay constants.
- Passed startMonth and endMonth props to the DayPicker component.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Calendar Component
    participant DP as DayPicker
    
    U->>C: Open calendar
    C->>C: Compute current year
    C->>C: Calculate 'thirtyYearsAgoFirstDay' and 'thirtyYearsFromNowFirstDay'
    C->>DP: Render DayPicker with startMonth and endMonth props
    DP-->>C: Return rendered calendar view
    C-->>U: Display calendar with defined month range
Loading

Possibly related PRs

  • Fix: date range selector #6625: This PR involves changes in integrating the Calendar component with modified DayPicker logic, which has a direct overlap with the presented changes.

Suggested labels

🌟enhancement

Suggested reviewers

  • gakshita
  • sriramveeraghanta

Poem

I'm a nimble bunny, coding with flair,
Hopping through logic with a digital stare.
Thirty years past and thirty ahead in sight,
My little paws dance, making calendars bright!
Cheers to code that makes our days light!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
packages/ui/src/calendar.tsx (1)

12-14: Consider optimizing with useMemo.

These date calculations are performed on every render, which is unnecessary since they depend only on the current year. Consider memoizing these values with useMemo to improve performance.

 export const Calendar = ({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) => {
-  const currentYear = new Date().getFullYear();
-  const thirtyYearsAgoFirstDay = new Date(currentYear - 30, 0, 1);
-  const thirtyYearsFromNowFirstDay = new Date(currentYear + 30, 11, 31);
+  const [thirtyYearsAgoFirstDay, thirtyYearsFromNowFirstDay] = React.useMemo(() => {
+    const currentYear = new Date().getFullYear();
+    return [
+      new Date(currentYear - 30, 0, 1),
+      new Date(currentYear + 30, 11, 31)
+    ];
+  }, []);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f82d4a9 and 8d563d7.

📒 Files selected for processing (1)
  • packages/ui/src/calendar.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
packages/ui/src/calendar.tsx (2)

11-15: Function refactored correctly with date range calculation.

The Calendar component has been effectively refactored from an implicit return to a block body function to accommodate the new date range logic. The calculation of 30 years before and after the current year is implemented correctly, with appropriate use of month indices (0 for January, 11 for December).


78-80: Date range correctly applied to DayPicker.

The new date range props are properly passed to the DayPicker component, which will constrain the selectable dates to the specified 30-year window as required by the PR objectives.

@sriramveeraghanta sriramveeraghanta merged commit f181b67 into preview Mar 19, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore/day-picker-years branch March 19, 2025 13:37
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.

2 participants