Skip to content

Commit 5dc3ba3

Browse files
committed
Lint
1 parent 684a802 commit 5dc3ba3

File tree

3 files changed

+65
-48
lines changed

3 files changed

+65
-48
lines changed

apps/sim/app/api/workflows/[id]/state/route.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
8787

8888
// Save to normalized tables
8989
logger.info(`[${requestId}] Saving workflow ${workflowId} state to normalized tables`)
90-
90+
9191
// Ensure all required fields are present for WorkflowState type
9292
const workflowState = {
9393
blocks: state.blocks,
@@ -101,7 +101,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
101101
hasActiveSchedule: state.hasActiveSchedule || false,
102102
hasActiveWebhook: state.hasActiveWebhook || false,
103103
}
104-
104+
105105
const saveResult = await saveWorkflowToNormalizedTables(workflowId, workflowState)
106106

107107
if (!saveResult.success) {
@@ -115,22 +115,24 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
115115
// Update workflow's lastSynced timestamp
116116
await db
117117
.update(workflow)
118-
.set({
118+
.set({
119119
lastSynced: new Date(),
120120
updatedAt: new Date(),
121-
state: saveResult.jsonBlob // Also update JSON blob for backward compatibility
121+
state: saveResult.jsonBlob, // Also update JSON blob for backward compatibility
122122
})
123123
.where(eq(workflow.id, workflowId))
124124

125125
const elapsed = Date.now() - startTime
126126
logger.info(`[${requestId}] Successfully saved workflow ${workflowId} state in ${elapsed}ms`)
127127

128-
return NextResponse.json({
129-
success: true,
130-
blocksCount: Object.keys(state.blocks).length,
131-
edgesCount: state.edges.length
132-
}, { status: 200 })
133-
128+
return NextResponse.json(
129+
{
130+
success: true,
131+
blocksCount: Object.keys(state.blocks).length,
132+
edgesCount: state.edges.length,
133+
},
134+
{ status: 200 }
135+
)
134136
} catch (error: any) {
135137
const elapsed = Date.now() - startTime
136138
if (error instanceof z.ZodError) {
@@ -143,7 +145,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
143145
)
144146
}
145147

146-
logger.error(`[${requestId}] Error saving workflow ${workflowId} state after ${elapsed}ms`, error)
148+
logger.error(
149+
`[${requestId}] Error saving workflow ${workflowId} state after ${elapsed}ms`,
150+
error
151+
)
147152
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
148153
}
149-
}
154+
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/import-controls/import-controls.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ export function ImportControls({ disabled = false }: ImportControlsProps) {
5151

5252
// Stores and hooks
5353
const { createWorkflow } = useWorkflowRegistry()
54-
const {
55-
collaborativeAddBlock,
56-
collaborativeAddEdge,
57-
collaborativeSetSubblockValue
58-
} = useCollaborativeWorkflow()
54+
const { collaborativeAddBlock, collaborativeAddEdge, collaborativeSetSubblockValue } =
55+
useCollaborativeWorkflow()
5956
const subBlockStore = useSubBlockStore()
6057

6158
const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {

apps/sim/stores/workflows/yaml/importer.ts

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,13 @@ export async function importWorkflowFromYaml(
367367
return { success: false, errors, warnings }
368368
}
369369

370-
logger.info(`Creating complete workflow state with ${blocks.length} blocks and ${edges.length} edges`)
371-
logger.debug('Blocks to import:', blocks.map(b => `${b.id} (${b.type}): ${b.name}`))
370+
logger.info(
371+
`Creating complete workflow state with ${blocks.length} blocks and ${edges.length} edges`
372+
)
373+
logger.debug(
374+
'Blocks to import:',
375+
blocks.map((b) => `${b.id} (${b.type}): ${b.name}`)
376+
)
372377

373378
// Get the existing workflow state (to preserve starter blocks if they exist)
374379
const existingBlocks = workflowActions.getExistingBlocks()
@@ -397,39 +402,40 @@ export async function importWorkflowFromYaml(
397402

398403
// Handle starter block
399404
let starterBlockId: string | null = null
400-
const starterBlock = blocks.find(block => block.type === 'starter')
401-
405+
const starterBlock = blocks.find((block) => block.type === 'starter')
406+
402407
if (starterBlock) {
403408
if (existingStarterBlocks.length > 0) {
404409
// Use existing starter block
405410
const existingStarter = existingStarterBlocks[0] as any
406411
starterBlockId = existingStarter.id
407412
yamlIdToActualId.set(starterBlock.id, existingStarter.id)
408-
413+
409414
// Keep existing starter but update its inputs
410415
completeBlocks[existingStarter.id] = {
411416
...existingStarter,
412417
// Update name if provided in YAML
413418
name: starterBlock.name !== 'Start' ? starterBlock.name : existingStarter.name,
414419
}
415-
420+
416421
// Set starter block values
417422
completeSubBlockValues[existingStarter.id] = {
418-
...currentWorkflowState.blocks[existingStarter.id]?.subBlocks ?
419-
Object.fromEntries(
420-
Object.entries(currentWorkflowState.blocks[existingStarter.id].subBlocks).map(
421-
([key, subBlock]: [string, any]) => [key, subBlock.value]
423+
...(currentWorkflowState.blocks[existingStarter.id]?.subBlocks
424+
? Object.fromEntries(
425+
Object.entries(currentWorkflowState.blocks[existingStarter.id].subBlocks).map(
426+
([key, subBlock]: [string, any]) => [key, subBlock.value]
427+
)
422428
)
423-
) : {},
424-
...starterBlock.inputs // Override with YAML values
429+
: {}),
430+
...starterBlock.inputs, // Override with YAML values
425431
}
426-
432+
427433
logger.debug(`Using existing starter block: ${existingStarter.id}`)
428434
} else {
429435
// Create new starter block
430436
starterBlockId = crypto.randomUUID()
431437
yamlIdToActualId.set(starterBlock.id, starterBlockId)
432-
438+
433439
// Create complete starter block from block config
434440
const blockConfig = getBlock('starter')
435441
if (blockConfig) {
@@ -441,7 +447,7 @@ export async function importWorkflowFromYaml(
441447
value: null,
442448
}
443449
})
444-
450+
445451
completeBlocks[starterBlockId] = {
446452
id: starterBlockId,
447453
type: 'starter',
@@ -455,10 +461,10 @@ export async function importWorkflowFromYaml(
455461
height: 0,
456462
data: starterBlock.data || {},
457463
}
458-
464+
459465
// Set starter block values
460466
completeSubBlockValues[starterBlockId] = { ...starterBlock.inputs }
461-
467+
462468
logger.debug(`Created new starter block: ${starterBlockId}`)
463469
}
464470
}
@@ -477,7 +483,7 @@ export async function importWorkflowFromYaml(
477483

478484
// Create complete block from block config
479485
const blockConfig = getBlock(block.type)
480-
486+
481487
if (!blockConfig && (block.type === 'loop' || block.type === 'parallel')) {
482488
// Handle loop/parallel blocks
483489
completeBlocks[blockId] = {
@@ -493,7 +499,7 @@ export async function importWorkflowFromYaml(
493499
height: 0,
494500
data: block.data || {},
495501
}
496-
502+
497503
completeSubBlockValues[blockId] = { ...block.inputs }
498504
blocksProcessed++
499505
logger.debug(`Prepared ${block.type} block: ${blockId} -> ${block.name}`)
@@ -521,7 +527,7 @@ export async function importWorkflowFromYaml(
521527
height: 0,
522528
data: block.data || {},
523529
}
524-
530+
525531
// Set block input values
526532
completeSubBlockValues[blockId] = { ...block.inputs }
527533
blocksProcessed++
@@ -530,15 +536,17 @@ export async function importWorkflowFromYaml(
530536
logger.warn(`No block config found for type: ${block.type} (block: ${block.id})`)
531537
}
532538
}
533-
534-
logger.info(`Processed ${blocksProcessed} non-starter blocks, total blocks in state: ${Object.keys(completeBlocks).length}`)
539+
540+
logger.info(
541+
`Processed ${blocksProcessed} non-starter blocks, total blocks in state: ${Object.keys(completeBlocks).length}`
542+
)
535543

536544
// Create complete edges using the ID mapping
537545
const completeEdges: any[] = []
538546
for (const edge of edges) {
539547
const sourceId = yamlIdToActualId.get(edge.source)
540548
const targetId = yamlIdToActualId.get(edge.target)
541-
549+
542550
if (sourceId && targetId) {
543551
completeEdges.push({
544552
...edge,
@@ -553,16 +561,18 @@ export async function importWorkflowFromYaml(
553561

554562
// Create complete workflow state with values already set in subBlocks
555563
logger.info('Creating complete workflow state with embedded values...')
556-
564+
557565
// Merge subblock values directly into block subBlocks
558566
for (const [blockId, blockData] of Object.entries(completeBlocks)) {
559567
const blockValues = completeSubBlockValues[blockId] || {}
560-
568+
561569
// Update subBlock values in place
562570
for (const [subBlockId, subBlockData] of Object.entries(blockData.subBlocks || {})) {
563571
if (blockValues[subBlockId] !== undefined && blockValues[subBlockId] !== null) {
564-
(subBlockData as any).value = blockValues[subBlockId]
565-
logger.debug(`Embedded value in block: ${blockId}.${subBlockId} = ${blockValues[subBlockId]}`)
572+
;(subBlockData as any).value = blockValues[subBlockId]
573+
logger.debug(
574+
`Embedded value in block: ${blockId}.${subBlockId} = ${blockValues[subBlockId]}`
575+
)
566576
}
567577
}
568578
}
@@ -623,16 +633,21 @@ export async function importWorkflowFromYaml(
623633
logger.info('Applying auto layout...')
624634
workflowActions.applyAutoLayout()
625635

626-
const totalBlocksCreated = Object.keys(completeBlocks).length - (existingStarterBlocks.length > 0 ? 1 : 0)
627-
628-
logger.info(`Successfully imported workflow: ${totalBlocksCreated} blocks created, ${completeEdges.length} edges, values set for ${Object.keys(completeSubBlockValues).length} blocks`)
636+
const totalBlocksCreated =
637+
Object.keys(completeBlocks).length - (existingStarterBlocks.length > 0 ? 1 : 0)
638+
639+
logger.info(
640+
`Successfully imported workflow: ${totalBlocksCreated} blocks created, ${completeEdges.length} edges, values set for ${Object.keys(completeSubBlockValues).length} blocks`
641+
)
629642

630643
return {
631644
success: true,
632645
errors: [],
633646
warnings,
634647
summary: `Imported ${totalBlocksCreated} new blocks and ${completeEdges.length} connections. ${
635-
existingStarterBlocks.length > 0 ? 'Updated existing starter block.' : 'Created new starter block.'
648+
existingStarterBlocks.length > 0
649+
? 'Updated existing starter block.'
650+
: 'Created new starter block.'
636651
}`,
637652
}
638653
} catch (error) {

0 commit comments

Comments
 (0)