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

Fixed : Automatic Correction for Invalid End Date Input #9583

Closed
wants to merge 3 commits into from

Conversation

Jeffrin2005
Copy link
Contributor

@Jeffrin2005 Jeffrin2005 commented Dec 26, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

date_time.mp4
  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Enhanced date range input to ensure the end date is always valid relative to the start date.
  • Bug Fixes

    • Fixed issue where an earlier end date could be set compared to the start date.

@Jeffrin2005 Jeffrin2005 requested a review from a team as a code owner December 26, 2024 15:32
Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request introduces a new handleDateRangeChange function in the DateRangeFormField component to address date range input validation. The function ensures that when a date range is selected, the end date cannot be earlier than the start date. If such a scenario occurs, the end date is automatically adjusted to match the start date, preventing invalid date range selections.

Changes

File Change Summary
src/components/Form/FormFields/DateRangeFormField.tsx Added handleDateRangeChange method to validate and adjust date range inputs

Assessment against linked issues

Objective Addressed Explanation
Prevent end date before start date [#9578]

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Dates dancing in line,
No more chaos, all so fine!
Start and end now play their part,
Validation's a work of art!
Rabbit's logic saves the day! 🗓️


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3554f4c and 2cc793d.

📒 Files selected for processing (1)
  • src/components/Form/FormFields/DateRangeFormField.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Form/FormFields/DateRangeFormField.tsx (2)

38-45: Ensure thorough test coverage for edge cases.

This logic correctly adjusts the end date if it's earlier than the start date, aligning with the PR’s objective. However, be sure to cover edge cases, such as when the user enters only one date or toggles back-and-forth between invalid dates. Automated tests will help confirm this works in all scenarios.

Do you want me to create sample test cases for these date adjustments or open a new GitHub issue to track it?


53-53: Confirm partial date updates won't cause undesired re-render loops.

Using the new handleDateRangeChange function here is perfectly logical. However, in certain date-picking workflows, partial or sequential updates can cause multiple re-renders. Double-check that these do not lead to performance hiccups or flickering in the UI.


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>, 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. (Beta)
  • @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

netlify bot commented Dec 26, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 2cc793d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676e3accfd7a47000862e8bb
😎 Deploy Preview https://deploy-preview-9583--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (2)
src/components/Patient/PatientFilter.tsx (2)

272-273: Consider using a unified date library for consistency.

You're using dayjs in other parts of the file but defaulting to native Date here. It would be more consistent (and potentially safer) to rely on the same library (dayjs) for parsing and comparing dates if possible.

- const startDate = event.value.start;
- let endDate = event.value.end;
+ const startDate = event.value.start ? dayjs(event.value.start) : null;
+ let endDate = event.value.end ? dayjs(event.value.end) : null;

274-276: Automatic end date fix is correct; consider notifying the user.

Automatically adjusting the end date to match the start date when it is earlier than the start date is logical. However, consider providing visual feedback or a small notification to the user for transparency.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d2e0d0 and b87b719.

📒 Files selected for processing (1)
  • src/components/Patient/PatientFilter.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Patient/PatientFilter.tsx (1)

278-279: Confirm date string format for downstream usage.

Storing the dates as string (startDate?.toString(), endDate?.toString()) might affect other components or queries. Verify if the next stages of processing expect stringified ISO dates or need a specific format.

✅ Verification successful

Date string format is properly handled through dateQueryString utility

The codebase shows that date strings in filterData are processed through the dateQueryString utility before being used in API calls. This is evident from the code in PatientFilter.tsx where all date fields are processed:

{
  date_declared_positive_before: dateQueryString(date_declared_positive_before),
  date_declared_positive_after: dateQueryString(date_declared_positive_after),
  created_date_before: dateQueryString(created_date_before),
  created_date_after: dateQueryString(created_date_after),
  // ... other date fields
}

The toString() conversion is safe as the dates are properly formatted before being used in queries.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Identify references to <event.name>_after / <event.name>_before fields to confirm any format expectations.

rg -A 5 "\_after\"\]|\_before\"\]"

Length of output: 123


Script:

#!/bin/bash
# Search for date-related fields with _after or _before suffixes
rg -A 5 "_after|_before"

Length of output: 37287


Script:

#!/bin/bash
# Search for filterData usage to understand how these dates are processed
rg -A 5 "filterData\["

Length of output: 3081


Script:

#!/bin/bash
# Look for API calls or query builders that might use these date filters
ast-grep --pattern 'axios.$_($$$, { params: filterData })'

Length of output: 60


Script:

#!/bin/bash
# Search for any date formatting or parsing utilities
rg -A 5 "toISOString|toLocaleDateString|format.*Date"

Length of output: 65880

@Jeffrin2005
Copy link
Contributor Author

@rithviknishad @Jacobjeevan Any changes required ?

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 26, 2024
@Jacobjeevan Jacobjeevan added needs testing needs review and removed question Further information is requested needs-triage labels Dec 26, 2024
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

this logic should be part of the date range component itself right?

currently this behaviour would be present only in the patient filters. we need it everywhere right?

@Jeffrin2005
Copy link
Contributor Author

@rithviknishad @Jacobjeevan Applied Same logic in all Filters related to calendar

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 (2)
src/components/Assets/AssetFilter.tsx (2)

84-86: Use dayjs-based comparisons for consistency.
Currently, you're creating Date objects for comparison (new Date(endDate) < new Date(startDate)), whereas the rest of the file uses dayjs. To avoid potential edge cases or time zone discrepancies, consider using dayjs consistently across the codebase.

- if (startDate && endDate && new Date(endDate) < new Date(startDate)) {
+ if (startDate && endDate && dayjs(endDate).isBefore(dayjs(startDate))) {

92-93: Ensure correct naming for before/after to prevent confusion.
It might be more intuitive to store warrantyExpiryStart and warrantyExpiryEnd or some naming that aligns with “start” and “end.” The current naming of before and after is somewhat reversed, potentially leading to confusion when reading the code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b87b719 and 3554f4c.

📒 Files selected for processing (3)
  • src/components/Assets/AssetFilter.tsx (1 hunks)
  • src/components/Resource/ResourceFilter.tsx (1 hunks)
  • src/components/Shifting/ShiftingFilters.tsx (1 hunks)
🔇 Additional comments (7)
src/components/Assets/AssetFilter.tsx (1)

87-89: Auto-correction logic looks good!
This condition enforces that the end date cannot precede the start date, thus aligning perfectly with the PR objective of automatic correction.

src/components/Resource/ResourceFilter.tsx (3)

131-133: Consistent naming of temporary variables.
Using startDate and endDate aligns well with your naming convention in the other files. Good job on unifying the approach.


134-136: Solid date validation.
Preventing endDate from being before startDate addresses the invalid range scenario efficiently. No issues spotted.


137-138: Consider a single source of truth for date-friendly strings.
After setting the new date range, you’re converting them directly to strings. If these values are used downstream, ensure they’re consistently parsed into valid Date objects or dayjs. Sudden type mismatches could lead to future debugging complexities.

src/components/Shifting/ShiftingFilters.tsx (3)

197-199: Helpful variable extraction for clarity.
Defining startDate and endDate before validation makes the code easier to read and maintain.


200-202: Matches PR objective of automatically correcting invalid end date inputs.
Swapping the end date to the start date if it’s earlier effectively prevents invalid ranges. This aligns with the user story in PR #9583.


204-205: String conversion might impact date/time offsets.
When storing dates as strings, confirm that no unexpected timezone offset is introduced. Consider maintaining a standardized format or using dayjs for safe reconversion downstream.

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

this is just code duplication, like already said, make the logic part of the date range component instead

@rithviknishad rithviknishad added the invalid This doesn't seem right label Dec 27, 2024
@Jeffrin2005
Copy link
Contributor Author

@rithviknishad Updated in Common DateRangeForm

@rithviknishad
Copy link
Member

Closing as we no longer have these filters in form-field-v1 branch and we have moved away from legacy components in favour of shadcn's components

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.

End Date Before Start Date Allowed in form
3 participants