Skip to content

fix(query-view): default time range to a relative window anchored at now - #298

Draft
haileyok wants to merge 2 commits into
mainfrom
claude/issue-96e-query-time-defaults
Draft

fix(query-view): default time range to a relative window anchored at now#298
haileyok wants to merge 2 commits into
mainfrom
claude/issue-96e-query-time-defaults

Conversation

@haileyok

Copy link
Copy Markdown
Member

Description

Fixes the issue from the friction log #96 (sub-item 4) where the query view shows no data by default.

Root cause

Two failure modes shared one root cause: the URL stored start/end as frozen literal timestamps while interval (when not custom) carried the semantic intent of "relative to now". extractQueryStateFromSearchParams in `osprey_ui/src/utils/QueryStoreUtils.tsx` never derived start/end from the relative interval at extraction time.

Both theories from the dispatch were correct:

  • Fresh page load (operator's claim): With no URL params, the initial state was `{start: '', end: '', interval: 'day'}`. `Timeseries.tsx` and `EventStream.tsx` short-circuit fetches on empty start/end (`if (start !== '' && end !== '')`), so graphs and the event stream sat empty until the user clicked Submit — without any indication that submit was needed.
  • Bookmarked URL with stale timestamps (friction log's theory): When a user submitted `interval=day` at noon, the URL got `start=2025-12-12T11:00Z&end=2025-12-12T12:00Z&interval=day`. Reloading that URL the next day queried the now-stale 24h window from the previous session, so recent data fell outside the range and the graphs rendered "No data available".

Fix

In `extractQueryStateFromSearchParams`:

  • When `interval` is a non-`custom` value (and is a known `IntervalOptions` key), derive `start`/`end` from `now` via the existing `getQueryDateRange` utility. Custom intervals still preserve the explicit timestamps the user picked from the date-range picker.
  • Only call `saveQueryToHistory` when the URL actually had explicit start/end timestamps, so a fresh page load with a derived default range doesn't record a phantom query history entry.

The defensive `interval in IntervalOptions` check guards against a URL with an unrecognized `interval=` value (which would otherwise blow up in `getQueryDateRange`'s destructuring).

Tests

Added `osprey_ui/src/utils/QueryStoreUtils.test.tsx` covering:

  • Fresh page load (no URL params) → start/end derived to `now - 1d` / `now`
  • URL with relative interval + stale timestamps → start/end recomputed fresh
  • URL with custom interval → explicit timestamps preserved
  • URL with relative interval but no timestamps → derived
  • URL with unknown interval value → falls through without throwing
  • `saveQueryToHistory` only fires when URL had explicit timestamps

Out of scope

  • Browser caching of empty responses (friction log mentions this; it's a separate concern from the time-range bug and didn't seem like the right place to fix it).
  • Adding a "Last hour" / "Last 30 min" quick-select option (the friction log mentions it; `IntervalOptions` already has `hour`, `thirtyMinutes`, `tenMinutes`, etc. — they're available in the dropdown, just not the default).

Closes #96 will be set once the operator confirms; for now this is sub-item 4 of the friction log, so refs #96.

Checklist

  • Tests pass locally (`react-scripts test` — 8 tests, 0 failures)
  • `uv run ruff check .` passes — no Python changes; `pre-commit run --all-files` clean
  • `uv tool run fawltydeps --check-unused --pyenv .venv` — N/A (no Python changes)
  • Updated `CHANGELOG.md` — N/A

haileyok added 2 commits May 24, 2026 05:12
When loading the query view, derive start/end from the relative
interval ("Last Day", "Last Hour", etc.) at extraction time instead of
honoring whatever literal timestamps were on the URL. Custom intervals
still preserve the explicit timestamps the user picked.

Two failure modes shared this root cause:
- Fresh page load (no URL params) silently rendered empty graphs and
  event stream because start/end were "" and Timeseries/EventStream
  short-circuit on empty range; users had to click Submit before
  seeing anything.
- Reloading a bookmarked URL with `interval=day` and stale start/end
  queried the historical 24h window from the previous session, so
  recent data fell outside the range.

Both flows now produce a "now - <interval>" to "now" range on every
extraction. saveQueryToHistory still only fires when the URL had
explicit start/end so a fresh page load does not record a query
history entry.

Refs #96
If a URL had an unrecognized `interval=...` value, the new recompute
path would call into getQueryDateRange and throw on the missing
IntervalOptions entry. Skip the recompute when the interval isn't a
known key, falling through to the URL timestamps so a malformed link
behaves the same way it did before this fix.
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fc5aff2-e6c4-4320-8185-74eac0b19bb9

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 claude/issue-96e-query-time-defaults

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

// the user picked from the date-range picker.
let start = startParam;
let end = endParam;
if (interval != null && interval !== CUSTOM_RANGE_OPTION && interval in IntervalOptions) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Friction Log for setting up Osprey

1 participant