Skip to content

NWP-101: let ops choose export columns and scope - #236

Closed
chiruoftpt-ai wants to merge 1 commit into
JJFromTenex:mainfrom
chiruoftpt-ai:NWP-101-export-options
Closed

chiruoftpt-ai wants to merge 1 commit into
JJFromTenex:mainfrom
chiruoftpt-ai:NWP-101-export-options

Conversation

@chiruoftpt-ai

@chiruoftpt-ai chiruoftpt-ai commented Dec 2, 2026 •

Copy link
Copy Markdown

Business impact: Ops can send payment exports to merchants without hand-removing card last-four first, which removes the 3–4 hours a month of manual spreadsheet cleanup and the risk of card data reaching the wrong merchant.

What changed

Export on /payments now opens a dialog before anything downloads. Ops chooses which columns go in the file, with card last-four unchecked by default, and whether to export the current filter or all payments, seeing the row count for each before they download. The file is named for its scope and the date, such as payments-disputed-2026-12-02.csv or payments-all-2026-12-02.csv. The server checks the requested columns and scope against allowlists and refuses unknown or empty choices, so a hand-built link cannot bring last-four back by accident or produce an empty file. Rows still come from the shared query builder and are not paginated, so "current filter" means every matching payment, not just the page on screen.

How I verified it

Run on commit c243432 (NWP-101-export-options), in build-battle/merchant-console:

  • npm test — Test Files 4 passed (4), Tests 55 passed (55), including the new cases in src/lib/csv.test.ts and src/app/api/payments/export/route.test.ts
  • npx tsc --noEmit — exit code 0
  • npm run lint — No ESLint warnings or errors
  • Requests to the dev server at localhost:3000/api/payments/export:
    • no params — 200, header id,created_at,merchant,description,status,method,card_brand,amount,currency (no last4), 1,658 rows
    • ?columns=amount,id — 200, header id,amount
    • ?columns=pan — 400 {"error":"One or more requested columns do not exist."}
    • ?columns= — 400 {"error":"Choose at least one column to export."}
    • ?status=disputed — 200, payments-disputed-2026-12-02.csv, 33 rows
    • ?status=disputed&merchantId=mch_01 — 200, payments-disputed-mch_01-2026-12-02.csv, 5 rows
    • ?scope=all&status=disputed — 200, payments-all-2026-12-02.csv, 1,658 rows
  • Browser, /payments?status=disputed: clicked Export. The dialog opened as "Export payments" with focus inside it. "Card last four" was unchecked and "Current filter (33 payments)" was selected, against "All payments (1,658 payments)"; both counts match the row counts above. Unchecking every column turned Download into a disabled button with no link and showed "Choose at least one column to download." Pressing Escape closed it and focus returned to Export. The close button is announced as "Close".

Acceptance criteria

  • Ops can choose which columns are included. Card last-four is off by default. — dialog checkboxes; browser check above; route.test.ts "leaves out card last four when no columns are requested"; no-params request has no last4 column
  • Ops can choose scope: current filter or all payments. Current filter is the default, and the row count is visible before download. — dialog radios with counts (33 / 1,658 in the browser check); route.test.ts covers both scopes and that the file is not paginated
  • The filename reflects the scope and the date, for example payments-disputed-2026-08-13.csv. — payments-disputed-…, payments-disputed-mch_01-… and payments-all-… from the requests above; filename cases in both test files
  • Amounts stay in minor units internally and are formatted once on the way out, with currency in its own column. — the amount path is unchanged: formatMoney is still called once, in cell() (src/lib/csv.ts:96); currency is its own column; the existing amount tests still pass
  • Deselecting every column disables Download rather than producing an empty file. — browser check above; the server also returns 400 for ?columns=

Deliberately not done

  • Columns come out in file order, not request order. ?columns=amount,id gives id,amount, so every export has a consistent layout. The dialog always sends file order, so ops never sees the difference.
  • "All payments" ignores the page's sort and always exports newest first.
  • Error response shape. The API routes had no existing error format to copy, so 400s return { "error": message }.
  • Amount sort bug, not fixed. src/data/queries.ts:81 — sortPayments compares amounts as strings, so sort=amount orders both the table and the export wrongly. It is outside this ticket and changes shared behavior.
  • Second filter parser on the payments page, not fixed. src/app/payments/page.tsx:21-44 parses filters itself instead of using parseFilters and ignores sort, direction, from and to, so the table can disagree with the export. The dialog's counts use parseFilters, so the count shown matches the file.
  • Unchecked filter inputs, not fixed. src/data/queries.ts:28,30-31 — merchantId, from and to reach the query without allowlist checks. The export filename is protected: it only uses a merchant id that exists.
  • Other pre-existing issues from /ship-ready, not fixed: src/data/metrics.ts:25 buckets days in server-local time, not UTC; metrics.ts:31,34 adds up converted major units, which brings in rounding error; metrics.ts:53-55,73 and analytics.ts:54,73,119 add USD, EUR and GBP together; the search input and dropdowns in filter-bar.tsx:52,66,84 and period-controls.tsx:17 have no labels.
  • One a11y fix along the way: src/components/Drawer.tsx — the close button held only an aria-hidden icon, so it had no accessible name. It now has aria-label="Close", which applies to every Drawer.

Ops can now pick the columns and the scope (current filter or all
payments) before downloading the CSV, with card last four off by default.

- csv.ts: default column set without last4, parseExportColumns checks
  names against the EXPORT_COLUMNS allowlist (unknown or empty is
  rejected, output follows file order), scope-aware exportFilename that
  only uses a validated status and an existing merchant id
- export route: validates `columns` and `scope`, returns 400 with a
  JSON error on bad input, otherwise reuses the shared query builder
- payments page: Export opens a Drawer-based dialog with labelled
  checkboxes, scope radios and row counts taken from parseFilters, so
  the number shown matches the file; Download is disabled with no columns
- Drawer: aria-label on the close button
- spec: docs/specs/NWP-101-export-options.md

Verified: npm test (55 passed, incl. new route tests), tsc --noEmit and
npm run lint clean. Dialog not yet checked in a browser.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chiruoftpt-ai chiruoftpt-ai changed the title NWP-101: choose columns and scope for the payments export NWP-101: let ops choose export columns and scope Dec 2, 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