Skip to content

feat(site/src/components/DateRangePicker): add maxDays and minDate props - #29625

Merged
ibetitsmike merged 6 commits into
mainfrom
mike/ai-spend/date-range-picker
Sep 22, 2026
Merged

ibetitsmike merged 6 commits into
mainfrom
mike/ai-spend/date-range-picker

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Adds maxDays and minDate to DateRangePicker, and labels the trigger with the committed inclusive days rather than the exclusive API boundary.

Why

The spend page higher in this stack must cap a custom range at the endpoint's 31-day limit and hide days and presets that start before the retention cutoff the report echoes. The page shows a skeleton until the first retention bound arrives, then keeps the picker mounted during report reloads. The picker does not need a disabled prop. toBoundary stays private here; the reporting-period PR exports it when the page first needs it.

What to scrutinize

  • selectableDaysFrom: when the maximal range of maxDays local days crosses a fall daylight-saving shift, the committed interval runs long by the shift, so the calendar allows one day less from that start instead of trimming the committed range.
  • excludeDisabled restarts a calendar selection if its previously committed start has fallen behind minDate.
  • The trigger label now shows fromBoundary(value), so a midnight exclusive end displays the previous day. TemplateInsightsPage is the other caller and is affected by that label change.

Validation

pnpm test src/components/DateRangePicker/DateRangePicker.test.tsx (new: maxDays restart, DST shave, minDate), pnpm test:storybook on DateRangePicker.stories.tsx (new ClosedExclusiveEnd and RetentionLimited), repository pre-commit (biome, tsc, knip).

Delivery record

Published head d1fc9334360 passed per-layer integration checks and commit hooks. The composed head d899228f798 passed format, check, full frontend lint, 125 unit tests, and 86 story tests. Pre-push hooks were skipped as requested. See #28964 for audit findings, their disposition, and historical UAT limits. No exact-head live UAT or new independent re-review is claimed.

Stack context

PR 1 of 9. The stack adds a User spend page under Admin settings > AI > User spend: total and per-user AI Gateway spend for one organization over a reporting period, read from GET /api/v2/organizations/{organization}/ai/spend/users (#29129, merged). It is #28964 split into one-concern PRs. Historical UAT covers earlier heads only; live UAT has not been rerun after these review fixes. Bottom to top: DateRangePicker limits, shared dimension badge, API client method, spend table, page view, page container, reporting period, dimension filters, route and navigation (#28964).

Xum prepared this PR on behalf of @ibetitsmike.

@ibetitsmike ibetitsmike changed the title mike/ai spend/date range picker feat(site/src/components/DateRangePicker): add maxDays, minDate, and disabled props Sep 20, 2026
@ibetitsmike
ibetitsmike marked this pull request as ready for review September 21, 2026 08:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-21T10:56:37.846409Z 2d1078b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc33009f62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@DanielleMaywood

Copy link
Copy Markdown
Collaborator

Do we need it to be possible for this component to be marked as disabled?

… limit of their own start

Check each calendar candidate in handleCalendarSelect against the
DST-aware limit computed from the candidate's own start instead of
passing react-day-picker's max, which was derived from the previous
start and treats a max of zero (maxDays 1) as unlimited. A backward
extension from a range starting after a fall transition can no longer
commit a window longer than maxDays * 24 hours, and maxDays 1 keeps a
single day selected.

Hide presets and calendar days before the first whole day on or after
minDate, so a cutoff inside a day never produces a committed midnight
start earlier than the cutoff.

Close the popover when the picker becomes disabled so it does not
reopen on its own once enabled again, and add a Disabled story.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5fc512005e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…xDays

Presets committed immediately without the maxDays check applied to
calendar selections, so a picker with maxDays 7 still offered and
committed the 14 and 30 day presets. Filter presets with the same
DST-aware limit the calendar uses, computed from each preset's own
start, so the list only offers ranges the picker would accept.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d1078b6ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2d1078b6ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike ibetitsmike reopened this Sep 21, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 21, 2026
@ibetitsmike ibetitsmike reopened this Sep 21, 2026
@coder coder unlocked this conversation Sep 21, 2026
@ibetitsmike

ibetitsmike commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Update: the disabled prop has been removed; see the implemented follow-up.

Edit: this analysis was wrong; see the correction below.

Do we need it to be possible for this component to be marked as disabled?

@DanielleMaywood No. It has a single consumer, SpendFilters, which passes disabled={reportQuery.isLoading}. Because usePaginatedQuery keeps previous data, isLoading is only true during the very first fetch, so the picker is greyed out while the initial report loads and never again on a range change. The sibling provider, model, and client filters are not disabled during that load either, and a range change mid-fetch is safe because the query is keyed on the range.

I will drop the prop, together with the reopen guard, story, and test that exist only for it, from the component here and from SpendFilters in #29629, and follow up on this comment with the commits.

Xum acted on behalf of @ibetitsmike.

@ibetitsmike

ibetitsmike commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Update: the disabled prop has been removed; see the implemented follow-up.

Correction to my previous comment: it is needed, and I had the analysis wrong.

paginatedOrganizationAISpend deliberately overrides placeholderData so that a change of organization or dimension filter does not keep the previous report on screen (only a page change does). While the report for the new selection loads there is no report at all, so the picker has no minDate from retention_start, and without disabled it offers presets such as "Last 30 days" that start before the retention cutoff. SpendPage.test.tsx pins this in "holds the date picker until the filtered report brings its retention bound", and removing the prop fails it. The picker is disabled exactly for that window and never on page changes.

I am keeping the prop. If you would rather not have a disabled state at all, the alternative is remembering the last known retention_start across selections (it is a deployment-level cutoff), which is more machinery than a prop; happy to do that if you prefer it.

Xum acted on behalf of @ibetitsmike.

Its only caller now renders a skeleton instead of a disabled picker, so
the prop, its close-on-disable handling, and the disabled story and test
have no consumer left.
@ibetitsmike ibetitsmike changed the title feat(site/src/components/DateRangePicker): add maxDays, minDate, and disabled props feat(site/src/components/DateRangePicker): add maxDays and minDate props Sep 22, 2026
@ibetitsmike
ibetitsmike removed this pull request from stack #29634 September 22, 2026 11:13
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Removed the disabled prop in d1fc933. The spend page now remembers the last deployment-wide retention cutoff across report fetches (#29631), so changing filters does not briefly offer dates before retention. It shows a skeleton only while the first cutoff is loading, then keeps the picker available during refetches. The picker also restarts a calendar selection if its old start has fallen before minDate.

This supersedes my earlier decision to keep the prop. The picker and spend-page regression tests pass.

Xum acted on behalf of @ibetitsmike.

@ibetitsmike
ibetitsmike merged commit 4c84dca into main Sep 22, 2026
33 of 34 checks passed
@ibetitsmike
ibetitsmike deleted the mike/ai-spend/date-range-picker branch September 22, 2026 12:15
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants