@@ -17,6 +17,7 @@ import { toError } from '@sim/utils/errors'
1717import { generateId } from '@sim/utils/id'
1818import type { AddWorkflowGroupBodyInput } from '@/lib/api/contracts/tables'
1919import type { ColumnDefinition , WorkflowGroup , WorkflowGroupOutput } from '@/lib/table'
20+ import { columnMatchesRef , getColumnId } from '@/lib/table/column-keys'
2021import { deriveOutputColumnName } from '@/lib/table/column-naming'
2122import { FieldError } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/sidebar-fields'
2223import type { EnrichmentConfig as EnrichmentDef } from '@/enrichments/types'
@@ -49,7 +50,7 @@ function defaultColumnFor(
4950 c . name . toLowerCase ( ) === input . id . toLowerCase ( ) ||
5051 c . name . toLowerCase ( ) === input . name . toLowerCase ( )
5152 )
52- return match ?. name ?? ''
53+ return match ? getColumnId ( match ) : ''
5354}
5455
5556/**
@@ -71,14 +72,23 @@ export function EnrichmentConfig({
7172 const updateColumn = useUpdateColumn ( { workspaceId, tableId } )
7273 const isEditing = Boolean ( existingGroup )
7374
74- /** Output column's persisted name (edit mode), used to detect renames. */
75- const originalOutputName = ( outputId : string ) : string | undefined =>
76- existingGroup ?. outputs . find ( ( o ) => o . outputId === outputId ) ?. columnName
75+ /** Output's column (edit mode). Persisted `columnName` refs hold a stable
76+ * column id (name for legacy groups), so resolve id-or-name to the column. */
77+ const outputColumn = ( outputId : string ) : ColumnDefinition | undefined => {
78+ const ref = existingGroup ?. outputs . find ( ( o ) => o . outputId === outputId ) ?. columnName
79+ return ref === undefined ? undefined : allColumns . find ( ( c ) => columnMatchesRef ( c , ref ) )
80+ }
81+
82+ /** Output column's persisted display name (edit mode), used to detect renames. */
83+ const originalOutputName = ( outputId : string ) : string | undefined => outputColumn ( outputId ) ?. name
7784
7885 const [ inputMappings , setInputMappings ] = useState < Record < string , string > > ( ( ) => {
7986 if ( existingGroup ) {
8087 const seed : Record < string , string > = { }
81- for ( const m of existingGroup . inputMappings ?? [ ] ) seed [ m . inputName ] = m . columnName
88+ for ( const m of existingGroup . inputMappings ?? [ ] ) {
89+ const col = allColumns . find ( ( c ) => columnMatchesRef ( c , m . columnName ) )
90+ seed [ m . inputName ] = col ? getColumnId ( col ) : m . columnName
91+ }
8292 return seed
8393 }
8494 const seed : Record < string , string > = { }
@@ -94,7 +104,9 @@ export function EnrichmentConfig({
94104 const seed : Record < string , string > = { }
95105 if ( existingGroup ) {
96106 for ( const o of existingGroup . outputs ) {
97- if ( o . outputId ) seed [ o . outputId ] = o . columnName
107+ if ( ! o . outputId ) continue
108+ const col = allColumns . find ( ( c ) => columnMatchesRef ( c , o . columnName ) )
109+ seed [ o . outputId ] = col ?. name ?? o . columnName
98110 }
99111 return seed
100112 }
@@ -111,7 +123,7 @@ export function EnrichmentConfig({
111123 const [ deps , setDeps ] = useState < string [ ] > ( ( ) => existingGroup ?. dependencies ?. columns ?? [ ] )
112124 const [ showValidation , setShowValidation ] = useState ( false )
113125
114- const columnOptions = allColumns . map ( ( c ) => ( { label : c . name , value : c . name } ) )
126+ const columnOptions = allColumns . map ( ( c ) => ( { label : c . name , value : getColumnId ( c ) } ) )
115127 const missingRequired = enrichment . inputs . some ( ( i ) => i . required && ! inputMappings [ i . id ] )
116128 const depsValid = ! autoRun || deps . length > 0
117129
@@ -162,10 +174,13 @@ export function EnrichmentConfig({
162174 autoRun,
163175 } )
164176 for ( const o of enrichment . outputs ) {
165- const original = originalOutputName ( o . id )
177+ const col = outputColumn ( o . id )
166178 const next = ( outputNames [ o . id ] ?? '' ) . trim ( )
167- if ( original && next && next !== original ) {
168- await updateColumn . mutateAsync ( { columnName : original , updates : { name : next } } )
179+ if ( col && next && next !== col . name ) {
180+ await updateColumn . mutateAsync ( {
181+ columnName : getColumnId ( col ) ,
182+ updates : { name : next } ,
183+ } )
169184 }
170185 }
171186 toast . success ( `Updated "${ enrichment . name } "` )
0 commit comments