Skip to content

feat(filters): wire provider/account subscriptions to RI Exchange tab - #582

Merged
cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/issue-186-history-filters-v2
May 27, 2026
Merged

cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/issue-186-history-filters-v2

Conversation

@cristim

@cristim cristim commented May 20, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The RI Exchange tab was the only main tab not reloading when the global provider/account filter changed (Dashboard, Recommendations, Plans, and History were all already wired)
  • Adds subscribeProvider + subscribeAccount subscriptions to setupRIExchangeHandlers with an active-subtab guard to skip off-screen reloads
  • Events are coalesced via queueMicrotask to prevent double-fetches when the topbar fires both a provider and account change in sequence

Closes #186

Test plan

  • cd frontend && npx jest riexchange passes (35 tests including 3 new subscription tests)
  • cd frontend && npx tsc --noEmit passes
  • Manual: change provider/account filter while on RI Exchange tab, verify tables reload

Summary by CodeRabbit

  • Bug Fixes
    • Improved RI Exchange filter subscription handling to prevent redundant reloads when provider or account changes occur.
    • RI Exchange filters now respect sub-tab visibility to avoid unnecessary updates.

Review Change Stack

…closes #186)

The RI Exchange sub-tab was the only main tab that did not reload when
the global provider/account filter changed. Dashboard, Recommendations,
Plans, and History already subscribed to state.subscribeProvider /
state.subscribeAccount; RI Exchange was silently skipped.

Changes:
- Import state module into riexchange.ts.
- Add isRIExchangeSubtabActive() guard (mirrors the Recommendations tab
  pattern) so filter changes off-screen don't trigger unnecessary fetches.
- setupRIExchangeHandlers now subscribes both state listeners; changes
  are coalesced via a queueMicrotask to avoid double-reloads when the
  topbar fires provider+account updates in sequence (same pattern as
  recommendations.ts).
- Tests: 3 new assertions pin subscription registration, active-tab
  reload, and hidden-tab skip.
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 9 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f7e9f171-038f-464a-a645-12032bf06ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 4e89c65 and 84a344c.

📒 Files selected for processing (1)
  • frontend/src/__tests__/riexchange.test.ts
📝 Walkthrough

Walkthrough

This PR addresses issue #186 by adding subscription-based filtering to the RI Exchange tab. The module now subscribes to provider and account state changes, triggering a coalesced reload only when the sub-tab is visible, preventing unnecessary API calls during rapid state updates.

Changes

RI Exchange subscription-based filtering

Layer / File(s) Summary
State module integration and sub-tab visibility guard
frontend/src/riexchange.ts
Import ./state module and add isRIExchangeSubtabActive() helper to detect when the RI Exchange sub-tab panel is currently visible, providing the foundation for conditional refresh logic.
Provider and account subscription wiring with coalesced reload
frontend/src/riexchange.ts
In setupRIExchangeHandlers(), subscribe to both provider and account state changes and use a reloadQueued flag with queueMicrotask() to coalesce both events into a single loadRIExchange() call, firing only when the sub-tab is active.
Test mocking and subscription behavior verification
frontend/src/__tests__/riexchange.test.ts
Add mock infrastructure that captures subscribeProvider and subscribeAccount callbacks into outer-scope arrays for manual invocation. Add new test suite verifying subscription registration and that simulated provider/account changes trigger loadRIExchange() only when the RI Exchange sub-tab is visible.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

effort/s

🐰 A subscription flows through the RI Exchange,
Provider and account both caught in the mesh,
When the sub-tab shows its face so bright,
The data reloads with coalesced might!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: wiring provider/account subscriptions to the RI Exchange tab to enable filter functionality.
Linked Issues check ✅ Passed The PR implements core requirements from #186: adds subscribeProvider/subscribeAccount to setupRIExchangeHandlers, includes active-subtab guard to skip reloads when not visible, and coalesces events via queueMicrotask.
Out of Scope Changes check ✅ Passed All changes directly support the #186 objective of wiring provider/account filters to the RI Exchange tab; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-186-history-filters-v2

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim cristim added priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/m Days type/feat New capability triaged Item has been triaged labels May 20, 2026
@cristim

cristim commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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.

@cristim

cristim commented May 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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.

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

🧹 Nitpick comments (2)
frontend/src/__tests__/riexchange.test.ts (2)

477-525: ⚡ Quick win

Consider adding test coverage for account subscription.

