Skip to content

fix(wallet,ui): keep one implementation of the transaction column filter - #232

Merged
argszero merged 1 commit into
mainfrom
fix/tx-column-filter-single-implementation
Sep 14, 2026
Merged

argszero merged 1 commit into
mainfrom
fix/tx-column-filter-single-implementation

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

The transactions table filtered its columns twice: txFilterParams() sends what the user typed to the server (tx_where -> model LIKE ?, with the parameter trimmed on the way out), and buildDataTable then re-filtered the very rows the server had already filtered, locally, with filterRows(list, TX_COLUMNS, txTable.filters).

The two implementations do not agree, and the local one wins, so a filter the server satisfied can end up showing nothing:

typed into the 模型 filter server returns table shows count
deepseek 1 row 1 row 1
deepseek (trailing space) 1 row (wire trims) 0 rows (local compares the raw string) 1
qwen (leading space) 1 row 0 rows 1
(blank) 5 rows (wire treats it as "no filter") 5 rows 5
% 5 rows (LIKE '%' matches everything) 0 rows (local literal %) 5

The same duplicated pass also ran inside the CSV export, so 导出 CSV produced a file with 0 data rows while the server had returned 5 for the filter in force.

Related Issue

Not applicable - self-discovered defect, no issue exists in the tracker (none fabricated).

Changes

  • ui/js/app.js: every TX_COLUMNS column that carries a filter now declares serverFilter: true (6 columns: type / user / model / key / pts / status), and filterRows skips those columns. That single change makes the duplicated pass a no-op at all three of its consumers - renderTxSummary, the table row count and exportTxCsv - so the rows the server returned are the rows on screen and in the file.
  • The invariant is written down where the declarations are (TX_COLUMNS, filterRows) and in ui/README.md, so a new filterable column must declare serverFilter or the local second implementation comes back.
  • ui/index.html: app.js?v=20260914-8 -> -9 (cache bust).
  • src/routes/wallet.rs: a new test pins the server-side rule the front end now relies on alone - tx_text_column_filters_trim_the_value_before_matching.
  • No config / data-structure change (nothing to sync with the example config).

No ledger, balance or settlement code is touched - this is the display / filter surface only.

Tests

  • cargo test - 239 passed, 0 failed (was 238; the new test is the +1).
  • cargo fmt --check - clean.
  • cargo clippy --all-targets -- -D warnings - clean.
  • New tests added: tx_text_column_filters_trim_the_value_before_matching asserts that a trailing space is equivalent to no space, that a blank value means "do not filter" (3 rows, not 0), that % behaves as a LIKE wildcard (3 rows), and carries a negative control (model=zzz -> 0 rows) so that a degenerate "never filter" implementation cannot pass.

Front-end instrument (jsdom, real ui/index.html + the four real scripts; only fetch and the download are stubbed)

15 checks: A0 built-in control (every fixture row renders), P0 a control on the wire rule itself, A1 the plain path (control), B1-B4 the axis (padded value / leading space / blank / LIKE wildcard), C1 the wire carries the trimmed value, E1 a genuinely non-matching value still yields 0 rows, D1 the exported CSV contains the rows the server returned for the filter in force.

leg md5 of ui/js/app.js passed red set
v0_orig (pre-fix, dfa7318) 58ce4a47ba5092e507b6659cbeb1461f 6/15 {B1a B1b B2a B2b B3a B3b B4a B4b D1}
m_trim (keep the duplicate, trim its value - the plausible half fix) 879407d8d3a7e693df4223680dd43188 13/15 {B4a B4b}
m_notrim (delete the wire normalisation instead - the wrong direction) bba9d6c505deb29688287115c88f131e 4/15 {B1a B1b B2a B2b B3a B3b B4a B4b C1 D1 P0}
live (this tree) 9f606a23367f95bf243662a474a8fe56 15/15 {}

The pre-change tree is rejected with exactly the frozen red set; m_trim shows that normalising the duplicate fixes the whitespace face but not the wildcard face (so "make the copies agree" is not the fix); m_notrim shows the mirror-image repair is rejected too, and it also trips the wire-rule control (C1/P0) - i.e. the instrument pins the correct direction, not merely "behaviour changed". Recorded honestly: m_trim ⊂ v0_orig, and m_notrim's red set strictly contains the baseline's.

Checklist

  • Branch name follows the convention: fix/tx-column-filter-single-implementation.
  • Commit message uses Conventional Commits.
  • Single responsibility, minimal change: 4 files, +79/-11, no config / schema / i18n key change, no new dependency.

The transactions table filtered its columns twice: `txFilterParams()` sends the
typed value to the server (`tx_where` -> `model LIKE ?`, a trimmed parameter),
and `buildDataTable` then re-filtered the very rows the server had already
filtered, locally, with `filterRows(list, TX_COLUMNS, txTable.filters)`. The two
implementations do not agree, so rows the server accepted could be dropped by
the local pass:

* text columns: the wire `trim()`s the value, the local predicate compares the
  raw string - typing `"deepseek "` (trailing space) matches on the server and
  then disappears from the table;
