@@ -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