@@ -36,6 +36,10 @@ import { cellValueFilterConditions } from '@/lib/table/query-builder/cell-filter
3636import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
3737import { FindBar } from '@/app/workspace/[workspaceId]/components'
3838import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
39+ import {
40+ persistColumnRename ,
41+ tryStartColumnRename ,
42+ } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/column-rename'
3943import {
4044 REFERENCE_ROW_PREVIEW_HEIGHT ,
4145 ReferenceRowPreview ,
@@ -1575,22 +1579,28 @@ export function TableGrid({
15751579 const columnRename = useInlineRename ( {
15761580 // `columnName` is the column id; record the prior display name + id so undo
15771581 // restores the label (not the id) and targets the right column.
1578- onSave : ( columnName , newName ) => {
1582+ onSave : async ( columnName , newName ) => {
15791583 const oldName = columnsRef . current . find ( ( c ) => c . key === columnName ) ?. name ?? columnName
1580- pushUndoRef . current ( { type : 'rename-column' , oldName, newName, columnId : columnName } )
1581- handleColumnRename ( columnName , newName )
1582- return updateColumnMutation
1583- . mutateAsync ( { columnName, updates : { name : newName } } )
1584- . catch ( ( error : unknown ) => {
1585- if ( isValidationError ( error ) ) {
1586- toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1587- }
1588- setRenameErrorColumnId ( columnName )
1589- throw error
1584+ try {
1585+ await persistColumnRename ( {
1586+ columnId : columnName ,
1587+ oldName,
1588+ newName,
1589+ persist : ( ) =>
1590+ updateColumnMutation . mutateAsync ( { columnName, updates : { name : newName } } ) ,
1591+ pushUndo : pushUndoRef . current ,
1592+ onRenamed : ( ) => handleColumnRename ( columnName , newName ) ,
15901593 } )
1594+ } catch ( error ) {
1595+ if ( isValidationError ( error ) ) {
1596+ toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1597+ }
1598+ setRenameErrorColumnId ( columnName )
1599+ throw error
1600+ }
15911601 } ,
15921602 } )
1593- const columnRenameRef = useRef ( columnRename )
1603+ const columnRenameRef = useRef < ReturnType < typeof useInlineRename > > ( columnRename )
15941604 columnRenameRef . current = columnRename
15951605
15961606 const handleRenameValueChange = useCallback ( ( value : string ) => {
@@ -4117,14 +4127,13 @@ export function TableGrid({
41174127 [ onOpenColumnConfig , onOpenWorkflowConfig , workflowGroupById ]
41184128 )
41194129
4120- const handleRenameColumn = useCallback (
4121- ( columnName : string ) => {
4122- setRenameErrorColumnId ( null )
4123- const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4124- columnRename . startRename ( columnName , column ?. name ?? columnName )
4125- } ,
4126- [ columnRename . startRename ]
4127- )
4130+ const handleRenameColumn = useCallback ( ( columnName : string ) => {
4131+ const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4132+ if ( ! tryStartColumnRename ( columnRenameRef . current , columnName , column ?. name ?? columnName ) ) {
4133+ return
4134+ }
4135+ setRenameErrorColumnId ( null )
4136+ } , [ ] )
41284137
41294138 const handleConfigureWorkflowGroup = useCallback (
41304139 ( groupId : string ) => {
0 commit comments