Skip to content

Fix MetricsDashboard::selected_index() to return Option<usize>#115

Open
ryanoneill wants to merge 1 commit intomainfrom
fix/metrics-dashboard-selected-index
Open

Fix MetricsDashboard::selected_index() to return Option<usize>#115
ryanoneill wants to merge 1 commit intomainfrom
fix/metrics-dashboard-selected-index

Conversation

@ryanoneill
Copy link
Owner

Summary

  • Change selected field from usize to Option<usize> for correctness
  • selected_index() now returns Option<usize> (was usize)
  • selected_position() now returns Option<(usize, usize)> (was (usize, usize))
  • Empty dashboard reports None instead of 0 pointing to nothing

Context

All other Envision components return Option<usize> from their index methods. MetricsDashboard was the outlier returning a bare usize. When the widgets vec was empty, selected_index() returned 0 which was misleading.

Test plan

  • All 66 MetricsDashboard unit tests pass
  • 4 doc tests pass (including updated module-level doc test)
  • New test_empty_dashboard_selected_index_is_none covers the empty case
  • cargo clippy --all-targets --all-features -- -D warnings clean

🤖 Generated with Claude Code

Change the internal selected field from usize to Option<usize> so that
an empty dashboard correctly reports no selection (None) instead of
returning 0 pointing to nothing.

- Change selected field from usize to Option<usize>
- Default state uses None, new() uses Some(0) when widgets exist
- selected_index() now returns Option<usize>
- selected_position() now returns Option<(usize, usize)>
- Update all navigation logic to wrap/unwrap Option
- Update view() to use Option comparison
- Update all test assertions to expect Some(value)
- Add test_empty_dashboard_selected_index_is_none test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.61%. Comparing base (087bee6) to head (30f67af).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #115   +/-   ##
=======================================
  Coverage   92.61%   92.61%           
=======================================
  Files         100      100           
  Lines        9530     9534    +4     
=======================================
+ Hits         8826     8830    +4     
  Misses        704      704           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants