feat: implement main data viewing component and reusable confirmation dialog for table management
This commit is contained in:
@@ -42,7 +42,8 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
|||||||
<Dialog
|
<Dialog
|
||||||
open={open}
|
open={open}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
PaperProps={{
|
slotProps={{
|
||||||
|
paper: {
|
||||||
sx: {
|
sx: {
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
p: 1,
|
p: 1,
|
||||||
@@ -53,6 +54,7 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
|||||||
bgcolor: 'background.paper',
|
bgcolor: 'background.paper',
|
||||||
backgroundImage: 'none'
|
backgroundImage: 'none'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogTitle sx={{ display: 'flex', alignItems: 'center', gap: 1.5, pb: 1 }}>
|
<DialogTitle sx={{ display: 'flex', alignItems: 'center', gap: 1.5, pb: 1 }}>
|
||||||
|
|||||||
@@ -48,14 +48,20 @@ const MainContent: React.FC = () => {
|
|||||||
pageSize: 100,
|
pageSize: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Custom Alert State
|
// Custom Notification State
|
||||||
const [errorInfo, setErrorInfo] = useState<{ open: boolean; message: string; title: string }>({
|
const [notification, setNotification] = useState<{
|
||||||
|
open: boolean;
|
||||||
|
message: string;
|
||||||
|
title: string;
|
||||||
|
severity: 'success' | 'error' | 'info' | 'warning'
|
||||||
|
}>({
|
||||||
open: false,
|
open: false,
|
||||||
message: '',
|
message: '',
|
||||||
title: ''
|
title: '',
|
||||||
|
severity: 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleCloseError = () => setErrorInfo({ ...errorInfo, open: false });
|
const handleCloseNotification = () => setNotification({ ...notification, open: false });
|
||||||
|
|
||||||
// Helper to map SQL types to MUI X Data Grid types
|
// Helper to map SQL types to MUI X Data Grid types
|
||||||
const mapSqlTypeToMuiType = (sqlType: string): 'string' | 'number' | 'date' | 'dateTime' | 'boolean' => {
|
const mapSqlTypeToMuiType = (sqlType: string): 'string' | 'number' | 'date' | 'dateTime' | 'boolean' => {
|
||||||
@@ -175,10 +181,11 @@ const MainContent: React.FC = () => {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Execution error', error);
|
console.error('Execution error', error);
|
||||||
const msg = error.response?.data?.error || 'An unexpected error occurred during SQL execution.';
|
const msg = error.response?.data?.error || 'An unexpected error occurred during SQL execution.';
|
||||||
setErrorInfo({
|
setNotification({
|
||||||
open: true,
|
open: true,
|
||||||
title: 'SQL Execution Error',
|
title: 'SQL Execution Error',
|
||||||
message: msg
|
message: msg,
|
||||||
|
severity: 'error'
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingData(false);
|
setLoadingData(false);
|
||||||
@@ -226,17 +233,19 @@ const MainContent: React.FC = () => {
|
|||||||
setShowConfirm(false);
|
setShowConfirm(false);
|
||||||
try {
|
try {
|
||||||
await SchemaService.truncateTable(table!);
|
await SchemaService.truncateTable(table!);
|
||||||
setErrorInfo({
|
setNotification({
|
||||||
open: true,
|
open: true,
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
message: `Table "${table}" has been truncated.`
|
message: `Table "${table}" has been truncated.`,
|
||||||
|
severity: 'success'
|
||||||
});
|
});
|
||||||
fetchMeta();
|
fetchMeta();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
setErrorInfo({
|
setNotification({
|
||||||
open: true,
|
open: true,
|
||||||
title: 'Truncate Error',
|
title: 'Truncate Error',
|
||||||
message: error.response?.data?.error || error.message
|
message: error.response?.data?.error || error.message,
|
||||||
|
severity: 'error'
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setTruncating(false);
|
setTruncating(false);
|
||||||
@@ -462,11 +471,15 @@ const MainContent: React.FC = () => {
|
|||||||
{/* Technical Info View */}
|
{/* Technical Info View */}
|
||||||
{dbTab === 'info' && <TechnicalOverview database={activeDatabase} table={activeTable} />}
|
{dbTab === 'info' && <TechnicalOverview database={activeDatabase} table={activeTable} />}
|
||||||
|
|
||||||
{/* Custom Alert (Snackbar) */}
|
{/* Custom Notification (Snackbar) */}
|
||||||
<Snackbar open={errorInfo.open} autoHideDuration={10000} onClose={handleCloseError} anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
|
<Snackbar open={notification.open} autoHideDuration={6000} onClose={handleCloseNotification} anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
|
||||||
<Alert onClose={handleCloseError} severity="error" variant="filled" sx={{ width: '100%', borderRadius: 2 }}>
|
<Alert onClose={handleCloseNotification} severity={notification.severity} variant="filled" sx={{
|
||||||
<AlertTitle sx={{ fontWeight: 800 }}>{errorInfo.title}</AlertTitle>
|
width: '100%',
|
||||||
<Typography variant="body2">{errorInfo.message}</Typography>
|
borderRadius: 2,
|
||||||
|
boxShadow: notification.severity === 'success' ? '0 8px 24px rgba(46, 125, 50, 0.25)' : '0 8px 24px rgba(211, 47, 47, 0.25)'
|
||||||
|
}}>
|
||||||
|
<AlertTitle sx={{ fontWeight: 800 }}>{notification.title}</AlertTitle>
|
||||||
|
<Typography variant="body2">{notification.message}</Typography>
|
||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user