Skip to content

feat(content): filter opportunities by prompt - #854

Merged
gkhngyk merged 1 commit into
mainfrom
feature/content-prompt-filter
Sep 29, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/content-prompt-filter

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #836.

Content opportunities are generated per prompt, but the Content page could only filter them by status, impact, type and free text. On larger brands the list runs past 100 opportunities spread across 20–80 prompts, so answering "what should I publish to show up for this prompt?" meant scrolling or guessing search terms.

Server

  • GET /api/content/brand/:brandId accepts prompt_id as an equality filter.
  • The summary cards above the list come from content_opportunity_aggregates. It gains a p_prompt_id parameter (migration 00099) so the cards describe the filtered list rather than the whole brand.
    • The five-argument version is dropped instead of overloaded, because PostgREST would find two candidates for the same named arguments.
    • The new parameter defaults to NULL, so existing callers are unaffected. The migration is already applied to production.
  • New GET /api/content/brand/:brandId/prompts returns the brand's prompts that have opportunities, each with its count, most first. It pages past PostgREST's 1,000-row cap. Opportunities whose prompt was deleted are left out, since there is nothing to name them by.
  • The brand list route now checks the caller's access to the brand, as the other content routes already do.

Web

  • A searchable prompt picker sits next to the Status / Impact / Type selects. It uses the same Combobox pattern as the Citations filter bar, and each option shows its opportunity count.
  • The picker appears when a brand's opportunities span two or more prompts, or while a prompt filter is set, so it can still be cleared.
  • The selection persists as ?prompt=<id>, so a filtered view can be linked to.
    • The page reads the parameter before its first load, so a linked view does not flash the unfiltered list.
    • An id that matches none of the brand's prompts (another brand's, or a deleted prompt) is dropped.
  • Clear resets the prompt filter, and the filter is part of the pager key. The prompt counts refresh after a generation run.
  • With no prompt picked, "All prompts" is selected as a real value rather than shown as a placeholder, so it matches the neighbouring selects.

Related issue

Closes #836

Type of change

  • New feature

How to test

  1. Open /dashboard/content for a brand whose opportunities span several prompts. The prompt picker shows "All prompts" in the same weight as the other selects.
  2. Pick a prompt. The list, total, pagination and summary cards all narrow to that prompt.
  3. Reload the page: the ?prompt= selection is kept. Clear brings the full list back and removes the parameter.
  4. Search inside the picker: options filter as you type, and each shows its count.
  5. Switch to another brand: the previous brand's prompt filter is dropped.
  6. On a brand whose opportunities all belong to one prompt, the picker is not shown.

Checklist

  • yarn build, yarn lint (no new warnings) and yarn format:check pass from web/
  • yarn test (854 passed) and yarn lint pass from server/
  • Migration 00099 applied via MCP and committed; supabase/schema.sql regenerated
  • Aggregate checked against production data: with a prompt filter it matches a direct count for that prompt, and without one it still returns the whole brand

🤖 Generated with Claude Code

Opportunities are generated per prompt, but the Content page could only
filter by status, impact, type and text. On larger brands the list runs
past 100 opportunities across 20-80 prompts, so finding what to publish
for one prompt meant scrolling or guessing search terms (#836).

- GET /api/content/brand/:brandId takes prompt_id, and the summary
  aggregate takes the same filter (content_opportunity_aggregates gains
  p_prompt_id, migration 00099) so the cards describe the filtered list.
- GET /api/content/brand/:brandId/prompts lists the brand's prompts that
  have opportunities, with counts, paged past PostgREST's 1,000-row cap.
- The Content page gets a searchable prompt picker next to the other
  filters, shown when opportunities span two or more prompts. The pick
  persists as ?prompt=<id>, is part of Clear, and an id that matches no
  prompt of the brand is dropped.

The brand list route now also checks the caller's access to the brand,
like the other content routes.

Closes #836
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Sep 29, 2026
@gkhngyk
gkhngyk merged commit 8446240 into main Sep 29, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/content-prompt-filter branch September 29, 2026 17:49
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(content): filter opportunities by prompt

1 participant