Skip to content

feat(analytics): 三个视图 Range 过滤器支持自定义日期范围 - #114

Open
Postroggy wants to merge 4 commits into
superduck-ai:mainfrom
Postroggy:feat/analytics-range-custom
Open

feat(analytics): 三个视图 Range 过滤器支持自定义日期范围#114
Postroggy wants to merge 4 commits into
superduck-ai:mainfrom
Postroggy:feat/analytics-range-custom

Conversation

@Postroggy

Copy link
Copy Markdown
Contributor

关联 #110

背景

#110 提出 Analytics 的 Range 过滤器目前只有固定预设,缺少自定义日期范围。本 PR 为 Caching / Cost / Logs 三个视图的 Range 过滤器增加自定义日期范围选择。

改动

  • 新增 AnalyticsRangeFilterControl:基于 Popover,上方是各视图原有的预设项(单选),下方是可折叠的「Custom range」入口;展开后是日历区间选择(react-day-picker),需要同时选中起止日期并点击 Apply 才提交,避免半选状态被应用。预设项点击即生效并关闭弹层。
  • Caching / Cost / Logs 三个视图的 Range FilterControl 改为 AnalyticsRangeFilterControl,预设列表沿用各视图原有的 rangeOptions
  • Range 过滤状态的类型由字符串改为判别式联合:{ kind: 'preset'; value: string } | { kind: 'custom'; from: string; to: string },自定义范围起止用 yyyy-MM-dd
  • 新增 web/src/shared/ui/calendar.tsx(shadcn 标准 Calendar 组件,基于 react-day-picker),供自定义范围选择使用。

说明

  • Analytics 三个视图目前渲染的是 mock 指标,Range 仅影响过滤器 UI,不涉及任何后端请求,所以本次只改前端。
  • 预设顺序保持各视图现状不变;Cost 视图预设顺序的问题在 [Analytics] 成本视图「Range」预设顺序与其它视图不一致 #112 单独处理,不在本 PR 范围内。
  • 已通过:bun run buildbun test(368 pass)、just web-format-check、ESLint naming / complexity、jscpd duplicates。

实现方向和文案待维护者确认。

Introduce AnalyticsRangeFilterControl with data-driven presets and a
collapsible Custom range calendar, replacing the Select-based Range
filter on the Caching, Cost and Logs dashboards. Range filter state now
holds either a preset value or yyyy-MM-dd custom bounds. The analytics
views still render mock metrics, so this is a UI-only change for now.

Closes superduck-ai#110
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Postroggy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 15 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12ab697e-baf9-4c2e-b15b-49d3d1722627

📥 Commits

Reviewing files that changed from the base of the PR and between 4445a4c and d57f863.

⛔ Files ignored due to path filters (1)
  • web/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • web/package.json
  • web/src/features/analytics/AnalyticsPages.tsx
  • web/src/features/analytics/AnalyticsRangeFilterControl.test.tsx
  • web/src/features/analytics/AnalyticsRangeFilterControl.tsx
  • web/src/shared/ui/calendar.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Postroggy
Postroggy marked this pull request as ready for review July 18, 2026 19:25

@duckpr duckpr 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.

DuckPR reviewer: opencode
Model: anthropic/glm-5.2

Caution

本 PR 引入的新依赖 date-fnsreact-day-picker 未在 web/package.json 中声明,会导致安装或构建失败。

Reviewed changes — 为 Analytics 的 Caching / Cost / Logs 三个视图添加支持自定义日期范围的 Range 过滤器,并新增可复用的 Calendar 组件。

  • 新增 AnalyticsRangeFilterControl,在 Popover 内提供预设单选和可折叠的 Custom range 日历选择。
  • 将三个视图的 Range 过滤器从 FilterControl 迁移到 AnalyticsRangeFilterControl,并把 Range 状态类型改为判别式联合 AnalyticsRangeFilter
  • 新增 web/src/shared/ui/calendar.tsx,基于 react-day-picker v9 实现 shadcn 风格的日期选择器。

⚠️ 新组件缺少测试覆盖

