File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
workspace/[workspaceId]/w/hooks Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,21 @@ export async function DELETE(
228228 return NextResponse . json ( { error : 'Access denied' } , { status : 403 } )
229229 }
230230
231+ // Check if this is the last workflow in the workspace
232+ if ( workflowData . workspaceId ) {
233+ const totalWorkflowsInWorkspace = await db
234+ . select ( { id : workflow . id } )
235+ . from ( workflow )
236+ . where ( eq ( workflow . workspaceId , workflowData . workspaceId ) )
237+
238+ if ( totalWorkflowsInWorkspace . length <= 1 ) {
239+ return NextResponse . json (
240+ { error : 'Cannot delete the only workflow in the workspace' } ,
241+ { status : 400 }
242+ )
243+ }
244+ }
245+
231246 // Check if workflow has published templates before deletion
232247 const { searchParams } = new URL ( request . url )
233248 const checkTemplates = searchParams . get ( 'check-templates' ) === 'true'
Original file line number Diff line number Diff line change @@ -95,28 +95,28 @@ export function useCanDelete({ workspaceId }: UseCanDeleteProps): UseCanDeleteRe
9595 )
9696
9797 /**
98- * Check if the given workflow IDs can be deleted
98+ * Check if the given workflow IDs can be deleted.
99+ * Returns false if deleting would remove all workflows from the workspace.
99100 */
100101 const canDeleteWorkflows = useCallback (
101102 ( workflowIds : string [ ] ) : boolean => {
102- if ( totalWorkflows === 0 ) return true
103-
104103 const workflowsToDelete = workflowIds . filter ( ( id ) => workflowIdSet . has ( id ) ) . length
105104
106- return workflowsToDelete < totalWorkflows
105+ // Must have at least one workflow remaining after deletion
106+ return totalWorkflows > 0 && workflowsToDelete < totalWorkflows
107107 } ,
108108 [ totalWorkflows , workflowIdSet ]
109109 )
110110
111111 /**
112- * Check if the given folder can be deleted
112+ * Check if the given folder can be deleted.
113+ * Empty folders are always deletable. Folders containing all workspace workflows are not.
113114 */
114115 const canDeleteFolder = useCallback (
115116 ( folderId : string ) : boolean => {
116- if ( totalWorkflows === 0 ) return true
117-
118117 const workflowsInFolder = countWorkflowsInFolder ( folderId )
119118
119+ if ( workflowsInFolder === 0 ) return true
120120 return workflowsInFolder < totalWorkflows
121121 } ,
122122 [ totalWorkflows , countWorkflowsInFolder ]
You can’t perform that action at this time.
0 commit comments