Skip to content

Commit 78d6082

Browse files
committed
fix edge cases
1 parent f0d2224 commit 78d6082

File tree

5 files changed

+360
-213
lines changed

5 files changed

+360
-213
lines changed

apps/sim/app/api/workspaces/route.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const logger = createLogger('Workspaces')
1313

1414
const createWorkspaceSchema = z.object({
1515
name: z.string().trim().min(1, 'Name is required'),
16+
skipDefaultWorkflow: z.boolean().optional().default(false),
1617
})
1718

1819
// Get all workspaces for the current user
@@ -63,9 +64,9 @@ export async function POST(req: Request) {
6364
}
6465

6566
try {
66-
const { name } = createWorkspaceSchema.parse(await req.json())
67+
const { name, skipDefaultWorkflow } = createWorkspaceSchema.parse(await req.json())
6768

68-
const newWorkspace = await createWorkspace(session.user.id, name)
69+
const newWorkspace = await createWorkspace(session.user.id, name, skipDefaultWorkflow)
6970

7071
return NextResponse.json({ workspace: newWorkspace })
7172
} catch (error) {
@@ -80,7 +81,7 @@ async function createDefaultWorkspace(userId: string, userName?: string | null)
8081
return createWorkspace(userId, workspaceName)
8182
}
8283

83-
async function createWorkspace(userId: string, name: string) {
84+
async function createWorkspace(userId: string, name: string, skipDefaultWorkflow = false) {
8485
const workspaceId = crypto.randomUUID()
8586
const workflowId = crypto.randomUUID()
8687
const now = new Date()
@@ -97,7 +98,6 @@ async function createWorkspace(userId: string, name: string) {
9798
updatedAt: now,
9899
})
99100

100-
// Create admin permissions for the workspace owner
101101
await tx.insert(permissions).values({
102102
id: crypto.randomUUID(),
103103
entityType: 'workspace' as const,
@@ -108,37 +108,41 @@ async function createWorkspace(userId: string, name: string) {
108108
updatedAt: now,
109109
})
110110

111-
// Create initial workflow for the workspace (empty canvas)
112-
// Create the workflow
113-
await tx.insert(workflow).values({
114-
id: workflowId,
115-
userId,
116-
workspaceId,
117-
folderId: null,
118-
name: 'default-agent',
119-
description: 'Your first workflow - start building here!',
120-
color: '#3972F6',
121-
lastSynced: now,
122-
createdAt: now,
123-
updatedAt: now,
124-
isDeployed: false,
125-
runCount: 0,
126-
variables: {},
127-
})
111+
if (!skipDefaultWorkflow) {
112+
await tx.insert(workflow).values({
113+
id: workflowId,
114+
userId,
115+
workspaceId,
116+
folderId: null,
117+
name: 'default-agent',
118+
description: 'Your first workflow - start building here!',
119+
color: '#3972F6',
120+
lastSynced: now,
121+
createdAt: now,
122+
updatedAt: now,
123+
isDeployed: false,
124+
runCount: 0,
125+
variables: {},
126+
})
127+
}
128128

129129
logger.info(
130-
`Created workspace ${workspaceId} with initial workflow ${workflowId} for user ${userId}`
130+
skipDefaultWorkflow
131+
? `Created workspace ${workspaceId} for user ${userId}`
132+
: `Created workspace ${workspaceId} with initial workflow ${workflowId} for user ${userId}`
131133
)
132134
})
133135

134-
const { workflowState } = buildDefaultWorkflowArtifacts()
135-
const seedResult = await saveWorkflowToNormalizedTables(workflowId, workflowState)
136+
if (!skipDefaultWorkflow) {
137+
const { workflowState } = buildDefaultWorkflowArtifacts()
138+
const seedResult = await saveWorkflowToNormalizedTables(workflowId, workflowState)
136139

137-
if (!seedResult.success) {
138-
throw new Error(seedResult.error || 'Failed to seed default workflow state')
140+
if (!seedResult.success) {
141+
throw new Error(seedResult.error || 'Failed to seed default workflow state')
142+
}
139143
}
140144
} catch (error) {
141-
logger.error(`Failed to create workspace ${workspaceId} with initial workflow:`, error)
145+
logger.error(`Failed to create workspace ${workspaceId}:`, error)
142146
throw error
143147
}
144148

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/workflow-list.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function DropIndicatorLine({ show, level = 0 }: { show: boolean; level?: number
3333
className='pointer-events-none absolute left-0 right-0 z-20 flex items-center'
3434
style={{ paddingLeft: `${level * TREE_SPACING.INDENT_PER_LEVEL}px` }}
3535
>
36-
<div className='h-[2px] flex-1 rounded-full bg-[#0096FF]' />
36+
<div className='h-[2px] flex-1 rounded-full bg-gray-400/60' />
3737
</div>
3838
)
3939
}
@@ -163,7 +163,7 @@ export function WorkflowList({
163163
active={isWorkflowActive(workflow.id)}
164164
level={level}
165165
onWorkflowClick={handleWorkflowClick}
166-
onDragStart={() => handleDragStart('workflow')}
166+
onDragStart={() => handleDragStart('workflow', folderId)}
167167
onDragEnd={handleDragEnd}
168168
/>
169169
</div>
@@ -224,18 +224,21 @@ export function WorkflowList({
224224
return (
225225
<div key={folder.id} className='relative'>
226226
<DropIndicatorLine show={showBefore} level={level} />
227+
{/* Drop target highlight overlay - covers entire folder section */}
227228
<div
228229
className={clsx(
229-
'rounded-[4px] transition-colors duration-75',
230-
showInside && isDragging && 'bg-[#0096FF]/10'
230+
'pointer-events-none absolute inset-0 z-10 rounded-[4px] transition-opacity duration-75',
231+
showInside && isDragging ? 'bg-gray-400/20 opacity-100' : 'opacity-0'
231232
)}
233+
/>
234+
<div
232235
style={{ paddingLeft: `${level * TREE_SPACING.INDENT_PER_LEVEL}px` }}
233236
{...createFolderDragHandlers(folder.id, parentFolderId)}
234237
>
235238
<FolderItem
236239
folder={folder}
237240
level={level}
238-
onDragStart={() => handleDragStart('folder')}
241+
onDragStart={() => handleDragStart('folder', parentFolderId)}
239242
onDragEnd={handleDragEnd}
240243
/>
241244
</div>
@@ -314,13 +317,16 @@ export function WorkflowList({
314317
return (
315318
<div className='flex min-h-full flex-col pb-[8px]' onClick={handleContainerClick}>
316319
<div
317-
className={clsx(
318-
'relative flex-1 rounded-[4px] transition-colors duration-75',
319-
!hasRootItems && 'min-h-[26px]',
320-
showRootInside && isDragging && 'bg-[#0096FF]/10'
321-
)}
320+
className={clsx('relative flex-1 rounded-[4px]', !hasRootItems && 'min-h-[26px]')}
322321
{...rootDropZoneHandlers}
323322
>
323+
{/* Root drop target highlight overlay */}
324+
<div
325+
className={clsx(
326+
'pointer-events-none absolute inset-0 z-10 rounded-[4px] transition-opacity duration-75',
327+
showRootInside && isDragging ? 'bg-gray-400/20 opacity-100' : 'opacity-0'
328+
)}
329+
/>
324330
<div className='space-y-[2px]'>
325331
{rootItems.map((item) =>
326332
item.type === 'folder'

0 commit comments

Comments
 (0)