* the LIKE wildcard: typing `%` returns every row from the server, while the
  local literal comparison keeps none (measured: server=5, table=0, count=5);
* `exportTxCsv` re-ran that same local filter, so the CSV exported 0 rows for a
  filter the server had satisfied.

Fix - one implementation: every `TX_COLUMNS` column that carries a `filter`
declares `serverFilter: true` (6 columns) and `filterRows` skips those columns.
That makes the duplicated pass a no-op at all three of its consumers
(`renderTxSummary`, the table row count, `exportTxCsv`) without touching the
server contract. The invariant is written next to the declarations and in
`ui/README.md`, so a new filterable column must declare it or the second
implementation returns.

The server side's rule - which the front end now relies on alone - is pinned by
a new Rust test (`tx_text_column_filters_trim_the_value_before_matching`):
a trailing space is equivalent to no space, a blank value means "do not
filter", and `%` is a LIKE wildcard, with a negative control so that a
degenerate "never filter" cannot pass.
@argszero
argszero merged commit e7bfc6f into main Sep 14, 2026
1 check passed
@argszero
argszero deleted the fix/tx-column-filter-single-implementation branch September 14, 2026 01:09
argszero added a commit that referenced this pull request Sep 22, 2026
)

The transactions table's column headers carry a sort arrow, and that arrow
is a claim about the WHOLE dataset: the pager below it counts the backend's
`total` (30 rows, "1 2 3 / 3 · 30 rows") and the summary card above it is a
backend aggregate. The ordering, however, only ever applied to the page in
hand.

`#135` turned the list into a server-paged table (`serverPaging` = backend
total, one page of rows per request, `LIMIT/OFFSET` over
`ORDER BY t.id DESC`), while sorting stayed where it was born in the static
prototype (`#7`, `d70e032`): client-side, over whatever rows the caller
passed in --

    if (state.sort.length) { data = data.slice().sort(...) }
    const pageRows = serverPaging ? data : data.slice(...)

a page. So clicking "Points" ▲ reordered the ten rows on screen and painted
▲, while the row that actually holds the minimum sat on page 2/3 and was
never fetched; the request never changed. The column FILTERS travelled the
other half of that road long ago (`#232` `e7bfc6f` / C2114: "local filter of
the current page" -> "backend full-dataset filter"); the sort half never did.

Fix: one claim, three carriers, and a server that renders `ORDER BY` from a
whitelist.

  * `ui/js/app.js` — `txSortParams()` projects the single sort state
    (`txTable.sort`) into the LIST request only (the trend endpoint buckets
    by time; row order means nothing to it). `txQuerySig()` now covers the
    sort, so the reload guard refetches when a header is clicked -- without
    that line the arrow would move over a list that does not, which is worse
    than the defect being fixed. The local sort steps aside when the call
    site declares `serverSort`: `if (state.sort.length && !(serverPaging &&
    serverSort))`.
  * `src/routes/wallet.rs` — `TX_SORT_KEYS` (11 keys, exactly the sortable
    columns of `TX_COLUMNS`) + `tx_sort_expr()` + `tx_order_by()`. The user
    string never reaches SQL; the `ORDER BY` fragment is rendered from the
    whitelist, always with a trailing `, t.id DESC` (a non-unique sort makes
    `LIMIT/OFFSET` page boundaries indeterminate -- one row twice, another
    never), and an unknown key / mismatched key-direction count / bad
    direction is a 400. Validation runs before the DB lock, as `type` does.
    Expressions match what the cell shows (`pts` via `signed_pts_expr`, the
    four token columns on their raw values, `model`/`key` byte-identical to
    the filter expressions).

Tests:

  * `state_gate::the_sort_indicator_and_the_order_by_share_one_source` —
    four rules, each with its own mutant leg, plus a
    `the_r164_rules_have_teeth` self-proof over self-contained mini sources
    and a `the_r164_roster_is_real` positive control. Roster == whitelist ==
    match arms, `q.sort`/`q.dir` bound in exactly one place, the guard reads
    the WHOLE condition (a `[^)]*` reader cannot see `!(a && b)`) and a
    control rule keeps the filter half of the same road honest.
  * `src/routes/wallet.rs` — three behaviour tests: the whole set is ordered
    (not the page), ties are stable across pages, and anything outside the
    whitelist is rejected.
  * jsdom probe (7 legs, both directions): on the pre-fix tree the two
    global-extremum legs and the "did the request carry sort" leg fail; on
    the landed bytes all seven pass. The two competing "fixes" (keep sorting
    the page and caption the arrow " (this page)"; stop painting the arrow)
    are rejected by the same legs.

Scope, stated honestly: the gate is lexical -- it proves the three carriers
agree and that the whitelist IS the column roster; it does not prove that
the rows on screen are globally ordered (that is the jsdom probe's job, and
there is no JS runner in `cargo test`), nor the `ORDER BY` semantics
themselves (those are the wallet behaviour tests). Recorded in
`ui/README.md`.
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.

1 participant