Skip to content

Conversation

@carlosthe19916
Copy link
Collaborator

@carlosthe19916 carlosthe19916 commented Oct 20, 2025

Fixes

Fixes: #393, #394, and:

JIRA fixes:

What changes

  • This PR is adding validators to each of the date picker components. That should avoid the user to select dates that wrong.
    • the Validators tell the date component to disable the dates that we know the user should not select. See the video below
  • Setting the "invalidFormatText" error in case the user types anything but dates
  • For the filters to be applied both FROM and TO should be selected
Screencast.From.2025-10-20.15-13-17.mp4

Summary by Sourcery

Add date format validation and range enforcement to the DateRangeFilter components in both the filter panel and toolbar.

Enhancements:

  • Show "Invalid date" error text when the user enters a malformed date in the date pickers
  • Disable and validate the end-date picker to ensure the "to" date is not earlier than the "from" date

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 20, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances the DateRangeFilter components by integrating validation logic into the PatternFly DatePicker inputs to disable invalid date selections, enforce that the end date follows the start date, and provide consistent error messaging.

Sequence diagram for date range filter validation and error handling

sequenceDiagram
  actor User
  participant "DateRangeFilter Component"
  participant "DatePicker"
  User->>"DateRangeFilter Component": Selects "From" date
  "DateRangeFilter Component"->>"DatePicker": Updates "From" date
  User->>"DateRangeFilter Component": Selects "To" date
  "DateRangeFilter Component"->>"DatePicker": Applies toValidator
  "DatePicker"->>"DateRangeFilter Component": Returns validation result
  alt Invalid "To" date
    "DateRangeFilter Component"->>User: Shows error 'The "to" date must be after the "from" date'
  else Valid dates
    "DateRangeFilter Component"->>User: Applies filter
  end
Loading

Class diagram for updated DateRangeFilter component

classDiagram
  class DateRangeFilter {
    - from: Date
    - to: Date
    + onFromDateChange(date: Date)
    + onToDateChange(date: Date)
    + toValidator(date: Date): string
  }
  class DatePicker {
    + invalidFormatText: string
    + validators: [function]
  }
  DateRangeFilter "1" --|> "2" DatePicker: uses
Loading

File-Level Changes

Change Details Files
Enforce 'to' date must be on or after 'from' date via custom validator
  • Imported isValidDate for date validation
  • Defined toValidator function to check date order
  • Added validators prop with toValidator to end date picker
client/src/app/components/FilterPanel/DateRangeFilter.tsx
client/src/app/components/FilterToolbar/DateRangeFilter.tsx
Standardize invalid format error text in date inputs
  • Replaced empty invalidFormatText with "Invalid date" for both start and end pickers
client/src/app/components/FilterPanel/DateRangeFilter.tsx
client/src/app/components/FilterToolbar/DateRangeFilter.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Extract the toValidator into a shared util to avoid duplicating validation logic across FilterPanel and FilterToolbar.
  • Consider implementing a complementary ‘from’ date validator to ensure the from date is always before the selected to date.
  • Avoid hard-coding the error messages (‘Invalid date’ and the validator text); extract them into shared constants or i18n resources.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Extract the toValidator into a shared util to avoid duplicating validation logic across FilterPanel and FilterToolbar.
- Consider implementing a complementary ‘from’ date validator to ensure the from date is always before the selected to date.
- Avoid hard-coding the error messages (‘Invalid date’ and the validator text); extract them into shared constants or i18n resources.

## Individual Comments

### Comment 1
<location> `client/src/app/components/FilterPanel/DateRangeFilter.tsx:76-79` </location>
<code_context>
     }
   };

+   const toValidator = (date: Date) =>
+      from && isValidDate(from) && date >= from
+        ? ""
+        : 'The "to" date must be after the "from" date';
+  
   return (
</code_context>

<issue_to_address>
**suggestion:** Consider handling cases where 'from' is not a valid date in the validator.

If 'from' is missing or invalid, consider skipping validation or returning an empty string to avoid unnecessary error messages.

```suggestion
   const toValidator = (date: Date) => {
      if (!from || !isValidDate(from)) {
        // Skip validation if 'from' is missing or invalid
        return "";
      }
      return date >= from
        ? ""
        : 'The "to" date must be after the "from" date';
    };
```
</issue_to_address>

### Comment 2
<location> `client/src/app/components/FilterToolbar/DateRangeFilter.tsx:119-122` </location>
<code_context>
     }
   };

+   const toValidator = (date: Date) =>
+      from && isValidDate(from) && date >= from
+        ? ""
+        : 'The "to" date must be after the "from" date';
+  
   return (
</code_context>

<issue_to_address>
**suggestion:** Validator logic may not handle cases where 'from' is missing or invalid.

Consider skipping validation or returning an empty string when 'from' is missing or invalid to avoid confusing error messages for users.

```suggestion
  const toValidator = (date: Date) => {
    if (!from || !isValidDate(from)) {
      // Skip validation if 'from' is missing or invalid
      return "";
    }
    return date >= from
      ? ""
      : 'The "to" date must be after the "from" date';
  };
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Carlos Feria <[email protected]>
@carlosthe19916 carlosthe19916 linked an issue Oct 20, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.72%. Comparing base (4153180) to head (2f85297).

Files with missing lines Patch % Lines
...src/app/components/FilterPanel/DateRangeFilter.tsx 0.00% 1 Missing ⚠️
...c/app/components/FilterToolbar/DateRangeFilter.tsx 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #806      +/-   ##
==========================================
- Coverage   57.76%   57.72%   -0.05%     
==========================================
  Files         163      163              
  Lines        2872     2874       +2     
  Branches      654      656       +2     
==========================================
  Hits         1659     1659              
- Misses        976      977       +1     
- Partials      237      238       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@carlosthe19916 carlosthe19916 added the backport release/0.4.z This PR should be backported to release/0.4.z branch. label Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.4.z This PR should be backported to release/0.4.z branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search SBOM - Created on-from filter field behave erratically Search SBOMs - Created on filter needs both dates filled

1 participant