Skip to content

feat(prompts): stop tracking prompts in a location - #1731

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompt-locations-remove
Oct 29, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompt-locations-remove

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Tracked Prompts could add locations to many prompts at once (#1657), but nothing stopped tracking a prompt in a location. This adds the way back, with the same scopes and the same plan arithmetic.

  • Locations dialog: Add | Remove. In Remove mode:
    • the locations the chosen prompts are tracked in show as chips, each with how many of those prompts track it (aria-label "Germany, tracked by 2 prompts");
    • same scopes as Add: one prompt, the selected, a topic, or all shown;
    • preview before saving: "Removes X tracked locations from N prompts · frees Y plan locations". A paused prompt's location counts in X but not in Y;
    • prompts tracked only in the chosen locations are skipped and named ("… so they keep them"), since a prompt keeps at least one location, as the server's blocked count already enforces;
    • "Past results stay; tracking stops from the next run." Checked against the code: apply_prompt_locations (00074) only rewrites regions, no trigger deletes results, and the tracking worker re-reads the prompts at the start of each job. A job already running finishes its list.
    • Preview and save use the same planBulkLocationChange; the save is bulkUpdatePromptLocations(ids, 'remove', locs).
  • Locations view:
    • each location column's header has a "…" menu with Stop tracking in (opens Remove with it chosen);
    • each tracked cell shows a small × on hover or keyboard focus (Stop tracking here, one prompt). It isn't shown for a prompt's last location, and it isn't clickable while hidden, so a tap on a touch screen still opens the cell's Positions panel.
  • Table view: the bulk bar's location button becomes Locations ▾ › Add locations / Remove locations.
  • Plan gate: every opener goes through guard, so a read-only or demo workspace gets the plan dialog. That now includes the Locations view's existing + Track and + Add location, which weren't gated. The dialog's save always clears its spinner.
  • Server: bulkUpdatePromptLocations checks location codes only when adding, so a code that's no longer valid (a city dropped from the list) can still be removed.
  • Docs: docs/guides/prompts.mdx gets a "Removing locations" section; the "No engine here" note links to it.

Follow-ups (not here): the dialog's usage bar doesn't yet show the share a removal frees (the number line does), and trackedLocations repeats matrixLocations with counts; they could share a helper.

Related issue

None (PROMPT-015 follow-up, reported in the product).

Type of change

  • feat — New feature

How to test

  1. Track a prompt in two locations (e.g. US and DE). In Tracked Prompts › Locations, hover its DE cell: × → Stop tracking here → the preview says 1 location from 1 prompt, 1 plan location freed → save. The DE cell empties from the next run; past DE results stay in the location filter.
  2. On a column header's "…" menu, choose Stop tracking in DE: Remove opens with DE chosen for all shown prompts. Prompts tracked only in DE are listed as kept.
  3. Table view: select a few prompts → Locations ▾ › Remove locations.
  4. On a workspace whose plan has ended (or the demo brand), every one of these opens the plan dialog.
  5. Check both themes at 1024 px.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web, first commit: yarn lint (0 errors), yarn typecheck and yarn build pass. yarn test 555/557 files; the Content Editor page and before-publish tests timed out under load (known). After the review fixes: tsc --noEmit, eslint, prettier, and the prompts folder + actions/prompt tests (14 files, 138 tests) pass.
  • Tests added: dialog (Remove mode, chips by scope, last-location rule, paused prompt, error path), matrix (column menu, cell × doesn't open the panel, none on a last location), page (all six openers gated when read-only), server (removing an unknown code, keeping the last location)
  • The embed guard from test(web): fail on an embed between twice-joined tables that doesn't name its foreign key #1714 passes on this branch
  • Docs updated
  • Pre-PR review done; its findings are fixed in this branch
  • Browser: the dialog, column menu, cell × and bulk menu were checked at 1024 px in both themes on the first commit. The review fixes are covered by tests.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 29, 2026 00:54
The locations dialog gets Add | Remove. Remove offers the locations the
prompts shown track (with how many track each), the same scopes, and a
preview of the tracked locations it removes and the plan locations it
frees; a prompt left with no location keeps it and is counted. The
preview and the save run planBulkLocationChange, as adding does.

Openers: a column "..." menu in the Locations view (Stop tracking in
<location>), a hover/focus x on each tracked cell (Stop tracking here,
one prompt), and a Locations > Add / Remove menu in the bulk bar. The
new openers go through the read-only guard. Past results stay: the RPC
only rewrites prompts.regions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Locations view: + Track and + Add location open the upgrade dialog on a
  read-only workspace, like the column menu, the cell's x and the bulk bar.
- The cell's x is clickable only while it shows (no unseen taps on touch
  screens) and is left off a prompt's last location.
- The Remove chips count the prompts chosen, keep a pick when the prompts
  change, and tell screen readers what the number counts.
- The dialog's save resets its button even when the write is refused.
- bulkUpdatePromptLocations checks location codes only when adding, so a
  code no list names any more can still be stopped.

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 221cc74.

Approve preview

… list per prompt

A removal's codes aren't checked against the known locations, so the list
can be long; planBulkLocationChange now keeps them in a set.

@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 9fd9e85: I made one small change on top.

What I changed

  • planBulkLocationChange checked each prompt's locations against the list to remove by scanning that list. Since this PR, a removal's codes are no longer checked against the known locations (rightly, so that a dropped city can still be taken off). That means the list can be as long as a request body allows. With 60,000 codes and 2,000 prompts, one save took about 5 s of server time. The codes to remove are now kept in a set, and the same case takes a few milliseconds. A test pins it: it fails on the PR's head at about 5,300 ms and passes with the change.

What I checked

  • Plan arithmetic. Preview and save both run planBulkLocationChange, and the server re-reads regions and is_active instead of trusting the client. "Removes X" is the sum of the changes' negative deltas, paused prompts included. "Frees Y" is -change.delta, which only counts active prompts. That matches org_prompt_location_usage, where paused prompts don't count. A prompt that would be left with no location is skipped and counted (blocked), and apply_prompt_locations still refuses an empty list. Removing never reaches the limit check (plan.delta <= 0), and the dialog's over is off in Remove mode, so an organization that is over its limit after a downgrade can still remove locations.
  • Organization scoping. No change to the read or the write. Prompts are read with the user's client (RLS) and written through apply_prompt_locations, which is security invoker, so a prompt id from another organization reads as nothing and is never written. Removal never charges a plan, so it doesn't matter which organization's plan the batch is measured against.
  • Validation. Only additions are checked with isValidLocation. A removal can only take codes out of a prompt's own list, so an unknown code just changes nothing.
  • Read-only workspace. bulkUpdatePromptLocations still starts with assertWritable(). All six openers go through guard (including + Track and + Add location, which weren't gated before). The dialog's finally clears the spinner when the action rejects. subscription-guard-coverage.test.ts passes on this branch merged with #1730 and main.
  • Past results. Nothing deletes prompt_results. The worker reads regions again at the start of each job, so "Past results stay; tracking stops from the next run" is accurate.
  • The cell's × is only shown when the prompt has another location, and it can't be clicked while it's hidden (pointer-events-none until hover or focus).
  • No migration. No PostgREST embeds, server actions or routes are added.
  • Tests on the branch: the prompts folder, actions/prompt, prompt-locations, tracking-countries, components/dashboard and the subscription guard tests pass (180 tests; 168 on the merge with #1730). tsc passes, and prettier and eslint pass on the touched files.

Follow-ups

  1. The chips and the matrix use the stored codes as they are, while the server upper-cases the codes it is sent. A prompt whose stored code isn't upper-case (from an older write path) would show a chip that removes nothing. Comparing case-insensitively in planBulkLocationChange would cover it.
  2. The column menu's Stop tracking in acts on the selected prompts when any are selected, not on all the prompts shown. The docs say so ("or the selected ones"), but the PR description doesn't.
  3. The ones the PR lists: the usage bar doesn't show the share a removal frees, and trackedLocations duplicates matrixLocations.

@gkhngyk
gkhngyk merged commit b220449 into ansvisor:main Oct 29, 2026
5 of 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