Skip to content

ROX-34989: Add date range serialization and chip formatting utils#21050

Open
sachaudh wants to merge 1 commit into
masterfrom
ROX-34989-date-range-filter-utils
Open

ROX-34989: Add date range serialization and chip formatting utils#21050
sachaudh wants to merge 1 commit into
masterfrom
ROX-34989-date-range-filter-utils

Conversation

@sachaudh

@sachaudh sachaudh commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Jira: ROX-34989

This is the first slice of date/time range filtering for VM 2.0 (ROX-28073), stacked on #21049 which added the ROX_VULN_MGMT_DATE_RANGE_FILTER feature flag. The backend already supports range queries (tr/<startMs>-<endMs> for absolute ranges, 30d-90d and >365d for relative ones), but the UI's date-picker filter only understands single-date values. Range values arriving via URL (for example from the Aging Images dashboard widget) render as raw strings in filter chips, and there's no way to produce a range from the filter UI at all. I'm starting with the pure logic so the upcoming "Between" condition UI and the widget retarget have a tested foundation to build on.

  • Added serializeAbsoluteDateRange(startMs, endMs), which widens the picked dates to full calendar days (start-of-day through end-of-day) and emits the backend tr/ epoch-ms format. It throws on invalid dates or a start after the end, so callers can't silently apply a garbage filter.
  • Extended convertFromInternalToExternalDatePicker to render human-readable chips for all three range formats: "Between Jan 01, 2025 and Mar 31, 2025", "Between 30 and 90 days ago", and "More than 365 days ago".
  • Closed a lenient-parsing hole while I was in there: a malformed tr/ value from an untrusted URL used to fall through to new Date() and render as a nonsense date ("On Jan 01, 123"). It now falls back to the original string, matching the existing fallback behavior.
  • Added a dateRangeCondition constant for the upcoming "Between" dropdown condition. The existing Before/On/After prefix handling is untouched, so the single-date contract is fully backward-compatible.

Note: nothing is user-visible yet. These utils get consumed by the "Between" condition UI and the Aging Images widget retarget in follow-up PRs, all behind the feature flag.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests

How I validated my change

  • Wrote the tests first and confirmed they failed before implementing (8 new tests covering day-boundary serialization, same-day ranges, NaN and start-after-end rejection, chip formatting for all three range formats, malformed-value fallback, and a serialize-then-format round-trip).
  • All 16 unit tests in utils.test.ts pass, including the 8 pre-existing single-date tests, unmodified, which covers the backward-compatibility regression.
  • npm run lint:fast-dev clean on both touched files; full npm run tsc clean.
  • No UI validation applicable: this is pure logic with no consumer yet.

@openshift-ci

openshift-ci Bot commented Jun 10, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: aa89eae7-052d-4967-9a8f-2c1cfb3e59e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ROX-34989-date-range-filter-utils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit 1294640. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.12.x-130-g1294640621

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit 0a32cb6. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.12.x-129-g0a32cb6e53

@sachaudh sachaudh changed the title ROX-34989: Add date range serialization and chip formatting utils for VM 2.0 filters ROX-34989: Add date range serialization and chip formatting utils Jun 10, 2026
Base automatically changed from ROX-34994-date-range-filter-flag to master June 10, 2026 04:11
The VM 2.0 date-picker filter only understands single-date values
(Before/On/After prefixes), so range values the backend already
supports (tr/<startMs>-<endMs>, 30d-90d, >365d) render as raw strings
in filter chips and cannot be produced by the UI.

Add the pure foundations for range support:
- serializeAbsoluteDateRange widens the picked dates to full calendar
  days (start-of-day/end-of-day) so a range covers the days the user
  selected, and emits the backend tr/ epoch-ms format.
- convertFromInternalToExternalDatePicker now renders human-readable
  chips for absolute ranges ("Between Jan 01, 2025 and Mar 31, 2025"),
  relative ranges ("Between 30 and 90 days ago"), and open-ended
  relative values ("More than 365 days ago"). Malformed tr/ values
  from untrusted URLs fall back to the original string instead of
  being leniently parsed as a date.
- dateRangeCondition constant for the upcoming "Between" condition in
  the date-picker dropdown; existing Before/On/After prefixes are
  untouched to keep the single-date contract backward-compatible.

Signed-off-by: Saif Chaudhry <schaudhr@redhat.com>
@sachaudh sachaudh force-pushed the ROX-34989-date-range-filter-utils branch from 0a32cb6 to 1294640 Compare June 10, 2026 04:31
@sachaudh sachaudh marked this pull request as ready for review June 11, 2026 00:28
@sachaudh sachaudh requested a review from a team as a code owner June 11, 2026 00:28
@sachaudh sachaudh requested a review from dvail June 11, 2026 00:28
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.

1 participant