Skip to content

Commit d6caee1

Browse files
committed
fix(tables): preserve explicit column undo metadata
1 parent ac81f4d commit d6caee1

5 files changed

Lines changed: 62 additions & 11 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type {
2525
WorkflowGroup,
2626
} from '@/lib/table'
2727
import { getColumnId } from '@/lib/table/column-keys'
28-
import { columnTypeOf, typeMetadataOf } from '@/lib/table/column-types'
28+
import { columnTypeOf } from '@/lib/table/column-types'
2929
import { TABLE_LIMITS } from '@/lib/table/constants'
3030
import { cellValueFilterConditions } from '@/lib/table/query-builder/cell-filter'
3131
import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
@@ -4124,7 +4124,14 @@ export function TableGrid({
41244124
columnPosition: adjustedPosition >= 0 ? adjustedPosition : cols.length,
41254125
columnUnique: entry.def?.unique ?? false,
41264126
columnRequired: entry.def?.required ?? false,
4127-
columnTypeMetadata: entry.def ? typeMetadataOf(entry.def) : {},
4127+
// Without these a deleted select column can't be re-created — it is
4128+
// invalid with no options, and the saved cell data is option ids.
4129+
...(entry.def?.options ? { columnOptions: entry.def.options } : {}),
4130+
...(entry.def?.multiple ? { columnMultiple: true } : {}),
4131+
...(entry.def?.currencyCode ? { columnCurrencyCode: entry.def.currencyCode } : {}),
4132+
...(entry.def?.referenceTableId
4133+
? { columnReferenceTableId: entry.def.referenceTableId }
4134+
: {}),
41284135
cellData,
41294136
previousOrder: orderSnapshot,
41304137
previousWidth,

apps/sim/hooks/use-table-undo.test.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ describe('useTableUndo – delete-column undo cell restore chunking', () => {
195195
columnPosition: 0,
196196
columnUnique: false,
197197
columnRequired: false,
198-
columnTypeMetadata: {},
199198
cellData: [],
200199
previousOrder: null,
201200
previousWidth: null,
@@ -249,10 +248,8 @@ describe('useTableUndo – restoring a deleted select column', () => {
249248
columnPosition: 0,
250249
columnUnique: false,
251250
columnRequired: false,
252-
columnTypeMetadata: {
253-
options: [{ id: 'opt_open', name: 'Open' }],
254-
multiple: true,
255-
},
251+
columnOptions: [{ id: 'opt_open', name: 'Open' }],
252+
columnMultiple: true,
256253
cellData: [],
257254
previousOrder: null,
258255
previousWidth: null,
@@ -276,6 +273,41 @@ describe('useTableUndo – restoring a deleted select column', () => {
276273
})
277274
})
278275

276+
describe('useTableUndo – restoring a deleted currency column', () => {
277+
it('re-creates the column with its original denomination', async () => {
278+
mockPopUndo.mockReturnValueOnce(
279+
makeEntry({
280+
type: 'delete-column',
281+
columnName: 'amount',
282+
columnId: 'col_amount',
283+
columnType: 'currency',
284+
columnPosition: 0,
285+
columnUnique: false,
286+
columnRequired: false,
287+
columnCurrencyCode: 'JPY',
288+
cellData: [],
289+
previousOrder: null,
290+
previousWidth: null,
291+
previousPinnedColumns: null,
292+
})
293+
)
294+
295+
const { undo } = TestHook()
296+
;(undo as () => void)()
297+
await flush()
298+
299+
expect(mockMutate).toHaveBeenCalledWith(
300+
expect.objectContaining({
301+
id: 'col_amount',
302+
name: 'amount',
303+
type: 'currency',
304+
currencyCode: 'JPY',
305+
}),
306+
expect.any(Object)
307+
)
308+
})
309+
})
310+
279311
describe('useTableUndo – restoring a deleted reference column', () => {
280312
it('re-creates the column with its target table', async () => {
281313
mockPopUndo.mockReturnValueOnce(
@@ -287,7 +319,7 @@ describe('useTableUndo – restoring a deleted reference column', () => {
287319
columnPosition: 0,
288320
columnUnique: false,
289321
columnRequired: false,
290-
columnTypeMetadata: { referenceTableId: 'tbl_people' },
322+
columnReferenceTableId: 'tbl_people',
291323
cellData: [],
292324
previousOrder: null,
293325
previousWidth: null,

apps/sim/hooks/use-table-undo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ export function useTableUndo({
386386
type: action.columnType,
387387
required: action.columnRequired,
388388
unique: action.columnUnique,
389-
...action.columnTypeMetadata,
389+
...(action.columnOptions ? { options: action.columnOptions } : {}),
390+
...(action.columnMultiple ? { multiple: true } : {}),
391+
...(action.columnCurrencyCode ? { currencyCode: action.columnCurrencyCode } : {}),
392+
...(action.columnReferenceTableId
393+
? { referenceTableId: action.columnReferenceTableId }
394+
: {}),
390395
position: action.columnPosition,
391396
},
392397
{

apps/sim/stores/table/store.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const deleteColumn: TableUndoAction = {
1919
columnPosition: 0,
2020
columnUnique: false,
2121
columnRequired: false,
22-
columnTypeMetadata: {},
2322
cellData: [],
2423
previousOrder: ['a', 'b'],
2524
previousWidth: null,

apps/sim/stores/table/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ export type TableUndoAction =
5555
columnPosition: number
5656
columnUnique: boolean
5757
columnRequired: boolean
58-
columnTypeMetadata: Partial<ColumnDefinition>
58+
// A `select` column is invalid without its option set, so the snapshot has
59+
// to carry it or the restore is rejected — and the saved cell data, which
60+
// holds option ids, would have nothing to attach to.
61+
columnOptions?: ColumnDefinition['options']
62+
columnMultiple?: boolean
63+
// Likewise for a `currency` column: without its code the restore would
64+
// silently re-denominate every cell to the default currency.
65+
columnCurrencyCode?: string
66+
columnReferenceTableId?: string
5967
cellData: Array<{ rowId: string; value: unknown }>
6068
previousOrder: string[] | null
6169
previousWidth: number | null

0 commit comments

Comments
 (0)