AnalyticsRangeFilterControl 是本次新增的核心交互组件,包含预设选择、自定义范围展开/收起、日期区间选择、Apply / Clear 等状态。当前 AnalyticsPages.test.tsx 未覆盖 Range 过滤器的交互,且没有为 AnalyticsRangeFilterControl 单独编写测试。建议在合并前补充至少覆盖以下路径的测试:

  • 预设项点击后关闭 Popover 并更新已选值;
  • 展开 Custom range、选择起止日期、点击 Apply 后状态变为 kind: 'custom'
  • 选择不完整日期时 Apply 按钮禁用;
  • 关闭 Popover 后重新打开时,草稿重置为已提交值。

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using anthropic/glm-5.2𝕏

Comment thread web/src/features/analytics/AnalyticsRangeFilterControl.tsx
Comment thread web/src/features/analytics/AnalyticsRangeFilterControl.tsx Outdated
@Postroggy Postroggy changed the title Analytics 三个视图的 Range 过滤器支持自定义日期范围 [Analytics] 三个视图「Range」过滤器支持自定义日期范围 Jul 18, 2026
@Postroggy Postroggy changed the title [Analytics] 三个视图「Range」过滤器支持自定义日期范围 feat(analytics): 三个视图 Range 过滤器支持自定义日期范围 Jul 19, 2026
1. web/package.json: 新增 date-fns 和 react-day-picker 依赖声明(代码已在用,但未声明导致构建报错)
2. web/bun.lock: bun install 后自动更新
3. AnalyticsRangeFilterControl.tsx: rangeLabel/rangeFilterLabel 中的用户可见日期格式从硬编码 format(date, 'MMM d, yyyy') 改为 useFormatters().date(date, {dateStyle:'medium'});applyCustomRange 中机器可读的 yyyy-MM-dd 格式保留不变

@duckpr duckpr 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.

DuckPR reviewer: opencode
Model: anthropic/glm-5.2

Important

上一次 review 提出的依赖声明和日期国际化问题已修复,但新组件 AnalyticsRangeFilterControl 仍缺少测试覆盖,建议在合并前补充。

Reviewed changes — 针对上一次 review 的反馈补充了缺失依赖并统一了日期国际化格式。

  • web/package.jsonweb/bun.lock 中声明并锁定 date-fnsreact-day-picker 依赖。
  • AnalyticsRangeFilterControl 的日期展示由硬编码 date-fns 英文格式改为 useFormatters().date(),走项目统一国际化方案。
  • Caching / Cost / Logs 三个视图的 Range 状态仍使用 { kind: 'preset'; value: string } | { kind: 'custom'; from: string; to: string } 判别式联合。

⚠️ AnalyticsRangeFilterControl 仍缺少测试覆盖

AnalyticsRangeFilterControl 是本次新增的核心交互组件,包含预设选择、自定义范围展开/收起、日期区间选择、Apply / Clear 等状态。虽然新提交修复了依赖和国际化问题,但尚未针对该组件补充测试;当前 AnalyticsPages.test.tsx 也未覆盖 Range 过滤器的交互。

建议在合并前至少覆盖以下路径:

  • 预设项点击后关闭 Popover 并更新已选值;
  • 展开 Custom range、选择起止日期、点击 Apply 后状态变为 kind: 'custom'
  • 选择不完整日期时 Apply 按钮禁用;
  • 关闭 Popover 后重新打开时,草稿重置为已提交值。

Pullfrog  | Fix it ➔View workflow run | Using anthropic/glm-5.2𝕏

@duckpr duckpr 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.

DuckPR reviewer: opencode
Model: anthropic/glm-5.2

✅ No new issues found.

Reviewed changes — 本次提交为 AnalyticsRangeFilterControl 补充了交互测试,回应了上一次 review 关于测试覆盖的反馈。

  • 新增 AnalyticsRangeFilterControl.test.tsx,覆盖预设项点击、自定义范围选择与 Apply、Apply 禁用状态、Popover 关闭后草稿重置。
  • 测试沿用了现有 AnalyticsPages.test.tsxdynamic import + resetTestDom 模式。

ℹ️ Nitpicks

  • AnalyticsRangeFilterControl.test.tsx 可考虑补充初始值为 kind: 'custom' 的场景,验证重新打开 Popover 时草稿被正确初始化并展开 Custom range。

Pullfrog  | View workflow run | Using anthropic/glm-5.2𝕏

@Postroggy

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

1 participant