@@ -32,6 +32,10 @@ import { cellValueFilterConditions } from '@/lib/table/query-builder/cell-filter
3232import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
3333import { FindBar } from '@/app/workspace/[workspaceId]/components'
3434import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
35+ import {
36+ persistColumnRename ,
37+ tryStartColumnRename ,
38+ } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/column-rename'
3539import { getTimezoneEditBlockedMessage } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/timezone-editing'
3640import type { RemoteTableSelection } from '@/app/workspace/[workspaceId]/tables/[tableId]/hooks/use-table-room'
3741import type { BlockedTableAction } from '@/app/workspace/[workspaceId]/tables/[tableId]/lock-copy'
@@ -1511,22 +1515,28 @@ export function TableGrid({
15111515 const columnRename = useInlineRename ( {
15121516 // `columnName` is the column id; record the prior display name + id so undo
15131517 // restores the label (not the id) and targets the right column.
1514- onSave : ( columnName , newName ) => {
1518+ onSave : async ( columnName , newName ) => {
15151519 const oldName = columnsRef . current . find ( ( c ) => c . key === columnName ) ?. name ?? columnName
1516- pushUndoRef . current ( { type : 'rename-column' , oldName, newName, columnId : columnName } )
1517- handleColumnRename ( columnName , newName )
1518- return updateColumnMutation
1519- . mutateAsync ( { columnName, updates : { name : newName } } )
1520- . catch ( ( error : unknown ) => {
1521- if ( isValidationError ( error ) ) {
1522- toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1523- }
1524- setRenameErrorColumnId ( columnName )
1525- throw error
1520+ try {
1521+ await persistColumnRename ( {
1522+ columnId : columnName ,
1523+ oldName,
1524+ newName,
1525+ persist : ( ) =>
1526+ updateColumnMutation . mutateAsync ( { columnName, updates : { name : newName } } ) ,
1527+ pushUndo : pushUndoRef . current ,
1528+ onRenamed : ( ) => handleColumnRename ( columnName , newName ) ,
15261529 } )
1530+ } catch ( error ) {
1531+ if ( isValidationError ( error ) ) {
1532+ toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1533+ }
1534+ setRenameErrorColumnId ( columnName )
1535+ throw error
1536+ }
15271537 } ,
15281538 } )
1529- const columnRenameRef = useRef ( columnRename )
1539+ const columnRenameRef = useRef < ReturnType < typeof useInlineRename > > ( columnRename )
15301540 columnRenameRef . current = columnRename
15311541
15321542 const handleRenameValueChange = useCallback ( ( value : string ) => {
@@ -4035,14 +4045,13 @@ export function TableGrid({
40354045 [ onOpenColumnConfig , onOpenWorkflowConfig , workflowGroupById ]
40364046 )
40374047
4038- const handleRenameColumn = useCallback (
4039- ( columnName : string ) => {
4040- setRenameErrorColumnId ( null )
4041- const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4042- columnRename . startRename ( columnName , column ?. name ?? columnName )
4043- } ,
4044- [ columnRename . startRename ]
4045- )
4048+ const handleRenameColumn = useCallback ( ( columnName : string ) => {
4049+ const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4050+ if ( ! tryStartColumnRename ( columnRenameRef . current , columnName , column ?. name ?? columnName ) ) {
4051+ return
4052+ }
4053+ setRenameErrorColumnId ( null )
4054+ } , [ ] )
40464055
40474056 const handleConfigureWorkflowGroup = useCallback (
40484057 ( groupId : string ) => {
0 commit comments