Skip to content

feat(lemon-ui): add date limit when selecting dates.#30259

Merged
rodrigoi merged 6 commits intomasterfrom
feature/add-date-limit-to-calendar-selections
Mar 24, 2025
Merged

feat(lemon-ui): add date limit when selecting dates.#30259
rodrigoi merged 6 commits intomasterfrom
feature/add-date-limit-to-calendar-selections

Conversation

@rodrigoi
Copy link
Contributor

Problem

We need to allow the user to update the stop date of experiments (a common practice), that is currently using the LemmonCalendarSelect component. We need to prevent the user from selecting a stop date before the experiment start date.

To support this feature, we need to add a limit to how many days one can select forward or backward.

Changes

This PR adds a new optional prop to the LemonCalendarSelect component so we can set a limit date. We also refactor the logic for setting a date to disable reason, add two new stories to storybook, and two more tests.

Also, the tests have been refactored to improve readability and reduce code duplication.

To run the tests from the /frontend folder:

pnpm jest src/lib/lemon-ui/LemonCalendar/
Limiting Upcoming Selection Limiting Past Selection
image image

Important

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@rodrigoi rodrigoi self-assigned this Mar 21, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added a new selectionPeriodLimit prop to LemonCalendarSelect component to restrict date selection ranges, with comprehensive test coverage and documentation.

  • Added getDateDisabledReason function in /frontend/src/lib/lemon-ui/LemonCalendar/LemonCalendarSelect.tsx to handle date validation with limits
  • Added two new Storybook stories in LemonCalendarSelect.stories.tsx demonstrating limit functionality for both past and future selections
  • Refactored test code in LemonCalendarSelect.test.tsx to reduce duplication with helper functions and added specific test cases for date limits
  • Integrated limit validation seamlessly with existing time selection functionality while maintaining backward compatibility

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@rodrigoi rodrigoi changed the title feature(lemon-ui): add date limit when selecting dates. feat(lemon-ui): add date limit when selecting dates. Mar 21, 2025
@github-actions
Copy link
Contributor

Size Change: +188 B (0%)

Total Size: 9.75 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 9.75 MB +188 B (0%)

compressed-size-action

@rodrigoi rodrigoi requested a review from a team March 21, 2025 14:10
@rodrigoi rodrigoi requested a review from daibhin March 21, 2025 15:59
@rodrigoi rodrigoi merged commit 125f555 into master Mar 24, 2025
106 checks passed
@rodrigoi rodrigoi deleted the feature/add-date-limit-to-calendar-selections branch March 24, 2025 15:08
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.

3 participants