Skip to content

fix(insights): show at least five brands on the leaderboard, yours always among them - #1352

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/insights-leaderboard-rows
Oct 22, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/insights-leaderboard-rows

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Content Editor feedback item 13 (Insights): when competitors are added, the leaderboard should show at least five rows, always with the brand's own rank.

Cause. leaderboardLines showed ranks 1 and 2 plus the brands directly ahead of and behind yours. Near the top those overlap: on production, Ansvisor is rank 2 of 8 at 24h and its leaderboard showed three rows (Profound, Ansvisor, Semrush). At 30d it is rank 6, and five rows showed.

Fix (lib/insights-summary.ts):

  • Past five brands, the board shows at least five. It fills up with the next ranks from the top, and your row is always there.
    • rank 1–4 of 8 → ranks 1–5
    • last of 8 → 1, 2, 3, "3 more", 7, 8
  • A single brand between two shown ones is listed, since "1 more" would take the same line.
    • rank 5 of 20 → 1–6
    • last of 6 → all six
  • Boards of five or fewer, and boards without the brand, are unchanged. "Show all" still lists everyone.

The component is unchanged; it renders leaderboardLines.

Related issue

Content Editor feedback round (no issue).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open Insights at 24h on a brand ranked 1st or 2nd among six or more tracked brands with data (Ansvisor on production today). The leaderboard lists ranks 1–5, with Show all for the rest.
  2. On a brand further down, ranks 1 and 2, "n more", then the brands around yours, as before.
  3. yarn test src/lib/insights-summary.test.ts covers the cases above.

The demo org has only four brands with data, so the longer board can't be shown locally. Adding competitors without data doesn't list them.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: yarn test (2630 tests pass) and yarn build.

🤖 Generated with Claude Code

…ways among them

The leaderboard showed ranks 1 and 2 and the brands around yours, so a brand
near the top saw three rows (rank 2 at 24h on a board of eight). It now
shows at least five, filling up from the top, with your row always there;
a single brand between two shown is listed rather than folded into "1 more".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is a small Insights fix from the feedback round. On production, Ansvisor at 24h is rank 2 of 8 and its leaderboard showed only three rows. It now shows at least five, filled from the top, with your row always included. Only the line-picking function and its tests change.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I checked leaderboardLines (web/src/lib/insights-summary.ts:179-197) against the edge cases:

  • Near the top, or last. The fill loop always ends: past five brands it only adds indexes below count. Your row stays in, and hidden matches what "Show all" adds.
  • Single gaps. Filling a single gap only narrows gaps, so no "1 more" line can appear. The cases 20/4, 6/5 and 8/7 hold, and the old 20/5 case still gives 1, 2, 2 more, 5, 6, 7.
  • Ties. getCompetitorComparison sorts by score, then mentions. JS sort is stable and your brand is pushed first, so it wins exact ties. The board only indexes that order, so nothing changes here.
  • Zero mentions. A competitor that was tracked but never mentioned still has rollup rows. It is listed at the bottom (score —) and counts toward the five. Only a competitor with no tracked answers yet is absent, as the description says.
  • Fewer than five competitors. With five brands or fewer, the board lists everyone, as before.

There is no SQL or RPC change.

Tested on top of main together with #1339–#1341, #1352 and #1337: web and server tests, tsc, lint and Prettier pass.

@gkhngyk
gkhngyk merged commit 7bda17e into ansvisor:main Oct 22, 2026
6 checks passed
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