refactor(tui): unify scoped empty-view presentation - #189
Conversation
|
Warning Review limit reached
Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Walkthrough新增 TUI 的统一 Presentation 与 ActionSet 状态契约,集中处理空视图、快捷键、滚轮、页脚帮助和排序能力;各报表渲染器接入共享空状态模板。同时将 UsageData.graph 改为必填结构并强化 schema-44 缓存校验。 ChangesTUI 状态与交互契约
Usage graph 数据契约
文档契约
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant App
participant Presentation
participant ActionSet
participant ViewRenderer
participant Footer
App->>Presentation: classify current view
Presentation->>ActionSet: derive available actions
ActionSet->>ViewRenderer: provide empty state and action context
ViewRenderer->>Footer: render action-aware footer
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/tokscale-cli/src/tui/ui/daily.rs (1)
1009-1030: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win多个文件的测试辅助函数重复构造
ViewState/Presentation/ActionSet样板代码。为适配新的
render(..., empty, &actions)签名,六个文件的测试模块都各自重复了同一段三行样板:ViewState::default()→Presentation::for_view(app, &state)→ActionSet::for_view(app, &state, presentation)。建议在共享测试工具模块中抽取一个辅助函数(如返回(ViewState, ActionSet)或直接返回ActionSet),供以下位置复用:
crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030:render_body中的三行样板改为调用共享辅助。crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189:render_buffer中的三行样板改为调用共享辅助。crates/tokscale-cli/src/tui/ui/models.rs#L703-L724:render_body中的三行样板改为调用共享辅助。crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476:测试内联的三行样板改为调用共享辅助。crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836:render_snapshot中的三行样板改为调用共享辅助(该函数已很好地做到文件内复用,可作为跨文件抽取的模板)。crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877:actions_for中的三行样板改为调用共享辅助(该实现已是较干净的独立函数,可直接作为共享辅助的起点)。若未来
Presentation::for_view/ActionSet::for_view的签名或调用方式变化,当前需要同步修改六处以上位置;抽取共享辅助后只需改一处。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/tokscale-cli/src/tui/ui/daily.rs` around lines 1009 - 1030, Extract the repeated ViewState::default → Presentation::for_view → ActionSet::for_view setup into a shared test helper, preferably based on the existing actions_for pattern in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877. Update render_body in crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030, render_buffer in crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189, render_body in crates/tokscale-cli/src/tui/ui/models.rs#L703-L724, the inline setup in crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476, render_snapshot in crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836, and actions_for in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877 to call the shared helper while preserving each caller’s existing rendering behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0028-tui-client-universe-and-view-selection.md`:
- Around line 121-125: 更新 ADR
中空视图动作契约的描述,使其明确移除排序、明细、复制和行点击等行级动作,同时保留适用的全局动作,包括主题、自动刷新、刷新间隔、导出和退出;不要再表述为空视图“只广告恢复与导航动作”,以与
ActionSet::for_view 的实际行为一致。
---
Nitpick comments:
In `@crates/tokscale-cli/src/tui/ui/daily.rs`:
- Around line 1009-1030: Extract the repeated ViewState::default →
Presentation::for_view → ActionSet::for_view setup into a shared test helper,
preferably based on the existing actions_for pattern in
crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877. Update render_body in
crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030, render_buffer in
crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189, render_body in
crates/tokscale-cli/src/tui/ui/models.rs#L703-L724, the inline setup in
crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476, render_snapshot in
crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836, and actions_for
in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877 to call the shared helper
while preserving each caller’s existing rendering behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 690d5d36-3883-406b-9647-1a8b405bb1cc
📒 Files selected for processing (30)
crates/tokscale-cli/src/tui/actions.rscrates/tokscale-cli/src/tui/app.rscrates/tokscale-cli/src/tui/cache.rscrates/tokscale-cli/src/tui/mod.rscrates/tokscale-cli/src/tui/presentation.rscrates/tokscale-cli/src/tui/ui/agents.rscrates/tokscale-cli/src/tui/ui/daily.rscrates/tokscale-cli/src/tui/ui/daily_profile.rscrates/tokscale-cli/src/tui/ui/empty_state.rscrates/tokscale-cli/src/tui/ui/footer.rscrates/tokscale-cli/src/tui/ui/hourly.rscrates/tokscale-cli/src/tui/ui/hourly_profile.rscrates/tokscale-cli/src/tui/ui/mod.rscrates/tokscale-cli/src/tui/ui/models.rscrates/tokscale-cli/src/tui/ui/overview.rscrates/tokscale-cli/src/tui/ui/overview_snapshot.rscrates/tokscale-cli/src/tui/ui/period.rscrates/tokscale-cli/src/tui/ui/sessions.rscrates/tokscale-cli/src/tui/ui/stats.rscrates/tokscale-cli/src/tui/ui/view_footer.rscrates/tokscale-cli/src/tui/view_state.rscrates/tokscale-core/benches/aggregation.rscrates/tokscale-core/src/aggregate/parity_tests.rscrates/tokscale-core/src/aggregate/tui.rscrates/tokscale-core/src/usage_views.rsdocs/adr/0008-single-copy-memory-pipeline.mddocs/adr/0010-period-views-derive-from-daily.mddocs/adr/0026-group-by-view-scope-contract.mddocs/adr/0028-tui-client-universe-and-view-selection.mddocs/cli.md
变更概述
统一本地 TUI 的 generation、projection、presentation 与 action 边界,使真实可达的空视图共享一套状态语义、页面模板和交互能力。
主要变更
Presentation分类入口:Loading | Failed | Empty(subject) | Ready,页面不再各自猜测数据状态。ActionSet,由同一 presentation 结果约束 footer、上下文键盘、滚轮和排序点击区域。data_clients:单选显示客户端名,多客户端全集显示All clients,其余只显示数量;窄终端按显示宽度逐级降级和截断。[s:clients]、[r:rescan]与视图导航,不再泄漏排序、详情等无效提示;合法的全局导出仍可执行。UsageData.graph改为总值,空图唯一表示为weeks: [];缓存中的 graph 仍为必填对象,缺失或null直接成为 cache miss,不增加兼容或迁移分支。文档清理
*反选及sessionstab 列表。验证
cargo check -p tokscale-cli --all-targetscargo clippy -p tokscale-cli --all-targets -- -D warningscargo test -p tokscale-cli:927 passed,1 ignoredcargo test -p tokscale-core:1485 passed,4 ignoredcargo fmt --all -- --checkgit diff --checkSummary by CodeRabbit