Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(insights): show at least five brands on the leaderboard, yours always among them (#1352)
Cihan7bda17e9fa49
diff --git a/web/src/lib/insights-summary.test.ts b/web/src/lib/insights-summary.test.tsindex e8cd3b794..975655d45 100644--- a/web/src/lib/insights-summary.test.ts+++ b/web/src/lib/insights-summary.test.ts@@ -278,13 +278,18 @@ describe('leaderboardLines', () => {expect(lines(20, 5)).toEqual({ lines: [1, 2, '2 more', 5, 6, 7], hidden: 15 });});- it('skips nothing in between when the brand is near the top', () => {- expect(lines(8, 2)).toEqual({ lines: [1, 2, 3, 4], hidden: 4 });- expect(lines(8, 0)).toEqual({ lines: [1, 2], hidden: 6 });+ it('shows at least five brands when the brand is near the top', () => {+ expect(lines(8, 0)).toEqual({ lines: [1, 2, 3, 4, 5], hidden: 3 });+ expect(lines(8, 1)).toEqual({ lines: [1, 2, 3, 4, 5], hidden: 3 });+ expect(lines(8, 2)).toEqual({ lines: [1, 2, 3, 4, 5], hidden: 3 });+ expect(lines(8, 3)).toEqual({ lines: [1, 2, 3, 4, 5], hidden: 3 });});- it('shows the brand directly ahead when last', () => {- expect(lines(8, 7)).toEqual({ lines: [1, 2, '4 more', 7, 8], hidden: 4 });+ it('shows the brand directly ahead when last, and fills up from the top', () => {+ expect(lines(8, 7)).toEqual({ lines: [1, 2, 3, '3 more', 7, 8], hidden: 3 });+ // One brand in between is shown, not folded into "1 more".+ expect(lines(6, 5)).toEqual({ lines: [1, 2, 3, 4, 5, 6], hidden: 0 });+ expect(lines(20, 4)).toEqual({ lines: [1, 2, 3, 4, 5, 6], hidden: 14 });});it('lists short boards whole, and starts from the top without the brand', () => {diff --git a/web/src/lib/insights-summary.ts b/web/src/lib/insights-summary.tsindex 0679af466..c13706687 100644--- a/web/src/lib/insights-summary.ts+++ b/web/src/lib/insights-summary.ts@@ -162,7 +162,7 @@ export function rankSummary(// ─── Leaderboard (VIS-004) ──────────────────────────────────────────────────-/** Up to this many brands, the leaderboard lists them all. */+/** Up to this many brands, the leaderboard lists them all; past it, it shows at least this many. */const LEADERBOARD_SHOW_ALL_UP_TO = 5;/** A leaderboard line: a brand (its index in rank order), or "n more" skipped brands. */@@ -171,21 +171,29 @@ export type LeaderboardItem = { kind: 'brand'; index: number } | { kind: 'more';/*** The leaderboard's lines as in the v2 mockup: ranks 1 and 2, then the brand* directly ahead of yours, yours and the one directly behind, with "n more"- * where brands are skipped in between. `hidden` counts every brand left out,- * for "Show all"; short lists, or one without the brand, start from the top.+ * where two or more brands are skipped in between. Never fewer than five+ * brands: a brand near the top or at the bottom fills up with the next ranks+ * from the top, and yours is always there. `hidden` counts every brand left out, for "Show+ * all"; short lists, or one without the brand, start from the top.*/export function leaderboardLines(count: number,ownIndex: number,): { items: LeaderboardItem[]; hidden: number } {- const shown =- count <= LEADERBOARD_SHOW_ALL_UP_TO- ? [...Array(count).keys()]- : ownIndex < 0- ? [...Array(LEADERBOARD_SHOW_ALL_UP_TO).keys()]- : [...new Set([0, 1, ownIndex - 1, ownIndex, ownIndex + 1])]- .filter((i) => i >= 0 && i < count)- .sort((a, b) => a - b);+ let shown: number[];+ if (count <= LEADERBOARD_SHOW_ALL_UP_TO) {+ shown = [...Array(count).keys()];+ } else if (ownIndex < 0) {+ shown = [...Array(LEADERBOARD_SHOW_ALL_UP_TO).keys()];+ } else {+ const picked = new Set(+ [0, 1, ownIndex - 1, ownIndex, ownIndex + 1].filter((i) => i >= 0 && i < count),+ );+ for (let i = 0; picked.size < LEADERBOARD_SHOW_ALL_UP_TO; i++) picked.add(i);+ // A single brand between two shown takes the line "1 more" would: show it.+ for (const i of [...picked]) if (picked.has(i + 2)) picked.add(i + 1);+ shown = [...picked].sort((a, b) => a - b);+ }const items: LeaderboardItem[] = [];shown.forEach((index, n) => {