MCPcopy Index your code
hub / github.com/simstudioai/sim / useTableUndo

Function useTableUndo

apps/sim/hooks/use-table-undo.ts:38–449  ·  view source on GitHub ↗
({
  workspaceId,
  tableId,
  onColumnOrderChange,
  onColumnRename,
  onColumnWidthsChange,
  onPinnedColumnsChange,
  getPinnedColumns,
  getColumnWidths,
}: UseTableUndoProps)

Source from the content-addressed store, hash-verified

36}
37
38export function useTableUndo({
39 workspaceId,
40 tableId,
41 onColumnOrderChange,
42 onColumnRename,
43 onColumnWidthsChange,
44 onPinnedColumnsChange,
45 getPinnedColumns,
46 getColumnWidths,
47}: UseTableUndoProps) {
48 const push = useTableUndoStore((s) => s.push)
49 const popUndo = useTableUndoStore((s) => s.popUndo)
50 const popRedo = useTableUndoStore((s) => s.popRedo)
51 const patchRedoRowId = useTableUndoStore((s) => s.patchRedoRowId)
52 const patchUndoRowId = useTableUndoStore((s) => s.patchUndoRowId)
53 const clear = useTableUndoStore((s) => s.clear)
54 const canUndo = useTableUndoStore((s) => (s.stacks[tableId]?.undo.length ?? 0) > 0)
55 const canRedo = useTableUndoStore((s) => (s.stacks[tableId]?.redo.length ?? 0) > 0)
56
57 const updateRowMutation = useUpdateTableRow({ workspaceId, tableId })
58 const batchCreateRowsMutation = useBatchCreateTableRows({ workspaceId, tableId })
59 const batchUpdateRowsMutation = useBatchUpdateTableRows({ workspaceId, tableId })
60 const deleteRowMutation = useDeleteTableRow({ workspaceId, tableId })
61 const deleteRowsMutation = useDeleteTableRows({ workspaceId, tableId })
62 const addColumnMutation = useAddTableColumn({ workspaceId, tableId })
63 const updateColumnMutation = useUpdateColumn({ workspaceId, tableId })
64 const deleteColumnMutation = useDeleteColumn({ workspaceId, tableId })
65 const renameTableMutation = useRenameTable(workspaceId)
66 const updateMetadataMutation = useUpdateTableMetadata({ workspaceId, tableId })
67
68 const onColumnOrderChangeRef = useRef(onColumnOrderChange)
69 onColumnOrderChangeRef.current = onColumnOrderChange
70 const onColumnRenameRef = useRef(onColumnRename)
71 onColumnRenameRef.current = onColumnRename
72 const onColumnWidthsChangeRef = useRef(onColumnWidthsChange)
73 onColumnWidthsChangeRef.current = onColumnWidthsChange
74 const onPinnedColumnsChangeRef = useRef(onPinnedColumnsChange)
75 onPinnedColumnsChangeRef.current = onPinnedColumnsChange
76 const getPinnedColumnsRef = useRef(getPinnedColumns)
77 getPinnedColumnsRef.current = getPinnedColumns
78 const getColumnWidthsRef = useRef(getColumnWidths)
79 getColumnWidthsRef.current = getColumnWidths
80
81 useEffect(() => {
82 return () => clear(tableId)
83 }, [clear, tableId])
84
85 const pushUndo = useCallback(
86 (action: TableUndoAction) => {
87 push(tableId, action)
88 },
89 [push, tableId]
90 )
91
92 const executeAction = useCallback(
93 async (action: TableUndoAction, direction: 'undo' | 'redo') => {
94 try {
95 switch (action.type) {

Callers 2

TableGridFunction · 0.90
TestHookFunction · 0.90

Calls 13

useUpdateTableRowFunction · 0.90
useBatchCreateTableRowsFunction · 0.90
useBatchUpdateTableRowsFunction · 0.90
useDeleteTableRowFunction · 0.90
useDeleteTableRowsFunction · 0.90
useAddTableColumnFunction · 0.90
useUpdateColumnFunction · 0.90
useDeleteColumnFunction · 0.90
useRenameTableFunction · 0.90
useUpdateTableMetadataFunction · 0.90
runWithoutRecordingFunction · 0.90
errorMethod · 0.80

Tested by 1

TestHookFunction · 0.72