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
This commit is contained in:
1 parent
f9052884ba
commit
eb82ab84cc
19 files changed
+113
-233
No files matched your search
@@ -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<void>;
|
||||
onRequestRenameTab?: (key: string, label: string) => void;
|
||||
@@ -352,7 +350,6 @@ export const ChatList = memo(function ChatList({
|
||||
);
|
||||
const [paneDropTarget, setPaneDropTarget] = useState<string | null>(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<string | null>(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({
|
||||
<div
|
||||
ref={selectionBarRef}
|
||||
data-testid="delete-selection-bar"
|
||||
aria-busy={deleteConfirmationPending}
|
||||
className="sticky bottom-2 z-30 mx-1 mt-3 flex min-h-11 items-center gap-1 rounded-floating border border-sidebar-border/80 bg-popover/95 p-1.5 pl-3 shadow-[0_10px_30px_rgba(15,23,42,0.14)] backdrop-blur-xl"
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate pr-2 text-[12.5px] font-medium text-foreground/85">
|
||||
@@ -1221,7 +1207,7 @@ export const ChatList = memo(function ChatList({
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t(allSelectedArchived ? "chat.unarchive" : "chat.archive")}
|
||||
disabled={selectedDeleteKeys.size === 0 || deleteConfirmationPending}
|
||||
disabled={selectedDeleteKeys.size === 0}
|
||||
onClick={() => setPendingArchive({
|
||||
keys: selectedArchiveKeys,
|
||||
archive: !allSelectedArchived,
|
||||
@@ -1238,8 +1224,11 @@ export const ChatList = memo(function ChatList({
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t("chat.delete")}
|
||||
disabled={selectedDeleteKeys.size === 0 || deleteConfirmationPending}
|
||||
onClick={confirmDeleteSelection}
|
||||
disabled={selectedDeleteKeys.size === 0}
|
||||
onClick={() => {
|
||||
requestDeleteKeys(Array.from(selectedDeleteKeys));
|
||||
closeDeleteSelection();
|
||||
}}
|
||||
className="touch-target inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-destructive transition-colors media-hover:hover:bg-destructive/10 disabled:pointer-events-none disabled:opacity-40"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" aria-hidden />
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { TOAST_ACTION_MS } from "@/components/ui/toast";
|
||||
import type { TFunction } from "i18next";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -20,7 +19,7 @@ interface DeleteConfirmProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
count?: number;
|
||||
automations?: SessionAutomationJob[];
|
||||
automations: SessionAutomationJob[];
|
||||
onCancel: () => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
@@ -29,13 +28,12 @@ export function DeleteConfirm({
|
||||
open,
|
||||
title,
|
||||
count = 1,
|
||||
automations = [],
|
||||
automations,
|
||||
onCancel,
|
||||
onConfirm,
|
||||
}: DeleteConfirmProps) {
|
||||
const { t } = useTranslation();
|
||||
const locale = currentLocale();
|
||||
const hasAutomations = automations.length > 0;
|
||||
const multiple = count > 1;
|
||||
const visibleAutomations = automations.slice(0, 4);
|
||||
const hiddenCount = Math.max(0, automations.length - visibleAutomations.length);
|
||||
@@ -60,38 +58,34 @@ export function DeleteConfirm({
|
||||
: t("deleteConfirm.title", { title })}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription className="mt-3 max-w-[17rem] text-center text-[14px] leading-6 text-muted-foreground">
|
||||
{hasAutomations
|
||||
? multiple
|
||||
? t("deleteConfirm.automationsDescriptionMany", {
|
||||
defaultValue: "Linked automations will also be deleted.",
|
||||
})
|
||||
: t("deleteConfirm.automationsDescription")
|
||||
: t("toast.deleteWindow", { seconds: TOAST_ACTION_MS / 1_000 })}
|
||||
{multiple
|
||||
? t("deleteConfirm.automationsDescriptionMany", {
|
||||
defaultValue: "Linked automations will also be deleted.",
|
||||
})
|
||||
: t("deleteConfirm.automationsDescription")}
|
||||
</AlertDialogDescription>
|
||||
{hasAutomations ? (
|
||||
<div className="mt-4 max-h-40 w-full overflow-y-auto rounded-2xl bg-muted/55 px-3 py-2 text-left">
|
||||
{visibleAutomations.map((job) => (
|
||||
<div key={job.id} className="min-w-0 py-1.5">
|
||||
<div className="truncate text-[13px] font-medium leading-5 text-foreground">
|
||||
{job.name || job.id}
|
||||
</div>
|
||||
<div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-[11.5px] leading-5 text-muted-foreground">
|
||||
<span className="truncate">
|
||||
{formatAutomationSchedule(job, t, locale)}
|
||||
</span>
|
||||
<span className="truncate">{formatAutomationNextRun(job, t, locale)}</span>
|
||||
</div>
|
||||
<div className="mt-4 max-h-40 w-full overflow-y-auto rounded-2xl bg-muted/55 px-3 py-2 text-left">
|
||||
{visibleAutomations.map((job) => (
|
||||
<div key={job.id} className="min-w-0 py-1.5">
|
||||
<div className="truncate text-[13px] font-medium leading-5 text-foreground">
|
||||
{job.name || job.id}
|
||||
</div>
|
||||
))}
|
||||
{hiddenCount > 0 ? (
|
||||
<div className="text-[13px] leading-6 text-muted-foreground">
|
||||
{t("deleteConfirm.moreAutomations", {
|
||||
count: hiddenCount,
|
||||
})}
|
||||
<div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-[11.5px] leading-5 text-muted-foreground">
|
||||
<span className="truncate">
|
||||
{formatAutomationSchedule(job, t, locale)}
|
||||
</span>
|
||||
<span className="truncate">{formatAutomationNextRun(job, t, locale)}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
{hiddenCount > 0 ? (
|
||||
<div className="text-[13px] leading-6 text-muted-foreground">
|
||||
{t("deleteConfirm.moreAutomations", {
|
||||
count: hiddenCount,
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="mt-6 !grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<AlertDialogCancel
|
||||
@@ -104,9 +98,7 @@ export function DeleteConfirm({
|
||||
onClick={onConfirm}
|
||||
className="w-full min-w-0 !whitespace-normal bg-destructive text-center text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{hasAutomations
|
||||
? t("deleteConfirm.confirmWithAutomations")
|
||||
: t("deleteConfirm.confirm")}
|
||||
{t("deleteConfirm.confirm")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
|
||||
@@ -12,7 +12,6 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
ChatList,
|
||||
type SidebarDeleteDecision,
|
||||
type SidebarDeleteItem,
|
||||
type SidebarPaneGroup,
|
||||
} from "@/components/ChatList";
|
||||
@@ -42,8 +41,8 @@ interface SidebarProps {
|
||||
onNewChat: () => void;
|
||||
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<void>;
|
||||
onRequestRenameTab?: (key: string, label: string) => void;
|
||||
|
||||
Reference in new issue
Block a user