import { useState } from "react"; import { Play, Square, Wand2, Save } from "lucide-react"; import { Tooltip } from "../ui/Tooltip"; import { QueryHistoryDropdown } from "./QueryHistoryDropdown"; import { SaveQueryDialog } from "./SaveQueryDialog"; import { useDbViewerStore } from "../../stores/dbViewerStore"; import type { DbType } from "../../lib/types"; const DB_TYPE_LABELS: Record = { postgresql: "PostgreSQL", mysql: "MySQL", sqlite: "SQLite", redis: "Redis", }; /** * Resolve the run-query modifier key for the given platform string * (from `navigator.platform`). Mac platforms show ⌘ + the return glyph, * everything else shows Ctrl + Enter. */ export function queryShortcut(platform: string): { mod: string; enter: string; } { const isMac = /Mac|iPhone|iPad/.test(platform); return isMac ? { mod: "⌘", enter: "⏎" } : { mod: "Ctrl", enter: "Enter" }; } interface QueryToolbarProps { onRun: () => void; onFormat: () => void; connectionId: string; onRestore: (sql: string) => void; onRunFromHistory: (sql: string) => void; dbType?: DbType; readOnly?: boolean; isRunning?: boolean; onCancel?: () => void; } export function QueryToolbar({ onRun, onFormat, connectionId, onRestore, onRunFromHistory, dbType, readOnly = false, isRunning: isRunningProp, onCancel, }: QueryToolbarProps) { const tabs = useDbViewerStore((s) => s.tabs); const activeTabId = useDbViewerStore((s) => s.activeTabId); const isRunning = isRunningProp ?? tabs.find((t) => t.id === activeTabId)?.loading ?? false; const [saveDialogOpen, setSaveDialogOpen] = useState(false); const activeTab = tabs.find((t) => t.id === activeTabId); const currentQueryText = activeTab?.query ?? ""; const shortcut = queryShortcut( typeof navigator !== "undefined" ? navigator.platform : "", ); return (
{/* run pulse: mirrors the table toolbar refresh pulse, absolutely positioned so it never shifts layout */} {isRunning && ( ); }