Align Recheck button with balance inputs; add table sort/filter/search

- Recheck Balance now lines up with the balance input fields on wide
  viewports via an invisible label-height spacer, instead of the row's
  top edge.
- Each transaction column gets its own up/down sort arrows, plus a
  filter row beneath the header (Description doubles as search, Status
  is a dropdown of values actually present). Sorting/filtering never
  disturbs row identity - edits and flags still target the original
  index, not the displayed position.
This commit is contained in:
JasonFraser 2026-10-12 07:53:36 -04:00
parent 37fdd0f235
commit 12e18ae235
4 changed files with 208 additions and 14 deletions

View File

@ -616,7 +616,33 @@ restructure; the behavior itself predates it and is unchanged:
"not_available" (its detail — "No opening and/or closing balance available..." — already
reads as a complete sentence) — both outcomes used to leave the readout silently grey with
no explanation; "not_available"'s case was only noticed and fixed 2026-10-12, after "fail"
already had it.
already had it. On wide viewports the button is wrapped in `.recheck-wrap` with an
invisible `.recheck-spacer` label above it mirroring `.fields label`'s own box (same
font-size/margin-bottom) — this is what lines the button's top edge up with the balance
inputs' own top edge rather than the row's labels, without a hardcoded pixel offset that
would drift if the label style ever changes. The spacer is hidden at the 640px mobile
breakpoint, where the button drops below the fields instead (see above).
- Sort + filter/search on the transactions table (`TransactionsTable.vue` +
`useTransactionFilters.js`, added 2026-10-12) — purely client-side display state, no
backend involvement, same scope as `useImageZoom.js`. Each sortable header (Date,
Description, Amount, Balance, Status) gets its own up/down arrow pair
(`.sort-arrows`/`.sort-arrow`) rather than one toggle arrow, so both directions stay
visible; the active column+direction turns blue. A second `<tr class="filter-row">`
sits inside `<thead>`, directly beneath the header row (so it inherits the same
`colgroup` widths via `table-layout:fixed`) — free-text filter inputs per column
(Description's doubles as the search box), Status as an exact-match `<select>`
populated from whatever statuses are actually present (never offers one the statement
doesn't have), and a small × button in the corner cell to clear every filter at once
(only rendered while a filter is active). Filtering to zero rows shows a
"No transactions match the current filters" row instead of an empty table.
**The one thing that had to be gotten right:** `TransactionRow`/`useRowEditing` read and
write `currentResult.transactions` by its own ORIGINAL index, not by position in
whatever's currently displayed — so `visibleRows` is a list of `{index, transaction}`
pairs (original index preserved through both the filter and the sort), never a plain
re-ordered array, or editing/flagging would silently target the wrong row the moment a
sort or filter was active. Confirmed correct by executing the real composable directly
(not just reading it): sorted/filtered a 3-row fixture several ways and checked the
original index stayed attached to the right transaction through every case.
- Per-row edit lock (`TransactionRow.vue`/`useRowEditing.js`): cells are read-only until
that row's pencil icon is clicked (pencil rendered in the blue accent color, fixed
2026-10-11 — it was the default muted gray, inconsistent with the Save button's own blue);

View File

@ -75,6 +75,12 @@ h1{ font-family:var(--fd); font-weight:800; font-size:30px; letter-spacing:-.01e
field on narrow viewports - see the mobile breakpoint below. */
.fields-row{ display:flex; align-items:flex-start; gap:16px; margin-bottom:16px; }
.fields-row .fields{ flex:1 1 auto; min-width:0; margin-bottom:0; }
/* .recheck-spacer mirrors .fields label's own box (same font-size/
margin-bottom) invisibly, so the button below it starts at exactly the
same y as the balance inputs - aligned with the closing-balance field,
not the row's top edge (where the labels sit). */
.recheck-wrap{ display:flex; flex-direction:column; flex-shrink:0; }
.recheck-spacer{ font-size:11.5px; line-height:1; margin-bottom:6px; visibility:hidden; }
.btn-recheck{ flex-shrink:0; white-space:nowrap; }
.fields{ display:flex; flex-wrap:wrap; gap:16px; }
.fields > div{ flex:1 1 180px; min-width:160px; }
@ -164,6 +170,36 @@ td.amt, th.amt{ text-align:right; font-family:var(--fm); }
tr.flagged td{ background:rgba(217,119,6,.08); }
tr.flagged td:first-child{ border-left:2px solid var(--amber); }
/* Sort arrows sit inline next to each sortable header's own label - a
muted up/down pair that turns the accent blue for whichever column +
direction is currently active, rather than a single toggle arrow, so
both directions are always visibly available, not just the active one. */
.sort-arrows{ display:inline-flex; flex-direction:column; vertical-align:middle; margin-left:4px; gap:1px; }
.sort-arrow{
background:transparent; border:none; cursor:pointer; padding:0; margin:0; font-size:6px;
line-height:1; color:var(--border-b);
}
.sort-arrow:hover{ color:var(--blue); }
.sort-arrow.active{ color:var(--blue); }
/* Filter row sits directly beneath the header row, one input per column
(Description's doubles as a free-text search) - same colgroup widths
apply automatically since the table is table-layout:fixed. */
.filter-row th{ padding:6px 8px 10px; text-transform:none; font-weight:400; }
.filter-input{
width:100%; padding:5px 7px; background:var(--navy); border:1px solid var(--border-2);
border-radius:6px; font-size:11.5px; color:var(--t1); font-family:var(--fb); outline:none;
transition:border-color .2s;
}
.filter-input:focus{ border-color:var(--blue); }
.filter-select{ cursor:pointer; }
.clear-filters-btn{
background:transparent; border:none; cursor:pointer; color:var(--t4); font-size:12px;
padding:4px; line-height:1; border-radius:5px;
}
.clear-filters-btn:hover{ color:var(--red); background:rgba(16,24,40,.06); }
.no-rows-note{ text-align:center; color:var(--t4); padding:20px 10px; white-space:normal; }
.cell-input{
width:100%; background:transparent; border:1px solid transparent; border-radius:5px;
padding:6px 6px; font:inherit; color:inherit; text-align:inherit; font-family:inherit;
@ -321,5 +357,6 @@ tr.editing td{ background:rgba(37,99,235,.03); }
by side, so this is its own, narrower cutoff. */
@media (max-width: 640px){
.fields-row{ flex-direction:column; align-items:stretch; }
.recheck-spacer{ display:none; }
.btn-recheck{ align-self:flex-end; }
}

View File

@ -24,12 +24,16 @@ import { useExtractionStore } from '../stores/extractionStore'
import { useUiStore } from '../stores/uiStore'
import { fmtMoney } from '../services/formatService'
import * as extractionService from '../services/extractionService'
import { useTransactionFilters } from '../composables/useTransactionFilters'
import TransactionRow from './TransactionRow.vue'
const extractionStore = useExtractionStore()
const uiStore = useUiStore()
const result = computed(() => extractionStore.currentResult)
const transactions = computed(() => result.value?.transactions || [])
const { sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows } =
useTransactionFilters(transactions)
const balanceCheck = computed(() => result.value?.checks?.find((c) => c.name === 'statement_balance'))
const balanceMatches = computed(() => balanceCheck.value?.outcome === 'pass')
@ -111,9 +115,12 @@ async function handleRecheck() {
<div class="calc-readout" :class="{ match: balanceMatches }">{{ closingCalcText }}</div>
</div>
</div>
<button class="btn-toggle btn-recheck" type="button" :disabled="!result || rechecking" @click="handleRecheck">
{{ rechecking ? 'Checking…' : 'Recheck Balance' }}
</button>
<div class="recheck-wrap">
<label class="recheck-spacer">&nbsp;</label>
<button class="btn-toggle btn-recheck" type="button" :disabled="!result || rechecking" @click="handleRecheck">
{{ rechecking ? 'Checking…' : 'Recheck Balance' }}
</button>
</div>
</div>
<div v-if="balanceMismatchText" class="error-note visible">{{ balanceMismatchPrefix }}{{ balanceMismatchText }}</div>
<div class="note">This statement format may not print a clean opening/closing balance — enter them here to run the full statement balance check; otherwise it's marked "not available" rather than guessed.</div>
@ -135,20 +142,68 @@ async function handleRecheck() {
<thead>
<tr>
<th></th>
<th>Date</th>
<th>Description</th>
<th class="amt">Amount</th>
<th class="amt">Balance</th>
<th>Status</th>
<th>
Date
<span class="sort-arrows">
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'date' && sortDir === 'asc' }" title="Sort by date, oldest first" @click="setSort('date', 'asc')">&#9650;</button>
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'date' && sortDir === 'desc' }" title="Sort by date, newest first" @click="setSort('date', 'desc')">&#9660;</button>
</span>
</th>
<th>
Description
<span class="sort-arrows">
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'description' && sortDir === 'asc' }" title="Sort A-Z" @click="setSort('description', 'asc')">&#9650;</button>
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'description' && sortDir === 'desc' }" title="Sort Z-A" @click="setSort('description', 'desc')">&#9660;</button>
</span>
</th>
<th class="amt">
Amount
<span class="sort-arrows">
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'amount' && sortDir === 'asc' }" title="Sort lowest first" @click="setSort('amount', 'asc')">&#9650;</button>
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'amount' && sortDir === 'desc' }" title="Sort highest first" @click="setSort('amount', 'desc')">&#9660;</button>
</span>
</th>
<th class="amt">
Balance
<span class="sort-arrows">
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'balance' && sortDir === 'asc' }" title="Sort lowest first" @click="setSort('balance', 'asc')">&#9650;</button>
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'balance' && sortDir === 'desc' }" title="Sort highest first" @click="setSort('balance', 'desc')">&#9660;</button>
</span>
</th>
<th>
Status
<span class="sort-arrows">
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'status' && sortDir === 'asc' }" title="Sort A-Z" @click="setSort('status', 'asc')">&#9650;</button>
<button type="button" class="sort-arrow" :class="{ active: sortKey === 'status' && sortDir === 'desc' }" title="Sort Z-A" @click="setSort('status', 'desc')">&#9660;</button>
</span>
</th>
</tr>
<tr class="filter-row">
<th class="row-actions">
<button v-if="hasActiveFilters" type="button" class="clear-filters-btn" title="Clear all filters" @click="clearFilters">&#10005;</button>
</th>
<th><input v-model="filters.date" type="text" class="filter-input" placeholder="Filter…"></th>
<th><input v-model="filters.description" type="text" class="filter-input" placeholder="Search description…"></th>
<th class="amt"><input v-model="filters.amount" type="text" class="filter-input" placeholder="Filter…"></th>
<th class="amt"><input v-model="filters.balance" type="text" class="filter-input" placeholder="Filter…"></th>
<th>
<select v-model="filters.status" class="filter-input filter-select">
<option value="">All</option>
<option v-for="s in statusOptions" :key="s" :value="s">{{ s }}</option>
</select>
</th>
</tr>
</thead>
<tbody>
<tr v-if="visibleRows.length === 0">
<td colspan="6" class="no-rows-note">No transactions match the current filters.</td>
</tr>
<TransactionRow
v-for="(t, i) in result.transactions"
:key="i"
:index="i"
:transaction="t"
:is-flagged="extractionStore.flaggedIndexes.has(i)"
v-for="entry in visibleRows"
:key="entry.index"
:index="entry.index"
:transaction="entry.transaction"
:is-flagged="extractionStore.flaggedIndexes.has(entry.index)"
/>
</tbody>
</table>

