Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions apps/web/src/components/nosql-explorer/connection-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import type { Locale } from "date-fns";
import { cn } from "@/lib/utils";
import { useTranslations, useLocale } from "next-intl";
import { af, ar, ca, cs as csLocale, da, de, el, enUS, es, faIR, fr as frLocale, ms, nb, nl, pt, zhCN } from "date-fns/locale";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";

interface ConnectionFormProps {
onConnect: (connectionString: string) => Promise<void>;
Expand All @@ -41,6 +51,7 @@ export function ConnectionForm({ onConnect, loading, error }: ConnectionFormProp
const [isLoadingConnections, setIsLoadingConnections] = useState(false);
const [isTesting, setIsTesting] = useState(false);
const [editingId, setEditingId] = useState<string | null>(null);
const [deleteConnDialog, setDeleteConnDialog] = useState<{ open: boolean; id: string | null }>({ open: false, id: null });

useEffect(() => {
if (user) {
Expand Down Expand Up @@ -124,16 +135,22 @@ export function ConnectionForm({ onConnect, loading, error }: ConnectionFormProp

const handleDeleteConnection = async (e: React.MouseEvent, id: string) => {
e.stopPropagation();
if (!user) return;
if (!confirm(t("confirmDelete"))) return;
setDeleteConnDialog({ open: true, id });
};

const confirmDeleteConnection = async () => {
const id = deleteConnDialog.id;
if (!user || !id) return;

try {
await deleteConnection(user.uid, id);
toast.success(t("toastDeletedConn"));
if (editingId === id) handleCancelEdit();
loadConnections();
await loadConnections();
} catch (error) {
toast.error(t("toastDeleteFail"));
} finally {
setDeleteConnDialog({ open: false, id: null });
}
};

Expand Down Expand Up @@ -313,6 +330,21 @@ export function ConnectionForm({ onConnect, loading, error }: ConnectionFormProp
</CardContent>
</Card>
</div>

<AlertDialog open={deleteConnDialog.open} onOpenChange={(open) => setDeleteConnDialog(prev => ({ ...prev, open }))}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t("confirmDelete")}</AlertDialogTitle>
<AlertDialogDescription>{t("toastDeletedConn")}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("cancel")}</AlertDialogCancel>
<AlertDialogAction onClick={confirmDeleteConnection} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
{t("menuDeleteConnection")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
9 changes: 3 additions & 6 deletions apps/web/src/components/nosql-explorer/explorer-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ export function ExplorerSidebar({
}
};

const handleDeleteConnection = async (index: number) => {
const handleDeleteConnection = (index: number) => {
setDeleteConnDialog({ open: true, index });
return;
};

const confirmDeleteConnection = async () => {
Expand All @@ -289,9 +288,8 @@ export function ExplorerSidebar({
}
};

const handleDropDatabase = async (connIndex: number, dbName: string) => {
const handleDropDatabase = (connIndex: number, dbName: string) => {
setDropDbDialog({ open: true, connIndex, dbName });
return;
};

const confirmDropDatabase = async () => {
Expand All @@ -315,9 +313,8 @@ export function ExplorerSidebar({
}
};

const handleDropCollection = async (connIndex: number, dbName: string, collectionName: string) => {
const handleDropCollection = (connIndex: number, dbName: string, collectionName: string) => {
setDropCollDialog({ open: true, connIndex, dbName, collectionName });
return;
};

const confirmDropCollection = async () => {
Expand Down