Skip to content

Commit 160c6ca

Browse files
committed
fix tests + add context into block preview
1 parent c369e04 commit 160c6ca

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

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

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ export const WorkflowBlock = memo(function WorkflowBlock({
889889
if (type === 'condition') {
890890
rowsCount = conditionRows.length + defaultHandlesRow
891891
} else if (type === 'router_v2') {
892-
rowsCount = routerRows.length + defaultHandlesRow
892+
// +1 for context row, plus route rows
893+
rowsCount = 1 + routerRows.length + defaultHandlesRow
893894
} else {
894895
const subblockRowCount = subBlockRows.reduce((acc, row) => acc + row.length, 0)
895896
rowsCount = subblockRowCount + defaultHandlesRow
@@ -1107,40 +1108,45 @@ export const WorkflowBlock = memo(function WorkflowBlock({
11071108

11081109
{hasContentBelowHeader && (
11091110
<div className='flex flex-col gap-[8px] p-[8px]'>
1110-
{type === 'condition'
1111-
? conditionRows.map((cond) => (
1111+
{type === 'condition' ? (
1112+
conditionRows.map((cond) => (
1113+
<SubBlockRow key={cond.id} title={cond.title} value={getDisplayValue(cond.value)} />
1114+
))
1115+
) : type === 'router_v2' ? (
1116+
<>
1117+
<SubBlockRow
1118+
key='context'
1119+
title='Context'
1120+
value={getDisplayValue(subBlockState.context?.value)}
1121+
/>
1122+
{routerRows.map((route, index) => (
11121123
<SubBlockRow
1113-
key={cond.id}
1114-
title={cond.title}
1115-
value={getDisplayValue(cond.value)}
1124+
key={route.id}
1125+
title={`Route ${index + 1}`}
1126+
value={getDisplayValue(route.value)}
11161127
/>
1117-
))
1118-
: type === 'router_v2'
1119-
? routerRows.map((route, index) => (
1128+
))}
1129+
</>
1130+
) : (
1131+
subBlockRows.map((row, rowIndex) =>
1132+
row.map((subBlock) => {
1133+
const rawValue = subBlockState[subBlock.id]?.value
1134+
return (
11201135
<SubBlockRow
1121-
key={route.id}
1122-
title={`Route ${index + 1}`}
1123-
value={getDisplayValue(route.value)}
1136+
key={`${subBlock.id}-${rowIndex}`}
1137+
title={subBlock.title ?? subBlock.id}
1138+
value={getDisplayValue(rawValue)}
1139+
subBlock={subBlock}
1140+
rawValue={rawValue}
1141+
workspaceId={workspaceId}
1142+
workflowId={currentWorkflowId}
1143+
blockId={id}
1144+
allSubBlockValues={subBlockState}
11241145
/>
1125-
))
1126-
: subBlockRows.map((row, rowIndex) =>
1127-
row.map((subBlock) => {
1128-
const rawValue = subBlockState[subBlock.id]?.value
1129-
return (
1130-
<SubBlockRow
1131-
key={`${subBlock.id}-${rowIndex}`}
1132-
title={subBlock.title ?? subBlock.id}
1133-
value={getDisplayValue(rawValue)}
1134-
subBlock={subBlock}
1135-
rawValue={rawValue}
1136-
workspaceId={workspaceId}
1137-
workflowId={currentWorkflowId}
1138-
blockId={id}
1139-
allSubBlockValues={subBlockState}
1140-
/>
1141-
)
1142-
})
1143-
)}
1146+
)
1147+
})
1148+
)
1149+
)}
11441150
{shouldShowDefaultHandles && <SubBlockRow title='error' />}
11451151
</div>
11461152
)}
@@ -1198,9 +1204,10 @@ export const WorkflowBlock = memo(function WorkflowBlock({
11981204
{type === 'router_v2' && (
11991205
<>
12001206
{routerRows.map((route, routeIndex) => {
1207+
// +1 row offset for context row at the top
12011208
const topOffset =
12021209
HANDLE_POSITIONS.CONDITION_START_Y +
1203-
routeIndex * HANDLE_POSITIONS.CONDITION_ROW_HEIGHT
1210+
(routeIndex + 1) * HANDLE_POSITIONS.CONDITION_ROW_HEIGHT
12041211
return (
12051212
<Handle
12061213
key={`handle-${route.id}`}

apps/sim/blocks/blocks.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ describe('Blocks Module', () => {
321321

322322
it('should have correct metadata', () => {
323323
expect(block?.type).toBe('router')
324-
expect(block?.name).toBe('Router')
324+
expect(block?.name).toBe('Router (Legacy)')
325325
expect(block?.category).toBe('blocks')
326326
expect(block?.authMode).toBe(AuthMode.ApiKey)
327327
})
@@ -454,6 +454,7 @@ describe('Blocks Module', () => {
454454
'workflow-selector',
455455
'workflow-input-mapper',
456456
'text',
457+
'router-input',
457458
]
458459

459460
const blocks = getAllBlocks()

0 commit comments

Comments
 (0)