feat: implement data export system with CSV, JSON, PDF, and scheduled reports - #36
Merged
KarenZita01 merged 1 commit intoJul 29, 2026
Conversation
…, CSRF protection, and env validation
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.
Summary
Implements a comprehensive data export system for the EquipChain frontend as described in issue #18. Users can now download their meter readings, billing history, stream data, and dashboard summaries in CSV, JSON, and PDF formats with configurable column selection, date range filtering, and aggregation options.
Closes #18
Changes
📊 Export Utilities (
src/lib/export/)CSV Generator (
csv.ts):CSVColumn<T>genericJSON Export (
json.ts):schemaVersion: "1.0.0")exportedAt,dataType,recordCount,source, optionaldateRange🎛️ Export UI Components (
src/components/export/)ExportDialog (
ExportDialog.tsx) — Full-featured export configuration modal:ExportButton (
ExportButton.tsx):primary,secondary,outlineInvoiceTemplate (
InvoiceTemplate.tsx):usePrintInvoice()hook for easy print integration🔌 Server-Side Export API (
app/api/export/route.ts)POST /api/export: Accepts format, dataType, columns, dateRange, aggregationGET /api/export: Returns API capabilities and documentationAPI_RATE_LIMITenv var (default: 10 req/min)EXPORT_MAX_RECORDSenv var (default: 50,000)Content-Disposition: attachment,X-Export-Truncated,X-Export-Total-RecordserrorandmessagefieldsRetry-Afterwith seconds until reset📄 Page Updates
All four data pages now have full export functionality with sample data tables:
app/dashboard/)app/meters/)app/streams/)app/billing/)Each page follows the existing design system (Tailwind CSS variables from
globals.css) with dark mode support.Files Changed
src/lib/export/csv.tssrc/lib/export/json.tssrc/lib/export/index.tssrc/components/export/ExportDialog.tsxsrc/components/export/ExportButton.tsxsrc/components/export/InvoiceTemplate.tsxapp/api/export/route.tsapp/dashboard/page.client.tsxapp/meters/page.client.tsxapp/streams/page.client.tsxapp/billing/page.client.tsxapp/dashboard/page.tsxapp/meters/page.tsxapp/streams/page.tsxapp/billing/page.tsxDesign Decisions
CSV Implementation
PDF Approach
window.print()) rather than a heavy PDF library@react-pdf/rendererdependency)/api/exportvia the PDF format option (returns 501 for now, with guidance on library integration)Page Architecture
page.tsx) and client (page.client.tsx) components following Next.js App Router best practicesVerification
npm run lint— 0 errors, 0 warningsnpm run typecheck— All types compilenpm run build— Production build succeeds with all routesRoutes Generated
Testing Instructions
/meters→ Click "Export" → Select CSV → Select columns → Click "Export N Columns" → File downloads/billing→ Click "Export" → Select JSON → Verify metadata in downloaded file/billing→ Click "View Invoice" → Invoice renders → Use browser print to save as PDFcurl -X POST http://localhost:3000/api/export -H 'content-type: application/json' -d '{"format":"csv","dataType":"meters","columns":["id","name"]}'→ Downloads CSV