Repository navigation
feat(prompts): delete a topic from the Topics tab, admins and managers only - #1779
Merged
Merged
Conversation
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]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
What I checked
- Role on the server.
deleteTopicnow reads the caller'sprofiles.roleand 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
deleteTopicruns 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.
- The row menu shows only for
- What a delete does in the database (all as on main; the PR doesn't change it):
prompts.topic_id,prompt_suggestions.topic_idandtopic_suggestions.added_topic_idareON DELETE SET NULL. Prompts keep their results and become prompts without a topic, as the dialog says.- The
SET NULLonprompts.topic_idfiresprompts_queue_citation_rollup_rebuild, so the citation rollups that carrytopic_idare queued for a rebuild. prompt_clustersandprompt_cluster_scopesfor that topic areON DELETE CASCADE, so the topic's fan-out clusters go. Its prompts are clustered again under "no topic" when that scope's fingerprint changes.deleteTopicalso clearsprompts.categorywhere 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.tsxandtopic.test.tspass. Webtsc, eslint and prettier pass on the touched files. The full web suite passes with this PR merged with main.
Follow-ups (not blocking)
- 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.
deleteTopicmakes 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.
5 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
on delete set null, and theprompt_clusterscache is rebuilt.useUpgradeGate).Server:
deleteTopicnow 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 featurefix— Bug fix (deleteTopichad no role check)How to test
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
🤖 Generated with Claude Code