@@ -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'
@@ -1509,22 +1513,28 @@ export function TableGrid({
15091513 const columnRename = useInlineRename ( {
15101514 // `columnName` is the column id; record the prior display name + id so undo
15111515 // restores the label (not the id) and targets the right column.
1512- onSave : ( columnName , newName ) => {
1516+ onSave : async ( columnName , newName ) => {
15131517 const oldName = columnsRef . current . find ( ( c ) => c . key === columnName ) ?. name ?? columnName
1514- pushUndoRef . current ( { type : 'rename-column' , oldName, newName, columnId : columnName } )
1515- handleColumnRename ( columnName , newName )
1516- return updateColumnMutation
1517- . mutateAsync ( { columnName, updates : { name : newName } } )
1518- . catch ( ( error : unknown ) => {
1519- if ( isValidationError ( error ) ) {
1520- toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1521- }
1522- setRenameErrorColumnId ( columnName )
1523- throw error
1518+ try {
1519+ await persistColumnRename ( {
1520+ columnId : columnName ,
1521+ oldName,
1522+ newName,
1523+ persist : ( ) =>
1524+ updateColumnMutation . mutateAsync ( { columnName, updates : { name : newName } } ) ,
1525+ pushUndo : pushUndoRef . current ,
1526+ onRenamed : ( ) => handleColumnRename ( columnName , newName ) ,
15241527 } )
1528+ } catch ( error ) {
1529+ if ( isValidationError ( error ) ) {
1530+ toast . error ( extractValidationIssues ( error ) [ 0 ] ?. message ?? getErrorMessage ( error ) )
1531+ }
1532+ setRenameErrorColumnId ( columnName )
1533+ throw error
1534+ }
15251535 } ,
15261536 } )
1527- const columnRenameRef = useRef ( columnRename )
1537+ const columnRenameRef = useRef < ReturnType < typeof useInlineRename > > ( columnRename )
15281538 columnRenameRef . current = columnRename
15291539
15301540 const handleRenameValueChange = useCallback ( ( value : string ) => {
@@ -4033,14 +4043,13 @@ export function TableGrid({
40334043 [ onOpenColumnConfig , onOpenWorkflowConfig , workflowGroupById ]
40344044 )
40354045
4036- const handleRenameColumn = useCallback (
4037- ( columnName : string ) => {
4038- setRenameErrorColumnId ( null )
4039- const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4040- columnRename . startRename ( columnName , column ?. name ?? columnName )
4041- } ,
4042- [ columnRename . startRename ]
4043- )
4046+ const handleRenameColumn = useCallback ( ( columnName : string ) => {
4047+ const column = columnsRef . current . find ( ( candidate ) => candidate . key === columnName )
4048+ if ( ! tryStartColumnRename ( columnRenameRef . current , columnName , column ?. name ?? columnName ) ) {
4049+ return
4050+ }
4051+ setRenameErrorColumnId ( null )
4052+ } , [ ] )
40444053
40454054 const handleConfigureWorkflowGroup = useCallback (
40464055 ( groupId : string ) => {
0 commit comments