View File

@ -0,0 +1,76 @@
/**
* Client-side sort + per-column filter/search over the transactions table.
* Pure UI state, no service calls - mirrors useImageZoom.js's own scope.
*
* Operates on {index, transaction} pairs rather than the transaction list
* directly, and always returns the ORIGINAL index (position in
* currentResult.transactions) alongside each visible row - TransactionRow
* reads/writes the store by that index, so sorting or filtering the
* DISPLAY order must never change which index a row actually points to.
*/
import { ref, computed } from 'vue'
const FILTERABLE_FIELDS = ['date', 'description', 'amount', 'balance', 'status']
function compareValues(a, b, key) {
if (key === 'amount' || key === 'balance') {
return (a ?? 0) - (b ?? 0)
}
if (key === 'date') {
const at = Date.parse(a)
const bt = Date.parse(b)
if (!Number.isNaN(at) && !Number.isNaN(bt)) return at - bt
}
return String(a ?? '').localeCompare(String(b ?? ''))
}
export function useTransactionFilters(transactionsRef) {
const sortKey = ref(null)
const sortDir = ref('asc')
const filters = ref({ date: '', description: '', amount: '', balance: '', status: '' })
function setSort(key, dir) {
sortKey.value = key
sortDir.value = dir
}
function clearFilters() {
filters.value = { date: '', description: '', amount: '', balance: '', status: '' }
}
const hasActiveFilters = computed(() => Object.values(filters.value).some((v) => v !== ''))
// Status is filtered via an exact-match dropdown (a small enum), not free
// text like the other columns - populated from whatever values are
// actually present, so it never offers a status this statement doesn't have.
const statusOptions = computed(() => {
const seen = new Set()
for (const t of transactionsRef.value || []) {
if (t.status) seen.add(t.status)
}
return [...seen].sort()
})
const visibleRows = computed(() => {
let rows = (transactionsRef.value || []).map((transaction, index) => ({ transaction, index }))
rows = rows.filter(({ transaction }) =>
FILTERABLE_FIELDS.every((key) => {
const filterValue = filters.value[key]
if (!filterValue) return true
if (key === 'status') return transaction.status === filterValue
return String(transaction[key] ?? '').toLowerCase().includes(filterValue.toLowerCase())
}),
)
if (sortKey.value) {
const dir = sortDir.value === 'asc' ? 1 : -1
const key = sortKey.value
rows = [...rows].sort((a, b) => compareValues(a.transaction[key], b.transaction[key], key) * dir)
}
return rows
})
return { sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows }
}