Skip to content

Commit 7d268b8

Browse files
committed
fix(tables): harden inline column renaming
1 parent 0d6538b commit 7d268b8

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
@@ -234,6 +234,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
234234
return
235235
}
236236
if (isRenaming) return
237+
if (e.detail > 1) return
237238
onColumnSelect(colIndex, e.shiftKey)
238239
}
239240

@@ -294,7 +295,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
294295
<div className='flex h-full w-full min-w-0 items-center px-2 py-[7px]'>
295296
<ColumnTypeIcon
296297
type={column.type}
297-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
298+
isWorkflowColumn={isWorkflowOutput}
298299
blockIconInfo={sourceInfo?.blockIconInfo}
299300
blockMissing={blockMissing}
300301
/>
@@ -319,7 +320,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
319320
<div className='flex h-full w-full min-w-0 items-center px-2 py-[7px]'>
320321
<ColumnTypeIcon
321322
type={column.type}
322-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
323+
isWorkflowColumn={isWorkflowOutput}
323324
blockIconInfo={sourceInfo?.blockIconInfo}
324325
blockMissing={blockMissing}
325326
/>
@@ -351,7 +352,7 @@ export const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
351352
>
352353
<ColumnTypeIcon
353354
type={column.type}
354-
isWorkflowColumn={!!column.workflowGroupId && ownGroup?.type !== 'enrichment'}
355+
isWorkflowColumn={isWorkflowOutput}
355356
blockIconInfo={sourceInfo?.blockIconInfo}
356357
blockMissing={blockMissing}
357358
/>

‎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
@@ -1570,7 +1570,7 @@ export function TableGrid({
15701570
const handleFindCloseRef = useRef(handleFindClose)
15711571
handleFindCloseRef.current = handleFindClose
15721572

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

15751575
const columnRename = useInlineRename({
15761576
// `columnName` is the column id; record the prior display name + id so undo
@@ -1585,7 +1585,7 @@ export function TableGrid({
15851585
if (isValidationError(error)) {
15861586
toast.error(extractValidationIssues(error)[0]?.message ?? getErrorMessage(error))
15871587
}
1588-
setRenameError(true)
1588+
setRenameErrorColumnId(columnName)
15891589
throw error
15901590
})
15911591
},
@@ -1594,7 +1594,7 @@ export function TableGrid({
15941594
columnRenameRef.current = columnRename
15951595

15961596
const handleRenameValueChange = useCallback((value: string) => {
1597-
setRenameError(false)
1597+
setRenameErrorColumnId(null)
15981598
columnRenameRef.current.setEditValue(value)
15991599
}, [])
16001600

@@ -1603,7 +1603,7 @@ export function TableGrid({
16031603
const { editingId, editValue, submitRename } = columnRenameRef.current
16041604
const trimmedName = editValue.trim()
16051605
const currentColumn = columnsRef.current.find((column) => column.key === editingId)
1606-
if (trimmedName && currentColumn && trimmedName !== currentColumn.name) {
1606+
if (currentColumn && trimmedName !== currentColumn.name) {
16071607
const issue = columnNameIssue(
16081608
trimmedName,
16091609
schemaColumnsRef.current
@@ -1612,16 +1612,16 @@ export function TableGrid({
16121612
)
16131613
if (issue) {
16141614
toast.error(issue)
1615-
setRenameError(true)
1615+
setRenameErrorColumnId(editingId)
16161616
return
16171617
}
16181618
}
1619-
setRenameError(false)
1619+
setRenameErrorColumnId(null)
16201620
void submitRename()
16211621
}, [])
16221622

16231623
const handleRenameCancel = useCallback(() => {
1624-
setRenameError(false)
1624+
setRenameErrorColumnId(null)
16251625
columnRenameRef.current.cancelRename()
16261626
}, [])
16271627

@@ -4119,7 +4119,7 @@ export function TableGrid({
41194119

41204120
const handleRenameColumn = useCallback(
41214121
(columnName: string) => {
4122-
setRenameError(false)
4122+
setRenameErrorColumnId(null)
41234123
const column = columnsRef.current.find((candidate) => candidate.key === columnName)
41244124
columnRename.startRename(columnName, column?.name ?? columnName)
41254125
},
@@ -5016,7 +5016,7 @@ export function TableGrid({
50165016
renameValue={
50175017
columnRename.editingId === column.key ? columnRename.editValue : ''
50185018
}
5019-
renameError={renameError && columnRename.editingId === column.key}
5019+
renameError={renameErrorColumnId === column.key}
50205020
onRenameValueChange={handleRenameValueChange}
50215021
onRenameSubmit={handleRenameSubmit}
50225022
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)