Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Sep 13, 2025

Summary by CodeRabbit

  • Refactor

    • Groups table now uses total-based metrics (Total Clicks, Leads, Conversions, Sales, Sale Amount, Commissions) with default sort updated to Total Sale Amount.
    • Sorting options updated to match the new total metrics; Net Revenue and Partners remain available.
    • Partners table “Commissions” sorting now aligns with Total Commissions for consistency.
  • Chores

    • Removed debug logging from partner profile merge script to reduce noise.

@vercel
Copy link
Contributor

vercel bot commented Sep 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 13, 2025 6:17am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 13, 2025

Walkthrough

Renames 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

Cohort / File(s) Summary
Dashboard Groups Table
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx
Switched column accessors, IDs, sortable keys, and currency formatters from clicks/leads/conversions/saleAmount/commissions to totalClicks/totalLeads/totalConversions/totalSaleAmount/totalCommissions; default sort now totalSaleAmount.
Dashboard Partners Table
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
Updated sortableColumns entry from commissions to totalCommissions.
Groups API
apps/web/lib/api/groups/get-groups.ts
Renamed aggregated output aliases and sortColumnsMap to totalClicks/totalLeads/totalConversions/totalSales/totalSaleAmount/totalCommissions; adjusted mapping and defaults to new fields.
Partners API
apps/web/lib/api/partners/get-partners.ts
Updated sortColumnsMap and sortColumnExtraMap keys from commissions to totalCommissions; underlying columns unchanged.
Zod Schemas (Groups)
apps/web/lib/zod/schemas/groups.ts
Renamed schema fields to total* variants; updated getGroupsQuerySchema sortBy enum to total* names; default sortBy changed to totalSaleAmount.
Zod Schemas (Partners)
apps/web/lib/zod/schemas/partners.ts
Replaced sortBy enum value commissions with totalCommissions; default unchanged.
Script Cleanup
apps/web/scripts/partners/merge-partner-profile.ts
Removed console.log statements after commissions and payouts updateMany operations.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

I tallied clicks to totals bright,
Summed sales to shine in sorted light.
Commissions grew a “total” tail,
Our schemas sailed without a fail.
Logs went quiet—no more sprawl—
A tidy hop through fields, that’s all. 🐇📊

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Fix sortBy for getPartners and getGroups" is concise and directly describes the primary change in the PR, namely adjustments to sort keys/defaults for partners and groups (moving to total-prefixed fields and updating defaults). It avoids noise and is specific enough for a reviewer scanning history to understand the main intent. The title aligns with the provided changeset and objectives.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sortby-fixes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 references commissions (stale naming).

Update the description to totalCommissions for 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 remove console.time/timeEnd in 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c0c661 and b3197b8.

📒 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 + netRevenue match the API and table accessors.

apps/web/lib/api/partners/get-partners.ts (3)

6-15: Primary sort map update to totalCommissions is 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 totalSaleAmount when sorting by commissions preserves deterministic ordering.


155-157: ```shell
#!/usr/bin/env bash
set -euo pipefail

echo "PWD: $(pwd)"
echo
echo "rg --version:"
rg --version || true
echo

echo "---- Searching for 'sortBy' occurrences (no --type flags) ----"
rg -nP -C2 '\bsortBy\b' || true
echo

echo "---- Searching for 'sortColumnsMap' definitions ----"
rg -nP -n -C5 'sortColumnsMap' || true
echo

echo "---- Searching for literal '"commissions"' ----"
rg -nP -n -C3 '"commissions"' || true
echo

echo "---- Searching for unquoted word 'commissions' ----"
rg -nP -n -C3 '\bcommissions\b' || true
echo

TARGET_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
echo

echo "---- 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 -->

@steven-tey steven-tey merged commit 18d744e into main Sep 13, 2025
9 of 10 checks passed
@steven-tey steven-tey deleted the sortby-fixes branch September 13, 2025 06:22
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.

2 participants