-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix partner CSV export #2780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix partner CSV export #2780
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds expanded column metadata to partners schema, introduces includeExpandedFields in the partners export API to fetch expanded data when requested, updates numeric/string typing based on expanded columns, and adds totalCommissions and netRevenue columns to exports. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant API as /api/partners/export
participant S as getPartners(...)
participant DB as Database
C->>API: GET /partners/export?columns=...
API->>API: Parse requested columns
API->>API: expandedColumns = from schema
API->>API: includeExpandedFields = any(requested ∩ expandedColumns)
API->>S: getPartners({ includeExpandedFields, ... })
S->>DB: Query partners (join/select expanded fields if requested)
DB-->>S: Partners data
S-->>API: Partners with/without expanded fields
API->>API: Build schemaFields (numeric if in expandedColumns)
API-->>C: Export response (ordered, formatted dates)
note over API,S: New decision point: includeExpandedFields controls expanded fetch and typing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
apps/web/lib/zod/schemas/partners.ts (3)
106-111: OpenAPI/docs mismatch: use “totalCommissions” instead of “commissions”.Public description should match field ids used elsewhere.
Apply:
- "Whether to include stats fields on the partner (`clicks`, `leads`, `conversions`, `sales`, `saleAmount`, `commissions`, `netRevenue`). If false, those fields will be returned as 0.", + "Whether to include stats fields on the partner (`clicks`, `leads`, `conversions`, `sales`, `saleAmount`, `totalCommissions`, `netRevenue`). If false, those fields will be returned as 0.",
136-140: Filter/validate requested columns to avoid “undefined” CSV headers.Unknown ids currently flow through, producing an “undefined” column header. Filter to known ids (and optionally dedupe) during parsing.
Apply:
- columns: z - .string() - .default(exportPartnersColumnsDefault.join(",")) - .transform((v) => v.split(",")), + columns: z + .string() + .default(exportPartnersColumnsDefault.join(",")) + .transform((v) => v.split(",")) + .transform((ids) => { + const allowed = new Set(exportPartnerColumns.map((c) => c.id)); + return [...new Set(ids.filter((id) => allowed.has(id)))]; + }),
79-89: Align sort key naming: use “totalCommissions” everywhere instead of “commissions”To avoid the mismatch between the UI, Zod schema, and API mapping, please make the following mandatory refactors:
• apps/web/lib/zod/schemas/partners.ts
– Around thesortByenum (lines ~79–89), replace"commissions"with"totalCommissions".• apps/web/lib/api/partners/get-partners.ts
– InsortColumnsMap(around line 6), rename the key
commissions: "totalCommissions"
to
totalCommissions: "totalCommissions".
– InsortColumnExtraMap(around line 23), rename the key
commissions: "totalSaleAmount"
to
totalCommissions: "totalSaleAmount"(or adjust as needed for your desired secondary sort).• UI consistency check
– Confirm that inprogram/partners/partners-table.tsxthe sort‐by options array already uses"totalCommissions"(no change needed if it does).This will ensure the Zod schema, the server‐side mapping, and the client‐side sort keys all refer to the same
"totalCommissions"identifier.apps/web/app/(ee)/api/partners/export/route.ts (1)
44-46: Sanitize and dedupe requested columns before schema/build.Prevents unknown ids producing an “undefined” header and removes duplicates.
Apply:
- columns = columns.sort( + // keep only known columns and dedupe + columns = [...new Set(columns.filter((id) => columnIdToLabel[id]))].sort( (a, b) => (columnOrderMap[a] || 999) - (columnOrderMap[b] || 999), ); @@ - columns.forEach((column) => { + columns.forEach((column) => { if (expandedColumns.includes(column)) {Note: if you adopt the Set change above, replace the includes call per that diff.
Also applies to: 48-61
🧹 Nitpick comments (3)
apps/web/app/(ee)/api/partners/export/route.ts (3)
16-19: Use a Set for expanded columns to simplify lookups.Minor perf/readability win and avoids repeated includes scans.
Apply:
-const expandedColumns = exportPartnerColumns - .filter((column) => column.expanded) - .map((column) => column.id); +const expandedColumnsSet = new Set( + exportPartnerColumns.filter((c) => c.expanded).map((c) => c.id), +); @@ -const includeExpandedFields = expandedColumns.some((column) => - columns.includes(column), -); +const includeExpandedFields = columns.some((col) => + expandedColumnsSet.has(col), +); @@ - if (expandedColumns.includes(column)) { + if (expandedColumnsSet.has(column)) {Also applies to: 27-30, 50-55
63-77: Avoid recreating the Zod object per row.Hoist the schema once and reuse during parsing.
Apply:
- const formattedPartners = partners.map((partner) => { + const rowSchema = z.object(schemaFields); + const formattedPartners = partners.map((partner) => { @@ - return z.object(schemaFields).parse(result); + return rowSchema.parse(result); });
79-84: Add a filename to the CSV attachment.Improves UX and downstream handling.
Apply:
- headers: { + headers: { "Content-Type": "text/csv", - "Content-Disposition": `attachment`, + "Content-Disposition": `attachment; filename="partners.csv"`, },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/app/(ee)/api/partners/export/route.ts(2 hunks)apps/web/lib/zod/schemas/partners.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-29T04:45:18.504Z
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
Applied to files:
apps/web/lib/zod/schemas/partners.ts
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/partners/export/route.ts (2)
apps/web/lib/zod/schemas/partners.ts (2)
exportPartnerColumns(29-51)partnersExportQuerySchema(132-141)apps/web/lib/api/partners/get-partners.ts (1)
getPartners(33-171)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (1)
apps/web/lib/zod/schemas/partners.ts (1)
30-51: Expanded metadata and new metrics columns look good; confirm header change impact.Expanded flags align with route logic and the addition of totalCommissions/netRevenue is consistent with EnrolledPartnerSchema. Note: changing createdAt’s label to “Enrolled at” may affect downstream CSV consumers relying on exact headers.
Please confirm the header rename (“Created at” → “Enrolled at”) is intentional and communicated to users relying on stable CSV headings.
Summary by CodeRabbit
New Features
Improvements