Skip to content

Commit c6c975d

Browse files
committed
fix: address review comments on saga flow and preview tabs
- Fix duplicate edge when step has earlyExit by tracking when decision "No" edge already connects to the next step - Add type="button" to clipboard copy button to prevent form submits - Add .catch() to clipboard writeText for restricted contexts - Add relative positioning to saga flow wrapper for legend overlay
1 parent 22fa640 commit c6c975d

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

frontend/src/features/cookbook/components/preview-source-tabs.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ interface PreviewSourceTabsProps {
1111
export function PreviewSourceTabs({ preview, source, sourceLabel = 'Source', className }: PreviewSourceTabsProps) {
1212
const [copied, setCopied] = useState(false)
1313

14-
const handleCopy = async () => {
15-
await navigator.clipboard.writeText(source)
16-
setCopied(true)
17-
setTimeout(() => setCopied(false), 2000)
14+
const handleCopy = () => {
15+
navigator.clipboard.writeText(source).then(() => {
16+
setCopied(true)
17+
setTimeout(() => setCopied(false), 2000)
18+
}).catch(() => {
19+
// Silently fail in restricted contexts
20+
})
1821
}
1922

2023
return (
@@ -31,6 +34,7 @@ export function PreviewSourceTabs({ preview, source, sourceLabel = 'Source', cla
3134
<TabsContent value="source" className="mt-4">
3235
<div className="relative">
3336
<button
37+
type="button"
3438
onClick={handleCopy}
3539
className="absolute right-2 top-2 z-10 rounded border bg-background px-2 py-1 text-xs text-muted-foreground hover:bg-accent"
3640
>

frontend/src/features/cookbook/components/saga-flow.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function buildFlowGraph(flow: SagaFlow): { nodes: Node[]; edges: Edge[] } {
228228
}
229229

230230
// Step + decision + exit nodes
231-
let prevId = 'start'
231+
let prevId: string | null = 'start'
232232

233233
for (let i = 0; i < flow.steps.length; i++) {
234234
const step = flow.steps[i]
@@ -245,11 +245,14 @@ function buildFlowGraph(flow: SagaFlow): { nodes: Node[]; edges: Edge[] } {
245245
} satisfies StepNodeData,
246246
})
247247

248-
edges.push({
249-
id: `${prevId}-${stepId}`,
250-
source: prevId,
251-
target: stepId,
252-
})
248+
// Connect from previous node (null when previous decision's "No" edge already connects)
249+
if (prevId) {
250+
edges.push({
251+
id: `${prevId}-${stepId}`,
252+
source: prevId,
253+
target: stepId,
254+
})
255+
}
253256

254257
if (step.earlyExit) {
255258
const decisionId = `decision-${i}`
@@ -285,15 +288,15 @@ function buildFlowGraph(flow: SagaFlow): { nodes: Node[]; edges: Edge[] } {
285288
style: { stroke: '#ef4444', strokeDasharray: '6 3' },
286289
})
287290

288-
// "No" -> next step
291+
// "No" -> next step (already connects to nextId, so skip prevId for next iteration)
289292
edges.push({
290293
id: `${decisionId}-${nextId}`,
291294
source: decisionId,
292295
target: nextId,
293296
label: 'No',
294297
})
295298

296-
prevId = decisionId
299+
prevId = null
297300
} else {
298301
prevId = stepId
299302
}
@@ -307,9 +310,8 @@ function buildFlowGraph(flow: SagaFlow): { nodes: Node[]; edges: Edge[] } {
307310
data: {},
308311
})
309312

310-
// Connect last step to end (only if no early exit on last step)
311-
const lastStep = flow.steps[flow.steps.length - 1]
312-
if (!lastStep.earlyExit) {
313+
// Connect last step to end (only if no early exit on last step already connected it)
314+
if (prevId) {
313315
edges.push({
314316
id: `${prevId}-end`,
315317
source: prevId,
@@ -343,7 +345,7 @@ export function SagaFlowDiagram({ flow, onStepClick, className }: SagaFlowDiagra
343345
}, [flow])
344346

345347
return (
346-
<div className={className} style={{ width: '100%', height: '100%', minHeight: 400 }}>
348+
<div className={`relative ${className ?? ''}`} style={{ width: '100%', height: '100%', minHeight: 400 }}>
347349
<ReactFlow
348350
nodes={nodes}
349351
edges={edges}

0 commit comments

Comments
 (0)