Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add delete chat functionality to explorer chats (#49250)

Joshen Limcf2322d1989e
diff --git a/apps/studio/components/interfaces/Explorer/ExplorerChatToolbar.tsx b/apps/studio/components/interfaces/Explorer/ExplorerChatToolbar.tsx
index 0444012d883..14edcaf9f6d 100644
--- a/apps/studio/components/interfaces/Explorer/ExplorerChatToolbar.tsx
+++ b/apps/studio/components/interfaces/Explorer/ExplorerChatToolbar.tsx
@@ -1,4 +1,4 @@
-import { Clipboard, MessageSquare, MoreVertical, Settings } from 'lucide-react'
+import { Clipboard, MessageSquare, MoreVertical, Settings, Trash } from 'lucide-react'
import { useState } from 'react'
import { toast } from 'sonner'
import {
@@ -9,6 +9,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from 'ui'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import {
ExplorerToolbar,
@@ -41,6 +42,7 @@ export const ExplorerChatToolbar = ({
const snap = useAiAssistantStateSnapshot()
const chat = snap.chats[chatId]
const [isOptInModalOpen, setIsOptInModalOpen] = useState(false)
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false)
const handleCopyChatId = () => {
copyToClipboard(chatId, () => toast.success(`Copied chat ID for ${chat?.name}`))
@@ -50,6 +52,12 @@ export const ExplorerChatToolbar = ({
if (name.trim()) snap.renameChat(chatId, name.trim())
}
+ const handleDeleteChat = () => {
+ snap.deleteChat(chatId)
+ setIsDeleteModalOpen(false)
+ toast.success(`Deleted "${chat?.name}"`)
+ }
+
useShortcut(SHORTCUT_IDS.AI_ASSISTANT_COPY_CHAT_ID, handleCopyChatId, {
enabled: shortcutsEnabled && !isChatLoading,
})
@@ -83,7 +91,6 @@ export const ExplorerChatToolbar = ({
sequence={SHORTCUT_DEFINITIONS[SHORTCUT_IDS.AI_ASSISTANT_COPY_CHAT_ID].sequence}
/>
</DropdownMenuItem>
- <DropdownMenuSeparator />
<DropdownMenuItem
className="justify-between"
onClick={() => setIsOptInModalOpen(true)}
@@ -98,10 +105,16 @@ export const ExplorerChatToolbar = ({
}
/>
</DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem className="gap-x-2" onClick={() => setIsDeleteModalOpen(true)}>
+ <Trash size={14} />
+ <span>Delete chat</span>
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</ExplorerToolbarActions>
</ExplorerToolbar>
+
<AIAssistantMetadataWarning
visible={isOptInModalOpen}
onVisibleChange={setIsOptInModalOpen}
@@ -110,6 +123,20 @@ export const ExplorerChatToolbar = ({
isHipaaProjectDisallowed={isHipaaProjectDisallowed}
aiOptInLevel={aiOptInLevel}
/>
+
+ <ConfirmationModal
+ variant="destructive"
+ visible={isDeleteModalOpen}
+ title={`Delete "${chat?.name}"?`}
+ confirmLabel="Delete chat"
+ onCancel={() => setIsDeleteModalOpen(false)}
+ onConfirm={handleDeleteChat}
+ >
+ <p className="text-sm text-foreground-light">
+ This will permanently delete this chat and its message history. This action cannot be
+ undone.
+ </p>
+ </ConfirmationModal>
</div>
)
}