Skip to content

Commit 5d5160c

Browse files
committed
fix(tables): resolve highlighted option on blur, carry newOptions through type-change redo
1 parent 9ab2632 commit 5d5160c

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ function InlineSelectEditor({
198198
[draft, onSave]
199199
)
200200

201+
// The option Enter/Tab/blur should apply: the highlighted one once the user
202+
// has arrow-navigated or typed a non-empty filter, else the raw draft.
203+
const resolvePick = useCallback(
204+
() =>
205+
highlighted !== undefined && (navigated || (typed && query !== '')) ? highlighted : undefined,
206+
[highlighted, navigated, typed, query]
207+
)
208+
201209
const handleKeyDown = useCallback(
202210
(e: React.KeyboardEvent) => {
203211
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
@@ -209,21 +217,20 @@ function InlineSelectEditor({
209217
} else if (e.key === 'Enter' || e.key === 'Tab') {
210218
e.preventDefault()
211219
const reason: SaveReason = e.key === 'Tab' ? (e.shiftKey ? 'shift-tab' : 'tab') : 'enter'
212-
const pick = highlighted !== undefined && (navigated || (typed && query !== ''))
213-
doSave(reason, pick ? highlighted : undefined)
220+
doSave(reason, resolvePick())
214221
} else if (e.key === 'Escape') {
215222
e.preventDefault()
216223
doneRef.current = true
217224
clearTimeout(blurTimeoutRef.current)
218225
onCancel()
219226
}
220227
},
221-
[doSave, onCancel, filtered.length, highlighted, query, typed, navigated]
228+
[doSave, onCancel, filtered.length, resolvePick]
222229
)
223230

224231
const handleBlur = useCallback(() => {
225-
blurTimeoutRef.current = setTimeout(() => doSave('blur'), 200)
226-
}, [doSave])
232+
blurTimeoutRef.current = setTimeout(() => doSave('blur', resolvePick()), 200)
233+
}, [doSave, resolvePick])
227234

228235
return (
229236
<Popover open>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ export function useTableUndo({
384384

385385
case 'update-column-type': {
386386
const type = direction === 'undo' ? action.previousType : action.newType
387-
const restoreOptions =
388-
direction === 'undo' && type === 'select' && action.previousOptions !== undefined
387+
const options = direction === 'undo' ? action.previousOptions : action.newOptions
388+
const restoreOptions = type === 'select' && options !== undefined
389389
updateColumnMutation.mutate({
390390
columnName: action.columnName,
391-
updates: { type, ...(restoreOptions ? { options: action.previousOptions } : {}) },
391+
updates: { type, ...(restoreOptions ? { options } : {}) },
392392
})
393393
break
394394
}

apps/sim/stores/table/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export type TableUndoAction =
7474
/** Options to restore when undoing back to a select column (the server
7575
* strips them on the way out of select). */
7676
previousOptions?: string[]
77+
/** Options to re-apply when redoing a change to a select column. */
78+
newOptions?: string[]
7779
}
7880
| {
7981
type: 'toggle-column-constraint'

0 commit comments

Comments
 (0)