@@ -136,13 +136,15 @@ export function editorRequestForScript(
136136 */
137137export function ProjectScriptEditorDialog ( {
138138 environmentId,
139+ editScope = AuthOrchestrationOperateScope ,
139140 request,
140141 scripts,
141142 onSubmit,
142143 onDelete,
143144 onClose,
144145} : {
145146 environmentId : EnvironmentId ;
147+ editScope ?: typeof AuthOrchestrationOperateScope | typeof AuthSettingsWriteScope ;
146148 request : ProjectScriptEditorRequest | null ;
147149 /** Existing scripts, used to derive a unique id for new scripts. */
148150 scripts : ReadonlyArray < ProjectScript > ;
@@ -153,19 +155,19 @@ export function ProjectScriptEditorDialog({
153155 onDelete : ( scriptId : string ) => void ;
154156 onClose : ( ) => void ;
155157} ) {
156- const canEditProject = useEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ;
158+ const canEditActions = useEnvironmentScope ( environmentId , editScope ) ;
157159 const canWriteSettings = useEnvironmentScope ( environmentId , AuthSettingsWriteScope ) ;
158160 const formId = React . useId ( ) ;
159161 const [ name , setName ] = useState ( "" ) ;
160162 const [ command , setCommand ] = useState ( "" ) ;
161163 const [ icon , setIcon ] = useState < ProjectScriptIcon > ( "play" ) ;
162- const [ iconPickerOpen , setIconPickerOpen ] = useComposerMenuState ( ! canEditProject ) ;
164+ const [ iconPickerOpen , setIconPickerOpen ] = useComposerMenuState ( ! canEditActions ) ;
163165 const [ runOnWorktreeCreate , setRunOnWorktreeCreate ] = useState ( false ) ;
164166 const [ keybinding , setKeybinding ] = useState ( "" ) ;
165167 const [ previewUrl , setPreviewUrl ] = useState ( "" ) ;
166168 const [ autoOpenPreview , setAutoOpenPreview ] = useState ( false ) ;
167169 const [ validationError , setValidationError ] = useState < string | null > ( null ) ;
168- const [ deleteConfirmOpen , setDeleteConfirmOpen ] = useComposerMenuState ( ! canEditProject ) ;
170+ const [ deleteConfirmOpen , setDeleteConfirmOpen ] = useComposerMenuState ( ! canEditActions ) ;
169171
170172 const isOpen = request !== null ;
171173 const isEditing = request ?. scriptId != null ;
@@ -185,7 +187,7 @@ export function ProjectScriptEditorDialog({
185187 } , [ request , setIconPickerOpen ] ) ;
186188
187189 const captureKeybinding = ( event : KeyboardEvent < HTMLInputElement > ) => {
188- if ( ! readEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ) return ;
190+ if ( ! readEnvironmentScope ( environmentId , editScope ) ) return ;
189191 if ( ! readEnvironmentScope ( environmentId , AuthSettingsWriteScope ) ) return ;
190192 if ( event . key === "Tab" ) return ;
191193 event . preventDefault ( ) ;
@@ -201,7 +203,7 @@ export function ProjectScriptEditorDialog({
201203 const submit = async ( event : FormEvent ) => {
202204 event . preventDefault ( ) ;
203205 if ( ! request ) return ;
204- if ( ! readEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ) {
206+ if ( ! readEnvironmentScope ( environmentId , editScope ) ) {
205207 setValidationError ( "This connection cannot change project actions." ) ;
206208 return ;
207209 }
@@ -284,7 +286,7 @@ export function ProjectScriptEditorDialog({
284286 </ DialogDescription >
285287 </ DialogHeader >
286288 < DialogPanel >
287- { ! canEditProject && (
289+ { ! canEditActions && (
288290 < p className = "mb-4 text-sm text-muted-foreground" >
289291 This connection cannot change project actions.
290292 </ p >
@@ -293,15 +295,15 @@ export function ProjectScriptEditorDialog({
293295 < div className = "space-y-1.5" >
294296 < Label htmlFor = "script-name" > Name</ Label >
295297 < div className = "flex items-center gap-2" >
296- < Popover onOpenChange = { setIconPickerOpen } open = { iconPickerOpen && canEditProject } >
298+ < Popover onOpenChange = { setIconPickerOpen } open = { iconPickerOpen && canEditActions } >
297299 < PopoverTrigger
298300 render = {
299301 < Button
300302 type = "button"
301303 variant = "outline"
302304 className = "size-9 shrink-0 hover:bg-popover active:bg-popover data-pressed:bg-popover data-pressed:shadow-xs/5 data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] dark:border-transparent dark:bg-white/[0.035] dark:data-pressed:before:shadow-none"
303305 aria-label = "Choose icon"
304- disabled = { ! canEditProject }
306+ disabled = { ! canEditActions }
305307 />
306308 }
307309 >
@@ -315,7 +317,7 @@ export function ProjectScriptEditorDialog({
315317 < button
316318 key = { entry . id }
317319 type = "button"
318- disabled = { ! canEditProject }
320+ disabled = { ! canEditActions }
319321 className = { `relative flex flex-col items-center gap-2 rounded-md border px-2 py-2 text-xs dark:border-transparent ${
320322 isSelected
321323 ? "border-primary/70 bg-primary/10 dark:ring-1 dark:ring-primary/30"
@@ -336,7 +338,7 @@ export function ProjectScriptEditorDialog({
336338 </ Popover >
337339 < Input
338340 id = "script-name"
339- disabled = { ! canEditProject }
341+ disabled = { ! canEditActions }
340342 autoFocus
341343 placeholder = "Test"
342344 value = { name }
@@ -350,7 +352,7 @@ export function ProjectScriptEditorDialog({
350352 id = "script-keybinding"
351353 placeholder = "Press shortcut"
352354 value = { keybinding }
353- disabled = { ! canEditProject || ! canWriteSettings }
355+ disabled = { ! canEditActions || ! canWriteSettings }
354356 readOnly
355357 onKeyDown = { captureKeybinding }
356358 />
@@ -368,7 +370,7 @@ export function ProjectScriptEditorDialog({
368370 < Label htmlFor = "script-command" > Command</ Label >
369371 < Textarea
370372 id = "script-command"
371- disabled = { ! canEditProject }
373+ disabled = { ! canEditActions }
372374 placeholder = "bun test"
373375 value = { command }
374376 onChange = { ( event ) => setCommand ( event . target . value ) }
@@ -378,7 +380,7 @@ export function ProjectScriptEditorDialog({
378380 < Label htmlFor = "script-preview-url" > Preview URL (optional)</ Label >
379381 < Input
380382 id = "script-preview-url"
381- disabled = { ! canEditProject }
383+ disabled = { ! canEditActions }
382384 placeholder = "http://localhost:5173"
383385 value = { previewUrl }
384386 onChange = { ( event ) => setPreviewUrl ( event . target . value ) }
@@ -391,7 +393,7 @@ export function ProjectScriptEditorDialog({
391393 < span > Run automatically on worktree creation</ span >
392394 < Switch
393395 checked = { runOnWorktreeCreate }
394- disabled = { ! canEditProject }
396+ disabled = { ! canEditActions }
395397 onCheckedChange = { ( checked ) => setRunOnWorktreeCreate ( Boolean ( checked ) ) }
396398 />
397399 </ label >
@@ -403,7 +405,7 @@ export function ProjectScriptEditorDialog({
403405 < span > Open preview automatically when this action runs</ span >
404406 < Switch
405407 checked = { autoOpenPreview }
406- disabled = { ! canEditProject || previewUrl . trim ( ) . length === 0 }
408+ disabled = { ! canEditActions || previewUrl . trim ( ) . length === 0 }
407409 onCheckedChange = { ( checked ) => setAutoOpenPreview ( Boolean ( checked ) ) }
408410 />
409411 </ label >
@@ -416,7 +418,7 @@ export function ProjectScriptEditorDialog({
416418 type = "button"
417419 variant = "destructive-outline"
418420 className = "mr-auto"
419- disabled = { ! canEditProject }
421+ disabled = { ! canEditActions }
420422 onClick = { ( ) => setDeleteConfirmOpen ( true ) }
421423 >
422424 Delete
@@ -425,14 +427,14 @@ export function ProjectScriptEditorDialog({
425427 < Button type = "button" variant = "outline" onClick = { onClose } >
426428 Cancel
427429 </ Button >
428- < Button form = { formId } type = "submit" disabled = { ! canEditProject } >
430+ < Button form = { formId } type = "submit" disabled = { ! canEditActions } >
429431 { isEditing ? "Save changes" : "Save action" }
430432 </ Button >
431433 </ DialogFooter >
432434 </ DialogPopup >
433435 </ Dialog >
434436
435- < AlertDialog open = { deleteConfirmOpen && canEditProject } onOpenChange = { setDeleteConfirmOpen } >
437+ < AlertDialog open = { deleteConfirmOpen && canEditActions } onOpenChange = { setDeleteConfirmOpen } >
436438 < AlertDialogPopup >
437439 < AlertDialogHeader >
438440 < AlertDialogTitle > Delete action "{ name } "?</ AlertDialogTitle >
@@ -442,10 +444,10 @@ export function ProjectScriptEditorDialog({
442444 < AlertDialogClose render = { < Button variant = "outline" /> } > Cancel</ AlertDialogClose >
443445 < Button
444446 variant = "destructive"
445- disabled = { ! canEditProject }
447+ disabled = { ! canEditActions }
446448 onClick = { ( ) => {
447449 if ( ! request ?. scriptId ) return ;
448- if ( ! readEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ) {
450+ if ( ! readEnvironmentScope ( environmentId , editScope ) ) {
449451 setValidationError ( "This connection cannot change project actions." ) ;
450452 return ;
451453 }
0 commit comments