Skip to content

feat(frontend/history): inline column filters via shared lib (refs #166)#790

Open
cristim wants to merge 7 commits into
mainfrom
refactor/history-column-filters
Open

feat(frontend/history): inline column filters via shared lib (refs #166)#790
cristim wants to merge 7 commits into
mainfrom
refactor/history-column-filters

Conversation

@cristim

@cristim cristim commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

Wires the History page to the shared frontend/src/lib/column-filters.ts extracted by merged PR #570. Adds inline per-column filter buttons to both History tables (Purchase History + Approval Queue) using the same applyColumnFilters<TRow, TColumnId> shape that recommendations.ts already uses.

  • New state slices: PurchaseHistoryColumnId + ApprovalQueueColumnId, each with its own in-memory filter record, get/set/clear accessors. Two separate enums because the queue uses Account/Payment/Monthly Cost/Created By while Purchase History uses Resource Type/Region — overlap is too narrow to share a single column-id type without ugly unions.
  • New frontend/src/lib/history-filter-popover.ts — small reusable popover helper shared by the two tables; reuses the existing .column-filter-popover CSS so the visual matches recommendations.
  • Filterable columns:
    • Purchase History: Provider, Service, Type, Region, Term (categorical) + Count, Upfront Cost, Monthly Savings (numeric).
    • Approval Queue: Provider, Account, Service, Term, Payment, Created by (categorical) + Count, Monthly Cost, Upfront Cost, Monthly Savings (numeric).
  • Status is intentionally excluded — the existing status chip-row stays as the canonical status filter on Purchase History; the Approval Queue scope is status-defined.
  • Numeric extractors apply roundForDisplay(_, 0) so a typed $X matches the rendered cell (matches the issue ux(opportunities): numeric column filter doesn't match exact values (typed value compares against unrounded backend) #484 contract on recommendations).
  • monthly_cost returns NaN for null (= 0 and > 0 filters don't coincidentally match unreported rows).

Sibling PRs

Part of the issue #166 follow-up trio:

  • This PR: History tables.
  • Sibling: Plans table.
  • Sibling: RI Exchange table.

Each PR touches only its own state slice, so all three rebase cleanly against feat/multicloud-web-frontend.

Test plan

  • npm test -- history — all history-related suites green.
  • npm test -- approval-queue — new regression suite passes.
  • npm test -- column-filters — shared lib regression unchanged.
  • npx tsc --noEmit — clean.
  • Full npm test — 67 suites / 2154 tests / 1 skipped — all green.

Refs #166.

Summary by CodeRabbit

Release Notes

New Features

  • Column filtering added to Purchase History table supporting numeric expressions and categorical selections
  • Column filtering added to Approval Queue table with interactive popover-based filter UI
  • New filter buttons in table headers enabling quick application and clearing of active filters

Tests

  • Added regression test suites for column filter functionality

@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/few Limited audience effort/m Days type/feat New capability labels May 28, 2026
@cristim

cristim commented May 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 28, 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 commented May 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 8 minutes and 9 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

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

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

🚦 How do rate limits work?

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

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 705f89fd-f84f-4f40-be50-86d336c999ed

📥 Commits

Reviewing files that changed from the base of the PR and between eb409e1 and d8caeef.

📒 Files selected for processing (14)
  • frontend/src/__tests__/allowed-accounts.test.ts
  • frontend/src/__tests__/approval-queue-column-filters.test.ts
  • frontend/src/__tests__/history-approval-queue.test.ts
  • frontend/src/__tests__/history-approve-button.test.ts
  • frontend/src/__tests__/history-cancel-button.test.ts
  • frontend/src/__tests__/history-cancel-permissions.test.ts
  • frontend/src/__tests__/history-column-filters.test.ts
  • frontend/src/__tests__/history-filter-popover-xss.test.ts
  • frontend/src/__tests__/history-retry-button.test.ts
  • frontend/src/__tests__/history.test.ts
  • frontend/src/__tests__/xss-provider-class.test.ts
  • frontend/src/history.ts
  • frontend/src/lib/history-filter-popover.ts
  • frontend/src/state.ts
📝 Walkthrough

Walkthrough

This PR adds per-column filtering to Purchase History and Approval Queue tables with a shared portal-rendered popover UI. New state management stores filter selections, filter application functions transform row arrays, and filter buttons in table headers open popover controls for numeric expression and categorical set filtering.

Changes

History Column Filters

Layer / File(s) Summary
Column Filter State Management
frontend/src/state.ts
In-memory filter state with separate column-id enums for Purchase History and Approval Queue; exported accessor/mutator functions get/set/clear each table's filters.
History Filter Popover Component
frontend/src/lib/history-filter-popover.ts
Portal-rendered popover for numeric expression and categorical checkbox filtering with positioning, global event listeners (outside click, Escape, scroll, resize), focus management, and footer "Clear" control.
Purchase History Column Filters
frontend/src/history.ts
Filter application logic with numeric/categorical cell extractors (rounded to match display), exports applyPurchaseHistoryColumnFilters, integrates filtering into renderHistoryList, adds filter buttons to table header, and wires button-popover interaction.
Approval Queue Column Filters
frontend/src/history.ts
Parallel filter logic for approval queue with monthly_cost -> NaN when missing, exports applyApprovalQueueColumnFilters, integrates into queue rendering, updates header with filter buttons, and wires popover controls.
History Loading Integration
frontend/src/history.ts
In loadHistory(), closes open history column-filter popover before re-rendering to prevent stale popover anchoring to rewritten header cells.
Purchase History Filter Tests
frontend/src/__tests__/history-column-filters.test.ts
New Jest regression suite for applyPurchaseHistoryColumnFilters covering numeric expression filtering, categorical set filtering, AND combination, invalid expression no-op, and clearing with fresh clone semantics.
Approval Queue Filter Tests
frontend/src/__tests__/approval-queue-column-filters.test.ts
New Jest regression suite for applyApprovalQueueColumnFilters covering numeric/categorical filtering, AND combination, null-contract non-matching, and clearing behavior.
Test Mock Updates
frontend/src/__tests__/*.test.ts
Extended Jest mocks across 8 test files to provide column filter state API getter/setter/clear stubs, aligning test environments with updated history.ts expectations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • LeanerCloud/CUDly#570: Main PR's column-filter popover uses parseNumericFilter helper and ColumnFilterKind type extracted from this PR.
  • LeanerCloud/CUDly#387: Main PR's new approval-queue column filtering and popover UI logic directly extend the approval-queue card/table rendering from this PR.
  • LeanerCloud/CUDly#587: Main PR extends test mock setup in allowed-accounts.test.ts to match the new state API surface introduced in this PR.

Suggested labels

feature/filtering, frontend, tables, ui-components, state-management

Poem

🐰 With popover controls and filters bright,
Rows dance through numeric and set delight,
Purchase and approval queues now see,
Column by column, what they could be!
⛛ gear icons turn the filtering key,
History tables—finally set free! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding inline column filters to the History page using a shared library component, and references the associated issue.
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.

✏️ 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 refactor/history-column-filters

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

@cristim

cristim commented May 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@cristim have exceeded the limit for the number of chat messages per hour. Please wait 54 minutes and 16 seconds before sending another message.

@cristim cristim force-pushed the refactor/history-column-filters branch from 2f2a298 to 3cec781 Compare June 1, 2026 17:08
@cristim

cristim commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 1, 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 force-pushed the refactor/history-column-filters branch from 3cec781 to 03c7a40 Compare June 3, 2026 20:59
@cristim

cristim commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

Rebased on feat/multicloud-web-frontend (now at 87f739a) after sibling PRs #887, #845, #826, #819, #791, #789 advanced the base.

Conflict resolution: only frontend/src/state.ts conflicted, and the conflict was purely additive. The base had gained the RI Exchange filter slice (sibling #789), the Plans filter slice (sibling #791), and a usage_history value on RecommendationsColumnId; this branch adds the History / Approval Queue filter slices at the same anchor point. Kept all blocks intact; no semantic or renamed-field divergence. The other touched files (history.ts, lib/history-filter-popover.ts, test suites) auto-merged.

Verification on the rebased head: tsc --noEmit clean; all 90 tests across the 9 touched files pass (history-column-filters, approval-queue-column-filters, history, history-approval-queue, history-approve/cancel/retry-button, allowed-accounts, xss-provider-class).

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@cristim Thanks for the detailed rebase context — purely additive conflict in frontend/src/state.ts with all sibling slices kept intact and a clean tsc + 90-test pass looks solid. Triggering the review now.


🧠 Learnings used
Learnt from: cristim
Repo: LeanerCloud/CUDly PR: 0
File: :0-0
Timestamp: 2026-05-05T15:44:54.463Z
Learning: In the LeanerCloud/CUDly repository, when a CodeRabbit review flags something as "outside-diff" that was already implemented in an earlier commit of the same PR, it is likely a stale-snapshot artifact where the review diff was generated against a pre-fix view. The inline comment convention `(CR pass on PR #<number> Finding N)` is used by the maintainer (cristim) to mark lines that were changed in direct response to a prior CodeRabbit review pass.
✅ 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.

@cristim

cristim commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
✅ 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.

cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

@cristim Sure, triggering a full re-review of this PR now.


🧠 Learnings used
Learnt from: cristim
Repo: LeanerCloud/CUDly PR: 0
File: :0-0
Timestamp: 2026-05-05T15:44:54.463Z
Learning: In the LeanerCloud/CUDly repository, when a CodeRabbit review flags something as "outside-diff" that was already implemented in an earlier commit of the same PR, it is likely a stale-snapshot artifact where the review diff was generated against a pre-fix view. The inline comment convention `(CR pass on PR #<number> Finding N)` is used by the maintainer (cristim) to mark lines that were changed in direct response to a prior CodeRabbit review pass.

Learnt from: cristim
Repo: LeanerCloud/CUDly PR: 0
File: :0-0
Timestamp: 2026-06-06T06:41:06.841Z
Learning: In LeanerCloud/CUDly PR `#804`, `canRevokeCompletedRow` in `frontend/src/history.ts` must check `canAccess` (not just `getCurrentUser()` truthiness) to align with peer predicates `canCancelPendingRow`, `canApprovePendingRow`, and `canRetryFailedRow`. `revoke-own` and `revoke-any` were added to the closed `Action` union to make future UX-vs-RBAC drift a compile error.

Learnt from: cristim
Repo: LeanerCloud/CUDly PR: 0
File: :0-0
Timestamp: 2026-06-06T06:43:53.792Z
Learning: In LeanerCloud/CUDly PR `#995` (issue `#950` ownership gate), the Dashboard "Upcoming purchases" widget (`dashboard.ts`) has two Cancel entry points (card-level and modal) that both call `api.deletePlannedPurchase`. The `UpcomingPurchase` response DTO must include `CreatedByUserID *string` (omitempty, mirroring `PlannedPurchase`) so the frontend can gate these buttons via a `canCancelUpcomingPurchase` helper that mirrors `canManageScheduledPurchase` on the Plans page. Without this, the backend correctly 403s non-owners but the UI has no gate and the UX is broken. Regressions: `frontend/src/__tests__/dashboard-ownership-950.test.ts` (6 tests) and `TestHandler_getUpcomingPurchases_PropagatesCreatedByUserID`. Fixed in commit 94326f6b9.
✅ Action performed

Full review finished.

@cristim

cristim commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@cristim cristim force-pushed the refactor/history-column-filters branch from 03c7a40 to eb409e1 Compare June 8, 2026 20:00
@cristim

cristim commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
✅ 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.

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

Actionable comments posted: 1

🤖 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 `@frontend/src/lib/history-filter-popover.ts`:
- Around line 71-84: closeOpenHistoryPopover currently removes the popover DOM
but doesn't reset the trigger button's aria-expanded, leaving stale
accessibility state; update closeOpenHistoryPopover (and any matching close
paths) to locate the trigger using the same selector used when opening (e.g.,
`.history-column-filter-btn[data-column="${CSS.escape(column)}"]`) and set its
aria-expanded attribute to "false" before or after calling trigger?.focus(),
ensuring this runs regardless of restoreFocus so the button state is always
cleared when openPopover is removed; keep existing removal of el, nulling
openPopover, calling detachGlobalListeners, and clearing lastAnchorSelector.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5bf961a8-97fa-42d8-a3e4-24ed6e2cc00b

📥 Commits

Reviewing files that changed from the base of the PR and between c7448ca and eb409e1.

📒 Files selected for processing (13)
  • frontend/src/__tests__/allowed-accounts.test.ts
  • frontend/src/__tests__/approval-queue-column-filters.test.ts
  • frontend/src/__tests__/history-approval-queue.test.ts
  • frontend/src/__tests__/history-approve-button.test.ts
  • frontend/src/__tests__/history-cancel-button.test.ts
  • frontend/src/__tests__/history-cancel-permissions.test.ts
  • frontend/src/__tests__/history-column-filters.test.ts
  • frontend/src/__tests__/history-retry-button.test.ts
  • frontend/src/__tests__/history.test.ts
  • frontend/src/__tests__/xss-provider-class.test.ts
  • frontend/src/history.ts
  • frontend/src/lib/history-filter-popover.ts
  • frontend/src/state.ts

Comment thread frontend/src/lib/history-filter-popover.ts
@cristim

cristim commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
✅ 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.

@cristim

cristim commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@cristim cristim changed the base branch from feat/multicloud-web-frontend to main June 9, 2026 15:46
cristim added 7 commits June 19, 2026 17:38
…ces (refs #166)

Adds two new closed column-id enums and matching filter slices for the
History page tables: PurchaseHistoryColumnId for the completed-purchases
table and ApprovalQueueColumnId for the pending-approvals card. The two
tables share Provider/Service/Term/Count/UpfrontCost/MonthlySavings
columns but diverge on the queue's Account/Payment/MonthlyCost/CreatedBy
vs Purchase History's ResourceType/Region, so each gets its own
in-memory slice with set/clear/getAll accessors mirroring the existing
recommendations equivalents.

In-memory only on this iteration; localStorage persistence stays a
follow-up under the same umbrella as the recommendations equivalent.
…se History table (refs #166)

Adds per-column filter buttons to the Purchase History table headers.
Filter columns: Provider, Service, Type (resource_type), Region, Term
(categorical), and Count, Upfront Cost, Monthly Savings (numeric).
Status is excluded — the existing status chip-row is the canonical
filter for that column.

Wires `applyColumnFilters` from lib/column-filters.ts through extractors
that match the rendered cell shape: categorical extractors return the
raw field; numeric extractors return the value rounded to display
precision so typed numbers match the rendered cells (issue #484
contract). Filters compose with the existing status chip filter, and
the column-filter popover lists distinct values from rows that survived
the status filter (so picking "Failed" then opening Provider only lists
providers with failed rows).

Introduces a small lib/history-filter-popover.ts module shared by both
History tables — keeps the popover DOM/teardown/keyboard wiring out of
history.ts itself and reuses the existing .column-filter-popover CSS so
the visual matches the recommendations equivalent.
…al Queue table (refs #166)

Adds per-column filter buttons to the Approval Queue table headers.
Filter columns: Provider, Account, Service, Term, Payment, Created by
(categorical), and Count, Monthly Cost, Upfront Cost, Monthly Savings
(numeric). Status is excluded — the queue scope is already pending|
notified by definition; the broader Status chip-row above is the
authoritative status filter for the page.

Uses the same lib/history-filter-popover.ts helper introduced for the
Purchase History table. Numeric extractors round to display precision
(CURRENCY_DEFAULT_DIGITS) so a "$X" filter matches the rendered cell;
monthly_cost returns NaN for null so a "= 0" predicate doesn't match
rows where the provider didn't report a value. Categorical extractors
mirror the cell rendering: account uses account_id with getAccountName
as the display label, created_by prefers email then falls back to UUID.

Test-suite mocks (history-* + allowed-accounts + xss-provider-class)
extended with the new state accessors so they keep passing against the
expanded state surface.
Adds two test files exercising the new History column-filter wiring:

* history-column-filters.test.ts — Purchase History table:
  numeric expr, categorical set, stacked AND, invalid expr (no-op),
  clear, and the term-as-stringified-categorical case.

* approval-queue-column-filters.test.ts — Approval Queue table:
  numeric expr (monthly_cost >= N), categorical set (payment in
  {…}), stacked AND across provider+created_by, invalid expr (no-op),
  the NaN-as-missing contract for null monthly_cost (so "= 0" and
  "> 0" don't coincidentally match unreported rows), and clear.

Both suites mock the heavy module transitive deps (api / navigation /
utils / state / confirmDialog / approval-details / toast / skeleton /
recommendations) so the pure column-filter helpers can be exercised
without standing up a DOM.
…ssions suite

Rebasing onto feat/multicloud-web-frontend surfaced a gap: the new
History/ApprovalQueue per-column-filter accessors added to ../state by
this PR (issue #166) were missing from the ../state mock in
history-cancel-permissions.test.ts. Without them renderApprovalQueue
threw "getApprovalQueueColumnFilters is not a function", suppressing the
whole approval-queue render and zeroing out the cancel buttons the
permission-gating assertions depend on.

Add the same six getter/setter/clear mocks already present in the other
history test suites so the render path completes and the cancel-gating
assertions exercise real button output again.

refs #166
closeOpenHistoryPopover removed the popover DOM but never restored the
trigger button's aria-expanded to "false", leaving stale expanded
accessibility state after outside-click, Escape, or toggle-close. Reset
it on every close path, independent of focus restoration.
…ttrs

renderHistoryFilterButton injected `column` and `label` raw into
aria-label, title, and data-column attributes via innerHTML template
literal. Apply escapeHtmlAttr to both before interpolation and replace
the em-dash in the active-state aria-label with a hyphen.

Add history-filter-popover-xss.test.ts to assert hostile payloads in
label and column are entity-encoded, not executed.
@cristim cristim force-pushed the refactor/history-column-filters branch from 4d42d02 to d8caeef Compare June 19, 2026 15:45
@cristim

cristim commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
✅ 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

effort/m Days impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/feat New capability urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant