Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/datepicker decade picker unclickable #1452

Merged

Conversation

Maraket
Copy link
Contributor

@Maraket Maraket commented Jul 20, 2024

Summary:
Fixed several bugs in the DatePicker component, including:

  • Issue with decade selection as per Bug in decade date option #1211
  • Issue with the ranges presented in the titles for years and decades not matching what is rendered
  • Datepicker Storybook story issue found when updating the defaultValue while minDate and maxDate are defined

Added unit tests to cover several basic use cases:

  • Ensuring rendering of titles of decades are rendered correctly
  • Ensuring in the DatePicker on the Decade view:
    • When maxDate is set:
      • confirm buttons outside of range are disabled
      • confirm buttons inside of range are enabled (not disabled)
    • When minDate is set:
      • confirm buttons outside of range are disabled
      • confirm buttons inside of range are enabled (not disabled)
    • When maxDate and minDate:
      • confirm buttons outside of range are disabled
      • confirm buttons inside of range are enabled (not disabled)

Summary by CodeRabbit

  • New Features

    • Enhanced date selection experience with improved decade and year range calculations.
    • Integrated constraints for minDate and maxDate to prevent invalid date selections.
  • Bug Fixes

    • Resolved issues with default date handling in the Datepicker component's story.
    • Improved accuracy in year display for the Years view.
  • Tests

    • Added comprehensive test coverage for decade selection constraints and behavior related to minDate and maxDate.

Marcus Gilmore-Lim added 8 commits July 20, 2024 21:14
- Range of years presented in title now match the calendar for
the year view
- Removed unnecessary subtraction and multiplication in year
 view
- Found the date range presented was offset
incorrectly. e.g. the range presented would be 1990-2100 but range presented was 2000-2090
- Found the use of `isDateInRange` was using the wrong
dates for the date, minDate and maxDate.
- Updated `isDisabled` check to ensure both the first and last
date are in range.
- Minor optimisation as `first` doesn't need to be regenerated
for each decade.
- Testing that decade titles are being rendered correctly (and technically days, years and months)
- Tested if the button for the earlier decade is enabled when max date is set
Tested if the button for the later decade is disabled when max date is set
- Tested if the button for the earlier decade is disabled when min date is set
- Tested if the button for the later decade is enabled when min date is set
- When minDate and maxDate were defined, defaultDate was not updated to a Date.
- Tested if decades within a maxDate minDate range are correctly selectable.
Copy link

changeset-bot bot commented Jul 20, 2024

⚠️ No Changeset found

Latest commit: d2268ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jul 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2024 11:24am
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2024 11:24am

Copy link
Contributor

coderabbitai bot commented Jul 20, 2024

Walkthrough

The updates to the Datepicker component enhance its functionality and test coverage, particularly in handling decade selection within specified minDate and maxDate limits. New tests ensure that users can only choose valid years, while code changes improve date range calculations for both decades and years. These modifications collectively enhance user experience by enforcing date constraints and clarifying the internal logic.

Changes

Files Change Summary
packages/ui/src/components/Datepicker/*.spec.tsx Added test cases for decade selection, validating minDate and maxDate constraints. Enhanced test coverage for selecting valid years within defined limits.
packages/ui/src/components/Datepicker/Datepicker.stories.tsx Modified defaultDate handling to ensure it is treated as a Date object, addressing a known issue with date interpretation in Storybook.
packages/ui/src/components/Datepicker/*.tsx Adjusted date range calculations in getViewTitle for "Decades" and "Years" views, improving the display logic. Integrated minDate and maxDate checks in Decades view.
packages/ui/src/components/Datepicker/Views/Years.tsx Corrected year calculation logic to accurately reflect the intended year range in the Years view.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Datepicker
    participant DecadesView
    participant YearsView

    User->>Datepicker: Select a decade
    Datepicker->>DecadesView: Update displayed decade range
    DecadesView->>Datepicker: Check minDate and maxDate
    alt Within range
        DecadesView->>User: Show available decades
    else Out of range
        DecadesView->>User: Disable unavailable decades
    end

    User->>Datepicker: Select a year
    Datepicker->>YearsView: Update displayed year range
    YearsView->>Datepicker: Validate selected year
    YearsView->>User: Show selected year
Loading

Poem

🐇 In the garden of dates, we hop and we play,
With decades and years, we brighten the day.
Constraints in our path, but joy in the air,
Valid choices abound, so choose with great care!
Hopping through time, we celebrate glee,
A Datepicker so fine, from constraints we are free! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3217f88 and d2268ce.

Files selected for processing (5)
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.stories.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Views/Decades.tsx (2 hunks)
  • packages/ui/src/components/Datepicker/Views/Years.tsx (1 hunks)
Additional comments not posted (16)
packages/ui/src/components/Datepicker/Datepicker.stories.tsx (1)

43-44: LGTM! Ensure proper date handling.

The conversion of args.defaultDate into a Date object before passing it to getFirstDateInRange ensures proper date handling.

packages/ui/src/components/Datepicker/Views/Years.tsx (1)

33-33: LGTM! Correct year calculation.

The updated logic correctly calculates the year variable by directly assigning the value of first plus index.

packages/ui/src/components/Datepicker/Views/Decades.tsx (5)

23-23: LGTM! Enhanced date handling.

The inclusion of minDate and maxDate in the useDatePickerContext hook enhances the date handling logic.


26-26: LGTM! Streamlined year calculation.

The calculation of the first year in the decade view has been streamlined for better readability and maintainability.


31-32: LGTM! Simplified date manipulation.

The introduction of the newDate variable simplifies date manipulation and enhances code clarity.


36-37: LGTM! Improved date range validation.

The updated isDisabled condition ensures that users cannot select dates outside the specified range.


51-51: LGTM! Correct view update logic.

The logic for updating the view when a decade button is clicked has been correctly implemented.

packages/ui/src/components/Datepicker/Datepicker.spec.tsx (8)

81-95: LGTM! The test case is well-structured.

The test case effectively verifies that the year range is correctly displayed when selecting a decade.


97-112: LGTM! The test case is well-structured.

The test case effectively verifies that earlier decades can be selected when the maxDate allows it.


114-129: LGTM! The test case is well-structured.

The test case effectively verifies that later decades are disabled if they exceed the maxDate.


131-146: LGTM! The test case is well-structured.

The test case effectively verifies that earlier decades are disabled if they fall below the minDate.


148-163: LGTM! The test case is well-structured.

The test case effectively verifies that later decades can be selected when within the minDate limit.


165-187: LGTM! The test case is well-structured.

The test case effectively verifies that only decades within the defined range of minDate and maxDate are selectable.


188-191: LGTM! The test case is well-structured.

The test case effectively verifies that the input is focused when ref.current.focus is called.


Line range hint 192-198:
LGTM! The test case is well-structured.

The test case effectively verifies that the value is cleared when ref.current.clear is called.

packages/ui/src/components/Datepicker/Datepicker.tsx (1)

200-202: LGTM! The changes improve date range representation.

The modifications to the getViewTitle function enhance the date range representation for both "Decades" and "Years" views.

Copy link
Collaborator

@rluders rluders left a comment

Choose a reason for hiding this comment

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

Thanks @Maraket.

@rluders rluders merged commit 83e5583 into themesberg:main Jul 20, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants