Skip to content

Commit 303934f

Browse files
committed
fix autolayout
1 parent 6a88b59 commit 303934f

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/error/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { Component, type ReactNode, useEffect } from 'react'
4+
import { ReactFlowProvider } from 'reactflow'
45
import { createLogger } from '@/lib/logs/console/logger'
56
import { Panel } from '@/app/workspace/[workspaceId]/w/[workflowId]/components'
67
import { Sidebar } from '@/app/workspace/[workspaceId]/w/components/sidebar/sidebar'
@@ -47,8 +48,9 @@ export function ErrorUI({
4748
</div>
4849
</div>
4950

50-
{/* Panel */}
51-
<Panel />
51+
<ReactFlowProvider>
52+
<Panel />
53+
</ReactFlowProvider>
5254
</div>
5355
</div>
5456
)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-auto-layout.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback } from 'react'
2+
import { useReactFlow } from 'reactflow'
23
import { createLogger } from '@/lib/logs/console/logger'
34
import type { AutoLayoutOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
45
import { applyAutoLayoutAndUpdateStore as applyAutoLayoutStandalone } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
@@ -7,45 +8,38 @@ export type { AutoLayoutOptions }
78

89
const logger = createLogger('useAutoLayout')
910

10-
interface UseAutoLayoutOptions {
11-
fitView?: (options?: { padding?: number; duration?: number }) => void
12-
}
13-
1411
/**
1512
* Hook providing auto-layout functionality for workflows.
1613
* Binds workflowId context and provides memoized callback for React components.
17-
* Optionally accepts a fitView function to animate after successful layout.
14+
* Includes automatic fitView animation after successful layout.
1815
*
19-
* @param workflowId - The workflow ID to apply layout to
20-
* @param options - Optional configuration including fitView function from useReactFlow
16+
* Note: This hook requires a ReactFlowProvider ancestor.
2117
*/
22-
export function useAutoLayout(workflowId: string | null, options: UseAutoLayoutOptions = {}) {
23-
const { fitView } = options
18+
export function useAutoLayout(workflowId: string | null) {
19+
const { fitView } = useReactFlow()
2420

2521
const applyAutoLayoutAndUpdateStore = useCallback(
26-
async (layoutOptions: AutoLayoutOptions = {}) => {
22+
async (options: AutoLayoutOptions = {}) => {
2723
if (!workflowId) {
2824
return { success: false, error: 'No workflow ID provided' }
2925
}
30-
return applyAutoLayoutStandalone(workflowId, layoutOptions)
26+
return applyAutoLayoutStandalone(workflowId, options)
3127
},
3228
[workflowId]
3329
)
3430

3531
/**
36-
* Applies auto-layout and optionally animates to fit all blocks in view
32+
* Applies auto-layout and animates to fit all blocks in view
3733
*/
3834
const handleAutoLayout = useCallback(async () => {
3935
try {
4036
const result = await applyAutoLayoutAndUpdateStore()
4137

4238
if (result.success) {
4339
logger.info('Auto layout completed successfully')
44-
if (fitView) {
45-
requestAnimationFrame(() => {
46-
fitView({ padding: 0.8, duration: 600 })
47-
})
48-
}
40+
requestAnimationFrame(() => {
41+
fitView({ padding: 0.8, duration: 600 })
42+
})
4943
} else {
5044
logger.error('Auto layout failed:', result.error)
5145
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ const WorkflowContent = React.memo(() => {
198198
return resizeLoopNodes(updateNodeDimensions)
199199
}, [resizeLoopNodes, updateNodeDimensions])
200200

201-
const { handleAutoLayout: autoLayoutWithFitView } = useAutoLayout(activeWorkflowId || null, {
202-
fitView,
203-
})
201+
const { handleAutoLayout: autoLayoutWithFitView } = useAutoLayout(activeWorkflowId || null)
204202

205203
const isWorkflowEmpty = useMemo(() => Object.keys(blocks).length === 0, [blocks])
206204

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ function BYOKKeySkeleton() {
6767
return (
6868
<div className='flex items-center justify-between gap-[12px] rounded-[8px] p-[12px]'>
6969
<div className='flex items-center gap-[12px]'>
70-
<Skeleton className='h-[24px] w-[24px] rounded-[6px]' />
71-
<div className='flex flex-col gap-[4px]'>
72-
<Skeleton className='h-[16px] w-[80px]' />
73-
<Skeleton className='h-[14px] w-[160px]' />
70+
<Skeleton className='h-9 w-9 flex-shrink-0 rounded-[6px]' />
71+
<div className='flex flex-col justify-center gap-[1px]'>
72+
<Skeleton className='h-[14px] w-[100px]' />
73+
<Skeleton className='h-[13px] w-[200px]' />
7474
</div>
7575
</div>
76-
<Skeleton className='h-[32px] w-[80px] rounded-[6px]' />
76+
<Skeleton className='h-[32px] w-[72px] rounded-[6px]' />
7777
</div>
7878
)
7979
}
@@ -164,8 +164,8 @@ export function BYOK() {
164164
className='flex items-center justify-between gap-[12px] rounded-[8px] p-[12px]'
165165
>
166166
<div className='flex items-center gap-[12px]'>
167-
<div className='flex h-[24px] w-[24px] items-center justify-center rounded-[4px] bg-[var(--surface-3)]'>
168-
<Icon className='h-[14px] w-[14px]' />
167+
<div className='flex h-9 w-9 flex-shrink-0 items-center justify-center overflow-hidden rounded-[6px] bg-[var(--surface-6)]'>
168+
<Icon className='h-4 w-4' />
169169
</div>
170170
<div className='flex flex-col gap-[2px]'>
171171
<span className='font-medium text-[14px]'>{provider.name}</span>

apps/sim/app/workspace/[workspaceId]/w/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect, useState } from 'react'
44
import { useParams, useRouter } from 'next/navigation'
5+
import { ReactFlowProvider } from 'reactflow'
56
import { createLogger } from '@/lib/logs/console/logger'
67
import { Panel, Terminal } from '@/app/workspace/[workspaceId]/w/[workflowId]/components'
78
import { useWorkflows } from '@/hooks/queries/workflows'
@@ -69,7 +70,9 @@ export default function WorkflowsPage() {
6970
}}
7071
/>
7172
</div>
72-
<Panel />
73+
<ReactFlowProvider>
74+
<Panel />
75+
</ReactFlowProvider>
7376
</div>
7477
<Terminal />
7578
</div>

0 commit comments

Comments
 (0)