'use client'; import { Command, ReturnKey } from '@/components/ui/icons'; import { AppCodeEditor } from '@/components/ui/inputs/AppCodeEditor'; import { useBusterNotifications } from '@/context/BusterNotifications'; import { useMemoizedFn } from '@/hooks'; import { Button } from '@/components/ui/buttons/Button'; import React, { useMemo, useState } from 'react'; import type { AppVerticalCodeSplitterProps } from './AppVerticalCodeSplitter'; import { ErrorClosableContainer } from '@/components/ui/error/ErrorClosableContainer'; import { FileCard } from '@/components/ui/card/FileCard'; export const SQLContainer: React.FC<{ className?: string; sql: string | undefined; setDatasetSQL: (sql: string) => void; onRunQuery: () => Promise; onSaveSQL: AppVerticalCodeSplitterProps['onSaveSQL']; disabledSave?: AppVerticalCodeSplitterProps['disabledSave']; error?: string | null; readOnly?: boolean; }> = React.memo( ({ disabledSave, className = '', readOnly = false, sql, setDatasetSQL, onRunQuery, onSaveSQL, error }) => { const [isRunning, setIsRunning] = useState(false); const [isSaving, setIsSaving] = 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); }); const onSaveSQLPreflight = useMemoizedFn(async () => { setIsSaving(true); await onSaveSQL?.(); setIsSaving(false); }); const memoizedFooter = useMemo(() => { return ( <>
{onSaveSQL && ( )} {!readOnly && (
}> Run )} ); }, [ disabledSave, isRunning, onCopySQL, onRunQueryPreflight, onSaveSQL, sql, isSaving, onSaveSQLPreflight ]); return ( {error && } ); } ); SQLContainer.displayName = 'SQLContainer';