From eb82ab84cc8acdb4f98a7aba32669e08a193681b Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:05:00 +0800 Subject: [PATCH] fix(webui): skip confirmation for undoable topic deletion (#6723) * fix(webui): skip confirmation for undoable topic deletion * refactor(webui): rely on gateway for linked automation confirmation --- docs/webui.md | 4 +- webui/src/App.tsx | 68 ++++--------- webui/src/components/ChatList.tsx | 39 +++----- webui/src/components/DeleteConfirm.tsx | 64 ++++++------- webui/src/components/Sidebar.tsx | 5 +- webui/src/dev/gallery/standalone.tsx | 8 +- webui/src/hooks/useSessions.ts | 9 -- webui/src/i18n/locales/en/common.json | 2 - webui/src/i18n/locales/es/common.json | 2 - webui/src/i18n/locales/fr/common.json | 2 - webui/src/i18n/locales/id/common.json | 2 - webui/src/i18n/locales/ja/common.json | 2 - webui/src/i18n/locales/ko/common.json | 2 - webui/src/i18n/locales/pt-BR/common.json | 2 - webui/src/i18n/locales/vi/common.json | 2 - webui/src/i18n/locales/zh-CN/common.json | 2 - webui/src/i18n/locales/zh-TW/common.json | 2 - webui/src/tests/app-layout.test.tsx | 116 +++++++++-------------- webui/src/tests/chat-list.test.tsx | 13 +-- 19 files changed, 113 insertions(+), 233 deletions(-) diff --git a/docs/webui.md b/docs/webui.md index bd6caa079..e3010056a 100644 --- a/docs/webui.md +++ b/docs/webui.md @@ -95,7 +95,9 @@ If creating or forking a topic times out, it may already have succeeded; it is n Drag topics within a sidebar group to reorder them. **Rename** edits a topic title in place; a failed save keeps the draft for retry. -Use **Select** in a topic's action menu to archive or delete several topics with one confirmation. Click outside the topic rows and toolbar, or press **Esc**, to leave selection mode. Cancelling a confirmation keeps your selection. Archiving removes pins and hides topics from the default list while keeping their conversations. Use **Show archived** to find them again; selecting only archived topics offers **Unarchive**. +Use **Select** in a topic's action menu to archive or delete several topics at once. Click outside the topic rows and toolbar, or press **Esc**, to leave selection mode. Archiving removes pins and hides topics from the default list while keeping their conversations. Use **Show archived** to find them again; selecting only archived topics offers **Unarchive**. + +**Delete** hides topics and gives you 8 seconds to choose **Undo**. When that window ends, topics with linked automations reappear so you can confirm whether to delete them and their automations. ### Conversation groups and panes diff --git a/webui/src/App.tsx b/webui/src/App.tsx index 37890f687..d015fd5c5 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -22,7 +22,7 @@ import { LanguageSwitcher } from "@/components/LanguageSwitcher"; import { SidebarResizeHandle, SIDEBAR_MIN_WIDTH, SIDEBAR_MAX_WIDTH } from "@/components/SidebarResizeHandle"; import { matchSidebarShortcut } from "@/lib/sidebar-shortcuts"; import { invalidateToolsCatalog } from "@/lib/tools-catalog-cache"; -import type { SidebarDeleteDecision, SidebarDeleteItem } from "@/components/ChatList"; +import type { SidebarDeleteItem } from "@/components/ChatList"; import type { SettingsSectionKey } from "@/components/settings/SettingsView"; import { StartupShell } from "@/components/StartupShell"; import { ComposerDraftStore, clearStoredComposerDrafts } from "@/lib/composer-draft"; @@ -831,8 +831,6 @@ type PendingDelete = { id: number; items: SidebarDeleteItem[]; automations: SessionAutomationJob[]; - automationKeys: Set; - onDecision?: SidebarDeleteDecision; }; function restorePinOrder(pins: readonly string[], previous: readonly string[], restoring: ReadonlySet) { @@ -895,7 +893,6 @@ function Shell({ createChat, forkChat, deleteChat, - getSessionAutomations, } = useSessions(); // Failed reads retain an empty list or partial reload cache, not proof of deletion. const sessionsLoaded = !loading && sessionsError === null; @@ -2085,21 +2082,18 @@ function Shell({ refresh, ); - const finishDeleteConfirmation = useCallback((request: PendingDelete, confirmed: boolean) => { - request.onDecision?.(confirmed); - setDeleteQueue((queue) => queue.filter((entry) => entry.id !== request.id)); + const dismissDeleteConfirmation = useCallback((id: number) => { + setDeleteQueue((queue) => queue.filter((entry) => entry.id !== id)); }, []); - const onConfirmDelete = useCallback(() => { - if (!pendingDelete) return; - const { automationKeys } = pendingDelete; - const items = pendingDelete.items.filter((item) => topicSessions.some((session) => session.key === item.key)); - finishDeleteConfirmation(pendingDelete, items.length > 0); + const stageDelete = useCallback((requested: SidebarDeleteItem[], deleteAutomations = false) => { + const items = requested.filter((item) => topicSessions.some((session) => session.key === item.key)); if (!items.length) return; const batchKeys = new Set(items.map((item) => item.key)); setDeletingKeys((current) => new Set([...current, ...batchKeys])); + closeMobileSidebar(); - if (activeKey && batchKeys.has(activeKey)) { + if (view === "chat" && activeKey && batchKeys.has(activeKey)) { const currentIndex = topicSessions.findIndex((session) => session.key === activeKey); const available = new Set(topicSessions.filter((session) => !batchKeys.has(session.key)).map((session) => session.key)); const fallbackKey = activeTabState?.paneKeys.find((key) => available.has(key)) @@ -2117,7 +2111,7 @@ function Shell({ try { for (const item of items) { try { - const result = await deleteChat(item.key, automationKeys.has(item.key) ? { deleteAutomations: true } : undefined); + const result = await deleteChat(item.key, deleteAutomations ? { deleteAutomations: true } : undefined); if (result.deleted) { filePreviewStore.delete(item.key); draftStore.delete(item.key); @@ -2140,7 +2134,6 @@ function Shell({ id: ++nextDeleteId.current, items: blockedItems, automations: blockedJobs, - automationKeys: new Set(blockedItems.map((item) => item.key)), }; setDeleteQueue((queue) => [...queue, confirmation]); } @@ -2156,39 +2149,11 @@ function Shell({ action: { label: t("toast.undo"), run: reveal }, onExpire: () => { void commit(); }, }); - }, [activeKey, activeTabState, deleteChat, draftStore, filePreviewStore, finishDeleteConfirmation, navigate, pendingDelete, showToast, t, topicSessions]); + }, [activeKey, activeTabState, closeMobileSidebar, deleteChat, draftStore, filePreviewStore, navigate, showToast, t, topicSessions, view]); - const onRequestDeleteMany = useCallback(async (items: SidebarDeleteItem[], onDecision?: SidebarDeleteDecision) => { - const uniqueItems = Array.from(new Map(items.filter((item) => !deletingKeys.has(item.key)).map((item) => [item.key, item])).values()); - if (uniqueItems.length === 0) { - onDecision?.(false); - return; - } - const automationResults = await Promise.allSettled(uniqueItems.map((item) => getSessionAutomations(item.key))); - const automationKeys = new Set(); - const automations = automationResults.flatMap((result, index) => { - if (result.status !== "fulfilled" || !result.value.length) return []; - automationKeys.add(uniqueItems[index].key); - return result.value; - }); - let decision = onDecision; - const confirmation: PendingDelete = { - id: ++nextDeleteId.current, - items: uniqueItems, - automations, - automationKeys, - onDecision: (confirmed) => { - const notify = decision; - decision = undefined; - notify?.(confirmed); - }, - }; - setDeleteQueue((queue) => [...queue, confirmation]); - }, [deletingKeys, getSessionAutomations]); - - const onRequestDelete = useCallback((key: string, label: string, onDecision?: SidebarDeleteDecision) => { - void onRequestDeleteMany([{ key, label }], onDecision); - }, [onRequestDeleteMany]); + const onRequestDelete = useCallback((key: string, label: string) => { + stageDelete([{ key, label }]); + }, [stageDelete]); const automaticSidebarSort = sidebarState.view.sort === "manual" ? "updated_desc" @@ -2460,7 +2425,7 @@ function Shell({ onSelect: onSelectSidebarItem, onCloseTemporaryChat, onRequestDelete, - onRequestDeleteMany, + onRequestDeleteMany: stageDelete, onTogglePin, onRequestRename, onToggleArchive, @@ -2858,8 +2823,11 @@ function Shell({ title={pendingDelete.items[0]?.label ?? ""} count={pendingDelete.items.length} automations={pendingDelete.automations} - onCancel={() => finishDeleteConfirmation(pendingDelete, false)} - onConfirm={onConfirmDelete} + onCancel={() => dismissDeleteConfirmation(pendingDelete.id)} + onConfirm={() => { + dismissDeleteConfirmation(pendingDelete.id); + stageDelete(pendingDelete.items, true); + }} /> ) : null} diff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsx index 1a80785d9..d3ffa2de7 100644 --- a/webui/src/components/ChatList.tsx +++ b/webui/src/components/ChatList.tsx @@ -192,8 +192,6 @@ export interface SidebarDeleteItem { label: string; } -export type SidebarDeleteDecision = (confirmed: boolean) => void; - function droppablePaneKey( dataTransfer: DataTransfer, group: SidebarPaneGroup, @@ -231,8 +229,8 @@ interface ChatListProps { activeKey: string | null; onSelect: (key: string) => void; onCloseTemporaryChat?: (key: string) => void; - onRequestDelete: (key: string, label: string, onDecision?: SidebarDeleteDecision) => void; - onRequestDeleteMany?: (items: SidebarDeleteItem[], onDecision?: SidebarDeleteDecision) => void; + onRequestDelete: (key: string, label: string) => void; + onRequestDeleteMany?: (items: SidebarDeleteItem[]) => void; onTogglePin: (key: string) => void; onRequestRename: (key: string, title: string) => Promise; onRequestRenameTab?: (key: string, label: string) => void; @@ -352,7 +350,6 @@ export const ChatList = memo(function ChatList({ ); const [paneDropTarget, setPaneDropTarget] = useState(null); const [deleteSelectionMode, setDeleteSelectionMode] = useState(false); - const [deleteConfirmationPending, setDeleteConfirmationPending] = useState(false); const [pendingArchive, setPendingArchive] = useState<{ keys: string[]; archive: boolean; @@ -378,7 +375,7 @@ export const ChatList = memo(function ChatList({ () => new Set(), ); const deleteSelectionAnchorRef = useRef(null); - const selectionConfirmationPending = pendingArchive !== null || deleteConfirmationPending; + const selectionConfirmationPending = pendingArchive !== null; const closeDeleteSelection = useCallback(() => { setDeleteSelectionMode(false); setSelectedDeleteKeys(new Set()); @@ -691,22 +688,12 @@ export const ChatList = memo(function ChatList({ }); if (!range) deleteSelectionAnchorRef.current = targetKey ?? null; }; - const requestDeleteItems = (items: SidebarDeleteItem[], onDecision?: SidebarDeleteDecision) => { + const requestDeleteKeys = (keys: string[]) => { + const items = keys.map((key) => deleteItemsByKey.get(key)) + .filter((item): item is SidebarDeleteItem => item !== undefined); if (items.length === 0) return; - if (onRequestDeleteMany) onRequestDeleteMany(items, onDecision); - else if (items.length === 1) onRequestDelete(items[0].key, items[0].label, onDecision); - }; - const requestDeleteKeys = (keys: string[], onDecision?: SidebarDeleteDecision) => { - requestDeleteItems(keys - .map((key) => deleteItemsByKey.get(key)) - .filter((item): item is SidebarDeleteItem => item !== undefined), onDecision); - }; - const confirmDeleteSelection = () => { - setDeleteConfirmationPending(true); - requestDeleteKeys(Array.from(selectedDeleteKeys), (confirmed) => { - setDeleteConfirmationPending(false); - if (confirmed) closeDeleteSelection(); - }); + if (onRequestDeleteMany) onRequestDeleteMany(items); + else if (items.length === 1) onRequestDelete(items[0].key, items[0].label); }; const selectedArchiveKeys = Array.from(selectedDeleteKeys).filter((key) => archivableKeys.has(key)); const allSelectedArchived = selectedArchiveKeys.length > 0 @@ -1207,7 +1194,6 @@ export const ChatList = memo(function ChatList({
@@ -1221,7 +1207,7 @@ export const ChatList = memo(function ChatList({