Skip to content

Commit 6cb15a6

Browse files
committed
Lint
1 parent c7b77bd commit 6cb15a6

File tree

2 files changed

+68
-65
lines changed
  • apps/sim
    • app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/export-controls
    • stores/workflows/yaml

2 files changed

+68
-65
lines changed

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
} from '@/components/ui/dropdown-menu'
1313
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
1414
import { createLogger } from '@/lib/logs/console-logger'
15-
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1615
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
16+
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1717
import { useWorkflowYamlStore } from '@/stores/workflows/yaml/store'
1818

1919
const logger = createLogger('ExportControls')
@@ -26,7 +26,7 @@ export function ExportControls({ disabled = false }: ExportControlsProps) {
2626
const [isExporting, setIsExporting] = useState(false)
2727
const workflowState = useWorkflowStore()
2828
const { workflows, activeWorkflowId } = useWorkflowRegistry()
29-
const getYaml = useWorkflowYamlStore(state => state.getYaml)
29+
const getYaml = useWorkflowYamlStore((state) => state.getYaml)
3030

3131
const currentWorkflow = activeWorkflowId ? workflows[activeWorkflowId] : null
3232

@@ -68,12 +68,12 @@ export function ExportControls({ disabled = false }: ExportControlsProps) {
6868
parallels: workflowState.parallels,
6969
},
7070
exportedAt: new Date().toISOString(),
71-
version: '1.0'
71+
version: '1.0',
7272
}
7373

