import { AppMaterialIcons } from '../../icons'; import { AppCodeEditor } from '../../inputs/AppCodeEditor'; import { useBusterNotifications } from '@/context/BusterNotifications'; import { useMemoizedFn } from 'ahooks'; import { Button, Divider } from 'antd'; import { createStyles } from 'antd-style'; import React, { useEffect, useMemo, useState } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; import type { AppVerticalSplitterWithGapProps } from './AppVerticalSplitterWithGap'; export const SQLContainer: React.FC<{ className?: string; sql: string | undefined; setDatasetSQL: (sql: string) => void; onRunQuery: () => Promise; onSaveSQL?: AppVerticalSplitterWithGapProps['onSaveSQL']; disabledSave?: AppVerticalSplitterWithGapProps['disabledSave']; error?: string | null; }> = React.memo( ({ disabledSave, className = '', sql, setDatasetSQL, onRunQuery, onSaveSQL, error }) => { const { styles, cx } = useStyles(); const [isRunning, setIsRunning] = useState(false); const [isError, setIsError] = useState(false); const { openInfoMessage } = useBusterNotifications(); const onCopySQL = useMemoizedFn(() => { navigator.clipboard.writeText(sql || ''); openInfoMessage('SQL copied to clipboard'); }); const onRunQueryPreflight = useMemoizedFn(async () => { setIsRunning(true); await onRunQuery(); setIsRunning(false); }); useEffect(() => { setIsError(!!error); }, [error]); return (
{onSaveSQL && ( )}
{error && ( setIsError(false)} isError={isError} /> )}
); } ); SQLContainer.displayName = 'SQLContainer'; const ErrorContainer: React.FC<{ error: string; onClose: () => void; isError: boolean; }> = React.memo(({ error, onClose, isError }) => { const { styles, cx } = useStyles(); return ( {isError && (
{error}
)}
); }); ErrorContainer.displayName = 'ErrorContainer'; const useStyles = createStyles(({ css, token }) => ({ container: css` background: ${token.colorBgBase}; border-radius: ${token.borderRadius}px; border: 0.5px solid ${token.colorBorder}; `, errorContainer: css` background: ${token.colorErrorBg}; color: ${token.colorError}; border: 0.5px solid ${token.colorError}; padding: 8px 12px; border-radius: ${token.borderRadius}px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); `, closeButton: css` color: ${token.colorError}; cursor: pointer; border: none; background: none; display: flex; align-items: center; justify-content: center; &:hover { opacity: 0.8; } ` }));