Skip to content

Fix: table sort resets on filter change - #223

Merged
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:fix/116-table-sort-resets-on-filter-change
Aug 28, 2026
Merged

Fix: table sort resets on filter change#223
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:fix/116-table-sort-resets-on-filter-change

Conversation

@greatest0fallt1me

@greatest0fallt1me greatest0fallt1me commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Note on scope

`useTransactions()` (`lib/hooks/useTransactions.ts`) already existed but had no UI consumer to reproduce this bug against. Built the table with the fix baked in from the start, rather than skip the issue.

Summary

A transaction table's sort and filter are easy to accidentally couple -- e.g. keying the table on the active filter, or resetting sort state in a `useEffect` triggered by the filter -- which resets whatever sort order the user picked the moment they change the filter.

Change

`components/TransactionsTable.tsx`: sort state (`sortKey`/`sortDirection`) and filter state (`typeFilter`) are two independent `useState` calls. The visible rows are derived by filtering then sorting in one `useMemo`, with no coupling between the two -- filtering never touches sort state.

Tests

`components/TransactionsTable.test.tsx`: default sort, sort-direction toggle, filter-by-type, and the regression case for #116 -- sort by amount ascending, then change the filter, and assert both the row order and the header's `aria-sort` still reflect the amount-ascending sort (not the date-descending default it would fall back to if sort had reset).

`npx vitest run components/TransactionsTable.test.tsx`: 4 passed. `npx tsc --noEmit` / `npx eslint` on changed files: clean.

Related to #116

useTransactions() had no UI consumer. Add TransactionsTable: sort
state (sortKey/sortDirection) and filter state (typeFilter) are two
independent useState calls, deliberately not coupled to each other,
so changing the type filter never resets the sort a user already
chose -- the bug class this guards against is deriving the visible
rows in a way that re-keys or resets sort state whenever the filtered
set changes.
@Baskarayelu
Baskarayelu merged commit 2aed725 into QuickLendX:main Aug 28, 2026
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