Skip to content

feat(prompts): add locations to many prompts at once, priced before saving, with more countries (PROMPT-015, part 3) - #1657

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

gkhngyk merged 26 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-add-locations

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

PROMPT-015, part 3 of 6: add locations to many prompts at once, with the plan usage shown before saving, and more countries.

Stacked on #1656. This PR's own change is its commits after part 2's.

Track in more locations, opened from the Locations view's + Add location or from a cell's + Track:

  • Pick countries or US states, and the prompts to ask there: the one clicked, the selected ones, a topic, or all shown.
  • Plan usage shows the used → after count of the plan's prompt locations before anything is saved. It uses the same arithmetic the save enforces (planBulkLocationChange, bulkUpdatePromptLocations); the server checks the limit again.
  • Past the limit, the dialog says what the choice needs and what is left, with the plan's way out (Starter: upgrade or a custom plan; Growth: a custom plan; Enterprise: raise the limit). Save stays off.
  • Pre-push review fix (cbc56ce): from a cell whose prompt is no longer shown, the dialog used to add the location to every shown prompt. It now targets none, says to choose the prompts, and keeps Save off.
  • Saving doesn't start tracking: the next daily run asks there, and it skips workspaces whose plan ended (feat(server): stop every automatic process for a workspace whose plan ended #1608).

More countries: prompts can be tracked in about 50 countries (TRACKING_COUNTRIES), up from 18. A brand's own region keeps the shorter list that volumes and audits read.

PromptLimitActions moves to its own file, because a page can't export it.

Where people see it: Prompts › Tracked Prompts › Locations › + Add location, or + Track in a cell.

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. Locations › + Add location: pick 2 countries and "All shown". Plan usage shows used → after. Save, and the new columns say "Within 24h" (part 6).
  2. On a plan near its limit, pick more: the dialog names the need, and Save stays off.
  3. cd web && npx vitest run src/app/[locale]/(dashboard)/dashboard/prompts/_add-locations-dialog.test.tsx src/lib/prompt-locations.test.ts

Browser check: local, 1024 px.

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 19 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]>
…aving, with more countries (PROMPT-015, part 3)

PROMPT-015c. Track in more locations, from the Locations view's
+ Add location or a cell's + Track:
- pick countries or US states (LocationPicker), and the prompts to ask
  there: the one clicked, the selected, a topic, or all shown;
- Plan usage shows used → after of the plan's prompt locations before
  anything is saved, with the same arithmetic the save enforces
  (planBulkLocationChange, bulkUpdatePromptLocations);
- past the limit the dialog says what the choice needs and what is left,
  with the plan's way out (Starter: upgrade or a custom plan; Growth: a
  custom plan; Enterprise: raise the limit), and Save stays off.

Prompts can be tracked in about 50 countries (TRACKING_COUNTRIES), not 18;
a brand's own region keeps the shorter list that volumes and audits read.
PromptLimitActions moves to its own file (a page can't export it).

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]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…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]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…o longer shown, not to every prompt (PROMPT-015, part 3)

Track in more locations opened from a Locations view cell fell back to
every prompt shown when the cell's prompt had left the rows. It now
targets none, says to choose the prompts, and keeps the save button off
until a scope is picked.

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 da382c7.

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. Item 1 is about release order: merge it together with #1659 (part 5).

What I checked

  • Own diff. 8cb4811d..518770c1 (#1656's head to this one): _add-locations-dialog.tsx and its tests, PromptLimitActions moved to its own file, the Locations view's + Add location and + Track, TRACKING_COUNTRIES in prompt-options.ts, region.ts and the location picker, en.json and the guide. The whole stack up to here merges on 8356ba3 with only supabase/schema.sql conflicting (from #1655).
  • Plan cap, server side. The dialog saves through the existing bulkUpdatePromptLocations. It re-reads each prompt's locations under the caller's RLS, measures the change with planBulkLocationChange (paused prompts take no room), checks it against the organization's usage and plan (locationLimitMessage), and writes in one apply_prompt_locations call. The dialog's preview runs the same arithmetic, so what it shows is what the save checks. A client that skips the dialog still hits the cap.
  • Targets. From a cell whose prompt is no longer shown, the dialog targets no prompt and keeps Save off (cbc56ce, tested). The other scopes are the selection, one topic, or every row the filters keep.
  • Countries. isValidLocation and regionLabel now take about 50 countries. A brand's own region still uses the 18 in REGIONS, which volumes and audits read. The API takes any two-letter country (server/src/lib/locations.js), so the new codes reach the engines as they are.
  • Copy. Plural and select forms in addLocations.* are well-formed, and the over-limit text names what's needed, what's left, and the plan's way out.
  • Tests and checks. The PR's tests pass (_add-locations-dialog, prompt-locations, region, the location picker, and the prompts folder: 17 files, 142 tests). Web tsc is clean. eslint and prettier are clean on the touched files. On the stack merged into 8356ba3 (schema.sql aside), web tsc is clean and the same tests plus the insights folder pass (22 files, 171 tests).

Follow-ups

  1. Not every engine answers from every new country. This PR offers all ~50 countries for every engine. 00364 (#1659) says the provider supports a different set per engine, and asking an engine in an unsupported country fails. Until #1659 is merged and 00364 is applied, a prompt added in such a country fails for that engine on every daily run. Merge the stack through #1659 together, and apply 00364 before the next daily run. The comment at prompt-options.ts:26-28 ("more markets every tracking engine answers from") should say the same.
  2. Save is on while plan usage loads. _add-locations-dialog.tsx:112 treats an unread quota (still loading, or the read failed) as unlimited, so Save is enabled and no over-limit warning shows. The server still refuses past the cap, so nothing gets through, but the person sees the refusal only after Save. Keep Save off until the quota is read, and say so if the read fails.
  3. Already listed in the description: the read-only guard (#1599) on + Add location and + Track, and a confirm step with "≈N runs a day" for big adds.

Rollout

None of its own. Needs #1655's 00363, and see item 1 for #1659.

@gkhngyk
gkhngyk merged commit 0bb8512 into ansvisor:main Oct 28, 2026
2 of 3 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