Skip to content

Commit 6ced23b

Browse files
ofershapcursoragent
andcommitted
fix: duplicate React keys in daily spend chart and TS error in generate-audio
Disambiguate first names with last initial when two top spenders share the same first name (e.g. "Roman O." vs "Roman S."). Also fix optional chaining in generate-audio.ts that broke CI typecheck. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5848af9 commit 6ced23b

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

scripts/video/generate-audio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function buildVoiceSettings(script: DemoScript) {
7575
}
7676

7777
async function generateSample(client: ElevenLabsClient, voice: VoiceCandidate, script: DemoScript) {
78-
const sampleText = script.scenes[0].narration;
78+
const sampleText = script.scenes[0]?.narration ?? "";
7979
const outPath = path.join(OUTPUT_DIR, `sample-${voice.name.toLowerCase()}.mp3`);
8080

8181
console.log(` Generating sample for "${voice.name}" → ${outPath}`);

src/app/dashboard-client.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ export interface DailySpendDataPoint {
480480
[key: string]: string | number;
481481
}
482482

483+
function shortDisplayName(fullName: string): string {
484+
const parts = fullName.split(" ");
485+
return parts[0] ?? fullName;
486+
}
487+
483488
function buildDailySpendData(breakdown: SpendBreakdownRow[]): {
484489
points: DailySpendDataPoint[];
485490
topNames: string[];
@@ -488,10 +493,28 @@ function buildDailySpendData(breakdown: SpendBreakdownRow[]): {
488493
for (const row of breakdown) {
489494
spendByUser.set(row.name, (spendByUser.get(row.name) ?? 0) + row.spend_cents);
490495
}
491-
const topNames = [...spendByUser.entries()]
496+
const topFullNames = [...spendByUser.entries()]
492497
.sort((a, b) => b[1] - a[1])
493498
.slice(0, 6)
494-
.map(([name]) => name.split(" ")[0] ?? name);
499+
.map(([name]) => name);
500+
501+
const firstNameCount = new Map<string, number>();
502+
for (const name of topFullNames) {
503+
const first = shortDisplayName(name);
504+
firstNameCount.set(first, (firstNameCount.get(first) ?? 0) + 1);
505+
}
506+
const fullToDisplay = new Map<string, string>();
507+
for (const name of topFullNames) {
508+
const first = shortDisplayName(name);
509+
if ((firstNameCount.get(first) ?? 0) > 1) {
510+
const lastInitial = name.split(" ")[1]?.[0] ?? "";
511+
fullToDisplay.set(name, `${first} ${lastInitial}.`);
512+
} else {
513+
fullToDisplay.set(name, first);
514+
}
515+
}
516+
517+
const topNames = topFullNames.map((n) => fullToDisplay.get(n) ?? n);
495518

496519
const byDate = new Map<string, DailySpendDataPoint>();
497520
for (const row of breakdown) {
@@ -501,11 +524,11 @@ function buildDailySpendData(breakdown: SpendBreakdownRow[]): {
501524
byDate.set(row.date, point);
502525
}
503526
const point = byDate.get(row.date) as Record<string, number>;
504-
const firstName = row.name.split(" ")[0] ?? row.name;
527+
const display = fullToDisplay.get(row.name);
505528
const dollars = row.spend_cents / 100;
506529
point.total = (point.total ?? 0) + dollars;
507-
if (topNames.includes(firstName)) {
508-
point[firstName] = (point[firstName] as number) + dollars;
530+
if (display) {
531+
point[display] = (point[display] as number) + dollars;
509532
} else {
510533
point.Others = (point.Others as number) + dollars;
511534
}

src/app/insights/insights-client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export function InsightsClient({ data }: { data: InsightsData }) {
418418
<tbody>
419419
{mergedCommands.slice(0, 20).map((row, i) => (
420420
<tr
421-
key={row.command_name}
421+
key={`${row.command_name}-${i}`}
422422
className="border-b border-zinc-800/30 hover:bg-zinc-800/30"
423423
>
424424
<td className="py-1 text-zinc-300 font-mono">{row.command_name}</td>

src/app/users/[email]/user-detail-client.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,11 @@ export function UserDetailClient({ email, stats }: UserDetailClientProps) {
410410
Commands
411411
</div>
412412
<div className="space-y-1.5">
413-
{stats.commandsSummary.slice(0, 10).map((c) => (
414-
<div key={c.command_name} className="flex items-center justify-between text-xs">
413+
{stats.commandsSummary.slice(0, 10).map((c, i) => (
414+
<div
415+
key={`${c.command_name}-${i}`}
416+
className="flex items-center justify-between text-xs"
417+
>
415418
<span className="text-zinc-300">{c.command_name}</span>
416419
<span className="font-mono text-zinc-500">
417420
{c.total_usage.toLocaleString()}

0 commit comments

Comments
 (0)