7474
const jsonContent = JSON.stringify(exportData, null, 2)
7575
const filename = `${currentWorkflow.name.replace(/[^a-z0-9]/gi, '_')}_workflow.json`
76-
76+
7777
downloadFile(jsonContent, filename, 'application/json')
7878
logger.info('Workflow exported as JSON')
7979
} catch (error) {
@@ -93,7 +93,7 @@ export function ExportControls({ disabled = false }: ExportControlsProps) {
9393
try {
9494
const yamlContent = getYaml()
9595
const filename = `${currentWorkflow.name.replace(/[^a-z0-9]/gi, '_')}_workflow.yaml`
96-
96+
9797
downloadFile(yamlContent, filename, 'text/yaml')
9898
logger.info('Workflow exported as YAML')
9999
} catch (error) {
@@ -108,9 +108,9 @@ export function ExportControls({ disabled = false }: ExportControlsProps) {
108108
<Tooltip>
109109
<TooltipTrigger asChild>
110110
<DropdownMenuTrigger asChild>
111-
<Button
112-
variant='ghost'
113-
size='icon'
111+
<Button
112+
variant='ghost'
113+
size='icon'
114114
disabled={disabled || isExporting || !currentWorkflow}
115115
className='hover:text-foreground'
116116
>
@@ -120,46 +120,41 @@ export function ExportControls({ disabled = false }: ExportControlsProps) {
120120
</DropdownMenuTrigger>
121121
</TooltipTrigger>
122122
<TooltipContent>
123-
{disabled
124-
? 'Export not available'
125-
: !currentWorkflow
123+
{disabled
124+
? 'Export not available'
125+
: !currentWorkflow
126126
? 'No workflow to export'
127-
: 'Export Workflow'
128-
}
127+
: 'Export Workflow'}
129128
</TooltipContent>
130129
</Tooltip>
131130

132131
<DropdownMenuContent align='end' className='w-48'>
133-
<DropdownMenuItem
132+
<DropdownMenuItem
134133
onClick={handleExportJson}
135134
disabled={isExporting || !currentWorkflow}
136-
className='flex items-center gap-2 cursor-pointer'
135+
className='flex cursor-pointer items-center gap-2'
137136
>
138137
<FileText className='h-4 w-4' />
139138
<div className='flex flex-col'>
140139
<span>Export as JSON</span>
141-
<span className='text-muted-foreground text-xs'>
142-
Full workflow data
143-
</span>
140+
<span className='text-muted-foreground text-xs'>Full workflow data</span>
144141
</div>
145142
</DropdownMenuItem>
146-
143+
147144
<DropdownMenuSeparator />
148-
149-
<DropdownMenuItem
145+
146+
<DropdownMenuItem
150147
onClick={handleExportYaml}
151148
disabled={isExporting || !currentWorkflow}
152-
className='flex items-center gap-2 cursor-pointer'
149+
className='flex cursor-pointer items-center gap-2'
153150
>
154151
<FileText className='h-4 w-4' />
155152
<div className='flex flex-col'>
156153
<span>Export as YAML</span>
157-
<span className='text-muted-foreground text-xs'>
158-
Condensed workflow language
159-
</span>
154+
<span className='text-muted-foreground text-xs'>Condensed workflow language</span>
160155
</div>
161156
</DropdownMenuItem>
162157
</DropdownMenuContent>
163158
</DropdownMenu>
164159
)
165-
}
160+
}

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

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { dump as yamlDump } from 'js-yaml'
12
import { create } from 'zustand'
23
import { devtools } from 'zustand/middleware'
3-
import { dump as yamlDump } from 'js-yaml'
4-
import { getBlock } from '@/blocks'
54
import { createLogger } from '@/lib/logs/console-logger'
6-
import { useWorkflowStore } from '../workflow/store'
5+
import { getBlock } from '@/blocks'
6+
import type { SubBlockConfig } from '@/blocks/types'
77
import { useSubBlockStore } from '../subblock/store'
8+
import { useWorkflowStore } from '../workflow/store'
89
import type { BlockState, WorkflowState } from '../workflow/types'
9-
import type { SubBlockConfig } from '@/blocks/types'
1010

1111
const logger = createLogger('WorkflowYamlStore')
1212

@@ -58,13 +58,13 @@ function extractBlockInputs(blockState: BlockState, blockId: string): Record<str
5858
// Process each subBlock configuration
5959
blockConfig.subBlocks.forEach((subBlockConfig: SubBlockConfig) => {
6060
const subBlockId = subBlockConfig.id
61-
61+
6262
// Skip hidden or conditional fields that aren't active
6363
if (subBlockConfig.hidden) return
64-
64+
6565
// Get value from subblock store or fallback to block state
66-
const value = subBlockStore.getValue(blockId, subBlockId) ??
67-
blockState.subBlocks[subBlockId]?.value
66+
const value =
67+
subBlockStore.getValue(blockId, subBlockId) ?? blockState.subBlocks[subBlockId]?.value
6868

6969
// Include value if it exists and isn't empty
7070
if (value !== undefined && value !== null && value !== '') {
@@ -76,14 +76,14 @@ function extractBlockInputs(blockState: BlockState, blockId: string): Record<str
7676
inputs[subBlockId] = value
7777
}
7878
break
79-
79+
8080
case 'checkbox-list':
8181
// Checkbox lists return arrays
8282
if (Array.isArray(value) && value.length > 0) {
8383
inputs[subBlockId] = value
8484
}
8585
break
86-
86+
8787
case 'code':
8888
// Code blocks should preserve formatting
8989
if (typeof value === 'string' && value.trim()) {
@@ -92,24 +92,31 @@ function extractBlockInputs(blockState: BlockState, blockId: string): Record<str
9292
inputs[subBlockId] = value
9393
}
9494
break
95-
95+
9696
case 'switch':
9797
// Boolean values
9898
inputs[subBlockId] = Boolean(value)
9999
break
100-
100+
101101
case 'slider':
102102
// Numeric values
103-
if (typeof value === 'number' || (typeof value === 'string' && !isNaN(Number(value)))) {
103+
if (
104+
typeof value === 'number' ||
105+
(typeof value === 'string' && !Number.isNaN(Number(value)))
106+
) {
104107
inputs[subBlockId] = Number(value)
105108
}
106109
break
107-
110+
108111
default:
109112
// Text inputs, dropdowns, etc.
110113
if (typeof value === 'string' && value.trim()) {
111114
inputs[subBlockId] = value.trim()
112-
} else if (typeof value === 'object' || typeof value === 'number' || typeof value === 'boolean') {
115+
} else if (
116+
typeof value === 'object' ||
117+
typeof value === 'number' ||
118+
typeof value === 'boolean'
119+
) {
113120
inputs[subBlockId] = value
114121
}
115122
break
@@ -125,8 +132,8 @@ function extractBlockInputs(blockState: BlockState, blockId: string): Record<str
125132
*/
126133
function findPrecedingBlocks(blockId: string, edges: any[]): string[] {
127134
return edges
128-
.filter(edge => edge.target === blockId)
129-
.map(edge => edge.source)
135+
.filter((edge) => edge.target === blockId)
136+
.map((edge) => edge.source)
130137
.filter((source, index, arr) => arr.indexOf(source) === index) // Remove duplicates
131138
}
132139

@@ -135,8 +142,8 @@ function findPrecedingBlocks(blockId: string, edges: any[]): string[] {
135142
*/
136143
function findFollowingBlocks(blockId: string, edges: any[]): string[] {
137144
return edges
138-
.filter(edge => edge.source === blockId)
139-
.map(edge => edge.target)
145+
.filter((edge) => edge.source === blockId)
146+
.map((edge) => edge.target)
140147
.filter((target, index, arr) => arr.indexOf(target) === index) // Remove duplicates
141148
}
142149

@@ -147,7 +154,7 @@ function generateWorkflowYaml(workflowState: WorkflowState): string {
147154
try {
148155
const yamlWorkflow: YamlWorkflow = {
149156
version: '1.0',
150-
blocks: {}
157+
blocks: {},
151158
}
152159

153160
// Process each block
@@ -158,7 +165,7 @@ function generateWorkflowYaml(workflowState: WorkflowState): string {
158165

159166
const yamlBlock: YamlBlock = {
160167
type: blockState.type,
161-
name: blockState.name
168+
name: blockState.name,
162169
}
163170

164171
// Only include inputs if they exist
@@ -170,7 +177,7 @@ function generateWorkflowYaml(workflowState: WorkflowState): string {
170177
if (preceding.length > 0) {
171178
yamlBlock.preceding = preceding
172179
}
173-
180+
174181
if (following.length > 0) {
175182
yamlBlock.following = following
176183
}
@@ -183,7 +190,7 @@ function generateWorkflowYaml(workflowState: WorkflowState): string {
183190
indent: 2,
184191
lineWidth: -1, // Disable line wrapping
185192
noRefs: true,
186-
sortKeys: false
193+
sortKeys: false,
187194
})
188195
} catch (error) {
189196
logger.error('Failed to generate workflow YAML:', error)
@@ -200,32 +207,32 @@ export const useWorkflowYamlStore = create<WorkflowYamlStore>()(
200207
generateYaml: () => {
201208
const workflowState = useWorkflowStore.getState()
202209
const yaml = generateWorkflowYaml(workflowState)
203-
210+
204211
set({
205212
yaml,
206-
lastGenerated: Date.now()
213+
lastGenerated: Date.now(),
207214
})
208215
},
209216

210217
getYaml: () => {
211218
const currentTime = Date.now()
212219
const { yaml, lastGenerated } = get()
213-
220+
214221
// Auto-refresh if data is stale (older than 1 second) or never generated
215222
if (!lastGenerated || currentTime - lastGenerated > 1000) {
216223
get().generateYaml()
217224
return get().yaml
218225
}
219-
226+
220227
return yaml
221228
},
222229

223230
refreshYaml: () => {
224231
get().generateYaml()
225-
}
232+
},
226233
}),
227234
{
228-
name: 'workflow-yaml-store'
235+
name: 'workflow-yaml-store',
229236
}
230237
)
231238
)
@@ -236,16 +243,17 @@ let lastWorkflowState: { blockCount: number; edgeCount: number } | null = null
236243
useWorkflowStore.subscribe((state) => {
237244
const currentState = {
238245
blockCount: Object.keys(state.blocks).length,
239-
edgeCount: state.edges.length
246+
edgeCount: state.edges.length,
240247
}
241-
248+
242249
// Only refresh if the structure has changed
243-
if (!lastWorkflowState ||
244-
lastWorkflowState.blockCount !== currentState.blockCount ||
245-
lastWorkflowState.edgeCount !== currentState.edgeCount) {
246-
250+
if (
251+
!lastWorkflowState ||
252+
lastWorkflowState.blockCount !== currentState.blockCount ||
253+
lastWorkflowState.edgeCount !== currentState.edgeCount
254+
) {
247255
lastWorkflowState = currentState
248-
256+
249257
// Debounce the refresh to avoid excessive updates
250258
const refreshYaml = useWorkflowYamlStore.getState().refreshYaml
251259
setTimeout(refreshYaml, 100)
@@ -257,12 +265,12 @@ let lastSubBlockChangeTime = 0
257265

258266
useSubBlockStore.subscribe((state) => {
259267
const currentTime = Date.now()
260-
268+
261269
// Debounce rapid changes
262270
if (currentTime - lastSubBlockChangeTime > 100) {
263271
lastSubBlockChangeTime = currentTime
264-
272+
265273
const refreshYaml = useWorkflowYamlStore.getState().refreshYaml
266274
setTimeout(refreshYaml, 100)
267275
}
268-
})
276+
})

0 commit comments

Comments
 (0)