Skip to content

Commit d6d165a

Browse files
waleedlatif1claude
andcommitted
fix(lock): fetch parent blocks for edge protection checks and consistent tooltip
- Fixed edge operations to fetch parent blocks before checking lock status - Previously, isBlockProtected checked if parent was locked, but the parent wasn't in blocksById because only source/target blocks were fetched - Now fetches parent blocks for all four edge operations: ADD, REMOVE, BATCH_ADD_EDGES, BATCH_REMOVE_EDGES - Fixed tooltip inconsistency: changed "Run previous blocks first" to "Run upstream blocks first" in action-bar to match workflow.tsx Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 104a828 commit d6d165a

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const ActionBar = memo(
194194
{(() => {
195195
if (disabled) return getTooltipMessage('Run from block')
196196
if (isExecuting) return 'Execution in progress'
197-
if (!dependenciesSatisfied) return 'Run previous blocks first'
197+
if (!dependenciesSatisfied) return 'Run upstream blocks first'
198198
return 'Run from block'
199199
})()}
200200
</Tooltip.Content>

apps/sim/socket/database/operations.ts

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,10 @@ async function handleBlocksOperationTx(
11331133
async function handleEdgeOperationTx(tx: any, workflowId: string, operation: string, payload: any) {
11341134
switch (operation) {
11351135
case EDGE_OPERATIONS.ADD: {
1136-
// Validate required fields
11371136
if (!payload.id || !payload.source || !payload.target) {
11381137
throw new Error('Missing required fields for add edge operation')
11391138
}
11401139

1141-
// Check if source or target blocks are protected (locked or inside locked parent)
11421140
const edgeBlocks = await tx
11431141
.select({
11441142
id: workflowBlocks.id,
@@ -1158,6 +1156,36 @@ async function handleEdgeOperationTx(tx: any, workflowId: string, operation: str
11581156
edgeBlocks.map((b: EdgeBlockRecord) => [b.id, b])
11591157
)
11601158

1159+
const parentIds = new Set<string>()
1160+
for (const block of edgeBlocks) {
1161+
const parentId = (block.data as Record<string, unknown> | null)?.parentId as
1162+
| string
1163+
| undefined
1164+
if (parentId && !blocksById[parentId]) {
1165+
parentIds.add(parentId)
1166+
}
1167+
}
1168+
1169+
// Fetch parent blocks if needed
1170+
if (parentIds.size > 0) {
1171+
const parentBlocks = await tx
1172+
.select({
1173+
id: workflowBlocks.id,
1174+
locked: workflowBlocks.locked,
1175+
data: workflowBlocks.data,
1176+
})
1177+
.from(workflowBlocks)
1178+
.where(
1179+
and(
1180+
eq(workflowBlocks.workflowId, workflowId),
1181+
inArray(workflowBlocks.id, Array.from(parentIds))
1182+
)
1183+
)
1184+
for (const b of parentBlocks) {
1185+
blocksById[b.id] = b
1186+
}
1187+
}
1188+
11611189
const isBlockProtected = (blockId: string): boolean => {
11621190
const block = blocksById[blockId]
11631191
if (!block) return false
@@ -1226,6 +1254,37 @@ async function handleEdgeOperationTx(tx: any, workflowId: string, operation: str
12261254
connectedBlocks.map((b: RemoveEdgeBlockRecord) => [b.id, b])
12271255
)
12281256

1257+
// Collect parent IDs that need to be fetched
1258+
const parentIds = new Set<string>()
1259+
for (const block of connectedBlocks) {
1260+
const parentId = (block.data as Record<string, unknown> | null)?.parentId as
1261+
| string
1262+
| undefined
1263+
if (parentId && !blocksById[parentId]) {
1264+
parentIds.add(parentId)
1265+
}
1266+
}
1267+
1268+
// Fetch parent blocks if needed
1269+
if (parentIds.size > 0) {
1270+
const parentBlocks = await tx
1271+
.select({
1272+
id: workflowBlocks.id,
1273+
locked: workflowBlocks.locked,
1274+
data: workflowBlocks.data,
1275+
})
1276+
.from(workflowBlocks)
1277+
.where(
1278+
and(
1279+
eq(workflowBlocks.workflowId, workflowId),
1280+
inArray(workflowBlocks.id, Array.from(parentIds))
1281+
)
1282+
)
1283+
for (const b of parentBlocks) {
1284+
blocksById[b.id] = b
1285+
}
1286+
}
1287+
12291288
const isBlockProtected = (blockId: string): boolean => {
12301289
const block = blocksById[blockId]
12311290
if (!block) return false
@@ -1319,6 +1378,37 @@ async function handleEdgesOperationTx(
13191378
connectedBlocks.map((b: EdgeBlockRecord) => [b.id, b])
13201379
)
13211380

1381+
// Collect parent IDs that need to be fetched
1382+
const parentIds = new Set<string>()
1383+
for (const block of connectedBlocks) {
1384+
const parentId = (block.data as Record<string, unknown> | null)?.parentId as
1385+
| string
1386+
| undefined
1387+
if (parentId && !blocksById[parentId]) {
1388+
parentIds.add(parentId)
1389+
}
1390+
}
1391+
1392+
// Fetch parent blocks if needed
1393+
if (parentIds.size > 0) {
1394+
const parentBlocks = await tx
1395+
.select({
1396+
id: workflowBlocks.id,
1397+
locked: workflowBlocks.locked,
1398+
data: workflowBlocks.data,
1399+
})
1400+
.from(workflowBlocks)
1401+
.where(
1402+
and(
1403+
eq(workflowBlocks.workflowId, workflowId),
1404+
inArray(workflowBlocks.id, Array.from(parentIds))
1405+
)
1406+
)
1407+
for (const b of parentBlocks) {
1408+
blocksById[b.id] = b
1409+
}
1410+
}
1411+
13221412
const isBlockProtected = (blockId: string): boolean => {
13231413
const block = blocksById[blockId]
13241414
if (!block) return false
@@ -1388,6 +1478,37 @@ async function handleEdgesOperationTx(
13881478
connectedBlocks.map((b: AddEdgeBlockRecord) => [b.id, b])
13891479
)
13901480

1481+
// Collect parent IDs that need to be fetched
1482+
const parentIds = new Set<string>()
1483+
for (const block of connectedBlocks) {
1484+
const parentId = (block.data as Record<string, unknown> | null)?.parentId as
1485+
| string
1486+
| undefined
1487+
if (parentId && !blocksById[parentId]) {
1488+
parentIds.add(parentId)
1489+
}
1490+
}
1491+
1492+
// Fetch parent blocks if needed
1493+
if (parentIds.size > 0) {
1494+
const parentBlocks = await tx
1495+
.select({
1496+
id: workflowBlocks.id,
1497+
locked: workflowBlocks.locked,
1498+
data: workflowBlocks.data,
1499+
})
1500+
.from(workflowBlocks)
1501+
.where(
1502+
and(
1503+
eq(workflowBlocks.workflowId, workflowId),
1504+
inArray(workflowBlocks.id, Array.from(parentIds))
1505+
)
1506+
)
1507+
for (const b of parentBlocks) {
1508+
blocksById[b.id] = b
1509+
}
1510+
}
1511+
13911512
const isBlockProtected = (blockId: string): boolean => {
13921513
const block = blocksById[blockId]
13931514
if (!block) return false

0 commit comments

Comments
 (0)