Skip to content

feat(prompts): compare each tracked prompt across its locations in a Locations view (PROMPT-015, part 2) - #1656

Merged
gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-locations-view
Oct 28, 2026
Merged

gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-locations-view

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

PROMPT-015, part 2 of 6: a Locations view that compares each tracked prompt across its locations.

Stacked on #1655. This PR's own change is its commits after part 1's.

  • A Table | Locations switch above Tracked Prompts.
  • Locations shows each prompt in each location the brand tracks, side by side:
    • one metric at a time: Visibility, Position, Mentions or Citations;
    • an average row and a Gap column (best location minus worst);
    • three cards: the weakest location, the strongest location, and the prompt that differs most between locations.
  • Cells use Brand Visibility's "Topics vs competitors" shades. HEAT_SHADES moved beside heatShade so both views share them.
  • A cell opens the prompt's Positions panel filtered to that location.
  • Columns (part 1) can add " · " columns to the table.
  • getPromptLocationMatrix reads each location with the table's own reads (visibility summaries and position sums). So a location's numbers equal the table filtered to that location. No migration.

Speed and load (the pre-push review fixes are in 56c9c02 and ba50673):

  • the server runs at most 3 heavy reads at a time (web/src/lib/limiter.ts, tested);
  • the page sends one matrix read at a time, including the read-ahead when the Locations button is hovered or focused;
  • each location's figures are cached for a minute on their own, so adding a location column reads only that location;
  • the cache is cleared after a prompt is paused, resumed, deleted or edited;
  • measured locally: the matrix read takes about 0.7 s, and Locations opens in about 0.1 s after a read-ahead.

Where people see it: Prompts › Tracked Prompts › Locations.

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 Tracked Prompts › Locations with a few prompts tracked in 2 or more countries. Switch the metric between Visibility, Position, Mentions and Citations. Check:
    • the average row and the Gap column;
    • the three cards;
    • a cell opens the Positions panel on that location.
  2. Use Columns › add "Visibility · ": the table gets that column, and only that location is read.
  3. cd web && npx vitest run src/lib/limiter.test.ts src/lib/prompt-location-matrix.test.ts

Browser check: local, 1024 px, light and dark (30-day range). The table scrolls inside its card and the page doesn't overflow.

Related issue

PROMPT-015 (location matrix and custom columns), spec and mockup in Drive › Prompt. No GitHub issue.

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

Full checks at the top of the stack (part 6, 29f649d):

  • server format, lint and npm test: 248 files, 3,364 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (453 files, 4,403 tests) and build: all pass;
  • schema.sql matches build-schema.sh.

A pre-push review found 9 issues; all are fixed in this stack (the fix(...) commits). Migrations 00363 and 00364 are applied on the dev database.

Follow-ups, not in this stack:

🤖 Generated with Claude Code

cihan-gyk and others added 13 commits October 28, 2026 03:46
…columns, and share them with the brand (PROMPT-015, part 1)

PROMPT-015a. A Columns panel beside the table's search:
- show or hide every column but Prompt, and reorder them by dragging or with
  the arrows;
- saved per person and brand (00363 prompt_table_views, RLS);
- an admin or manager can share their columns with everyone on the brand,
  who see them until they change their own;
- Reset goes back to the brand's view, or the default.

Nobody who never opens Columns sees a change: the default is today's
columns in today's order. The table builds its header and cells by column
id, unchanged inside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Locations view (PROMPT-015, part 2)

PROMPT-015b. A Table | Locations switch above Tracked Prompts:
- Locations shows each prompt in each location the brand tracks, side by
  side: Visibility, Position, Mentions or Citations; an average row; a Gap
  column (best minus worst location); and three cards: the weakest and
  strongest location and the prompt that differs most between them.
- Cells use Brand Visibility's Topics vs competitors shades (HEAT_SHADES,
  moved beside heatShade). A cell opens the prompt's Positions panel on that
  location; a location the prompt isn't tracked in offers + Track (its Edit
  dialog for now).
- The Columns panel can add "<metric> · <location>" columns to the table.
- getPromptLocationMatrix reads each location with the table's own reads
  (visibility summaries, position sums), side by side, so a location's
  numbers equal the table filtered to it. No migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… brand (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ound of reads (PROMPT-015, part 2)

The user's bar: data within 1–2 s of a choice. Measured locally (dev, hosted
dev DB) the matrix read took 1.4–1.8 s.
- getPromptLocationMatrix starts every read at once: the plan's engines no
  longer wait in front of the locations' reads.
