@@ -57,6 +57,8 @@ interface ColumnConfigSidebarProps {
5757 tableRowTtlEnabled : boolean
5858 workspaceId : string
5959 tableId : string
60+ /** Notify the grid so local layout metadata follows a successful rename. */
61+ onColumnRename ?: ( oldName : string , newName : string ) => void
6062}
6163
6264/**
@@ -106,6 +108,7 @@ function ColumnConfigBody({
106108 tableRowTtlEnabled,
107109 workspaceId,
108110 tableId,
111+ onColumnRename,
109112} : ColumnConfigBodyProps ) {
110113 const updateColumn = useUpdateColumn ( { workspaceId, tableId } )
111114 const addColumn = useAddTableColumn ( { workspaceId, tableId } )
@@ -166,7 +169,7 @@ function ColumnConfigBody({
166169 }
167170
168171 async function handleSave ( ) {
169- if ( config . mode === 'create' && ! trimmedName ) {
172+ if ( ! trimmedName ) {
170173 setShowValidation ( true )
171174 return
172175 }
@@ -198,6 +201,7 @@ function ColumnConfigBody({
198201 return
199202 }
200203
204+ const renamed = trimmedName !== ( existingColumn ?. name ?? config . columnName )
201205 const typeChanged = ! ! existingColumn && existingColumn . type !== typeInput
202206 const uniqueChanged =
203207 supportsUnique && ! ! existingColumn && ! ! existingColumn . unique !== uniqueInput
@@ -211,13 +215,15 @@ function ColumnConfigBody({
211215 wantsReference && existingColumn ?. referenceTableId !== referenceTableInput
212216
213217 const updates : {
218+ name ?: string
214219 type ?: ColumnDefinition [ 'type' ]
215220 unique ?: boolean
216221 options ?: SelectOption [ ]
217222 multiple ?: boolean
218223 currencyCode ?: string
219224 referenceTableId ?: string
220225 } = {
226+ ...( renamed ? { name : trimmedName } : { } ) ,
221227 ...( typeChanged ? { type : typeInput } : { } ) ,
222228 ...( uniqueChanged ? { unique : uniqueInput } : { } ) ,
223229 ...( uniqueCleared ? { unique : false } : { } ) ,
@@ -236,7 +242,8 @@ function ColumnConfigBody({
236242 }
237243
238244 await updateColumn . mutateAsync ( { columnName : config . columnName , updates } )
239- toast . success ( `Saved "${ existingColumn ?. name ?? config . columnName } "` )
245+ if ( renamed ) onColumnRename ?.( config . columnName , trimmedName )
246+ toast . success ( `Saved "${ trimmedName } "` )
240247 onClose ( )
241248 } catch ( err ) {
242249 if ( isValidationError ( err ) ) {
@@ -269,25 +276,23 @@ function ColumnConfigBody({
269276 </ div >
270277
271278 < div className = 'flex-1 overflow-y-auto overflow-x-hidden px-2 pt-3 pb-2 [overflow-anchor:none]' >
272- { config . mode === 'create' && (
273- < div className = 'flex flex-col gap-[9.5px]' >
274- < RequiredLabel htmlFor = 'column-sidebar-name' > Column name</ RequiredLabel >
275- < ChipInput
276- id = 'column-sidebar-name'
277- value = { nameInput }
278- onChange = { ( e ) => {
279- setNameInput ( e . target . value )
280- if ( nameError ) setNameError ( null )
281- } }
282- spellCheck = { false }
283- autoComplete = 'off'
284- error = { Boolean ( ( showValidation && ! trimmedName ) || nameError ) }
285- aria-invalid = { ( showValidation && ! trimmedName ) || nameError ? true : undefined }
286- />
287- { showValidation && ! trimmedName && < FieldError message = 'Column name is required' /> }
288- { nameError && ! ( showValidation && ! trimmedName ) && < FieldError message = { nameError } /> }
289- </ div >
290- ) }
279+ < div className = 'flex flex-col gap-[9.5px]' >
280+ < RequiredLabel htmlFor = 'column-sidebar-name' > Column name</ RequiredLabel >
281+ < ChipInput
282+ id = 'column-sidebar-name'
283+ value = { nameInput }
284+ onChange = { ( e ) => {
285+ setNameInput ( e . target . value )
286+ if ( nameError ) setNameError ( null )
287+ } }
288+ spellCheck = { false }
289+ autoComplete = 'off'
290+ error = { Boolean ( ( showValidation && ! trimmedName ) || nameError ) }
291+ aria-invalid = { ( showValidation && ! trimmedName ) || nameError ? true : undefined }
292+ />
293+ { showValidation && ! trimmedName && < FieldError message = 'Column name is required' /> }
294+ { nameError && ! ( showValidation && ! trimmedName ) && < FieldError message = { nameError } /> }
295+ </ div >
291296
292297 { config . mode === 'edit' && (
293298 < >
0 commit comments