-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix sortBy for getPartners and getGroups
#2838
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRenames aggregated partner/group metrics to total-prefixed fields across API, schemas, and UI tables. Updates sort keys to use the new names, with defaults shifting to totalSaleAmount. Removes two console.log statements in a partner merge script. No function signatures changed; response shapes and query schemas updated. Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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. Comment |
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
🧹 Nitpick comments (3)
apps/web/lib/zod/schemas/partners.ts (1)
144-149: Docstring still referencescommissions(stale naming).Update the description to
totalCommissionsfor consistency across API and docs.Apply this diff:
- "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.",apps/web/lib/api/partners/get-partners.ts (1)
139-151: Make shortLink search case-insensitive like name/email.You’re lowercasing the needle but not the haystack. Align with the other predicates.
Apply this diff:
- AND searchLink.shortLink LIKE LOWER(${`%${search}%`}) + AND LOWER(searchLink.shortLink) LIKE LOWER(${`%${search}%`})apps/web/lib/api/groups/get-groups.ts (1)
34-34: Guard or removeconsole.time/timeEndin production paths.These logs can be noisy in prod. Consider gating on
NODE_ENV === "development"or removing.Apply this diff:
- console.time("getGroups"); + if (process.env.NODE_ENV === "development") console.time("getGroups"); @@ - console.timeEnd("getGroups"); + if (process.env.NODE_ENV === "development") console.timeEnd("getGroups");Also applies to: 96-96
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx(3 hunks)apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx(1 hunks)apps/web/lib/api/groups/get-groups.ts(2 hunks)apps/web/lib/api/partners/get-partners.ts(2 hunks)apps/web/lib/zod/schemas/groups.ts(2 hunks)apps/web/lib/zod/schemas/partners.ts(1 hunks)apps/web/scripts/partners/merge-partner-profile.ts(0 hunks)
💤 Files with no reviewable changes (1)
- apps/web/scripts/partners/merge-partner-profile.ts
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx (1)
packages/utils/src/functions/currency-formatter.ts (1)
currencyFormatter(5-16)
⏰ 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). (3)
- GitHub Check: api-tests
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (14)
apps/web/lib/zod/schemas/partners.ts (2)
116-126: Rename in sortBy enum is correct and consistent.Switching to "totalCommissions" aligns the schema with API/UI and prevents invalid "commissions" values from slipping through.
348-360: Stats field naming is consistent (LGTM).
totalCommissions+netRevenuematch the API and table accessors.apps/web/lib/api/partners/get-partners.ts (3)
6-15: Primary sort map update tototalCommissionsis correct.Mapping the client
"totalCommissions"key to the selected column keeps ORDER BY stable with the new naming.
18-27: Secondary sort map update is correct.Falling back to
totalSaleAmountwhen sorting by commissions preserves deterministic ordering.
155-157: ```shell
#!/usr/bin/env bash
set -euo pipefailecho "PWD: $(pwd)"
echo
echo "rg --version:"
rg --version || true
echoecho "---- Searching for 'sortBy' occurrences (no --type flags) ----"
rg -nP -C2 '\bsortBy\b' || true
echoecho "---- Searching for 'sortColumnsMap' definitions ----"
rg -nP -n -C5 'sortColumnsMap' || true
echoecho "---- Searching for literal '"commissions"' ----"
rg -nP -n -C3 '"commissions"' || true
echoecho "---- Searching for unquoted word 'commissions' ----"
rg -nP -n -C3 '\bcommissions\b' || true
echoTARGET_FILE=apps/web/lib/api/partners/get-partners.ts
echo "---- Showing ${TARGET_FILE} (if present), first 300 lines ----"
if [ -f "$TARGET_FILE" ]; then
sed -n '1,300p' "$TARGET_FILE" || true
else
echo "file not found: $TARGET_FILE"
fi
echoecho "---- Showing lines 140-180 of ${TARGET_FILE} (if present) ----"
if [ -f "$TARGET_FILE" ]; then
sed -n '140,180p' "$TARGET_FILE" || true
fi</blockquote></details> <details> <summary>apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx (1)</summary><blockquote> `300-310`: **Sortable column key updated to `totalCommissions` — UI/API parity achieved.** Matches schema and backend; sorting should now work end-to-end. </blockquote></details> <details> <summary>apps/web/lib/zod/schemas/groups.ts (2)</summary><blockquote> `28-36`: **Totals-prefixed metrics look good.** `totalClicks/Leads/Sales/SaleAmount/Conversions/Commissions` unifies naming across groups. --- `79-91`: **sortBy enum + default switched to totals — consistent with UI and API.** Defaulting to `totalSaleAmount` is sensible and matches the groups table. </blockquote></details> <details> <summary>apps/web/lib/api/groups/get-groups.ts (3)</summary><blockquote> `10-20`: **Sort map migrated to totals fields — correct.** All sortable keys now point to the new aliases returned by the SELECT. --- `46-54`: **Aggregate aliases align with new totals fields and `netRevenue`.** Using `SUM(pe.totalCommissions)` and computing `netRevenue` keeps semantics intact. --- `101-108`: **Numeric coercion on returned totals is preserved — good.** Ensures consumers get numbers, not strings. </blockquote></details> <details> <summary>apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx (3)</summary><blockquote> `46-47`: **Default sort changed to `totalSaleAmount` — matches schema/API.** This prevents mismatch with server-side default. --- `108-131`: **Column accessors migrated to totals fields — correct.** Renderers now read `totalClicks/Leads/Conversions/SaleAmount/Commissions` with proper formatting. --- `164-171`: **Sortable column keys updated to totals — consistent end-to-end.** Should fix any previous “invalid sortBy” issues from the UI. </blockquote></details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Summary by CodeRabbit
Refactor
Chores