Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: add delete all thread inside projects

Faisal Amirf21efb36e558
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 9f133b1c2..126066934 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -1351,7 +1351,7 @@ const ChatInput = ({
<div
className={cn(
- 'relative z-20 px-0 pb-10 border rounded-3xl border-input dark:bg-input/30',
+ 'relative z-20 px-0 pb-10 border rounded-3xl border-input bg-white dark:bg-input/30',
isFocused && 'ring-1 ring-ring/50',
isDragOver && 'ring-2 ring-ring/50 border-primary'
)}
diff --git a/web-app/src/containers/dialogs/DeleteAllThreadsInProjectDialog.tsx b/web-app/src/containers/dialogs/DeleteAllThreadsInProjectDialog.tsx
new file mode 100644
index 000000000..f51e26c9f
--- /dev/null
+++ b/web-app/src/containers/dialogs/DeleteAllThreadsInProjectDialog.tsx
@@ -0,0 +1,101 @@
+import { useState, useRef } from 'react'
+import { useTranslation } from '@/i18n/react-i18next-compat'
+import {
+ Dialog,
+ DialogTrigger,
+ DialogContent,
+ DialogTitle,
+ DialogDescription,
+ DialogClose,
+ DialogFooter,
+ DialogHeader,
+} from '@/components/ui/dialog'
+import { Button } from '@/components/ui/button'
+import { IconTrash } from '@tabler/icons-react'
+import { DropdownMenuItem } from '@/components/ui/dropdown-menu'
+import { toast } from 'sonner'
+
+interface DeleteAllThreadsInProjectDialogProps {
+ projectName: string
+ threadCount: number
+ onDeleteAll: () => void
+ onDropdownClose?: () => void
+}
+
+export function DeleteAllThreadsInProjectDialog({
+ projectName,
+ threadCount,
+ onDeleteAll,
+ onDropdownClose,
+}: DeleteAllThreadsInProjectDialogProps) {
+ const { t } = useTranslation()
+ const [isOpen, setIsOpen] = useState(false)
+ const deleteButtonRef = useRef<HTMLButtonElement>(null)
+
+ const handleOpenChange = (open: boolean) => {
+ setIsOpen(open)
+ if (!open && onDropdownClose) {
+ onDropdownClose()
+ }
+ }
+
+ const handleDeleteAll = () => {
+ onDeleteAll()
+ setIsOpen(false)
+ if (onDropdownClose) onDropdownClose()
+ toast.success(t('common:toast.deleteAllThreads.title'), {
+ id: 'delete-all-threads-in-project',
+ description: t('common:toast.deleteAllThreads.description'),
+ })
+ }
+
+ const handleKeyDown = (e: React.KeyboardEvent) => {
+ if (e.key === 'Enter') {
+ handleDeleteAll()
+ }
+ }
+
+ return (
+ <Dialog open={isOpen} onOpenChange={handleOpenChange}>
+ <DialogTrigger asChild>
+ <DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
+ <IconTrash size={16} />
+ <span>{t('common:deleteAll')}</span>
+ </DropdownMenuItem>
+ </DialogTrigger>
+ <DialogContent
+ onOpenAutoFocus={(e) => {
+ e.preventDefault()
+ deleteButtonRef.current?.focus()
+ }}
+ >
+ <DialogHeader>
+ <DialogTitle>
+ {t('common:dialogs.deleteAllThreadsInProject.title')}
+ </DialogTitle>
+ <DialogDescription>
+ {t('common:dialogs.deleteAllThreadsInProject.description', { projectName, count: threadCount })}
+ </DialogDescription>
+ <DialogFooter className="flex flex-col-reverse sm:flex-row sm:justify-end gap-2">
+ <DialogClose asChild>
+ <Button variant="ghost" size="sm" className="w-full sm:w-auto">
+ {t('common:cancel')}
+ </Button>
+ </DialogClose>
+ <Button
+ ref={deleteButtonRef}
+ variant="destructive"
+ onClick={handleDeleteAll}
+ onKeyDown={handleKeyDown}
+ size="sm"
+ className="w-full sm:w-auto"
+ aria-label={t('common:deleteAll')}
+ >
+ {t('common:deleteAll')}
+ </Button>
+ </DialogFooter>
+ </DialogHeader>
+ </DialogContent>
+ </Dialog>
+ )
+}
\ No newline at end of file
diff --git a/web-app/src/hooks/useThreads.ts b/web-app/src/hooks/useThreads.ts
index 76b5c2c81..3e079a65a 100644
--- a/web-app/src/hooks/useThreads.ts
+++ b/web-app/src/hooks/useThreads.ts
@@ -32,6 +32,7 @@ type ThreadState = {
updateCurrentThreadAssistant: (assistant: Assistant) => void
updateThreadTimestamp: (threadId: string) => void
updateThread: (threadId: string, updates: Partial<Thread>) => void
+ deleteAllThreadsByProject: (projectId: string) => void
searchIndex: Fzf<Thread[]> | null
}
@@ -217,6 +218,41 @@ export const useThreads = create<ThreadState>()((set, get) => ({
}
})
},
+ deleteAllThreadsByProject: (projectId) => {
+ set((state) => {
+ const allThreadIds = Object.keys(state.threads)
+
+ // Identify threads belonging to this project
+ const threadsToDeleteIds = allThreadIds.filter(
+ (threadId) =>
+ state.threads[threadId].metadata?.project?.id === projectId
+ )
+
+ // Delete threads and clean up their vector DB collections
+ threadsToDeleteIds.forEach((threadId) => {
+ cleanupVectorDB(threadId)
+ getServiceHub().threads().deleteThread(threadId)
+ })
+
+ // Keep threads that don't belong to this project
+ const remainingThreads = allThreadIds
+ .filter((threadId) => !threadsToDeleteIds.includes(threadId))
+ .reduce(
+ (acc, threadId) => {
+ acc[threadId] = state.threads[threadId]
+ return acc
+ },
+ {} as Record<string, Thread>
+ )
+
+ return {
+ threads: remainingThreads,
+ searchIndex: new Fzf<Thread[]>(Object.values(remainingThreads).filter(t => t.id !== TEMPORARY_CHAT_ID), {
+ selector: (item: Thread) => item.title,
+ }),
+ }
+ })
+ },
unstarAllThreads: () => {
set((state) => {
const updatedThreads = Object.keys(state.threads).reduce(
diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.json
index 57a4817e1..764f68a67 100644
--- a/web-app/src/locales/en/common.json
+++ b/web-app/src/locales/en/common.json
@@ -234,6 +234,10 @@
"title": "Delete All Threads",
"description": "All threads will be deleted. This action cannot be undone."
},
+ "deleteAllThreadsInProject": {
+ "title": "Delete All Conversations",
+ "description": "{{count}} conversations in \"{{projectName}}\" will be deleted. This action cannot be undone."
+ },
"deleteThread": {
"description": "Are you sure you want to delete this thread? This action cannot be undone."
},
diff --git a/web-app/src/routes/project/$projectId.tsx b/web-app/src/routes/project/$projectId.tsx
index 5151dd88a..a7a840b22 100644
--- a/web-app/src/routes/project/$projectId.tsx
+++ b/web-app/src/routes/project/$projectId.tsx
@@ -24,6 +24,7 @@ import {
import { Button } from '@/components/ui/button'
import AddProjectDialog from '@/containers/dialogs/AddProjectDialog'
import { DeleteProjectDialog } from '@/containers/dialogs/DeleteProjectDialog'
+import { DeleteAllThreadsInProjectDialog } from '@/containers/dialogs/DeleteAllThreadsInProjectDialog'
import { SidebarMenu } from '@/components/ui/sidebar'
export const Route = createFileRoute('/project/$projectId')({
@@ -35,10 +36,12 @@ function ProjectPageContent() {
const { projectId } = useParams({ from: '/project/$projectId' })
const { getFolderById, updateFolder } = useThreadManagement()
const threads = useThreads((state) => state.threads)
+ const deleteAllThreadsByProject = useThreads((state) => state.deleteAllThreadsByProject)
const { assistants } = useAssistant()
const [editDialogOpen, setEditDialogOpen] = useState(false)
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
+ const [dropdownOpen, setDropdownOpen] = useState(false)
// Find the project
const project = getFolderById(projectId)
@@ -63,6 +66,10 @@ function ProjectPageContent() {
}
}
+ const handleDeleteAllThreads = () => {
+ deleteAllThreadsByProject(projectId)
+ }
+
if (!project) {
return (
<div className="flex h-full flex-col items-center justify-center">
@@ -129,9 +136,27 @@ function ProjectPageContent() {
{/* Conversation Section */}
{projectThreads.length > 0 && (
<div className="flex flex-col mb-6">
- <h2 className="text-base font-medium mb-4">
- {t('projects.conversation')}
- </h2>
+ <div className="flex items-center justify-between gap-2 mb-4">
+ <h2 className="text-base font-medium">
+ {t('projects.conversation')}
+ </h2>
+ <DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs">
+ <MoreHorizontal className="size-4" />
+ <span className="sr-only">More options</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="right" align="start">
+ <DeleteAllThreadsInProjectDialog
+ projectName={project.name}
+ threadCount={projectThreads.length}
+ onDeleteAll={handleDeleteAllThreads}
+ onDropdownClose={() => setDropdownOpen(false)}
+ />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
<SidebarMenu>
<ThreadList
threads={projectThreads}