({
scripts,
keybindings,
preferredScriptId = null,
onRunScript,
onAddScript,
onUpdateScript,
onDeleteScript,
}: ProjectScriptsControlProps)
| 112 | } |
| 113 | |
| 114 | export default function ProjectScriptsControl({ |
| 115 | scripts, |
| 116 | keybindings, |
| 117 | preferredScriptId = null, |
| 118 | onRunScript, |
| 119 | onAddScript, |
| 120 | onUpdateScript, |
| 121 | onDeleteScript, |
| 122 | }: ProjectScriptsControlProps) { |
| 123 | const addScriptFormId = React.useId(); |
| 124 | const [editingScriptId, setEditingScriptId] = useState<string | null>(null); |
| 125 | const [dialogOpen, setDialogOpen] = useState(false); |
| 126 | const [name, setName] = useState(""); |
| 127 | const [command, setCommand] = useState(""); |
| 128 | const [icon, setIcon] = useState<ProjectScriptIcon>("play"); |
| 129 | const [iconPickerOpen, setIconPickerOpen] = useState(false); |
| 130 | const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(false); |
| 131 | const [keybinding, setKeybinding] = useState(""); |
| 132 | const [previewUrl, setPreviewUrl] = useState(""); |
| 133 | const [autoOpenPreview, setAutoOpenPreview] = useState(false); |
| 134 | const [validationError, setValidationError] = useState<string | null>(null); |
| 135 | const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false); |
| 136 | |
| 137 | const primaryScript = useMemo(() => { |
| 138 | if (preferredScriptId) { |
| 139 | const preferred = scripts.find((script) => script.id === preferredScriptId); |
| 140 | if (preferred) return preferred; |
| 141 | } |
| 142 | return primaryProjectScript(scripts); |
| 143 | }, [preferredScriptId, scripts]); |
| 144 | const isEditing = editingScriptId !== null; |
| 145 | const dropdownItemClassName = |
| 146 | "data-highlighted:bg-transparent data-highlighted:text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground data-highlighted:hover:bg-accent data-highlighted:hover:text-accent-foreground data-highlighted:focus-visible:bg-accent data-highlighted:focus-visible:text-accent-foreground"; |
| 147 | |
| 148 | const captureKeybinding = (event: KeyboardEvent<HTMLInputElement>) => { |
| 149 | if (event.key === "Tab") return; |
| 150 | event.preventDefault(); |
| 151 | if (event.key === "Backspace" || event.key === "Delete") { |
| 152 | setKeybinding(""); |
| 153 | return; |
| 154 | } |
| 155 | const next = keybindingFromKeyboardEvent(event, navigator.platform); |
| 156 | if (!next) return; |
| 157 | setKeybinding(next); |
| 158 | }; |
| 159 | |
| 160 | const submitAddScript = async (event: FormEvent) => { |
| 161 | event.preventDefault(); |
| 162 | const trimmedName = name.trim(); |
| 163 | const trimmedCommand = command.trim(); |
| 164 | if (trimmedName.length === 0) { |
| 165 | setValidationError("Name is required."); |
| 166 | return; |
| 167 | } |
| 168 | if (trimmedCommand.length === 0) { |
| 169 | setValidationError("Command is required."); |
| 170 | return; |
| 171 | } |
nothing calls this directly
no test coverage detected