Skip to content

fix: persist orders table state for smooth scrolling - #113

Merged
arkanoider merged 1 commit into
MostroP2P:mainfrom
misaelzb:main
Aug 13, 2026
Merged

fix: persist orders table state for smooth scrolling#113
arkanoider merged 1 commit into
MostroP2P:mainfrom
misaelzb:main

Conversation

@misaelzb

@misaelzb misaelzb commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the Orders tab table scroll behavior when navigating upwards through the list.

  • Persists the TableState inside AppState to prevent Ratatui from resetting the viewport offset on every frame.
  • Ensures the viewport smoothly follows the cursor when scrolling up a long order book.
  • Updates render_orders_tab to use a mutable AppState reference.
  • Fixes the corresponding unit tests to reflect the new mutable signature.

Testing

  • cargo check --all-targets --all-features
  • cargo test --all-features
  • cargo clippy --all-targets --all-features -- -D warnings

All checks passed successfully.

Summary by CodeRabbit

  • Bug Fixes
    • Improved selection handling in the Orders table so the selected row is maintained consistently while navigating the interface.
    • Updated table state management to preserve the current selection during screen updates.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The Orders tab now keeps its table selection and scrolling state in AppState. The renderer accepts mutable application state, and related tests pass mutable state. The package version changes from 0.2.3 to 0.2.4.

Changes

Orders table state

Layer / File(s) Summary
AppState table state contract
src/ui/app_state.rs
AppState now exposes orders_table_state: TableState and initializes it with TableState::default().
Renderer integration and validation
src/ui/tabs/orders_tab.rs, Cargo.toml
render_orders_tab now updates the persistent table state in AppState. Related tests pass mutable application state. The package version is 0.2.4.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: 🔵 Low · up to c863e

The PR persists Orders table state to preserve smooth scrolling and appears localized, but the repository-mandated build and formatting checks still need to be run and reported before merge; this is a bounded readiness follow-up rather than a blocking product risk.

Suggested reviewers: arkanoider

Poem

I’m a rabbit with a table to tend,
Selection stays from start to end.
Scrolls no longer hop away,
AppState keeps them safe each day.
Version bumps, tests cheer—
0.2.4 is here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes persisting the Orders table state to support smooth scrolling.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ui/tabs/orders_tab.rs (1)

307-325: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a two-frame regression test for the persistent viewport.

The scrolling test renders render_orders_tab only once. It can pass with TableState::default() created on every frame, so it does not verify the behavior targeted by this PR. Render with the last order selected, change app.selected_order_id to the preceding order, render again, and assert that the viewport offset remains stable.

As per coding guidelines, keep this test deterministic with ratatui::backend::TestBackend and a fixed-size buffer.

🤖 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 `@src/ui/tabs/orders_tab.rs` around lines 307 - 325, Extend
orders_table_scrolls_to_keep_selected_row_visible to render two frames using the
existing fixed-size TestBackend: first with last_id selected, then update
app.selected_order_id to the preceding order and render again. Assert after the
second render that the stateful table viewport offset remains unchanged,
preserving the existing deterministic backend setup.

Source: Coding guidelines

🤖 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.

Outside diff comments:
In `@src/ui/tabs/orders_tab.rs`:
- Around line 307-325: Extend orders_table_scrolls_to_keep_selected_row_visible
to render two frames using the existing fixed-size TestBackend: first with
last_id selected, then update app.selected_order_id to the preceding order and
render again. Assert after the second render that the stateful table viewport
offset remains unchanged, preserving the existing deterministic backend setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a766a59-b207-4298-84c7-ce99b21c60b1

📥 Commits

Reviewing files that changed from the base of the PR and between 8f312ee and c863e28.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • src/ui/app_state.rs
  • src/ui/tabs/orders_tab.rs

Moved TableState to AppState to prevent Ratatui from resetting the viewport offset on every frame. This allows the viewport to smoothly follow the cursor when scrolling up the order book.

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

Review: changes requested

The code change is narrowly scoped and the stateful TableState approach looks correct, but the current head does not pass the repository formatting gate.

Blocking:

  • cargo fmt --all -- --check fails in src/ui/app_state.rs because the new ratatui::widgets::TableState import is out of rustfmt order. Please run cargo fmt --all and push the formatted result.

Verified locally on e739014d1ed761f54c9fc27867793ba6a37ecef8:

  • cargo fmt --all -- --check
  • cargo test orders_table --all-features
  • cargo check --all-targets --all-features
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features

@arkanoider
arkanoider merged commit f605c68 into MostroP2P:main Aug 13, 2026
6 of 7 checks passed
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