From 49e6ea33bb91115e1153b8a7d1f0a4abff09b51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Fri, 24 Apr 2026 12:56:13 +0300 Subject: [PATCH] feat: implement ConfirmDialog component and add table truncation functionality to MainContent --- frontend/src/components/ConfirmDialog.tsx | 116 ++++++++++++++++++++++ frontend/src/components/MainContent.tsx | 19 +++- 2 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 frontend/src/components/ConfirmDialog.tsx diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx new file mode 100644 index 0000000..15d216f --- /dev/null +++ b/frontend/src/components/ConfirmDialog.tsx @@ -0,0 +1,116 @@ +import React from 'react'; +import { + Dialog, + DialogTitle, + DialogContent, + DialogContentText, + DialogActions, + Button, + Typography, + Box, + IconButton, + Paper +} from '@mui/material'; +import { + Warning, + Close, + CleaningServices +} from '@mui/icons-material'; + +interface ConfirmDialogProps { + open: boolean; + onClose: () => void; + onConfirm: () => void; + title: string; + message: string; + confirmLabel?: string; + cancelLabel?: string; + loading?: boolean; +} + +const ConfirmDialog: React.FC = ({ + open, + onClose, + onConfirm, + title, + message, + confirmLabel = 'Confirm', + cancelLabel = 'Cancel', + loading = false +}) => { + return ( + + + + + + {title} + + + + + + + + + {message} + + + + + + + + + ); +}; + +export default ConfirmDialog; diff --git a/frontend/src/components/MainContent.tsx b/frontend/src/components/MainContent.tsx index 500038c..085a2f3 100644 --- a/frontend/src/components/MainContent.tsx +++ b/frontend/src/components/MainContent.tsx @@ -32,6 +32,7 @@ import Editor from '@monaco-editor/react'; import { useAppStore } from '../store/useAppStore'; import { SchemaService } from '../services/api'; import TransferContent from './TransferContent'; +import ConfirmDialog from './ConfirmDialog'; const MainContent: React.FC = () => { const { activeTable, activeDatabase, darkMode, dbTab, setDbTab } = useAppStore(); @@ -200,6 +201,7 @@ const MainContent: React.FC = () => { const [meta, setMeta] = useState(null); const [loadingMeta, setLoadingMeta] = useState(true); const [truncating, setTruncating] = useState(false); + const [showConfirm, setShowConfirm] = useState(false); const fetchMeta = useCallback(async () => { setLoadingMeta(true); @@ -220,11 +222,10 @@ const MainContent: React.FC = () => { }, [fetchMeta]); const handleTruncate = async () => { - if (!table || !window.confirm(`Are you sure you want to truncate table "${table}"? This will delete all data!`)) return; - setTruncating(true); + setShowConfirm(false); try { - await SchemaService.truncateTable(table); + await SchemaService.truncateTable(table!); setErrorInfo({ open: true, title: 'Success', @@ -271,7 +272,7 @@ const MainContent: React.FC = () => { variant="outlined" color="error" startIcon={truncating ? : } - onClick={handleTruncate} + onClick={() => setShowConfirm(true)} disabled={truncating} sx={{ borderRadius: 2, textTransform: 'none', fontWeight: 700 }} > @@ -279,6 +280,16 @@ const MainContent: React.FC = () => { )} + + setShowConfirm(false)} + onConfirm={handleTruncate} + title="Truncate Table" + message={`Are you sure you want to truncate table "${table}"? This action will permanently delete all ${meta?.rows || ''} records. This cannot be undone.`} + confirmLabel="Truncate Now" + loading={truncating} + /> {stats.map((stat, i) => (