Skip to content

Commit 863755d

Browse files
committed
added workflow name and desc to metadata for workflow preview
1 parent f39da97 commit 863755d

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
133133
const finalWorkflowData = {
134134
...workflowData,
135135
state: {
136-
// Default values for expected properties
137136
deploymentStatuses: {},
138-
// Data from normalized tables
139137
blocks: normalizedData.blocks,
140138
edges: normalizedData.edges,
141139
loops: normalizedData.loops,
142140
parallels: normalizedData.parallels,
143141
lastSaved: Date.now(),
144142
isDeployed: workflowData.isDeployed || false,
145143
deployedAt: workflowData.deployedAt,
144+
metadata: {
145+
name: workflowData.name,
146+
description: workflowData.description,
147+
},
146148
},
147-
// Include workflow variables
148149
variables: workflowData.variables || {},
149150
}
150151

@@ -166,6 +167,10 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
166167
lastSaved: Date.now(),
167168
isDeployed: workflowData.isDeployed || false,
168169
deployedAt: workflowData.deployedAt,
170+
metadata: {
171+
name: workflowData.name,
172+
description: workflowData.description,
173+
},
169174
},
170175
variables: workflowData.variables || {},
171176
}

apps/sim/app/workspace/[workspaceId]/w/components/preview/preview.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useCallback, useEffect, useMemo, useState } from 'react'
44
import { ArrowLeft } from 'lucide-react'
5-
import { Badge, Button, Tooltip } from '@/components/emcn'
5+
import { Button, Tooltip } from '@/components/emcn'
66
import { redactApiKeys } from '@/lib/core/security/redaction'
77
import { cn } from '@/lib/core/utils/cn'
88
import { PreviewEditor } from '@/app/workspace/[workspaceId]/w/components/preview/components/preview-editor'
@@ -35,7 +35,6 @@ interface WorkflowStackEntry {
3535
workflowState: WorkflowState
3636
traceSpans: TraceSpan[]
3737
blockExecutions: Record<string, BlockExecutionData>
38-
/** Name of the workflow at this level for display in the breadcrumb */
3938
workflowName: string
4039
}
4140

