The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix empty option in partner earnings Link filter
Cursor Agent313abfe379e6
diff --git a/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts b/apps/web/lib/api/partner-profile/get-partner-earnings-count.tsindex 8ff08cc6b2..adf1bffd88 100644--- a/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts+++ b/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts@@ -77,9 +77,13 @@ export async function getPartnerEarningsCount({if (groupBy === "customerId") {// grouped by program too, since customer data sharing is set per program enrollment+ // exclude null customerId so the Customer filter has no empty optionconst counts = await prisma.commission.groupBy({by: ["customerId", "programId"],- where: groupedWhere,+ where: {+ ...groupedWhere,+ customerId: { not: null },+ },_count: true,orderBy: {_count: {@@ -144,7 +148,11 @@ export async function getPartnerEarningsCount({const counts = await prisma.commission.groupBy({by: [groupBy],- where: groupedWhere,+ where: {+ ...groupedWhere,+ // exclude null linkId so the Link filter has no empty option+ ...(groupBy === "linkId" && { linkId: { not: null } }),+ },_count: true,orderBy: {_count: {@@ -172,15 +180,19 @@ export async function getPartnerEarningsCount({const linksById = new Map(links.map((l) => [l.id, l]));- return counts.map(({ linkId, _count }) => {- const link = linkId ? linksById.get(linkId) : undefined;- return {- id: linkId,- domain: link?.domain,- key: link?.key,- url: link?.url,- _count,- };+ return counts.flatMap(({ linkId, _count }) => {+ if (!linkId) return [];+ const link = linksById.get(linkId);+ if (!link) return [];+ return [+ {+ id: linkId,+ domain: link.domain,+ key: link.key,+ url: link.url,+ _count,+ },+ ];});}diff --git a/apps/web/playwright/api/partner-profile/earnings.spec.ts b/apps/web/playwright/api/partner-profile/earnings.spec.tsindex ac99fd7a1a..6084ff4358 100644--- a/apps/web/playwright/api/partner-profile/earnings.spec.ts+++ b/apps/web/playwright/api/partner-profile/earnings.spec.ts@@ -223,14 +223,31 @@ test.describe("GET /partner-profile/earnings", () => {playwright,}) => {await withPartnerApi(playwright, async (partnerApi) => {- for (const groupBy of ["linkId", "customerId"]) {- const { status, data } = await partnerApi.get<- { id: string | null; _count: number }[]- >(`/api/partner-profile/earnings/count?groupBy=${groupBy}`);+ // commissions without a link/customer are omitted so filter menus have no empty option+ const byLink = await partnerApi.get<{ id: string; _count: number }[]>(+ "/api/partner-profile/earnings/count?groupBy=linkId",+ );+ expect(byLink.status).toEqual(200);+ expect(byLink.data).toEqual([+ expect.objectContaining({+ id: programB.linkId,+ domain: expect.any(String),+ key: expect.any(String),+ _count: 1,+ }),+ ]);- expect(status).toEqual(200);- expect(data.reduce((sum, group) => sum + group._count, 0)).toEqual(3);- }+ const byCustomer = await partnerApi.get<+ { id: string; _count: number }[]+ >("/api/partner-profile/earnings/count?groupBy=customerId");+ expect(byCustomer.status).toEqual(200);+ expect(byCustomer.data).toEqual([+ expect.objectContaining({+ id: programB.customerId,+ email: programB.customerEmail,+ _count: 1,+ }),+ ]);});});diff --git a/apps/web/ui/partners/earnings/earnings-composite-chart.tsx b/apps/web/ui/partners/earnings/earnings-composite-chart.tsxindex 6b4f7a6301..e7b5fc79b7 100644--- a/apps/web/ui/partners/earnings/earnings-composite-chart.tsx+++ b/apps/web/ui/partners/earnings/earnings-composite-chart.tsx@@ -445,25 +445,38 @@ function EarningsTableControls() {return <LinkIcon url={props.option?.data?.url} />;},options:- links?.map(({ id, domain, key, url }) => ({- value: id,- label: linkConstructor({- domain,- key,- pretty: true,- }),- data: { url },- })) ?? null,+ links+ ?.flatMap(({ id, domain, key, url }) =>+ id && domain && key+ ? [+ {+ value: id,+ label: linkConstructor({+ domain,+ key,+ pretty: true,+ }),+ data: { url },+ },+ ]+ : [],+ ) ?? null,},{key: "customerId",icon: User,label: "Customer",options:- customers?.map(({ id, email }) => ({- value: id,- label: email || id,- })) ?? null,+ customers?.flatMap(({ id, email }) =>+ id+ ? [+ {+ value: id,+ label: email || id,+ },+ ]+ : [],+ ) ?? null,},{key: "status",