Repository navigation
NWP-101: let ops choose export columns and scope - #236
Closed
chiruoftpt-ai wants to merge 1 commit into
Closed
chiruoftpt-ai wants to merge 1 commit into
chiruoftpt-ai wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/paymentsnow 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 aspayments-disputed-2026-12-02.csvorpayments-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), inbuild-battle/merchant-console:npm test—Test Files 4 passed (4),Tests 55 passed (55), including the new cases insrc/lib/csv.test.tsandsrc/app/api/payments/export/route.test.tsnpx tsc --noEmit— exit code 0npm run lint—No ESLint warnings or errorslocalhost:3000/api/payments/export:id,created_at,merchant,description,status,method,card_brand,amount,currency(nolast4), 1,658 rows?columns=amount,id— 200, headerid,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/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
route.test.ts"leaves out card last four when no columns are requested"; no-params request has nolast4columnroute.test.tscovers both scopes and that the file is not paginatedpayments-disputed-2026-08-13.csv. —payments-disputed-…,payments-disputed-mch_01-…andpayments-all-…from the requests above; filename cases in both test filesformatMoneyis still called once, incell()(src/lib/csv.ts:96);currencyis its own column; the existing amount tests still pass?columns=Deliberately not done
?columns=amount,idgivesid,amount, so every export has a consistent layout. The dialog always sends file order, so ops never sees the difference.{ "error": message }.src/data/queries.ts:81—sortPaymentscompares amounts as strings, sosort=amountorders both the table and the export wrongly. It is outside this ticket and changes shared behavior.src/app/payments/page.tsx:21-44parses filters itself instead of usingparseFiltersand ignoressort,direction,fromandto, so the table can disagree with the export. The dialog's counts useparseFilters, so the count shown matches the file.src/data/queries.ts:28,30-31—merchantId,fromandtoreach the query without allowlist checks. The export filename is protected: it only uses a merchant id that exists./ship-ready, not fixed:src/data/metrics.ts:25buckets days in server-local time, not UTC;metrics.ts:31,34adds up converted major units, which brings in rounding error;metrics.ts:53-55,73andanalytics.ts:54,73,119add USD, EUR and GBP together; the search input and dropdowns infilter-bar.tsx:52,66,84andperiod-controls.tsx:17have no labels.src/components/Drawer.tsx— the close button held only anaria-hiddenicon, so it had no accessible name. It now hasaria-label="Close", which applies to every Drawer.