Add plain-language flags, source highlighting, and flag navigation (R.2)
The piece that gives R.1's highlighting infrastructure something to do, and the first genuinely new review-screen UI (R.1 was all plumbing - same page, same components, just a different PDF renderer underneath). New flagCatalogService.js translates each check's own raw mismatch/ issue data into a four-part plain-language flag (what/where/why/what to do). Only running_balance/date_sanity/structure_sanity/ narrative_direction ever carry row-level data - the other three checks are whole-statement, confirmed by reading checks_service.py directly. date_sanity/structure_sanity return a free-text issue string, not a structured type - pattern-matched against the backend's own known message shapes, with a fallback that always shows the raw text rather than silently dropping it if that text ever changes. TransactionRow.vue gained a flag-icon toggle opening a second <tr> with every flag's own explanation (Vue 3 supports multi-root components, so this is a real sibling row, not a wrapped div that would break the table's HTML) and a "Show on source" button. The real design question: how does a flagged row (deep inside TransactionsTable) tell the source panel (a sibling three levels up, no direct prop/event path) to highlight itself? Solved with uiStore.highlightRequest as the bridge - TransactionRow sets it, ExtractorView (which holds the actual ref to SourceDocumentPanel) watches it and calls the panel's own showHighlight(), built in R.1 but unused until now. SourceDocumentPanel also clears both the request and its own highlight state whenever the active document changes, so a stale box never lingers over a different document. useTransactionFilters.js gained a flaggedOnly toggle; TransactionsTable added "Flagged only"/"Next flagged" buttons (shown only when something is actually flagged) - the latter cycles through flagged rows via scrollIntoView on each row's own id, wrapping after the last. Verified: flagsForIndex executed directly against real backend output (a live /api/process call against the HSBC-Aug fixture, which has a real documented running_balance mismatch) plus synthetic data covering every builder's own branches, including two checks flagging the same row and confirming whole-statement checks never contribute a row flag. npm run build passes, the app container rebuilt, measure.py unaffected (pure frontend presentation, no backend touched). Not machine-verified: the actual click-through - Claude-in-Chrome did not connect this session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
deee78a6c1
commit
65fa93bb28
87
CLAUDE.md
87
CLAUDE.md
|
|
@ -30,7 +30,7 @@ to rough effort:
|
|||
| Phase | Contains | Status here |
|
||||
|---|---|---|
|
||||
| **1** | Extraction + 6 checks + Excel export, dual-engine, measurement harness | **In progress — see gaps below** |
|
||||
| 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — review screen **in progress, staged R.1-R.5** (see "Review screen" under Key decisions & lessons) — R.1's backend half (per-row source-position capture) shipped 2026-10-13; the pdf.js highlighting viewer, R.2's plain-language flags, and R.3's suggested-fix engine are not started yet |
|
||||
| 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — review screen **in progress, staged R.1-R.5** (see "Review screen"/"R.2" under Key decisions & lessons) — R.1 (source-position capture + the pdf.js highlighting viewer) and R.2 (plain-language flags + jump-to-flagged navigation) both shipped 2026-10-13; R.3's suggested-fix engine, R.4's structural row edits, and R.5's accept/acknowledge + edit log are not started yet |
|
||||
| 3 | Layout mapper (fingerprinting, versioning, drift detection) | Not started |
|
||||
| 4 | Multi-tenant practice/client accounts, Frappe data model | Not started |
|
||||
| 5 | Free front door, public accuracy page | Not started |
|
||||
|
|
@ -347,6 +347,13 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
`pdfColHidden`). `restoreBannerVisible` etc. were removed
|
||||
along with `RestoreBanner.vue` in Stage B.2 - see
|
||||
"PocketBase Stage B.2" under Key decisions & lessons.
|
||||
`highlightRequest`/`requestHighlight()`/
|
||||
`clearHighlightRequest()` (NEW 2026-10-13, review screen
|
||||
R.2) - the bridge between `TransactionRow`'s "Show on
|
||||
source" and `SourceDocumentPanel`'s exposed
|
||||
`showHighlight()`, siblings three levels apart with no
|
||||
direct prop/event path between them - see "R.2" under Key
|
||||
decisions & lessons.
|
||||
authStore.js — `user` (mirrors `pb.authStore.record`),
|
||||
`isAuthenticated` getter, `syncWithAuthStore()` (registered
|
||||
once in `App.vue`'s `onMounted`, keeps the store in sync
|
||||
|
|
@ -383,7 +390,13 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
were removed outright in Stage B.2, replaced by
|
||||
documentsService.js below). formatService.js
|
||||
(fmtMoney/fmtNum/parseNum - escapeHtml dropped, redundant
|
||||
once Vue's own {{ }} auto-escapes). authService.js (login/
|
||||
once Vue's own {{ }} auto-escapes). flagCatalogService.js
|
||||
(NEW 2026-10-13, review screen R.2 - translates each
|
||||
check's raw mismatch/issue data into the spec's
|
||||
four-part plain-language flag; only
|
||||
running_balance/date_sanity/structure_sanity/
|
||||
narrative_direction ever carry row-level data, see
|
||||
"R.2" under Key decisions & lessons). authService.js (login/
|
||||
signup/loginWithGoogle/logout, thin wrappers over the
|
||||
PocketBase SDK — the SDK itself persists/restores the auth
|
||||
token). documentsService.js (`saveDocument`/
|
||||
|
|
@ -451,7 +464,8 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
via pdf.js/usePdfViewer as of 2026-10-13, not the browser's
|
||||
native `<iframe>` — see "Review screen" under Key decisions
|
||||
& lessons; exposes `showHighlight`/`clearHighlight` for the
|
||||
review screen, not called from anywhere yet), TransactionsTable
|
||||
review screen, called via `ExtractorView.vue`'s own watch
|
||||
on `uiStore.highlightRequest` as of R.2), TransactionsTable
|
||||
(now also hosts its own top bar — a Results dropdown,
|
||||
DocumentNavBar, and the Download button; this is
|
||||
ResultCard.vue's old content, merged in and that file
|
||||
|
|
@ -1563,6 +1577,65 @@ showed) at every step. `npm run build` passes; the `app` container rebuilt;
|
|||
sidebar UI reflecting a live update without a manual collapse/re-expand -
|
||||
Claude-in-Chrome still did not connect this session.
|
||||
|
||||
**R.2 — plain-language flags + navigation, shipped 2026-10-13.** The piece that
|
||||
actually gives R.1's highlighting infrastructure something to do, and the first
|
||||
genuinely new review-screen UI surface (R.1 was all plumbing - same page, same
|
||||
components, just a different PDF renderer underneath).
|
||||
|
||||
New `flagCatalogService.js` translates each check's own raw mismatch/issue data into
|
||||
the spec's four-part plain-language flag (what/where/why/what-to-do,
|
||||
`docs/bankstatement.md` §5.1). Only `running_balance`/`date_sanity`/
|
||||
`structure_sanity`/`narrative_direction` ever carry row-level data - confirmed by
|
||||
reading `checks_service.py` directly: `statement_balance`/`page_coverage`/
|
||||
`engine_agreement`/`ocr_source` are whole-statement checks with no per-row
|
||||
mismatches/issues key at all, so a transaction flagged only via one of those (e.g. an
|
||||
OCR-sourced statement) has nothing to show here, correctly. `date_sanity`/
|
||||
`structure_sanity` return a free-text `issue` string, not a structured type -
|
||||
pattern-matched against the backend's own known message shapes, with a fallback that
|
||||
always shows the raw text rather than ever silently dropping it if that text changes.
|
||||
|
||||
`TransactionRow.vue` gained a flag-icon toggle (the `row-actions` cell widened
|
||||
34px→54px to fit it alongside edit/save/cancel) opening a second `<tr>` with every
|
||||
flag's own explanation - Vue 3 components can have multiple root nodes, so this is a
|
||||
genuine sibling table row, not a wrapped `<div>` that would make the table invalid
|
||||
HTML. A row can carry more than one flag (e.g. a bad date AND a broken running
|
||||
balance) - each shown as its own block, not just the first one found.
|
||||
|
||||
**The real architectural question R.2 had to answer: how does a flagged row (deep
|
||||
inside `TransactionsTable`) tell the source panel (`SourceDocumentPanel`, a sibling
|
||||
three levels up, not an ancestor/descendant) to highlight itself?** No direct prop or
|
||||
event path exists between them. Solved with `uiStore.highlightRequest`
|
||||
(`{page, bbox} | null`) as the bridge - `TransactionRow`'s "Show on source" button sets
|
||||
it; `ExtractorView.vue`, the one place that holds an actual `ref` to
|
||||
`SourceDocumentPanel`, watches it and calls the panel's own exposed
|
||||
`showHighlight(page, bbox)` (built in R.1, unused until now).
|
||||
`SourceDocumentPanel.vue` also now clears both the request and its own highlight state
|
||||
whenever the active document changes, so a stale highlight box from a PREVIOUS
|
||||
document can never linger visually over a newly-opened one.
|
||||
|
||||
`useTransactionFilters.js` gained a `flaggedOnly` toggle (a second, optional
|
||||
`flaggedIndexesRef` argument - `clearFilters` resets it too, `hasActiveFilters`
|
||||
includes it) and `TransactionsTable.vue` added "Flagged only"/"Next flagged" buttons,
|
||||
shown only when at least one row is actually flagged. "Next flagged" cycles ascending
|
||||
through flagged indices (wrapping back to the first after the last) via
|
||||
`scrollIntoView` on each row's own `id="txn-row-{index}"` - simpler and more robust
|
||||
than threading DOM refs for every row up through the parent, which a ref-per-row map
|
||||
would have needed instead.
|
||||
|
||||
Verified: `flagsForIndex` executed directly (not re-implemented) against REAL backend
|
||||
output - a live `/api/process` call against the HSBC-Aug fixture, which has a real,
|
||||
already-documented `running_balance` mismatch - confirming the real evidence text reads
|
||||
correctly (`"Expected the balance to be $1,280,218.25 here, but the statement shows
|
||||
$1,257,832.25."`), plus synthetic multi-check data exercising every one of the four
|
||||
builders' own branches, including two different checks flagging the SAME row (both
|
||||
shown, not just one) and confirming the whole-statement checks never contribute a row
|
||||
flag. `npm run build` passes; the built bundle confirmed to contain the new UI strings;
|
||||
the `app` container rebuilt; `measure.py` unaffected (no backend touched - this is
|
||||
pure frontend presentation over data the backend already returns). Not
|
||||
machine-verified: the actual click-through - the flag toggle, the highlight box
|
||||
appearing on the right row/page, "Flagged only"/"Next flagged" behaving correctly -
|
||||
Claude-in-Chrome still did not connect this session.
|
||||
|
||||
**Governing rule: never silently correct or exclude data.** This shows up in several
|
||||
concrete places, not just as an abstract principle:
|
||||
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is
|
||||
|
|
@ -1931,6 +2004,14 @@ restructure; the behavior itself predates it and is unchanged:
|
|||
nothing re-measured the textarea height when that happened (only an actual edit/save
|
||||
did) — now `uiStore.layoutVersion` bumps on that toggle (and on a resize-drag ending) and
|
||||
every row's own textarea watches it to re-measure.
|
||||
- A flagged row (added 2026-10-13, review screen R.2) gets its own amber flag-icon
|
||||
toggle in the row-actions cell, opening a second table row beneath it with a
|
||||
plain-language explanation for every check that flagged it (what/why/what-to-do -
|
||||
`flagCatalogService.js`) and a "Show on source" button that boxes the row's own
|
||||
printed position on the source document (disabled when no position data exists for
|
||||
that row - see R.1's `source_bbox`). `TransactionsTable.vue`'s own header gets
|
||||
"Flagged only" (filters the table to just flagged rows) and "Next flagged" (cycles
|
||||
through flagged rows, scrolling each into view) once anything is actually flagged.
|
||||
- All numeric displays are comma-formatted (`formatService.js`'s `fmtMoney`/`fmtNum`).
|
||||
- Edits persist to PocketBase (`documentsService.js`'s `saveDocument`/`updateDocument` -
|
||||
as of 2026-10-13, replacing the earlier localStorage-only version entirely, not
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ tr.editing .cell-input:not(:read-only):focus{ outline:none; border-color:var(--b
|
|||
}
|
||||
td.amt .cell-input{ text-align:right; font-family:var(--fm); }
|
||||
|
||||
.row-actions{ width:34px; padding:3px 0 3px 4px !important; }
|
||||
.row-actions{ width:54px; padding:3px 0 3px 4px !important; white-space:nowrap; }
|
||||
.row-btn{
|
||||
background:transparent; border:none; cursor:pointer; padding:4px; border-radius:5px;
|
||||
font-size:13px; line-height:1; color:var(--t4); transition:color .15s, background .15s;
|
||||
|
|
@ -250,8 +250,24 @@ td.amt .cell-input{ text-align:right; font-family:var(--fm); }
|
|||
.row-btn.edit{ color:var(--blue); }
|
||||
.row-btn.save{ color:var(--blue); }
|
||||
.row-btn.cancel{ color:var(--t4); }
|
||||
.row-btn.flag-toggle{ color:var(--amber); }
|
||||
.row-btn.flag-toggle.active{ color:var(--navy-2); background:var(--amber); }
|
||||
.row-btn.flag-toggle.active:hover{ background:var(--amber); color:var(--navy-2); }
|
||||
tr.editing td{ background:rgba(37,99,235,.03); }
|
||||
|
||||
/* The review screen's plain-language flag explanation - a second <tr>
|
||||
TransactionRow.vue renders beneath the flagged row itself when its own
|
||||
flag-toggle is active (Vue 3 components can have multiple root nodes,
|
||||
so this is a real sibling <tr>, not a wrapped div - keeps the table
|
||||
itself valid HTML). */
|
||||
.flag-detail-row td{ background:rgba(217,119,6,.06); padding:12px 14px; border-bottom:1px solid var(--border); }
|
||||
.flag-detail{ margin-bottom:10px; font-size:12.5px; line-height:1.6; color:var(--t2); white-space:normal; }
|
||||
.flag-detail:last-of-type{ margin-bottom:12px; }
|
||||
.flag-detail-part{ margin-bottom:2px; }
|
||||
.flag-detail-part strong{ color:var(--t1); font-family:var(--fd); }
|
||||
.flag-show-source{ font-size:11.5px; padding:0 12px; height:30px; }
|
||||
.flag-show-source:disabled{ opacity:.4; cursor:not-allowed; }
|
||||
|
||||
/* ── Top bar: Results (left) / DocumentNavBar (center, TRUE center via
|
||||
grid - not flex space-between, which would only center it when the
|
||||
left/right content happens to be equal width) / Download (right).
|
||||
|
|
@ -455,6 +471,9 @@ tr.editing td{ background:rgba(37,99,235,.03); }
|
|||
display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; flex-shrink:0;
|
||||
}
|
||||
.txn-col-head h2{ margin-bottom:0; }
|
||||
.txn-col-head-actions{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
|
||||
.btn-toggle-active{ background:var(--amber); box-shadow:0 2px 10px rgba(217,119,6,.25); }
|
||||
.btn-toggle-active:hover{ background:var(--amber); }
|
||||
.txn-col .fields, .txn-col .note{ flex-shrink:0; }
|
||||
.btn-toggle{
|
||||
display:inline-flex; align-items:center; justify-content:center; gap:7px; height:36px;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,13 @@
|
|||
* reachable before clicking Extract.
|
||||
*
|
||||
* Exposes showHighlight(page, bbox)/clearHighlight() for the review
|
||||
* screen (R.2) to box a flagged transaction's own printed row - routes
|
||||
* to whichever viewer (pdf.js pages or the image panel) is actually
|
||||
* active; not called from anywhere yet (R.1 only builds the capability).
|
||||
* screen to box a flagged transaction's own printed row - routes to
|
||||
* whichever viewer (pdf.js pages or the image panel) is actually active.
|
||||
* Called via ExtractorView.vue's own watch on uiStore.highlightRequest,
|
||||
* which TransactionRow.vue's "Show on source" button sets (see that
|
||||
* store's own comment on why a store bridges this, not a prop/event
|
||||
* chain - TransactionRow and this panel are siblings three levels apart,
|
||||
* not ancestor/descendant).
|
||||
*
|
||||
* Data flow:
|
||||
* previewUrl (string|null) - blob URL for the chosen file
|
||||
|
|
@ -24,6 +28,9 @@
|
|||
import { computed, watch } from 'vue'
|
||||
import { useImageZoom } from '../composables/useImageZoom'
|
||||
import { usePdfViewer } from '../composables/usePdfViewer'
|
||||
import { useUiStore } from '../stores/uiStore'
|
||||
|
||||
const uiStore = useUiStore()
|
||||
|
||||
const props = defineProps({
|
||||
previewUrl: { type: String, default: null },
|
||||
|
|
@ -53,6 +60,12 @@ function resetZoom() { props.isImage ? imgResetZoom() : pdfResetZoom() }
|
|||
watch(
|
||||
() => [props.previewUrl, props.isImage],
|
||||
([url, isImage]) => {
|
||||
// A highlight from the PREVIOUS document has no meaning once the
|
||||
// active document changes (different page numbers, different source
|
||||
// entirely) - clear both the request and whichever viewer's own
|
||||
// highlight state, so a stale box never lingers over a new document.
|
||||
uiStore.clearHighlightRequest()
|
||||
clearHighlight()
|
||||
if (!isImage) loadDocument(url)
|
||||
},
|
||||
{ immediate: true },
|
||||
|
|
|
|||
|
|
@ -5,15 +5,26 @@
|
|||
* One transaction row: read-only by default, editable after its own
|
||||
* pencil is clicked, with Save (commit + recheck) / Cancel (discard).
|
||||
*
|
||||
* A flagged row also gets its own flag-icon toggle, opening a second
|
||||
* row beneath it with the plain-language four-part explanation
|
||||
* (flagCatalogService.js) for every check that flagged THIS row - a row
|
||||
* can carry more than one. "Show on source" there requests a highlight
|
||||
* via uiStore (see that store's own comment on why a store bridges this
|
||||
* rather than a prop/event chain - TransactionRow and
|
||||
* SourceDocumentPanel are siblings three-deep apart, not ancestor/
|
||||
* descendant).
|
||||
*
|
||||
* Data flow:
|
||||
* index (number) - this row's position in currentResult.transactions
|
||||
* transaction (object) - {date, description, amount, balance, status}
|
||||
* transaction (object) - {date, description, amount, balance, status, source_page, source_bbox}
|
||||
* isFlagged (boolean) - whether any check flagged this row
|
||||
*/
|
||||
import { ref, watch, nextTick, onMounted } from 'vue'
|
||||
import { ref, computed, watch, nextTick, onMounted } from 'vue'
|
||||
import { useUiStore } from '../stores/uiStore'
|
||||
import { useExtractionStore } from '../stores/extractionStore'
|
||||
import { useRowEditing } from '../composables/useRowEditing'
|
||||
import { useAutoGrow } from '../composables/useAutoGrow'
|
||||
import { flagsForIndex } from '../services/flagCatalogService'
|
||||
|
||||
const props = defineProps({
|
||||
index: { type: Number, required: true },
|
||||
|
|
@ -22,6 +33,7 @@ const props = defineProps({
|
|||
})
|
||||
|
||||
const uiStore = useUiStore()
|
||||
const extractionStore = useExtractionStore()
|
||||
const { isEditing, wasEdited, draft, startEdit, cancelEdit, saveEdit } = useRowEditing(props.index)
|
||||
const { textareaRef, measure } = useAutoGrow()
|
||||
const firstInputRef = ref(null)
|
||||
|
|
@ -42,11 +54,31 @@ function handleEdit() {
|
|||
measure()
|
||||
})
|
||||
}
|
||||
|
||||
// ── Flag detail (review screen) ─────────────────────────────────────
|
||||
const flags = computed(() => flagsForIndex(extractionStore.currentResult, props.index))
|
||||
const showFlags = ref(false)
|
||||
function toggleFlags() {
|
||||
showFlags.value = !showFlags.value
|
||||
if (!showFlags.value) uiStore.clearHighlightRequest()
|
||||
}
|
||||
function showOnSource() {
|
||||
if (props.transaction.source_bbox) {
|
||||
uiStore.requestHighlight(props.transaction.source_page, props.transaction.source_bbox)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<tr :class="{ flagged: isFlagged, editing: isEditing }">
|
||||
<tr :id="`txn-row-${index}`" :class="{ flagged: isFlagged, editing: isEditing }">
|
||||
<td class="row-actions">
|
||||
<button
|
||||
v-if="isFlagged && flags.length"
|
||||
class="row-btn flag-toggle"
|
||||
:class="{ active: showFlags }"
|
||||
title="Why is this row flagged?"
|
||||
@click="toggleFlags"
|
||||
><i class="fa-solid fa-triangle-exclamation"></i></button>
|
||||
<button v-if="!isEditing" class="row-btn edit" title="Edit this row" @click="handleEdit"><i class="fa-solid fa-pen"></i></button>
|
||||
<template v-else>
|
||||
<button class="row-btn save" title="Save this row" @click="saveEdit"><i class="fa-solid fa-check"></i></button>
|
||||
|
|
@ -97,4 +129,24 @@ function handleEdit() {
|
|||
>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="showFlags && flags.length" class="flag-detail-row">
|
||||
<td colspan="6">
|
||||
<div v-for="(flag, i) in flags" :key="i" class="flag-detail">
|
||||
<div class="flag-detail-part"><strong>What:</strong> {{ flag.what }}</div>
|
||||
<div class="flag-detail-part"><strong>Where:</strong> {{ flag.where }}</div>
|
||||
<div class="flag-detail-part"><strong>Why:</strong> {{ flag.why }}</div>
|
||||
<div class="flag-detail-part"><strong>What to do:</strong> {{ flag.whatToDo }}</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-toggle flag-show-source"
|
||||
:disabled="!transaction.source_bbox"
|
||||
:title="transaction.source_bbox ? 'Highlight this row on the source document' : 'No position data available for this row'"
|
||||
@click="showOnSource"
|
||||
>
|
||||
<i class="fa-solid fa-location-crosshairs"></i>
|
||||
Show on source
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* again by applyCheckResults, while closingCalc's text IS recomputed on
|
||||
* every recheck).
|
||||
*/
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { ref, computed, watch, nextTick } from 'vue'
|
||||
import { useExtractionStore } from '../stores/extractionStore'
|
||||
import { useUiStore } from '../stores/uiStore'
|
||||
import { useProjectsStore } from '../stores/projectsStore'
|
||||
|
|
@ -267,11 +267,30 @@ const closingBalanceInput = computed({
|
|||
get: () => extractionStore.closingBalanceInputDisplay,
|
||||
set: (v) => extractionStore.setClosingBalanceInput(v),
|
||||
})
|
||||
const { sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows } =
|
||||
useTransactionFilters(transactions)
|
||||
const flaggedIndexesRef = computed(() => extractionStore.flaggedIndexes)
|
||||
const {
|
||||
sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows,
|
||||
flaggedOnly, toggleFlaggedOnly,
|
||||
} = useTransactionFilters(transactions, flaggedIndexesRef)
|
||||
const balanceCheck = computed(() => result.value?.checks?.find((c) => c.name === 'statement_balance'))
|
||||
const balanceMatches = computed(() => balanceCheck.value?.outcome === 'pass')
|
||||
|
||||
// ── "Jump to next flagged row" ──────────────────────────────────────
|
||||
// Cycles through flagged rows in ASCENDING index order, wrapping back to
|
||||
// the first after the last - lastJumpedIndex tracks where to resume
|
||||
// from rather than always restarting at the first flagged row.
|
||||
const lastJumpedIndex = ref(null)
|
||||
function jumpToNextFlagged() {
|
||||
const indices = [...extractionStore.flaggedIndexes].sort((a, b) => a - b)
|
||||
if (!indices.length) return
|
||||
const current = lastJumpedIndex.value
|
||||
const next = indices.find((i) => current === null || i > current) ?? indices[0]
|
||||
lastJumpedIndex.value = next
|
||||
nextTick(() => {
|
||||
document.getElementById(`txn-row-${next}`)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
})
|
||||
}
|
||||
|
||||
const openingCalcText = computed(() => {
|
||||
const v = result.value?.opening_balance
|
||||
return v !== null && v !== undefined ? 'Calculated: ' + fmtMoney(v) : ''
|
||||
|
|
@ -397,10 +416,28 @@ async function handleRecheck() {
|
|||
/>
|
||||
<div class="txn-col-head">
|
||||
<h2>Transactions</h2>
|
||||
<button class="btn-toggle" type="button" @click="uiStore.togglePdfCol">
|
||||
<i class="fa-solid" :class="uiStore.pdfColHidden ? 'fa-eye' : 'fa-eye-slash'"></i>
|
||||
{{ toggleLabel }}
|
||||
</button>
|
||||
<div class="txn-col-head-actions">
|
||||
<template v-if="extractionStore.flaggedIndexes.size > 0">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-toggle"
|
||||
:class="{ 'btn-toggle-active': flaggedOnly }"
|
||||
title="Show only flagged rows"
|
||||
@click="toggleFlaggedOnly"
|
||||
>
|
||||
<i class="fa-solid fa-triangle-exclamation"></i>
|
||||
Flagged only
|
||||
</button>
|
||||
<button type="button" class="btn-toggle" title="Jump to the next flagged row" @click="jumpToNextFlagged">
|
||||
<i class="fa-solid fa-forward-step"></i>
|
||||
Next flagged
|
||||
</button>
|
||||
</template>
|
||||
<button class="btn-toggle" type="button" @click="uiStore.togglePdfCol">
|
||||
<i class="fa-solid" :class="uiStore.pdfColHidden ? 'fa-eye' : 'fa-eye-slash'"></i>
|
||||
{{ toggleLabel }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields-row">
|
||||
<div class="fields">
|
||||
|
|
|
|||
|
|
@ -24,21 +24,33 @@ function compareValues(a, b, key) {
|
|||
return String(a ?? '').localeCompare(String(b ?? ''))
|
||||
}
|
||||
|
||||
export function useTransactionFilters(transactionsRef) {
|
||||
/**
|
||||
* flaggedIndexesRef (optional) - extractionStore.flaggedIndexes, passed
|
||||
* so "flagged only" can filter without this composable needing to know
|
||||
* about the store itself (same arm's-length style transactionsRef
|
||||
* already has).
|
||||
*/
|
||||
export function useTransactionFilters(transactionsRef, flaggedIndexesRef) {
|
||||
const sortKey = ref(null)
|
||||
const sortDir = ref('asc')
|
||||
const filters = ref({ date: '', description: '', amount: '', balance: '', status: '' })
|
||||
const flaggedOnly = ref(false)
|
||||
|
||||
function setSort(key, dir) {
|
||||
sortKey.value = key
|
||||
sortDir.value = dir
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
filters.value = { date: '', description: '', amount: '', balance: '', status: '' }
|
||||
function toggleFlaggedOnly() {
|
||||
flaggedOnly.value = !flaggedOnly.value
|
||||
}
|
||||
|
||||
const hasActiveFilters = computed(() => Object.values(filters.value).some((v) => v !== ''))
|
||||
function clearFilters() {
|
||||
filters.value = { date: '', description: '', amount: '', balance: '', status: '' }
|
||||
flaggedOnly.value = false
|
||||
}
|
||||
|
||||
const hasActiveFilters = computed(() => flaggedOnly.value || 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
|
||||
|
|
@ -54,6 +66,10 @@ export function useTransactionFilters(transactionsRef) {
|
|||
const visibleRows = computed(() => {
|
||||
let rows = (transactionsRef.value || []).map((transaction, index) => ({ transaction, index }))
|
||||
|
||||
if (flaggedOnly.value && flaggedIndexesRef?.value) {
|
||||
rows = rows.filter(({ index }) => flaggedIndexesRef.value.has(index))
|
||||
}
|
||||
|
||||
rows = rows.filter(({ transaction }) =>
|
||||
FILTERABLE_FIELDS.every((key) => {
|
||||
const filterValue = filters.value[key]
|
||||
|
|
@ -72,5 +88,8 @@ export function useTransactionFilters(transactionsRef) {
|
|||
return rows
|
||||
})
|
||||
|
||||
return { sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows }
|
||||
return {
|
||||
sortKey, sortDir, setSort, filters, clearFilters, hasActiveFilters, statusOptions, visibleRows,
|
||||
flaggedOnly, toggleFlaggedOnly,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* Translates each check's own raw mismatch/issue data
|
||||
* (backend/services/checks_service.py's {index, ...} shape) into the
|
||||
* review screen's plain-language, four-part flag format - what's wrong,
|
||||
* where, why, what to do (docs/bankstatement.md section 5.1). A pure
|
||||
* frontend presentation layer; the backend's own checks are untouched -
|
||||
* still return their own terse `detail` text, still used elsewhere (the
|
||||
* Results dropdown's checks list).
|
||||
*
|
||||
* Only four of the seven checks ever flag an individual row -
|
||||
* checks_service.py's own mismatches/issues are index-based only for
|
||||
* running_balance/date_sanity/structure_sanity/narrative_direction;
|
||||
* statement_balance/page_coverage/engine_agreement/ocr_source are
|
||||
* whole-statement checks with no per-row data at all (confirmed by
|
||||
* reading checks_service.py directly - none of those four ever return a
|
||||
* `mismatches` or `issues` key). A transaction with no entry from any of
|
||||
* the four has nothing to show here, regardless of its own `isFlagged`
|
||||
* state (which can also come from engine-disagreement/OCR flags that
|
||||
* aren't row-specific).
|
||||
*
|
||||
* date_sanity/structure_sanity return a free-text `issue` string, not a
|
||||
* structured type - pattern-matched here against the backend's own known
|
||||
* message shapes. If that text ever changes, the fallback below still
|
||||
* shows the raw string as the "why" rather than silently dropping it -
|
||||
* never hiding information the check actually found, per this project's
|
||||
* own governing rule.
|
||||
*/
|
||||
import { fmtMoney } from './formatService'
|
||||
|
||||
function runningBalanceFlag(item) {
|
||||
return {
|
||||
what: "The balance after this row doesn't follow from the row above.",
|
||||
why: `Expected the balance to be ${fmtMoney(item.expected)} here, but the statement shows ${fmtMoney(item.actual)}.`,
|
||||
whatToDo: "Check whether this row's debit and credit are the wrong way round, or whether a row above it is missing or wrong.",
|
||||
}
|
||||
}
|
||||
|
||||
function dateSanityFlag(item) {
|
||||
const issue = item.issue || ''
|
||||
if (issue.startsWith('unparseable date:')) {
|
||||
return {
|
||||
what: "This row's date couldn't be read at all.",
|
||||
why: `The extracted text was ${issue.slice('unparseable date: '.length)}.`,
|
||||
whatToDo: 'Check the date against the original statement.',
|
||||
}
|
||||
}
|
||||
if (issue.includes('before the statement period')) {
|
||||
return {
|
||||
what: "This row's date falls before the statement's own period.",
|
||||
why: issue,
|
||||
whatToDo: 'Check the date against the original statement - a misread digit or a day/month swap are the usual causes.',
|
||||
}
|
||||
}
|
||||
if (issue.includes('after the statement period')) {
|
||||
return {
|
||||
what: "This row's date falls after the statement's own period.",
|
||||
why: issue,
|
||||
whatToDo: 'Check the date against the original statement - a misread digit or a day/month swap are the usual causes.',
|
||||
}
|
||||
}
|
||||
if (issue.includes('is out of order')) {
|
||||
return {
|
||||
what: "This row's date is out of order relative to the rows around it.",
|
||||
why: issue,
|
||||
whatToDo: 'Check the date against the original statement - a misread digit or a day/month swap are the usual causes.',
|
||||
}
|
||||
}
|
||||
return { what: "This row's date looks wrong.", why: issue, whatToDo: 'Check the date against the original statement.' }
|
||||
}
|
||||
|
||||
function structureSanityFlag(item) {
|
||||
const issue = item.issue || ''
|
||||
if (issue === 'no amount at all') {
|
||||
return {
|
||||
what: 'This row has no debit, credit, or amount at all.',
|
||||
why: issue,
|
||||
whatToDo: 'Check the original statement for a value this extractor missed.',
|
||||
}
|
||||
}
|
||||
if (issue === 'blank description') {
|
||||
return {
|
||||
what: 'This row has no description text.',
|
||||
why: issue,
|
||||
whatToDo: 'Check the original statement - a wrapped description line may have been missed.',
|
||||
}
|
||||
}
|
||||
if (issue.startsWith('looks identical to row')) {
|
||||
return {
|
||||
what: 'This row looks identical to another row (same date, amount, and description).',
|
||||
why: issue,
|
||||
whatToDo: 'Confirm this is a real repeated transaction, not an accidental duplicate.',
|
||||
}
|
||||
}
|
||||
return { what: 'This row has a structural problem.', why: issue, whatToDo: 'Check this row against the original statement.' }
|
||||
}
|
||||
|
||||
function narrativeDirectionFlag(item) {
|
||||
return {
|
||||
what: "This row's description attachment was a close geometric call.",
|
||||
why: item.issue || 'No clear label or geometric signal settled which transaction this wrapped text belongs to.',
|
||||
whatToDo: 'Confirm the description text actually belongs to this row, not the one before or after it.',
|
||||
}
|
||||
}
|
||||
|
||||
const BUILDERS = {
|
||||
running_balance: runningBalanceFlag,
|
||||
date_sanity: dateSanityFlag,
|
||||
structure_sanity: structureSanityFlag,
|
||||
narrative_direction: narrativeDirectionFlag,
|
||||
}
|
||||
|
||||
/**
|
||||
* Every flag for a given transaction index, across all four row-flagging
|
||||
* checks - a row can carry more than one (e.g. a bad date AND a broken
|
||||
* running balance), each returned as its own four-part explanation
|
||||
* rather than only the first one found.
|
||||
*/
|
||||
export function flagsForIndex(result, index) {
|
||||
const flags = []
|
||||
for (const check of result?.checks || []) {
|
||||
const builder = BUILDERS[check.name]
|
||||
if (!builder) continue
|
||||
for (const item of check.mismatches || check.issues || []) {
|
||||
if (item.index === index) flags.push({ checkName: check.name, where: `Row ${index + 1}`, ...builder(item) })
|
||||
}
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
|
@ -23,6 +23,19 @@ export const useUiStore = defineStore('ui', {
|
|||
* call pattern with something each row can react to independently.
|
||||
*/
|
||||
layoutVersion: 0,
|
||||
/**
|
||||
* The review screen's "show this flagged row on the source document"
|
||||
* request - {page, bbox} | null. TransactionRow.vue (deep inside
|
||||
* TransactionsTable) and SourceDocumentPanel.vue (a sibling, not an
|
||||
* ancestor/descendant of it) have no direct way to call into each
|
||||
* other, so this is the bridge: TransactionRow sets it,
|
||||
* ExtractorView.vue (which holds the actual ref to
|
||||
* SourceDocumentPanel) watches it and calls that panel's own
|
||||
* showHighlight(page, bbox) - kept here rather than a one-off event
|
||||
* bus, consistent with how this app already uses uiStore for
|
||||
* cross-component view-chrome signals.
|
||||
*/
|
||||
highlightRequest: null,
|
||||
}),
|
||||
actions: {
|
||||
toggleResultsOpen() {
|
||||
|
|
@ -41,5 +54,11 @@ export const useUiStore = defineStore('ui', {
|
|||
toggleSidebar() {
|
||||
this.sidebarHidden = !this.sidebarHidden
|
||||
},
|
||||
requestHighlight(page, bbox) {
|
||||
this.highlightRequest = { page, bbox }
|
||||
},
|
||||
clearHighlightRequest() {
|
||||
this.highlightRequest = null
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@
|
|||
* FileUploadZone needs the staged files and SourceDocumentPanel needs
|
||||
* the ACTIVE (already-processed) document's own preview.
|
||||
*/
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useExtractionStore } from '../stores/extractionStore'
|
||||
import { useProjectsStore } from '../stores/projectsStore'
|
||||
import { useUiStore } from '../stores/uiStore'
|
||||
import { useFileUpload } from '../composables/useFileUpload'
|
||||
import { useBatchExtraction } from '../composables/useBatchExtraction'
|
||||
import { useDocuments } from '../composables/useDocuments'
|
||||
|
|
@ -21,6 +22,20 @@ import TransactionsTable from '../components/TransactionsTable.vue'
|
|||
|
||||
const extractionStore = useExtractionStore()
|
||||
const projectsStore = useProjectsStore()
|
||||
const uiStore = useUiStore()
|
||||
|
||||
// Bridges TransactionRow.vue's "Show on source" request (uiStore.
|
||||
// highlightRequest - see that store's own comment on why a store, not a
|
||||
// prop/event chain, is the right bridge here) into the actual
|
||||
// SourceDocumentPanel instance - the one place in the component tree
|
||||
// that holds a direct ref to it.
|
||||
const sourcePanelRef = ref(null)
|
||||
watch(
|
||||
() => uiStore.highlightRequest,
|
||||
(req) => {
|
||||
if (req) sourcePanelRef.value?.showHighlight(req.page, req.bbox)
|
||||
},
|
||||
)
|
||||
const {
|
||||
chosenFiles, isDragOver,
|
||||
removeChosenFile, clearChosenFiles, onFileInputChange, onDragOver, onDragLeave, onDrop,
|
||||
|
|
@ -93,6 +108,7 @@ onMounted(async () => {
|
|||
<ResizablePanels>
|
||||
<template #source>
|
||||
<SourceDocumentPanel
|
||||
ref="sourcePanelRef"
|
||||
:preview-url="extractionStore.activeDocument?.previewUrl ?? null"
|
||||
:is-image="extractionStore.activeDocument?.isImage ?? false"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue