Skip to content

feat(prompts): retarget a selection of prompts in one go - #786

Merged
gkhngyk merged 1 commit into
mainfrom
feature/bulk-prompt-locations
Aug 25, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/bulk-prompt-locations

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

#783 made a prompt's tracking locations editable — one card at a time. A brand with 310 prompts needed 310 edits to start tracking Germany, which is precisely the operation multi-location targeting exists for.

The brand's prompt page now has a Locations dialog beside Analyze Prompts (same select-from-a-list shape that dialog already uses): choose add or remove, choose the locations, choose the prompts.

Add/remove, not assign. A selection can hold prompts targeting different places, so assigning one list to all of them would erase that targeting silently. Adding a location a prompt already has costs nothing and writes nothing.

No prompt is left with zero locations. A removal that would empty a prompt skips it and reports how many stayed — a prompt with no location cannot be tracked at all, and refusing the whole batch because one prompt of forty is single-location would be worse than saying which ones held.

Cost is on screen before the click: how many prompts change, how many locations that adds, and where that lands against the plan cap. The dialog prices it with planBulkLocationChange and the server action enforces it with the same function, so the preview and the guard cannot disagree.

The batch cannot land half-applied. The cap is measured once for the whole selection and the write goes out as one statement (apply_prompt_locations, migration 00074, already applied). Looping the single-prompt action would check the cap once per prompt and could stop part-way through — a partly-retargeted selection plus a bill for whatever landed before the limit bit. Current locations are re-read server-side rather than taken from the caller: the quota arithmetic must not rest on numbers the client supplied.

Two smaller things fell out of it: the reads chunk their id lists at 100 (a few hundred UUIDs in a PostgREST query string overruns the request line long before the row cap matters), and LocationPicker gained optional label / countNoun / allowEmpty props so the dialog can reuse it for choosing locations rather than holding a prompt's own.

Related issue

Follow-up to #691 — the bulk editing gap left after #783.

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. cd web && yarn test — 191 pass, including 9 new cases for the planner (append order, already-present no-op, the never-empty rule, batch pricing, case normalization).
  2. Brand → Prompts → Locations: add a country, select a few prompts. The preview reads e.g. "3 prompts will change · +3 locations (128 of 200 used)". Apply, then confirm the chips on those cards.
  3. Add the same location again with the same prompts selected: preview says nothing to change, Apply is disabled.
  4. Switch to Remove and remove a location that some selected prompts hold as their only one: those are reported as keeping it, the rest lose it, and capacity frees immediately.
  5. Near the plan cap, a batch that would cross it is refused with the location math spelled out, and nothing is written.
  6. Self-host (IS_CLOUD unset): no cap is shown or enforced.

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

Locations became editable per prompt in #783, one card at a time. A brand
with 310 prompts needed 310 edits to start tracking Germany, which is
the operation multi-location targeting exists for.

The brand's prompt page gets a Locations dialog beside Analyze Prompts:
pick add or remove, pick the locations, pick the prompts. It adds and
removes rather than assigning a list, because a selection can hold
prompts targeting different places and assigning one list to all of them
would erase that targeting without saying so. Adding a location a prompt
already has costs nothing, and a removal that would leave a prompt with
no location at all skips it and says how many stayed — a prompt with no
location cannot be tracked, and refusing the whole batch over one
single-location prompt would be worse than reporting it.

Cost is on screen before the click: how many prompts change, how many
locations that adds, and where it lands against the plan. The dialog
prices the change with planBulkLocationChange and the server action
enforces it with the same function, so the preview and the guard cannot
disagree.

The cap is measured once for the batch and the write goes out as a
single statement (apply_prompt_locations, 00074, applied). Looping the
single-prompt action would check the cap per prompt and could stop
half-way, leaving a partly-retargeted selection and a bill for whatever
landed first. Current locations are re-read server-side: quota
arithmetic must not rest on numbers the client sent.
@gkhngyk gkhngyk added prompts Prompt management, suggestions, query fan-out needs-migration Adds or edits a migration — apply it to the hosted database labels Aug 25, 2026
@gkhngyk
gkhngyk merged commit 46a2015 into main Aug 25, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the feature/bulk-prompt-locations branch August 25, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database prompts Prompt management, suggestions, query fan-out

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant