import { Hotkey } from '@tanstack/react-hotkeys' import { LOCAL_STORAGE_KEYS, useParams } from 'common' import { AlignLeft, Check, Heart, Keyboard, MoreVertical } from 'lucide-react' import { toast } from 'sonner' import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, KeyboardShortcut, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { SqlRunButton } from './RunButton' import SavingIndicator from './SavingIndicator' import { RoleImpersonationPopover } from '@/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover' import { DatabaseSelector } from '@/components/ui/DatabaseSelector' import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' import { IS_PLATFORM } from '@/lib/constants' import { hotkeyToKeys } from '@/state/shortcuts/formatShortcut' import { SHORTCUT_DEFINITIONS, SHORTCUT_IDS } from '@/state/shortcuts/registry' import { useSqlEditorV2StateSnapshot } from '@/state/sql-editor-v2' export type UtilityActionsProps = { id: string isExecuting?: boolean isDisabled?: boolean hasSelection?: boolean prettifyQuery: () => void executeQuery: () => void } export const UtilityActions = ({ id, isExecuting = false, isDisabled = false, hasSelection = false, prettifyQuery, executeQuery, }: UtilityActionsProps) => { const { ref } = useParams() const snapV2 = useSqlEditorV2StateSnapshot() const [isAiOpen] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.SQL_EDITOR_AI_OPEN, true) const [intellisenseEnabled, setIntellisenseEnabled] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.SQL_EDITOR_INTELLISENSE, true ) const [lastSelectedDb, setLastSelectedDb] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.SQL_EDITOR_LAST_SELECTED_DB(ref as string), '' ) const snippet = snapV2.snippets[id] const isFavorite = snippet !== undefined ? snippet.snippet.favorite : false const hotkeySequnece: Hotkey | undefined = SHORTCUT_DEFINITIONS[SHORTCUT_IDS.SQL_EDITOR_FORMAT].sequence[0] const formatKeys = hotkeySequnece ? hotkeyToKeys(hotkeySequnece) : undefined const toggleIntellisense = () => { setIntellisenseEnabled(!intellisenseEnabled) toast.success( `Successfully ${intellisenseEnabled ? 'disabled' : 'enabled'} intellisense. ${intellisenseEnabled ? 'Please refresh your browser for changes to take place.' : ''}` ) } const addFavorite = () => snapV2.addFavorite(id) const removeFavorite = () => snapV2.removeFavorite(id) const onSelectDatabase = (databaseId: string) => { snapV2.resetResults(id) setLastSelectedDb(databaseId) } return (
{IS_PLATFORM && }
{IS_PLATFORM && ( )}
) }