Skip to content

Commit 430c52c

Browse files
committed
fix(tables): harden inline column renaming
1 parent 04c9204 commit 430c52c

5 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/headers/column-header-menu.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ describe('ColumnHeaderMenu interactions', () => {
132132
const headerButton = renderHeader({ onColumnSelect, onRenameColumn })
133133

134134
act(() => {
135-
headerButton.click()
136-
headerButton.click()
135+
headerButton.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))
136+
headerButton.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 2 }))
137137
headerButton.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }))
138138
})
139139

140-
expect(onColumnSelect).toHaveBeenCalledTimes(2)
140+
expect(onColumnSelect).toHaveBeenCalledTimes(1)
141141
expect(onRenameColumn).toHaveBeenCalledWith('col-name')
142142
})
143143

‎apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/headers/column-header-menu.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
240240
return
241241
}
242242
if (isRenaming) return
243+
if (e.detail > 1) return
243244
onColumnSelect(colIndex, e.shiftKey)
244245
}
245246

@@ -300,7 +301,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
300301
<div className='flex h-full w-full min-w-0 items-center px-2 py-[7px]'>
301302
<ColumnTypeIcon
302303
type={column.type}
303-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
304+
isWorkflowColumn={isWorkflowOutput}
304305
blockIconInfo={sourceInfo?.blockIconInfo}
305306
blockMissing={blockMissing}
306307
/>
@@ -325,7 +326,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
325326
<div className='flex h-full w-full min-w-0 items-center px-2 py-[7px]'>
326327
<ColumnTypeIcon
327328
type={column.type}
328-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
329+
isWorkflowColumn={isWorkflowOutput}
329330
blockIconInfo={sourceInfo?.blockIconInfo}
330331
blockMissing={blockMissing}
331332
/>
@@ -357,7 +358,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
357358
>
358359
<ColumnTypeIcon
359360
type={column.type}
360-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
361+
isWorkflowColumn={isWorkflowOutput}
361362
blockIconInfo={sourceInfo?.blockIconInfo}
362363
blockMissing={blockMissing}
363364
/>

‎apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ export function TableGrid({
15851585
const handleFindCloseRef = useRef(handleFindClose)
15861586
handleFindCloseRef.current = handleFindClose
15871587

1588-
const [renameError, setRenameError] = useState(false)
1588+
const [renameErrorColumnId, setRenameErrorColumnId] = useState<string | null>(null)
15891589

15901590
const columnRename = useInlineRename({
15911591
// `columnName` is the column id; record the prior display name + id so undo
@@ -1600,7 +1600,7 @@ export function TableGrid({
16001600
if (isValidationError(error)) {
16011601
toast.error(extractValidationIssues(error)[0]?.message ?? getErrorMessage(error))
16021602
}
1603-
setRenameError(true)
1603+
setRenameErrorColumnId(columnName)
16041604
throw error
16051605
})
16061606
},
@@ -1609,7 +1609,7 @@ export function TableGrid({
16091609
columnRenameRef.current = columnRename
16101610

16111611
const handleRenameValueChange = useCallback((value: string) => {
1612-
setRenameError(false)
1612+
setRenameErrorColumnId(null)
16131613
columnRenameRef.current.setEditValue(value)
16141614
}, [])
16151615

@@ -1618,7 +1618,7 @@ export function TableGrid({
16181618
const { editingId, editValue, submitRename } = columnRenameRef.current
16191619
const trimmedName = editValue.trim()
16201620
const currentColumn = columnsRef.current.find((column) => column.key === editingId)
1621-
if (trimmedName && currentColumn && trimmedName !== currentColumn.name) {
1621+
if (currentColumn && trimmedName !== currentColumn.name) {
16221622
const issue = columnNameIssue(
16231623
trimmedName,
16241624
schemaColumnsRef.current
@@ -1627,16 +1627,16 @@ export function TableGrid({
16271627
)
16281628
if (issue) {
16291629
toast.error(issue)
1630-
setRenameError(true)
1630+
setRenameErrorColumnId(editingId)
16311631
return
16321632
}
16331633
}
1634-
setRenameError(false)
1634+
setRenameErrorColumnId(null)
16351635
void submitRename()
16361636
}, [])
16371637

16381638
const handleRenameCancel = useCallback(() => {
1639-
setRenameError(false)
1639+
setRenameErrorColumnId(null)
16401640
columnRenameRef.current.cancelRename()
16411641
}, [])
16421642

@@ -4173,7 +4173,7 @@ export function TableGrid({
41734173

41744174
const handleRenameColumn = useCallback(
41754175
(columnName: string) => {
4176-
setRenameError(false)
4176+
setRenameErrorColumnId(null)
41774177
const column = columnsRef.current.find((candidate) => candidate.key === columnName)
41784178
columnRename.startRename(columnName, column?.name ?? columnName)
41794179
},
@@ -5076,7 +5076,7 @@ export function TableGrid({
50765076
renameValue={
50775077
columnRename.editingId === column.key ? columnRename.editValue : ''
50785078
}
5079-
renameError={renameError && columnRename.editingId === column.key}
5079+
renameError={renameErrorColumnId === column.key}
50805080
onRenameValueChange={handleRenameValueChange}
50815081
onRenameSubmit={handleRenameSubmit}
50825082
onRenameCancel={handleRenameCancel}

‎apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/utils.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ describe('columnNameIssue', () => {
242242
expect(columnNameIssue('email_address', ['name', 'status'])).toBeNull()
243243
})
244244

245+
it('requires a name', () => {
246+
expect(columnNameIssue('', [])).toBe('Column name is required')
247+
})
248+
245249
it('refuses invalid patterns and names that begin with a digit', () => {
246250
expect(columnNameIssue('New Text', [])).toMatch(/letter or underscore/)
247251
expect(columnNameIssue('1st', [])).toMatch(/letter or underscore/)

‎apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/utils.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ export function canWriteRowsWithChip(opts: {
521521
* @param takenNames Names of every other column in the table.
522522
*/
523523
export function columnNameIssue(name: string, takenNames: Iterable<string>): string | null {
524+
if (!name) return 'Column name is required'
524525
if (name.length > TABLE_LIMITS.MAX_COLUMN_NAME_LENGTH) {
525526
return `Column names must be ${TABLE_LIMITS.MAX_COLUMN_NAME_LENGTH} characters or less`
526527
}

0 commit comments

Comments
 (0)