Skip to content

feat(content): show prompt's observed query fan-outs in Source Data (#392) - #405

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:feat/prompt-fanout-in-source-data
Jul 11, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:feat/prompt-fanout-in-source-data

Conversation

@Maqbool61

Copy link
Copy Markdown
Contributor

Summary

Closes #392

Adds an Observed fan-out queries block to the Source Data card on
/dashboard/content/[id], showing the sub-queries answer engines
actually ran when answering this opportunity's prompt — first-hand
demand signal for content writers.

Changes

web/src/lib/actions/fanout.ts

Added getPromptFanout(brandId, promptId, opts?) — a new server action
that filters prompt_results by both brand_id and prompt_id (30-day
rolling window by default, clamped to MAX_FANOUT_DAYS). Aggregation is
identical to getQueryFanout: normalize whitespace/case, dedupe per
answer row so one answer counts once per sub-query, count distinct
answers. Returns QueryFanoutData — no sourcedPrompts/tracked fields
needed for this display-only context.

web/src/app/[locale]/(dashboard)/dashboard/content/[id]/page.tsx

  • Import getPromptFanout and FanoutSubQuery from fanout.ts
  • Add fanoutQueries: FanoutSubQuery[] state (default [])
  • Inside the existing getOpportunity().then() block, load fan-out when
    opp.brandId and opp.promptId are both present; errors caught
    silently so a missing fan-out never breaks the page load
  • Render fan-out chips (violet, consistent with the Keywords style) below
    the Keywords block — each chip shows the sub-query text and a
    ×{timesSearched} count
  • Block is hidden entirely when fanoutQueries is empty

Acceptance criteria

  • Source Data card shows observed fan-out sub-queries with
    times-searched count when data exists
  • Block is hidden when the prompt has no captured fan-outs
  • Aggregation matches Query Fan-out tab semantics
    (same normalizeQuery + per-answer dedup + distinct answer count)
  • No layout regression when block is absent — purely conditional,
    sits between existing Keywords and Competitors Cited blocks

…392)

Adds an 'Observed fan-out queries' block to the Source Data card on
the content opportunity detail page (/dashboard/content/[id]).

Changes:
- web/src/lib/actions/fanout.ts: add getPromptFanout(brandId, promptId)
  server action — filters prompt_results by both brand_id and prompt_id,
  applies the same normalise/dedupe/count-distinct-answers aggregation as
  getQueryFanout, returns QueryFanoutData

- web/src/app/[locale]/(dashboard)/dashboard/content/[id]/page.tsx:
  - import getPromptFanout and FanoutSubQuery
  - add fanoutQueries state (FanoutSubQuery[])
  - load fan-out inside existing getOpportunity().then() when
    opp.brandId and opp.promptId are present; errors caught silently
  - render fan-out chips (violet) below Keywords block, each showing
    query text + times-searched count
  - block hidden entirely when fanoutQueries is empty

Closes #392

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

Verified the aggregation matches getQueryFanout and all acceptance criteria from #392 are met. CI is green. Thanks!

@gkhngyk
gkhngyk merged commit 47abf40 into ansvisor:main Jul 11, 2026
4 checks passed
@Maqbool61
Maqbool61 deleted the feat/prompt-fanout-in-source-data branch July 11, 2026 15:14
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.

feat(content): show the related prompt's observed query fan-outs in the opportunity's Source Data

2 participants