- A matrix read stays a minute in the browser (loadLocationMatrix), so going
  Table ↔ Locations, or back to a location column, reads nothing again;
  switching the metric was already in the browser.
- The Locations button reads ahead on hover or focus, so the view opens on
  data already there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…their own view with the brand (PROMPT-015, part 1)

Someone looking at the brand's shared view without one of their own
changed it with every click: a member got "Only admins and managers can
share" errors, and a manager hiding one column changed it for everyone.
Changes now update the brand's view only after an admin or manager
shared their own, which sharing now also saves as theirs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ations-view

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.tsx
… and each location once a minute (PROMPT-015, part 2)

Up to twelve locations ran two heavy aggregates each, all at once, on
every open, every read-ahead on hover and every new location column.
The server now runs at most three of them at a time, the page sends one
read at a time, read-ahead included, and each location's figures are
kept for a minute on their own, so a new location column reads only its
location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed, resumed, deleted or edited (PROMPT-015, part 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a promise (PROMPT-015, part 2)

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

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 10f843e.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) through the stack; no new conflicts on this branch. Typecheck and lint pass on the chain tip.

@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, with follow-ups.

Nothing blocks the merge. No migration; it needs #1655's 00363 (it's stacked on it).

What I checked

  • Own diff. 293a00b2..8cb4811d (#1655's head to this one): getPromptLocationMatrix and the getPositionRows split in prompt.ts, prompt-location-matrix.ts, limiter.ts, the location column ids in prompt-table-columns.ts and the save schema, _location-matrix.tsx, the Columns panel's location columns, the page's layout switch, HEAT_SHADES moved beside heatShade, en.json and the guide. The whole stack up to here merges on 8356ba3 with only supabase/schema.sql conflicting (from #1655).
  • Reads and scoping. The matrix reads each location with the table's own reads (prompt_visibility_summaries and prompt_position_summaries_json) through the caller's client, so another organization's brand reads nothing. The brand id is checked as a UUID, locations are filtered with isValidLocation and capped at 12, and the engines counted for Position come from the brand's own plan.
  • Load. The server runs at most 3 of a matrix read's database reads at once (createLimiter, tested for order and the cap). The page sends one matrix read at a time, the hover/focus read-ahead included, and keeps each location's figures for a minute, so adding a location column reads only that location. Pausing, resuming, deleting or editing prompts clears that cache (reloadAfterChange).
  • Saved views. Location column ids are loc:<metric>:<code> with an anchored, bounded pattern. The save takes at most 12 + 8 ids, the reader keeps at most 8 location columns and drops hidden ids that aren't in the order. The 8 KB check in 00363 still bounds the row.
  • Rendering. The shades use only the current page's values (inView), so shading is linear in the cells shown. The averages, Gap and the three cards are linear in prompts × locations.
  • Speed. The only new pattern is the anchored location column id (^loc:(…):([A-Za-z0-9~_-]{2,64})$), linear on any input. No regex or loop runs over prompt or answer text.
  • Tests and checks. The PR's tests pass (limiter, prompt-location-matrix, _location-matrix, _columns-panel, prompt-table-columns, prompt.test.ts, and the insights heatmap tests after the HEAT_SHADES move: 20 files, 136 tests). Web tsc is clean. eslint and prettier are clean on the touched files.

Follow-ups

  1. The guide names the wrong roles for + Track. docs/guides/prompts.mdx:60 says + Track shows "for admins, managers and analysts". The page passes onEditPrompt only when canManage (page.tsx:2142), so analysts don't get it. Say "for admins and managers".
  2. A big brand's matrix costs up to 12 × the table's read. prompt_visibility_summaries is read through readAllRpcRows, which re-runs the aggregate for every 1,000 prompts. So a brand with 3,000 prompts in 12 locations runs it 36 times, plus 12 position sums, when Locations opens. The 3-at-a-time cap keeps it from piling up. If it shows in the database's load, return the summaries as one jsonb value, as 00153 did for positions.
  3. Until #1657 lands, + Track opens the prompt's edit dialog without the clicked location. #1657 replaces it with Track in more locations, so merge the two together.

Rollout

None beyond #1655's: 00363 must be applied first.

@gkhngyk
gkhngyk merged commit 29051ea into ansvisor:main Oct 28, 2026
5 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
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