Feature request: Add delete confirmation dialog to file manager
- Added confirmation dialog before deleting files/folders - Users must confirm deletion with a warning message - Works for both Delete key and right-click delete - Shows different messages for single file, folder, or multiple items - Includes permanent deletion warning - Follows existing design patterns using confirmWithToast
This commit is contained in:
@@ -844,8 +844,12 @@
|
|||||||
"selectServerToEdit": "Select a server from the sidebar to start editing files",
|
"selectServerToEdit": "Select a server from the sidebar to start editing files",
|
||||||
"fileOperations": "File Operations",
|
"fileOperations": "File Operations",
|
||||||
"confirmDeleteMessage": "Are you sure you want to delete <strong>{{name}}</strong>?",
|
"confirmDeleteMessage": "Are you sure you want to delete <strong>{{name}}</strong>?",
|
||||||
|
"confirmDeleteSingleItem": "Are you sure you want to permanently delete \"{{name}}\"?",
|
||||||
|
"confirmDeleteMultipleItems": "Are you sure you want to permanently delete {{count}} items?",
|
||||||
|
"confirmDeleteFolder": "Are you sure you want to permanently delete the folder \"{{name}}\" and all its contents?",
|
||||||
"deleteDirectoryWarning": "This will delete the folder and all its contents.",
|
"deleteDirectoryWarning": "This will delete the folder and all its contents.",
|
||||||
"actionCannotBeUndone": "This action cannot be undone.",
|
"actionCannotBeUndone": "This action cannot be undone.",
|
||||||
|
"permanentDeleteWarning": "This action cannot be undone. The item(s) will be permanently deleted from the server.",
|
||||||
"recent": "Recent",
|
"recent": "Recent",
|
||||||
"pinned": "Pinned",
|
"pinned": "Pinned",
|
||||||
"folderShortcuts": "Folder Shortcuts",
|
"folderShortcuts": "Folder Shortcuts",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { FileWindow } from "./components/FileWindow";
|
|||||||
import { DiffWindow } from "./components/DiffWindow";
|
import { DiffWindow } from "./components/DiffWindow";
|
||||||
import { useDragToDesktop } from "../../../hooks/useDragToDesktop";
|
import { useDragToDesktop } from "../../../hooks/useDragToDesktop";
|
||||||
import { useDragToSystemDesktop } from "../../../hooks/useDragToSystemDesktop";
|
import { useDragToSystemDesktop } from "../../../hooks/useDragToSystemDesktop";
|
||||||
|
import { useConfirmation } from "@/hooks/use-confirmation.ts";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -82,6 +83,7 @@ function formatFileSize(bytes?: number): string {
|
|||||||
function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
||||||
const { openWindow } = useWindowManager();
|
const { openWindow } = useWindowManager();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { confirmWithToast } = useConfirmation();
|
||||||
|
|
||||||
const [currentHost, setCurrentHost] = useState<SSHHost | null>(
|
const [currentHost, setCurrentHost] = useState<SSHHost | null>(
|
||||||
initialHost || null,
|
initialHost || null,
|
||||||
@@ -587,6 +589,32 @@ function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
|||||||
async function handleDeleteFiles(files: FileItem[]) {
|
async function handleDeleteFiles(files: FileItem[]) {
|
||||||
if (!sshSessionId || files.length === 0) return;
|
if (!sshSessionId || files.length === 0) return;
|
||||||
|
|
||||||
|
// Determine the confirmation message based on file count and type
|
||||||
|
let confirmMessage: string;
|
||||||
|
if (files.length === 1) {
|
||||||
|
const file = files[0];
|
||||||
|
if (file.type === "directory") {
|
||||||
|
confirmMessage = t("fileManager.confirmDeleteFolder", {
|
||||||
|
name: file.name,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
confirmMessage = t("fileManager.confirmDeleteSingleItem", {
|
||||||
|
name: file.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
confirmMessage = t("fileManager.confirmDeleteMultipleItems", {
|
||||||
|
count: files.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add permanent deletion warning
|
||||||
|
const fullMessage = `${confirmMessage}\n\n${t("fileManager.permanentDeleteWarning")}`;
|
||||||
|
|
||||||
|
// Show confirmation dialog
|
||||||
|
confirmWithToast(
|
||||||
|
fullMessage,
|
||||||
|
async () => {
|
||||||
try {
|
try {
|
||||||
await ensureSSHConnection();
|
await ensureSSHConnection();
|
||||||
|
|
||||||
@@ -635,6 +663,9 @@ function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
|||||||
}
|
}
|
||||||
console.error("Delete failed:", error);
|
console.error("Delete failed:", error);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"destructive",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCreateNewFolder() {
|
function handleCreateNewFolder() {
|
||||||
|
|||||||
Reference in New Issue
Block a user