Skip to content

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

Open
aalavala wants to merge 2 commits into
JJFromTenex:mainfrom
aalavala:NWP-101-export-options
Open

aalavala wants to merge 2 commits into
JJFromTenex:mainfrom
aalavala:NWP-101-export-options

Conversation

@aalavala

@aalavala aalavala commented Sep 23, 2026 •

Copy link
Copy Markdown

What changed

Ops can now click Export on /payments and get an options dialog instead of an immediate download: pick which columns ship (card last-four is off by default), choose between the current filter or every payment, and see the row count before downloading. Deselecting every column disables Download instead of producing an empty file. (Two unrelated files also ride along in this branch — docs/architecture-overview.html and its copy under public/ — a codebase-orientation doc from earlier investigation, not part of this ticket.)

How I verified it

npm test:

✓ src/lib/csv.test.ts (12 tests) 13ms
✓ src/lib/money.test.ts (12 tests) 11ms
✓ src/lib/dates.test.ts (7 tests) 12ms

Test Files  3 passed (3)
     Tests  31 passed (31)

Route, via curl against the running dev server:

  • No scope/columns params → same plain filename and full column set as before (payments-2026-09-23.csv).
  • columns=id,amount&scope=all → 2-column CSV covering every payment, regardless of the on-screen filter.
  • columns= (empty) → 400 with {"message":"Select at least one column to export."}.
  • status=disputed&scope=filtered → payments-disputed-2026-09-23.csv.
  • status=disputed with no scope param → old plain filename, unchanged (backward compatible).

Dialog, checked by hand in the browser on /payments:

  • Opened it — "Card last four" unchecked, every other column checked.
  • With status=disputed active, toggled scope from "Current filter" to "All payments" and watched the row count go from 33 to 1,658.
  • Cleared every column checkbox and confirmed Download swapped from a link to a disabled button.

Acceptance criteria

  • Ops can choose which columns are included. Card last-four is off by default.
  • Ops can choose scope: current filter or all payments. Current filter is the default, and the row count is visible before download.
  • The filename reflects the scope and the date.
  • Amounts stay in minor units internally and are formatted once on the way out, with currency in its own column. (Already true before this ticket — preserved, not changed.)
  • Deselecting every column disables Download rather than producing an empty file.

Deliberately not done

  • No automated test for the new exportFilename(date, scope) token logic or the export route's scope-branching — the ticket's DoD only calls for a unit test on the column serializer, so those two got manual/curl verification only, not a test file.
  • No error state in the dialog if the row-count fetch fails — it just shows "Counting rows…" indefinitely rather than a retry or error message.
  • No pageSize allowlist entry added to parseFilters — the dialog's count fetch accepts GET /api/payments's default page of rows and reads only .total, rather than requesting a smaller page.
  • NWP-102 (the linked ticket) not investigated or touched.

Abhi Reddy added 2 commits September 22, 2026 22:52
Add an options dialog to the payments Export button so ops can pick
which columns ship (card last-four off by default) and whether the
export covers the current filter or all payments, with a live row
count shown before download.

- src/lib/csv.ts: DEFAULT_EXPORT_COLUMNS, parseExportColumns()
  (server-side allowlist for the client-supplied columns param),
  exportFilename() gains an optional scope token.
- src/app/api/payments/export/route.ts: validates columns/scope,
  400s on an empty column list, reuses the existing query builder
  (filterPayments/sortPayments) for both scopes.
- src/app/payments/export-dialog.tsx (new): column checkboxes, scope
  radios, live count via GET /api/payments, Download disabled at
  zero columns.
- src/app/payments/page.tsx: wire the dialog in place of the plain
  Export link.
- src/lib/csv.test.ts: cover column subset+order, last-four excluded
  by default, and an empty selection.

Verified: npm test (31/31 passing); manual browser pass confirming
default columns, scope-driven row count, and Download's disabled
state; route sanity-checked via curl for the no-params/backward-compat,
all-scope, and empty-columns cases.
Covers what the merchant console does, its tech stack, how src/ is
organized, and the payments export flow end to end. Copied into
public/ as well so it can be served by the dev server for viewing.
@aalavala aalavala closed this Sep 23, 2026
@aalavala aalavala changed the title Nwp 101 export options NWP-101: let ops choose export columns and scope Sep 23, 2026
@aalavala aalavala reopened this Sep 23, 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.

1 participant