@@ -37,6 +37,10 @@ import { cellValueFilterConditions } from '@/lib/table/query-builder/cell-filter
3737import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
3838import { FindBar } from '@/app/workspace/[workspaceId]/components'
3939import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
40+ import {
41+ persistColumnRename ,
42+ tryStartColumnRename ,
43+ } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/column-rename'
4044import {
4145 REFERENCE_ROW_PREVIEW_HEIGHT ,
4246 ReferenceRowPreview ,
@@ -1590,22 +1594,28 @@ export function TableGrid({
15901594 const columnRename = useInlineRename ( {
15911595 // `columnName` is the column id; record the prior display name + id so undo
15921596 // restores the label (not the id) and targets the right column.
1593- onSave : ( columnName , newName ) => {
1597+ onSave : async ( columnName , newName ) => {
15941598 const oldName = columnsRef . current . find ( ( c ) => c . key === columnName ) ?. name ?? columnName
1595- pushUndoRef . current ( { type : 'rename-column' , oldName, newName, columnId : columnName } )
1596- handleColumnRename ( columnName , newName )
1597- return updateColumnMutation
1598- . mutateAsync ( { columnName, updates : { name : newName } } )
1599- . catch ( ( error : unknown ) => {
1600- if ( isValidationError ( error ) ) {
1601- toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1602- }
1603- setRenameErrorColumnId ( columnName )
1604- throw error
1599+ try {
1600+ await persistColumnRename ( {
1601+ columnId : columnName ,
1602+ oldName,
1603+ newName,
1604+ persist : ( ) =>
1605+ updateColumnMutation . mutateAsync ( { columnName, updates : { name : newName } } ) ,
1606+ pushUndo : pushUndoRef . current ,
1607+ onRenamed : ( ) => handleColumnRename ( columnName , newName ) ,
16051608 } )
1609+ } catch ( error ) {
1610+ if ( isValidationError ( error ) ) {
1611+ toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1612+ }
1613+ setRenameErrorColumnId ( columnName )
1614+ throw error
1615+ }
16061616 } ,
16071617 } )
1608- const columnRenameRef = useRef ( columnRename )
1618+ const columnRenameRef = useRef < ReturnType < typeof useInlineRename > > ( columnRename )
16091619 columnRenameRef . current = columnRename
16101620
16111621 const handleRenameValueChange = useCallback ( ( value : string ) => {
@@ -4171,14 +4181,13 @@ export function TableGrid({
41714181 [ onOpenColumnConfig , onOpenWorkflowConfig , workflowGroupById ]
41724182 )
41734183
4174- const handleRenameColumn = useCallback (
4175- ( columnName : string ) => {
4176- setRenameErrorColumnId ( null )
4177- const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4178- columnRename . startRename ( columnName , column ?. name ?? columnName )
4179- } ,
4180- [ columnRename . startRename ]
4181- )
4184+ const handleRenameColumn = useCallback ( ( columnName : string ) => {
4185+ const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4186+ if ( ! tryStartColumnRename ( columnRenameRef . current , columnName , column ?. name ?? columnName ) ) {
4187+ return
4188+ }
4189+ setRenameErrorColumnId ( null )
4190+ } , [ ] )
41824191
41834192 const handleConfigureWorkflowGroup = useCallback (
41844193 ( groupId : string ) => {
0 commit comments