Skip to content

Commit 325eff5

Browse files
committed
cleanup
1 parent 50fffe0 commit 325eff5

File tree

2 files changed

+27
-39
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components

2 files changed

+27
-39
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/variables-input/variables-input.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ export function VariablesInput({
8989

9090
/**
9191
* Get the display name for a variable assignment
92+
* Prioritizes store lookup to ensure we always show the latest name
9293
*/
9394
const getVariableDisplayName = (assignment: VariableAssignment): string => {
94-
if (assignment.variableName) {
95-
return assignment.variableName
96-
}
97-
95+
// Look up by ID first (source of truth)
9896
if (assignment.variableId) {
9997
const variable = currentWorkflowVariables.find((v) => v.id === assignment.variableId)
100-
return variable?.name || `Variable ${assignment.variableId.slice(0, 8)}...`
98+
return variable?.name || ''
99+
}
100+
101+
// Fallback to stored name (for backwards compatibility)
102+
if (assignment.variableName) {
103+
return assignment.variableName
101104
}
102105

103-
return 'Select a variable...'
106+
return ''
104107
}
105108

106109
const hasNoWorkflowVariables = currentWorkflowVariables.length === 0

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

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,8 @@ const getDisplayValue = (value: unknown): string => {
103103
if (value == null || value === '') return '-'
104104

105105
if (isVariableAssignmentsArray(value)) {
106-
const assignments = value.filter((a) => {
107-
// Check if we have either a non-empty variableName or a variableId
108-
const hasName = a.variableName && a.variableName.trim() !== ''
109-
const hasId = a.variableId && a.variableId.trim() !== ''
110-
return hasName || hasId
111-
})
112-
if (assignments.length === 0) return '-'
113-
114-
// Get display names for assignments
115-
const names = assignments.map((a) => a.variableName || a.variableId || 'Unknown')
116-
106+
const names = value.map((a) => a.variableName).filter((name): name is string => !!name)
107+
if (names.length === 0) return '-'
117108
if (names.length === 1) return names[0]
118109
if (names.length === 2) return `${names[0]}, ${names[1]}`
119110
return `${names[0]}, ${names[1]} +${names.length - 2}`
@@ -273,42 +264,36 @@ const SubBlockRow = ({
273264
planId: getStringValue('planId'),
274265
})
275266

267+
// Subscribe to variables store to reactively update when variables change
268+
const allVariables = useVariablesStore((state) => state.variables)
269+
276270
// Special handling for variables-input to hydrate variable IDs to names from variables store
277271
const variablesDisplayValue = useMemo(() => {
278272
if (subBlock?.type !== 'variables-input' || !isVariableAssignmentsArray(rawValue)) {
279273
return null
280274
}
281275

282-
const assignments = rawValue.filter((a) => {
283-
const hasName = a.variableName && a.variableName.trim() !== ''
284-
const hasId = a.variableId && a.variableId.trim() !== ''
285-
return hasName || hasId
286-
})
287-
288-
if (assignments.length === 0) return null
289-
290-
// Get variables from the variables store
291-
const allVariables = useVariablesStore.getState().variables
292276
const workflowVariables = Object.values(allVariables).filter(
293277
(v: any) => v.workflowId === workflowId
294278
)
295279

296-
const names = assignments.map((a) => {
297-
// Prefer variableName, then try to look up variableId in variables store
298-
if (a.variableName && a.variableName.trim()) {
299-
return a.variableName
300-
}
301-
if (a.variableId) {
302-
const variable = workflowVariables.find((v: any) => v.id === a.variableId)
303-
return variable?.name || a.variableId
304-
}
305-
return 'Unknown'
306-
})
280+
const names = rawValue
281+
.map((a) => {
282+
// Prioritize ID lookup (source of truth) over stored name
283+
if (a.variableId) {
284+
const variable = workflowVariables.find((v: any) => v.id === a.variableId)
285+
return variable?.name
286+
}
287+
if (a.variableName) return a.variableName
288+
return null
289+
})
290+
.filter((name): name is string => !!name)
307291

292+
if (names.length === 0) return null
308293
if (names.length === 1) return names[0]
309294
if (names.length === 2) return `${names[0]}, ${names[1]}`
310295
return `${names[0]}, ${names[1]} +${names.length - 2}`
311-
}, [subBlock?.type, rawValue, workflowId])
296+
}, [subBlock?.type, rawValue, workflowId, allVariables])
312297

313298
const isPasswordField = subBlock?.password === true
314299
const maskedValue = isPasswordField && value && value !== '-' ? '•••' : null

0 commit comments

Comments
 (0)