import { useCallback, useMemo } from 'react'; import { ScrollText, Play, Settings2, SquareArrowOutUpRight } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { useAppStore } from '@/store/app-store'; import { useProjectSettings } from '@/hooks/queries'; import { cn } from '@/lib/utils'; import { DEFAULT_TERMINAL_SCRIPTS } from '../project-settings-view/terminal-scripts-constants'; interface TerminalScriptsDropdownProps { /** Callback to send a command + newline to the terminal */ onRunCommand: (command: string) => void; /** Callback to run a command in a new terminal tab */ onRunCommandInNewTab?: (command: string) => void; /** Whether the terminal is connected and ready */ isConnected: boolean; /** Optional callback to navigate to project settings scripts section */ onOpenSettings?: () => void; } /** * Dropdown menu in the terminal header bar that provides quick-access * to user-configured project scripts. Each script is a split button: * clicking the left side runs the command in the current terminal, * clicking the "new tab" icon on the right runs it in a new tab. */ export function TerminalScriptsDropdown({ onRunCommand, onRunCommandInNewTab, isConnected, onOpenSettings, }: TerminalScriptsDropdownProps) { const currentProject = useAppStore((state) => state.currentProject); const { data: projectSettings } = useProjectSettings(currentProject?.path); // Use project-configured scripts or fall back to defaults const scripts = useMemo(() => { const configured = projectSettings?.terminalScripts; if (configured && configured.length > 0) { return configured; } return DEFAULT_TERMINAL_SCRIPTS; }, [projectSettings?.terminalScripts]); const handleRunScript = useCallback( (command: string) => { if (!isConnected) return; onRunCommand(command); }, [isConnected, onRunCommand] ); const handleRunScriptInNewTab = useCallback( (command: string) => { if (!isConnected || !onRunCommandInNewTab) return; onRunCommandInNewTab(command); }, [isConnected, onRunCommandInNewTab] ); return ( e.stopPropagation()} > Quick Scripts {scripts.map((script) => ( handleRunScript(script.command)} disabled={!isConnected} className="gap-2 pr-1" >
{script.name} {script.command}
{onRunCommandInNewTab && ( )}
))} Edit Commands & Scripts
); }