The test suite verifies provider change behavior but not account change, even though the PR adds subscriptions for both filters. Since both use the same scheduleReload callback, the logic is already proven correct, but explicitly testing the account path would improve confidence and completeness.

📋 Suggested test case

Add after the existing "provider change does NOT trigger..." test:

it('an account change triggers loadRIExchange when the sub-tab is active', async () => {
  setupRIExchangeHandlers();
  _accountListeners.forEach(cb => cb());
  await new Promise(r => setTimeout(r, 0));
  expect(api.listConvertibleRIs).toHaveBeenCalled();
});
🤖 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 `@frontend/src/__tests__/riexchange.test.ts` around lines 477 - 525, Add a test
that mirrors the provider-change test but exercises the account subscription:
after calling setupRIExchangeHandlers() iterate over _accountListeners and
invoke each callback (e.g. _accountListeners.forEach(cb => cb())), await a
microtask (e.g. setTimeout 0) and assert that api.listConvertibleRIs was called;
place this new it(...) immediately after the existing "provider change does NOT
trigger..." test so it verifies the subscribeAccount path uses the same
scheduleReload behavior.

477-525: ⚡ Quick win

Consider adding test coverage for coalescing behavior.

The PR description emphasizes that the implementation "coalesces provider/account change events via queueMicrotask to prevent duplicate fetches when both change in sequence." Adding an explicit test that fires both listeners and verifies a single reload would directly validate this key requirement.

🔄 Suggested test case

Add after the account change tests:

it('coalesces provider and account changes into a single reload', async () => {
  setupRIExchangeHandlers();
  // Simulate topbar filter cascade: provider change triggers account reset
  _providerListeners.forEach(cb => cb());
  _accountListeners.forEach(cb => cb());
  await new Promise(r => setTimeout(r, 0));
  // Should be called once, not twice
  expect(api.listConvertibleRIs).toHaveBeenCalledTimes(1);
});
🤖 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 `@frontend/src/__tests__/riexchange.test.ts` around lines 477 - 525, Add a test
that verifies coalescing by invoking both _providerListeners and
_accountListeners in sequence and asserting only one reload call to
api.listConvertibleRIs; specifically, after calling the listener callbacks (from
the setup created in setupRIExchangeHandlers()), wait a microtask (e.g., await
new Promise(r => setTimeout(r, 0))) and expect api.listConvertibleRIs
toHaveBeenCalledTimes(1) to ensure queueMicrotask batching prevents duplicate
fetches.
🤖 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.

Nitpick comments:
In `@frontend/src/__tests__/riexchange.test.ts`:
- Around line 477-525: Add a test that mirrors the provider-change test but
exercises the account subscription: after calling setupRIExchangeHandlers()
iterate over _accountListeners and invoke each callback (e.g.
_accountListeners.forEach(cb => cb())), await a microtask (e.g. setTimeout 0)
and assert that api.listConvertibleRIs was called; place this new it(...)
immediately after the existing "provider change does NOT trigger..." test so it
verifies the subscribeAccount path uses the same scheduleReload behavior.
- Around line 477-525: Add a test that verifies coalescing by invoking both
_providerListeners and _accountListeners in sequence and asserting only one
reload call to api.listConvertibleRIs; specifically, after calling the listener
callbacks (from the setup created in setupRIExchangeHandlers()), wait a
microtask (e.g., await new Promise(r => setTimeout(r, 0))) and expect
api.listConvertibleRIs toHaveBeenCalledTimes(1) to ensure queueMicrotask
batching prevents duplicate fetches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d473870-8815-4646-82da-b53aa7cf16d8

📥 Commits

Reviewing files that changed from the base of the PR and between bc8831b and 4e89c65.

📒 Files selected for processing (2)
  • frontend/src/__tests__/riexchange.test.ts
  • frontend/src/riexchange.ts

…R 4344791727)

Address two CR nitpicks: verify subscribeAccount path triggers a reload
when the sub-tab is active, and that queueMicrotask batches simultaneous
provider+account changes into one loadRIExchange call.
@cristim

cristim commented May 27, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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.

@cristim

cristim commented May 27, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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.

@cristim
cristim merged commit d986b4d into feat/multicloud-web-frontend May 27, 2026
5 checks passed
@cristim
cristim deleted the fix/issue-186-history-filters-v2 branch June 3, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/many Affects most users priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/feat New capability urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant