Skip to content

Commit 7a4359d

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

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
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 & 23 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'
@@ -146,7 +146,6 @@ export function Preview({
146146
initialSelectedBlockId,
147147
autoSelectLeftmost = true,
148148
}: PreviewProps) {
149-
/** Initialize pinnedBlockId synchronously to ensure sidebar is present from first render */
150149
const [pinnedBlockId, setPinnedBlockId] = useState<string | null>(() => {
151150
if (initialSelectedBlockId) return initialSelectedBlockId
152151
if (autoSelectLeftmost) {
@@ -155,45 +154,38 @@ export function Preview({
155154
return null
156155
})
157156

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

161-
/** Block executions for the root level */
162159
const rootBlockExecutions = useMemo(() => {
163160
if (providedBlockExecutions) return providedBlockExecutions
164161
if (!rootTraceSpans || !Array.isArray(rootTraceSpans)) return {}
165162
return buildBlockExecutions(rootTraceSpans)
166163
}, [providedBlockExecutions, rootTraceSpans])
167164

168-
/** Current block executions - either from stack or root */
169165
const blockExecutions = useMemo(() => {
170166
if (workflowStack.length > 0) {
171167
return workflowStack[workflowStack.length - 1].blockExecutions
172168
}
173169
return rootBlockExecutions
174170
}, [workflowStack, rootBlockExecutions])
175171

176-
/** Current workflow state - either from stack or root */
177172
const workflowState = useMemo(() => {
178173
if (workflowStack.length > 0) {
179174
return workflowStack[workflowStack.length - 1].workflowState
180175
}
181176
return rootWorkflowState
182177
}, [workflowStack, rootWorkflowState])
183178

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

189-
/** Handler to drill down into a nested workflow block */
190183
const handleDrillDown = useCallback(
191184
(blockId: string, childWorkflowState: WorkflowState) => {
192185
const blockExecution = blockExecutions[blockId]
193186
const childTraceSpans = extractChildTraceSpans(blockExecution)
194187
const childBlockExecutions = buildBlockExecutions(childTraceSpans)
195188

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

199191
setWorkflowStack((prev) => [
@@ -206,20 +198,17 @@ export function Preview({
206198
},
207199
])
208200

209-
/** Set pinned block synchronously to avoid double fitView from sidebar resize */
210201
const leftmostId = getLeftmostBlockId(childWorkflowState)
211202
setPinnedBlockId(leftmostId)
212203
},
213204
[blockExecutions]
214205
)
215206

216-
/** Handler to go back up the stack */
217207
const handleGoBack = useCallback(() => {
218208
setWorkflowStack((prev) => prev.slice(0, -1))
219209
setPinnedBlockId(null)
220210
}, [])
221211

222-
/** Handlers for node interactions - memoized to prevent unnecessary re-renders */
223212
const handleNodeClick = useCallback((blockId: string) => {
224213
setPinnedBlockId(blockId)
225214
}, [])
@@ -238,7 +227,6 @@ export function Preview({
238227

239228
const isNested = workflowStack.length > 0
240229

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

244232
return (
@@ -251,27 +239,26 @@ export function Preview({
251239
)}
252240
>
253241
{isNested && (
254-
<div className='absolute top-[12px] left-[12px] z-20 flex items-center gap-[8px]'>
242+
<div className='absolute top-[12px] left-[12px] z-20 flex items-center gap-[6px]'>
255243
<Tooltip.Root>
256244
<Tooltip.Trigger asChild>
257245
<Button
258246
variant='ghost'
259247
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)]'
248+
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)]'
261249
>
262-
<ArrowLeft className='h-[13px] w-[13px]' />
263-
<span className='font-medium text-[13px]'>Back</span>
250+
<ArrowLeft className='h-[12px] w-[12px]' />
251+
<span className='font-medium text-[12px]'>Back</span>
264252
</Button>
265253
</Tooltip.Trigger>
266254
<Tooltip.Content side='bottom'>Go back to parent workflow</Tooltip.Content>
267255
</Tooltip.Root>
268256
{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>
257+
<div className='flex h-[28px] max-w-[200px] items-center rounded-[6px] border border-[var(--border)] bg-[var(--surface-2)] px-[10px] shadow-sm'>
258+
<span className='truncate font-medium text-[12px] text-[var(--text-secondary)]'>
259+
{currentWorkflowName}
260+
</span>
261+
</div>
275262
)}
276263
</div>
277264
)}

0 commit comments

Comments
 (0)