Skip to content

Conversation

@carlosthe19916
Copy link
Collaborator

@carlosthe19916 carlosthe19916 commented Aug 14, 2025

Fixes: #393, #394, and:

JIRA fixes:

Changes:

  • This PR creates a new FilterType date.
  • All current filters using "dateRange" are being replaced by "date". This way we avoid all issues described in the JIRAs and Github issues linked above.

The image below is an example of how the date filter is visulized:
image

Summary by Sourcery

Add a new date filter type and migrate all dateRange filters to separate before/after date filters across multiple list contexts, updating the UI components and request parameter handling to fix related issues

New Features:

  • Introduce a new 'date' filter type with dedicated DateFilter components for toolbar and panel

Bug Fixes:

  • Replace all existing dateRange filters with before/after date filters to resolve related Github and JIRA issues

Enhancements:

  • Update advisory, SBOM, and vulnerability search contexts to use separate 'before' and 'after' date filters
  • Adjust filter request parameter logic to handle 'date' filters correctly

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 14, 2025

Reviewer's Guide

Introduce a new "date" filter type and replace all existing dateRange filters with separate before/after date filters across list contexts, update request parameter handling to support the new filter type, and add dedicated DateFilter components and rendering logic.

Sequence diagram for applying a date filter in the filter toolbar

sequenceDiagram
    participant User as actor User
    participant FilterToolbar
    participant DateFilter
    participant getFilterHubRequestParams
    User->>FilterToolbar: Selects a date filter
    FilterToolbar->>DateFilter: Renders DatePicker
    User->>DateFilter: Picks a date
    DateFilter->>FilterToolbar: Updates filter value
    FilterToolbar->>getFilterHubRequestParams: Prepares request params with date filter
    getFilterHubRequestParams->>FilterToolbar: Returns updated params
Loading

Class diagram for new and updated filter components

classDiagram
    class FilterType {
        <<enum>>
        multiselect
        search
        numsearch
        date
        dateRange
        autocompleteLabel
    }
    class DateFilter {
        +category
        +filterValue
        +setFilterValue
        +showToolbarItem
        +isDisabled
        +onDateChange()
    }
    class DateRangeFilter {
        +category
        +filterValue
        +setFilterValue
        +showToolbarItem
        +isDisabled
        +onDateChange()
    }
    FilterType <|-- DateFilter
    FilterType <|-- DateRangeFilter
    class FilterControl {
        +category
        +props
        +render()
    }
    FilterControl --> DateFilter : uses
    FilterControl --> DateRangeFilter : uses
Loading

Class diagram for updated filter context interfaces

classDiagram
    class IAdvisorySearchContext {
        +modifiedBefore
        +modifiedAfter
    }
    class ISbomSearchContext {
        +publishedBefore
        +publishedAfter
    }
    class IVulnerabilitySearchContext {
        +publishedBefore
        +publishedAfter
    }
    IAdvisorySearchContext o-- FilterType
    ISbomSearchContext o-- FilterType
    IVulnerabilitySearchContext o-- FilterType
Loading

File-Level Changes

Change Details Files
Add a new FilterType "date" and wire up rendering for date filters
  • Extend the FilterType enum with "date"
  • Add conditional rendering of DateFilter for type date in both toolbar and panel FilterControl components
client/src/app/components/FilterToolbar/FilterToolbar.tsx
client/src/app/components/FilterControl.tsx
client/src/app/components/FilterPanel/FilterControl.tsx
Replace dateRange filters with separate before/after date filters in list contexts
  • Split each dateRange filter into two filters (before and after) with serverFilterField and operator
  • Update categoryKey and title for revised/created before and after filters in advisory, SBOM, and vulnerability contexts
client/src/app/pages/advisory-list/advisory-context.tsx
client/src/app/pages/sbom-list/sbom-context.tsx
client/src/app/pages/vulnerability-list/vulnerability-context.tsx
Update search tabs filter props to use the new date filters
  • Adjust generic filter key unions to include publishedBefore/publishedAfter and modifiedBefore/modifiedAfter
client/src/app/pages/search/components/SearchTabs.tsx
Enhance filter parameter builder to handle date filters
  • Modify existing merge logic to key off both field and operator
  • Insert logic to parse American dates and push ISO-formatted date filters for type date
client/src/app/hooks/table-controls/filtering/getFilterHubRequestParams.ts
Create DateFilter components for toolbar and panel views
  • Implement DateFilter with PatternFly DatePicker, formatting, validation, and state syncing
  • Add parsing and formatting utilities (americanDateFormat, parseAmericanDate, isValidAmericanShortDate)
client/src/app/components/FilterToolbar/DateFilter.tsx
client/src/app/components/FilterPanel/DateFilter.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:

  • The two DateFilter implementations in FilterToolbar and FilterPanel are nearly identical—consider consolidating them into a single reusable component to reduce duplication and ensure consistency.
  • The date parsing/formatting utilities are duplicated under both FilterToolbar and FilterPanel—extract them into a shared module to avoid code duplication and divergence.
  • In getFilterHubRequestParams, add a return or else branch after handling FilterType.date to prevent falling through and unintentionally processing the dateRange logic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The two DateFilter implementations in FilterToolbar and FilterPanel are nearly identical—consider consolidating them into a single reusable component to reduce duplication and ensure consistency.
