Skip to content

feat(prompts): delete a topic from the Topics tab, admins and managers only - #1779

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/topic-delete
Oct 29, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/topic-delete

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Customer feedback: "There's no way to delete a topic I added." There was one, but only on the brand page's Topics list (/dashboard/brands/[id]/topics, reached from "Manage topics"). The Topics tab people actually use (/dashboard/prompts/topics) had no row actions.

Topics tab

  • Row menu: each row gets a "…" menu with a red Delete topic, shown to admins and managers only.
  • Confirmation: the dialog reads the topic's prompt count from the server, paused prompts included, and says the prompts stay: they keep tracking and results, and become topic-less. Prompts, suggestions and topic suggestions point at the topic with on delete set null, and the prompt_clusters cache is rebuilt.
  • Undo: the row hides at once and the delete runs after 10 s, so Undo changes nothing in the database. This is how deleting a prompt already works on the Prompts tab.
  • Read-only: in a read-only workspace, the menu item opens the plan dialog (useUpgradeGate).

Server: deleteTopic now refuses anyone but admins and managers. This is the product owner's role model of 2026-10-29: deletes are for admins and managers. RLS still lets every member delete a topic, but the app no longer does.

Docs: docs/guides/prompts.mdx › Topics gets one sentence on deleting.

Related issue

None (customer feedback).

Type of change

  • feat — New feature
  • fix — Bug fix (deleteTopic had no role check)

How to test

  1. As an admin, go to Prompts › Topics, open a row's "…" and choose Delete topic. The dialog shows the prompt count. Confirm, and the row goes, with Undo for 10 s. After that, the topic's prompts show with no topic.
  2. As an analyst, no "…" menu shows.
  3. Tests: cd web && yarn vitest run 'src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.test.tsx' src/lib/actions/topic.test.ts. 10 new tests cover admin delete, no menu for analysts, the count, prompts kept, Undo, the error path and read-only.

Screenshots

Checked locally at 1024 px in light and dark mode. The "…" first pushed the table 10 px wider; the last cell's padding is narrowed.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: the related test files (26 tests) pass; prettier, eslint and typecheck clean
  • Browser check (1024 px, light and dark)
  • Full suite and build: CI

🤖 Generated with Claude Code

A customer couldn't find how to delete a topic: the Topics tab had no
row actions, and the only delete was in the brand page's Topics list
behind "Manage topics".

Each leaderboard row now has a "…" menu with Delete topic, for admins
and managers. The dialog counts every prompt in the topic, paused ones
too, and says they aren't deleted: they keep their tracking and results
and become prompts without a topic (prompts.topic_id is ON DELETE SET
NULL). The row hides at once and the topic is deleted after a 10-second
Undo window, as the Prompts tab deletes prompts. On a read-only
workspace the menu item opens the plan dialog.

deleteTopic now refuses anyone but an admin or a manager: the topics
table's row rules let every member write.

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

mintlify Bot commented Oct 29, 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 bbc864f.

Approve preview

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

What I checked

  • Role on the server. deleteTopic now reads the caller's profiles.role and refuses anyone but an admin or a manager (MANAGER_ROLES) before it reads or writes anything. assertWritable() still comes first.
    • The topic is read under the caller's RLS, so another workspace's topic id is "not found".
    • The other caller, the brand page's Topics list, already shows Delete only to canManage (admin/manager). So nobody loses a button they could use.
  • The UI.
    • The row menu shows only for canManage. On a read-only workspace it opens the plan dialog (guard(…, deleteTopics)).
    • The dialog counts every prompt in the topic with getPromptCountByTopic, paused ones too. If that read fails, it shows a sentence without a number. Confirm stays disabled while it counts.
    • The row hides at once, and deleteTopic runs after the 10 s Undo window. Undo only clears the timer, so nothing changes in the database.
    • When the tab unmounts inside the window, the pending delete is sent rather than dropped, as the Prompts tab does.
    • A failed delete puts the row back and shows a toast.
    • The duplicate-name check on Add Topic still sees a topic whose delete is pending.
  • What a delete does in the database (all as on main; the PR doesn't change it):
    • prompts.topic_id, prompt_suggestions.topic_id and topic_suggestions.added_topic_id are ON DELETE SET NULL. Prompts keep their results and become prompts without a topic, as the dialog says.
    • The SET NULL on prompts.topic_id fires prompts_queue_citation_rollup_rebuild, so the citation rollups that carry topic_id are queued for a rebuild.
    • prompt_clusters and prompt_cluster_scopes for that topic are ON DELETE CASCADE, so the topic's fan-out clusters go. Its prompts are clustered again under "no topic" when that scope's fingerprint changes.
    • deleteTopic also clears prompts.category where it equals the topic's name (old behaviour).
  • Docs (guides/prompts.mdx) match the behaviour.
  • Merges clean on current main. No migration, no PostgREST embeds.
  • Tests: _topics-tab.test.tsx and topic.test.ts pass. Web tsc, eslint and prettier pass on the touched files. The full web suite passes with this PR merged with main.

Follow-ups (not blocking)

  1. The dialog says the prompts "keep their tracking and results". It could also say that the topic's prompt clusters (fan-out intents) are rebuilt under "no topic", since they're deleted with it.
  2. deleteTopic makes three round trips before the delete (user, profile, topic). That's fine for a single click. If this is ever reused in a bulk delete, read the role once.

@gkhngyk
gkhngyk merged commit 0da45a3 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