@@ -76,6 +76,9 @@ interface ColumnConfigSidebarProps {
7676 readOnly ?: boolean
7777 /** Why saving is unavailable; surfaced on the disabled Save button. */
7878 readOnlyReason ?: string
79+ /** Notify parent of a rename so it can rewrite local `columnOrder` /
80+ * `columnWidths` keys that reference the old name. */
81+ onColumnRename ?: ( oldName : string , newName : string ) => void
7982}
8083
8184/**
@@ -127,6 +130,7 @@ function ColumnConfigBody({
127130 tableId,
128131 readOnly,
129132 readOnlyReason,
133+ onColumnRename,
130134} : ColumnConfigBodyProps ) {
131135 const updateColumn = useUpdateColumn ( { workspaceId, tableId } )
132136 const addColumn = useAddTableColumn ( { workspaceId, tableId } )
@@ -189,7 +193,7 @@ function ColumnConfigBody({
189193 async function handleSave ( ) {
190194 // Belt and braces: the button is disabled, and the server refuses too.
191195 if ( readOnly ) return
192- if ( config . mode === 'create' && ! trimmedName ) {
196+ if ( ! trimmedName ) {
193197 setShowValidation ( true )
194198 return
195199 }
@@ -221,6 +225,7 @@ function ColumnConfigBody({
221225 return
222226 }
223227
228+ const renamed = trimmedName !== ( existingColumn ?. name ?? config . columnName )
224229 const typeChanged = ! ! existingColumn && existingColumn . type !== typeInput
225230 const uniqueChanged =
226231 supportsUnique && ! ! existingColumn && ! ! existingColumn . unique !== uniqueInput
@@ -234,13 +239,15 @@ function ColumnConfigBody({
234239 wantsReference && existingColumn ?. referenceTableId !== referenceTableInput
235240
236241 const updates : {
242+ name ?: string
237243 type ?: ColumnDefinition [ 'type' ]
238244 unique ?: boolean
239245 options ?: SelectOption [ ]
240246 multiple ?: boolean
241247 currencyCode ?: string
242248 referenceTableId ?: string
243249 } = {
250+ ...( renamed ? { name : trimmedName } : { } ) ,
244251 ...( typeChanged ? { type : typeInput } : { } ) ,
245252 ...( uniqueChanged ? { unique : uniqueInput } : { } ) ,
246253 ...( uniqueCleared ? { unique : false } : { } ) ,
@@ -259,7 +266,8 @@ function ColumnConfigBody({
259266 }
260267
261268 await updateColumn . mutateAsync ( { columnName : config . columnName , updates } )
262- toast . success ( `Saved "${ existingColumn ?. name ?? config . columnName } "` )
269+ if ( renamed ) onColumnRename ?.( config . columnName , trimmedName )
270+ toast . success ( `Saved "${ trimmedName } "` )
263271 onClose ( )
264272 } catch ( err ) {
265273 if ( isValidationError ( err ) ) {
@@ -296,25 +304,23 @@ function ColumnConfigBody({
296304 including the comboboxes' trigger buttons; `contents` keeps the
297305 existing layout. Values stay readable and selectable. */ }
298306 < fieldset disabled = { readOnly } className = 'contents' >
299- { config . mode === 'create' && (
300- < div className = 'flex flex-col gap-[9.5px]' >
301- < RequiredLabel htmlFor = 'column-sidebar-name' > Column name</ RequiredLabel >
302- < ChipInput
303- id = 'column-sidebar-name'
304- value = { nameInput }
305- onChange = { ( e ) => {
306- setNameInput ( e . target . value )
307- if ( nameError ) setNameError ( null )
308- } }
309- spellCheck = { false }
310- autoComplete = 'off'
311- error = { Boolean ( ( showValidation && ! trimmedName ) || nameError ) }
312- aria-invalid = { ( showValidation && ! trimmedName ) || nameError ? true : undefined }
313- />
314- { showValidation && ! trimmedName && < FieldError message = 'Column name is required' /> }
315- { nameError && ! ( showValidation && ! trimmedName ) && < FieldError message = { nameError } /> }
316- </ div >
317- ) }
307+ < div className = 'flex flex-col gap-[9.5px]' >
308+ < RequiredLabel htmlFor = 'column-sidebar-name' > Column name</ RequiredLabel >
309+ < ChipInput
310+ id = 'column-sidebar-name'
311+ value = { nameInput }
312+ onChange = { ( e ) => {
313+ setNameInput ( e . target . value )
314+ if ( nameError ) setNameError ( null )
315+ } }
316+ spellCheck = { false }
317+ autoComplete = 'off'
318+ error = { Boolean ( ( showValidation && ! trimmedName ) || nameError ) }
319+ aria-invalid = { ( showValidation && ! trimmedName ) || nameError ? true : undefined }
320+ />
321+ { showValidation && ! trimmedName && < FieldError message = 'Column name is required' /> }
322+ { nameError && ! ( showValidation && ! trimmedName ) && < FieldError message = { nameError } /> }
323+ </ div >
318324
319325 { config . mode === 'edit' && (
320326 < >
0 commit comments