- The date parsing/formatting utilities are duplicated under both FilterToolbar and FilterPanel—extract them into a shared module to avoid code duplication and divergence.
- In getFilterHubRequestParams, add a return or else branch after handling FilterType.date to prevent falling through and unintentionally processing the dateRange logic.

## Individual Comments

### Comment 1
<location> `client/src/app/hooks/table-controls/filtering/getFilterHubRequestParams.ts:146` </location>
<code_context>
           },
         });
       }
+      if (filterCategory.type === "date") {
+        const date = parseAmericanDate(serverFilterValue[0]);
+        pushOrMergeFilter(filters, {
+          field: serverFilterField,
+          operator: filterCategory.operator ?? "=",
</code_context>

<issue_to_address>
Date filter assumes serverFilterValue[0] is always present and valid.

Add a check to ensure serverFilterValue[0] exists and is a valid date before calling parseAmericanDate to prevent downstream errors.
</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.

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 39.13043% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.95%. Comparing base (888b0d3) to head (e84f150).

Files with missing lines Patch % Lines
...nt/src/app/components/FilterToolbar/DateFilter.tsx 35.00% 10 Missing and 3 partials ⚠️
...ient/src/app/components/FilterPanel/DateFilter.tsx 37.50% 8 Missing and 2 partials ⚠️
...le-controls/filtering/getFilterHubRequestParams.ts 0.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #655      +/-   ##
==========================================
- Coverage   57.28%   55.95%   -1.33%     
==========================================
  Files         146      148       +2     
  Lines        2430     2475      +45     
  Branches      552      565      +13     
==========================================
- Hits         1392     1385       -7     
- Misses        833      884      +51     
- Partials      205      206       +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 linked an issue Aug 14, 2025 that may be closed by this pull request
@carlosthe19916 carlosthe19916 changed the title 🌱 add date filter and replace dateRange ✨ : add date filter and replace dateRange Aug 14, 2025
@carlosthe19916 carlosthe19916 changed the title ✨ : add date filter and replace dateRange ✨ add date filter and replace dateRange Aug 14, 2025
@carlosthe19916 carlosthe19916 requested a review from gildub August 14, 2025 12:03
@carlosthe19916 carlosthe19916 added the needs-backport Indicates a PR needs to be backported label Aug 18, 2025
@carlosthe19916 carlosthe19916 changed the title ✨ add date filter and replace dateRange ✨ Add date filter and replace dateRange Aug 25, 2025
Copy link
Contributor

@gildub gildub left a comment

Choose a reason for hiding this comment

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

Not sure if that was covered in the UXD but what about the date format depending on the locale ?

@gildub
Copy link
Contributor

gildub commented Sep 8, 2025

@carlosthe19916, I just added #712 which we need to support. I think this is a good place to get started to avoid accumulating technical debt.

@carlosthe19916
Copy link
Collaborator Author

@gildub yes, good point about the dates. It is an important piece of work and it deserves its own PR

@gildub
Copy link
Contributor

gildub commented Sep 9, 2025

@carlosthe19916 ,

In a separate PR we can revisit/replace americanDateFormat to support locale.
Meanwhile it would make sense to do it before this PR to avoid more tech debt

@PhilipCattanach
Copy link

PhilipCattanach commented Sep 23, 2025

@gildub - Gilles can you review this PR please? As this one PR addresses the 3 bugs (Carlos listed above).

@gildub
Copy link
Contributor

gildub commented Sep 23, 2025

@carlosthe19916,

The filter date fields for the "Search Page" make sense this way with "Created before" and "Created after" titles.

Meanwhile it seems issue https://issues.redhat.com/browse/TC-2402 has not been fully addressed.
It should not be possible to pick a "Created after" date that is prior to the "Created before" with the dates disabled in the picker or a warning message to be displayed if the date is entered manually.

Per UXD recommendation we should stick to Patternfly standards :

image

@carlosthe19916
Copy link
Collaborator Author

@carlosthe19916,

The filter date fields for the "Search Page" make sense this way with "Created before" and "Created after" titles.

Meanwhile it seems issue https://issues.redhat.com/browse/TC-2402 has not been fully addressed. It should not be possible to pick a "Created after" date that is prior to the "Created before" with the dates disabled in the picker or a warning message to be displayed if the date is entered manually.

Per UXD recommendation we should stick to Patternfly standards :

image

@gildub I think it is important to make a difference between a Date Range Filter vs Date Filter.

  • main branch -> uses Date Range Filter
    • I think your suggestion is very valid in this context
  • this PR -> uses Date Filter
    • Comparison of 2 independent Date Filter are not possible in this context I think.

Date range filter (main branch):
image

Date filter (this PR):
image

Note: notice that the screenshots above were taken from the List Pages. Both "Search Page" and "SBOM|Advisory" List page render the same filter but in a different layout. IMHO, the Search page breaks all filtering guidelines from Patternfly but it is something we carry from Trustify V1 so we keep it.

There were many JIRAS + Github Issues that complained about the Date Range Component TC-2402, TC-2422, TC-2393, #393, #394

Date Range Filter

Problems reported on the jiras and issues above:

  • Forces the user to always select FROM and TO dates. (reported at #393)
  • It is not possible to only select documents greater or lesser than a Date
  • The current main branch, tries to validate that "From" date is lesser than "To" date by clearing the "To" date every time the "From" date is changed. And it seems not something the reporter of this issue #394 liked. Also the reporter of this other issue didn't like that validation approach TC-2422

Advantages:

  • We can apply many validations to both "FROM" and "TO" dates. Just like you suggested

Date Filter

As a response to all JIRAS and issues, this PR was raised to replace the Date Range Filter and replace it by 2 independent Filters "From date" and "To date"

Problems:

  • given the fact that we have 2 separate independent filters, we cannot apply validations that involves the value of the other filter

Advantages:

  • The user can filter by Date without being forced to select a range but only a single date

What to do?

I don't think neither the Date Range Filter or the Single Date Filter cover all the JIRAS and Issues mentioned above. We need to, first, choose which one of those can fix most of the complains.

By choosing one option or the other, we also need to mindful of its limitations as a component.

Some options (feel free to suggest other options):

  • Move ahead with this PR and use the Date Filter. 2 independent filters for FROM and TO dates
    • The problem will be exactly what you pointed out. The validation on both dates.
  • Close this PR and do not use Date Filter but enhance the current Date range filter.
    • We will need to accept that only date ranges will be valid. There won't be a way to filter only 1 date.
    • We will need to clearly define what other validations we could add. And try to match those validations with the complains of the issues and jiras.

What do you think?

@gildub
Copy link
Contributor

gildub commented Sep 23, 2025

@carlosthe19916,

I understand it's currently impossible with built-in filter in the table hook to have two independent filters to share data and be conditionally dependent on each others. This is a limitation seen in Tackle-ui which is using that framework.

That's where a Range filter becomes handy and should work with the table hook.

Now if the requirements have evolved to give to the user only Single Date filter then need to make that more explicit to the user that the date filters before an after are not correlated. UXD should be able to help.

I think there might be a third option, with a custom Date filter with a before or after option. But they would be exclusive.
Basically a single Date filter with > or < option or equivalent.

But overall the requirements of what type filters are needed on which page and how they're expected to behave should be decided by the design.

@carlosthe19916
Copy link
Collaborator Author

carlosthe19916 commented Sep 23, 2025

@gildub

I think there might be a third option, with a custom Date filter with a before or after option. But they would be exclusive. Basically a single Date filter with > or < option or equivalent.

If I understand correctly, that would mean that either we choose > or <. So I can do:

  • Select all documents whose creation date is greater and XYZ date (scenario 1)
  • Select all documents whose creation date is less and XYZ date (scenario 2)

But how would I select documents that are greater than X date but less than Y date? Seems like it won't be possible. (scenario 3)

Somehow this looks similar to what this PR is proposing, the difference is that > and < are set in the title of the Filter using the words Before and After. The advantage, and at the same time the problem, is:

  • It allows the selection of a range date if the user selects Before and After. But no validation can be done (scenario 3)
  • It allows to select only Before date (scenario 1)
  • It allows to select only After date (scenario 2)

But overall the requirements of what type filters are needed on which page and how they're expected to behave should be decided by the design.

I think that is a fair point. If needed we can put on hold this and ask UXD to design it and wait until there is a design. However, it wouldn't hurt give them some concrete proposals.

@gildub
Copy link
Contributor

gildub commented Sep 24, 2025

@carlosthe19916,

Yes, I think we need to circle that back with UXD.

From a functional viewpoint, we have :

  • Use case 1
    A date filter is needed to filter items by creation date, the user can choose a date, and decide to filter items before or after that date.

  • Use case 2
    A date filter is needed to select items by creation date using a range of dates.

Use case 1 could be implemented in different ways and that's where all the troubles came from.
Using a couple of date filters displaying before/after (to replace the confusing from/to) is easily confusing because it looks like a range (and cannot behave as a range logically).
That could be mitigated by making it explicit to the user it's not a range.
The third solution I mentioned is to have (if possible with the table hook filter, I haven't verified) a smart customized date filter in one single field where the user can choose before/after (or the carets > or <) without ambiguity.

The requirements must decide when we need either use cases.

@carlosthe19916
Copy link
Collaborator Author

@gildub I am closing this PR in favor of #806
The UX team recommended not to split the Filters in 2 different filters, like in this PR, but instead add validators to the current date range component so the user does not type incorrect range of dates

@gildub
Copy link
Contributor

gildub commented Oct 20, 2025

@carlosthe19916, noted, thanks for the follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-backport Indicates a PR needs to be backported

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

3 participants