Skip to content

feat(prompts): move Topics into the Prompts area as its Topics tab - #1107

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-by-topic
Oct 17, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-by-topic

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Topics moves into the Prompts area as its second tab, at /dashboard/prompts/topics. The old address keeps working through a redirect.

Stacked on #1106. This branch is built on #1106 (the date-ranged topics overview and migration 00156). Its diff includes #1106's commit until that merges. Please merge #1106 first.

What changes

  • Tabs: Prompts – Topics – Query Fan-out – Insights.
  • Sidebar: Topics becomes a child of the Prompts submenu, under Prompt Suggestions. The top-level Topics item goes, and its place between Prompts and Citations is left for Mentions.
    • A child also stays highlighted on its own sub-pages, so a topic's page lights Topics.
  • Routes:
    • /dashboard/prompts/topics is the new route. It re-exports the Prompts page, like tracked, suggestions, fan-outs and insights (PROMPT-001). lib/prompts-routes.ts gains the section.
    • A topic's page moves to /dashboard/prompts/topics/<id>.
    • /dashboard/topics and /dashboard/topics/<id> redirect there, so bookmarks, shared links and older builds keep working.
  • Links updated:
    • the Insights topic heat map;
    • the Action Center topic gap and topic opportunity contexts;
    • the topic page's back button;
    • revalidatePath after accepting a topic suggestion;
    • the docs (guides/topics.mdx, concepts/topics-and-prompts.mdx).
  • Date range: the tab uses the page's range (24h / 7d / 30d / 90d / custom, 24h by default), which fix(topics): read the overview over a date range, fast enough not to time out #1106 gave the overview. Location is hidden on this tab, because topics are not split by location.
  • No cost to the other tabs:
    • The tab loads as its own chunk (next/dynamic), only when it is shown.
    • Opened on Topics, the page holds back the prompts table's reads until the topics are in, or until another tab opens.
  • The stall: tab and view switches now write their route before the next tab mounts (showSection).
    • Next 16.1.6 turns a history.replaceState into a router "restore". A restore that lands while a server action is in flight leaves the action queue pointing at the discarded action, so the actions queued after it never run, and the table spins forever.
    • Writing the route first lets the next tab's reads start on an idle queue.
  • Copy: the tab and the sidebar child read "Topics" (nav.topics). The old page's own header keys (topics.title, topics.description) are removed.

Known limit

  • Switching tabs within about half a second of opening Topics, while its first read is in flight, can still leave the table spinning.
  • This is the Next.js bug above. Main has it too, on quick tab or range switches.
  • It is fixed upstream in Next 16.3.0 and later: chore(web): upgrade next to 16.4.2 #1108 upgrades Next to 16.4.2. Merging it before or with this PR removes the limit (checked: 6 of 6 quick switches from Topics loaded the table on chore(web): upgrade next to 16.4.2 #1108).

Related issue

None. Follows #1106.

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. Apply 00156 (from fix(topics): read the overview over a date range, fast enough not to time out #1106).
  2. Open /dashboard/topics. It lands on /dashboard/prompts/topics:
    • the tabs are Prompts, Topics, Query Fan-out, Insights;
    • the range is 24h;
    • there is no Location selector.
  3. Switch between 24h, 7d, 30d, 90d and Custom. The figures follow the range, and the URL carries ?range=.
  4. Open a topic: its page is at /dashboard/prompts/topics/<id>, and Topics returns to the tab. An old /dashboard/topics/<id> link lands on the same page.
  5. In the sidebar, Prompts holds Tracked Prompts, Prompt Suggestions, Topics, Query Fan-outs and Insights. There is no top-level Topics item.
  6. From the Insights topic heat map, or an Action Center topic action's Open topic, you land on the new address.
  7. Move between Prompts, Topics and the other tabs: each loads.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web: yarn test (864) and yarn build pass.

  • Tests:

    • topics/page.test.ts: both redirects, and an id staying within its own path segment;
    • lib/prompts-routes.test.ts: the topics section, and a topic's page not counted as a section;
    • lib/dashboard-navigation.test.ts: the Prompts children's order and Topics' route, and no top-level /dashboard/topics.
  • In the browser, on a production build with demo data:

    • the redirects;
    • every range on the tab, including quick switches (the table ends on the last range picked);
    • Topics → Prompts → Topics;
    • checked at 1440px and 1024px, in the light and dark themes.
  • Review: a code review raised these, now fixed:

    • stale comments;
    • unused translation keys;
    • the docs' "Topics page";
    • a derivable effect;
    • the untested redirects.

    The Next.js stall is noted above.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 17, 2026 01:04
…time out

The Topics page failed to load on the largest brand: its overview,
topics_overview_aggregates (00057, 00098), scans 30 days of answers as
the caller under RLS and ran past the authenticated role's 8 s statement
timeout, so the request ended in a 500 after ~9 s and the page read
"Failed to load topics".

Migration 00156 adds topics_overview_window(brand, from, to): a window
under two days reads its answers directly; a longer one reads whole UTC
days from the rollups the Insights page reads (insights_prompt_daily,
insights_competitor_prompt_daily), and each topic's last answer from the
covering index. It is plpgsql with force_custom_plan and work_mem, and
security definer with the organization check made explicit, as 00152 and
00153 are. The change compares the window with the one of the same
length before it, and the trend has a point per day (none under two
days, where the cell shows only the change).

The page gets the Prompts page's date range (24h, 7d, 30d, 90d,
custom), opening on 24 hours. Custom dates read as whole UTC days, a
newer range's answer is never overwritten by an older one's, the roster
and the aggregate are read in parallel, and the CSV names its range. A
web build deployed before the migration falls back to the old function
(PGRST202).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Topics becomes the Prompts page's second tab (Prompts, Topics, Query
Fan-out, Insights) at /dashboard/prompts/topics, and a child of the
sidebar's Prompts submenu under Prompt Suggestions. The top-level Topics
item goes; /dashboard/topics and /dashboard/topics/<id> redirect to the
new routes, and in-app links (Insights heat map, Action Center topic
contexts, the topic page's back button, revalidatePath) point there.

The tab shares the page's date range (24h by default) and hides Location,
which doesn't apply to topics. It loads as its own chunk only when shown,
and the page holds back the prompts table's reads until the topics are in
or another tab opens, so the other tabs' first load is unchanged.

Tab and view switches write their route before the next tab mounts:
Next 16.1.6 drops server actions queued behind a history "restore" that
lands while one is in flight.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is ready for review. It's stacked on #1106, so please merge that one (and apply its migration 00156) first. The tab-switch stall noted under Known limit is a Next.js 16.1.6 bug that main has too; I'll propose the Next upgrade in a separate PR.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 17, 2026

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

Reviewed. Merged main into the branch: the sidebar drops its Topics item for the Prompts submenu entry and keeps main's Mentions item. /dashboard/topics and /dashboard/topics/[id] redirect the way the other dashboard redirects do. Tested on the full prompts chain.

@gkhngyk
gkhngyk merged commit 139e9b1 into ansvisor:main Oct 17, 2026
4 of 5 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