@@ -146,7 +145,6 @@ export function Preview({
146145
initialSelectedBlockId,
147146
autoSelectLeftmost = true,
148147
}: PreviewProps) {
149-
/** Initialize pinnedBlockId synchronously to ensure sidebar is present from first render */
150148
const [pinnedBlockId, setPinnedBlockId] = useState<string | null>(() => {
151149
if (initialSelectedBlockId) return initialSelectedBlockId
152150
if (autoSelectLeftmost) {
@@ -155,45 +153,38 @@ export function Preview({
155153
return null
156154
})
157155

158-
/** Stack for nested workflow navigation. Empty means we're at the root level. */
159156
const [workflowStack, setWorkflowStack] = useState<WorkflowStackEntry[]>([])
160157

161-
/** Block executions for the root level */
162158
const rootBlockExecutions = useMemo(() => {
163159
if (providedBlockExecutions) return providedBlockExecutions
164160
if (!rootTraceSpans || !Array.isArray(rootTraceSpans)) return {}
165161
return buildBlockExecutions(rootTraceSpans)
166162
}, [providedBlockExecutions, rootTraceSpans])
167163

168-
/** Current block executions - either from stack or root */
169164
const blockExecutions = useMemo(() => {
170165
if (workflowStack.length > 0) {
171166
return workflowStack[workflowStack.length - 1].blockExecutions
172167
}
173168
return rootBlockExecutions
174169
}, [workflowStack, rootBlockExecutions])
175170

176-
/** Current workflow state - either from stack or root */
177171
const workflowState = useMemo(() => {
178172
if (workflowStack.length > 0) {
179173
return workflowStack[workflowStack.length - 1].workflowState
180174
}
181175
return rootWorkflowState
182176
}, [workflowStack, rootWorkflowState])
183177

184-
/** Whether we're in execution mode (have trace spans/block executions) */
185178
const isExecutionMode = useMemo(() => {
186179
return Object.keys(blockExecutions).length > 0
187180
}, [blockExecutions])
188181

189-
/** Handler to drill down into a nested workflow block */
190182
const handleDrillDown = useCallback(
191183
(blockId: string, childWorkflowState: WorkflowState) => {
192184
const blockExecution = blockExecutions[blockId]
193185
const childTraceSpans = extractChildTraceSpans(blockExecution)
194186
const childBlockExecutions = buildBlockExecutions(childTraceSpans)
195187

196-
/** Extract workflow name from metadata or use a fallback */
197188
const workflowName = childWorkflowState.metadata?.name || 'Nested Workflow'
198189

199190
setWorkflowStack((prev) => [
@@ -206,20 +197,17 @@ export function Preview({
206197
},
207198
])
208199

209-
/** Set pinned block synchronously to avoid double fitView from sidebar resize */
210200
const leftmostId = getLeftmostBlockId(childWorkflowState)
211201
setPinnedBlockId(leftmostId)
212202
},
213203
[blockExecutions]
214204
)
215205

216-
/** Handler to go back up the stack */
217206
const handleGoBack = useCallback(() => {
218207
setWorkflowStack((prev) => prev.slice(0, -1))
219208
setPinnedBlockId(null)
220209
}, [])
221210

222-
/** Handlers for node interactions - memoized to prevent unnecessary re-renders */
223211
const handleNodeClick = useCallback((blockId: string) => {
224212
setPinnedBlockId(blockId)
225213
}, [])
@@ -238,7 +226,6 @@ export function Preview({
238226

239227
const isNested = workflowStack.length > 0
240228

241-
/** Current workflow name from the top of the stack */
242229
const currentWorkflowName = isNested ? workflowStack[workflowStack.length - 1].workflowName : null
243230

244231
return (
@@ -251,27 +238,26 @@ export function Preview({
251238
)}
252239
>
253240
{isNested && (
254-
<div className='absolute top-[12px] left-[12px] z-20 flex items-center gap-[8px]'>
241+
<div className='absolute top-[12px] left-[12px] z-20 flex items-center gap-[6px]'>
255242
<Tooltip.Root>
256243
<Tooltip.Trigger asChild>
257244
<Button
258245
variant='ghost'
259246
onClick={handleGoBack}
260-
className='flex h-[30px] items-center gap-[5px] border border-[var(--border)] bg-[var(--surface-2)] px-[10px] hover:bg-[var(--surface-4)]'
247+
className='flex h-[28px] items-center gap-[5px] rounded-[6px] border border-[var(--border)] bg-[var(--surface-2)] px-[10px] text-[var(--text-secondary)] shadow-sm hover:bg-[var(--surface-4)] hover:text-[var(--text-primary)]'
261248
>
262-
<ArrowLeft className='h-[13px] w-[13px]' />
263-
<span className='font-medium text-[13px]'>Back</span>
249+
<ArrowLeft className='h-[12px] w-[12px]' />
250+
<span className='font-medium text-[12px]'>Back</span>
264251
</Button>
265252
</Tooltip.Trigger>
266253
<Tooltip.Content side='bottom'>Go back to parent workflow</Tooltip.Content>
267254
</Tooltip.Root>
268255
{currentWorkflowName && (
269-
<Badge
270-
variant='default'
271-
className='max-w-[200px] cursor-default truncate bg-[var(--surface-2)] text-[12px] hover:border-[var(--border)] hover:bg-[var(--surface-2)]'
272-
>
273-
{currentWorkflowName}
274-
</Badge>
256+
<div className='flex h-[28px] max-w-[200px] items-center rounded-[6px] border border-[var(--border)] bg-[var(--surface-2)] px-[10px] shadow-sm'>
257+
<span className='truncate font-medium text-[12px] text-[var(--text-secondary)]'>
258+
{currentWorkflowName}
259+
</span>
260+
</div>
275261
)}
276262
</div>
277263
)}

0 commit comments

Comments
 (0)