Skip to content

Commit 1d36b80

Browse files
improvement(selectors): remove dead semantic fallback code (#3454)
* improvement(selectors): simplify selectorContext + add tests * fix resolve values fallback * another workflowid pass through * remove dead code * make workspace id required
1 parent e6a5e7f commit 1d36b80

File tree

2 files changed

+17
-55
lines changed

2 files changed

+17
-55
lines changed

apps/sim/lib/workflows/comparison/resolve-values.ts

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,8 @@ interface ResolutionContext {
4040
blockId?: string
4141
}
4242

43-
function getSemanticFallback(subBlockId: string, subBlockConfig?: SubBlockConfig): string {
44-
if (subBlockConfig?.title) {
45-
return subBlockConfig.title.toLowerCase()
46-
}
47-
48-
const patterns: Record<string, string> = {
49-
credential: 'credential',
50-
channel: 'channel',
51-
channelId: 'channel',
52-
user: 'user',
53-
userId: 'user',
54-
workflow: 'workflow',
55-
workflowId: 'workflow',
56-
file: 'file',
57-
fileId: 'file',
58-
folder: 'folder',
59-
folderId: 'folder',
60-
project: 'project',
61-
projectId: 'project',
62-
team: 'team',
63-
teamId: 'team',
64-
sheet: 'sheet',
65-
sheetId: 'sheet',
66-
document: 'document',
67-
documentId: 'document',
68-
knowledgeBase: 'knowledge base',
69-
knowledgeBaseId: 'knowledge base',
70-
server: 'server',
71-
serverId: 'server',
72-
tool: 'tool',
73-
toolId: 'tool',
74-
calendar: 'calendar',
75-
calendarId: 'calendar',
76-
label: 'label',
77-
labelId: 'label',
78-
site: 'site',
79-
siteId: 'site',
80-
collection: 'collection',
81-
collectionId: 'collection',
82-
item: 'item',
83-
itemId: 'item',
84-
contact: 'contact',
85-
contactId: 'contact',
86-
task: 'task',
87-
taskId: 'task',
88-
chat: 'chat',
89-
chatId: 'chat',
90-
}
91-
92-
return patterns[subBlockId] || 'value'
43+
function getSemanticFallback(subBlockConfig: SubBlockConfig): string {
44+
return (subBlockConfig.title ?? subBlockConfig.id).toLowerCase()
9345
}
9446

9547
async function resolveCredential(credentialId: string, workflowId: string): Promise<string | null> {
@@ -219,7 +171,10 @@ export async function resolveValueForDisplay(
219171

220172
const blockConfig = getBlock(context.blockType)
221173
const subBlockConfig = blockConfig?.subBlocks.find((sb) => sb.id === context.subBlockId)
222-
const semanticFallback = getSemanticFallback(context.subBlockId, subBlockConfig)
174+
if (!subBlockConfig) {
175+
return { original: value, displayLabel: formatValueForDisplay(value), resolved: false }
176+
}
177+
const semanticFallback = getSemanticFallback(subBlockConfig)
223178

224179
const selectorCtx = context.blockId
225180
? extractSelectorContext(context.blockId, context.currentState, context.workflowId)

apps/sim/lib/workflows/persistence/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export async function loadDeployedWorkflowState(
117117
resolvedWorkspaceId = wfRow?.workspaceId ?? undefined
118118
}
119119

120+
if (!resolvedWorkspaceId) {
121+
throw new Error(`Workflow ${workflowId} has no workspace`)
122+
}
123+
120124
const { blocks: migratedBlocks } = await applyBlockMigrations(
121125
state.blocks || {},
122126
resolvedWorkspaceId
@@ -139,7 +143,7 @@ export async function loadDeployedWorkflowState(
139143

140144
interface MigrationContext {
141145
blocks: Record<string, BlockState>
142-
workspaceId?: string
146+
workspaceId: string
143147
migrated: boolean
144148
}
145149

@@ -148,7 +152,7 @@ type BlockMigration = (ctx: MigrationContext) => MigrationContext | Promise<Migr
148152
function createMigrationPipeline(migrations: BlockMigration[]) {
149153
return async (
150154
blocks: Record<string, BlockState>,
151-
workspaceId?: string
155+
workspaceId: string
152156
): Promise<{ blocks: Record<string, BlockState>; migrated: boolean }> => {
153157
let ctx: MigrationContext = { blocks, workspaceId, migrated: false }
154158
for (const migration of migrations) {
@@ -170,7 +174,6 @@ const applyBlockMigrations = createMigrationPipeline([
170174
}),
171175

172176
async (ctx) => {
173-
if (!ctx.workspaceId) return ctx
174177
const { blocks, migrated } = await migrateCredentialIds(ctx.blocks, ctx.workspaceId)
175178
return { ...ctx, blocks, migrated: ctx.migrated || migrated }
176179
},
@@ -409,9 +412,13 @@ export async function loadWorkflowFromNormalizedTables(
409412
blocksMap[block.id] = assembled
410413
})
411414

415+
if (!workflowRow?.workspaceId) {
416+
throw new Error(`Workflow ${workflowId} has no workspace`)
417+
}
418+
412419
const { blocks: finalBlocks, migrated } = await applyBlockMigrations(
413420
blocksMap,
414-
workflowRow?.workspaceId ?? undefined
421+
workflowRow.workspaceId
415422
)
416423

417424
if (migrated) {

0 commit comments

Comments
 (0)