Skip to content

Instantly share code, notes, and snippets.

@matthew-gerstman
Created February 6, 2026 14:37
Show Gist options
  • Select an option

  • Save matthew-gerstman/430c7327dacaa3eeb0bccf550440ebe4 to your computer and use it in GitHub Desktop.

Select an option

Save matthew-gerstman/430c7327dacaa3eeb0bccf550440ebe4 to your computer and use it in GitHub Desktop.
Workbook Architecture Refactoring — Remaining Work (Steps 5-7)

Workbook Architecture Refactoring — Remaining Work

Completed in PR #6396: Steps 1–4 (WorkbookSessionContext, useSimpleWorkbookData decomposition, ColumnOperationsShared, orchestrator extraction).

Step 5: Rename & Reorganize (Low Priority — Cosmetic)

Rename simple-workbook-table/workbook-table/ and reorganize hooks into subdirectories.

Why deferred: Touches 29+ files for mechanical import renaming. High conflict risk, no behavioral change. Best done during a quiet period with no other active workbook PRs.

If you do it:

  • Rename directory: features/simple-workbook-table/features/workbook-table/
  • Update all 29 import paths across the codebase
  • Organize hooks into subdirectories:
    hooks/
    ├── data/        (use-simple-workbook-data, use-workbook-worker, use-data-store, use-cell-edit-batching, use-row-mutations, use-row-drag-preview, use-optimistic-column-data)
    ├── columns/     (use-column-actions-with-history, use-column-menu-actions, use-column-ordering, use-column-widths, use-pinned-columns, use-column-undo-redo)
    ├── orchestration/ (use-workbook-toolbar-effect, use-grid-selection-handler, use-cell-content-pipeline)
    └── (remaining)  (use-formatting, use-search, use-selection, use-bulk-paste, etc.)
    
  • Move workbook-renderer/use-column-operations.ts into workbook-table/hooks/columns/

Step 6: Add Error Toasts for Silent Failures (Medium Priority)

Replace console.error / console.warn with toast.error for user-initiated operations that fail silently.

Files to audit:

  • hooks/use-column-menu-actions.tshandleClearColumnAction catches errors with alert() (should use toast), undo/redo callbacks use console.warn
  • hooks/use-toolbar-actions.tsclearSelectedColumn catches with alert()
  • hooks/use-row-mutations.ts — row operations catch errors silently
  • hooks/use-column-actions-with-history.ts — column operations catch errors
  • hooks/use-simple-workbook-data.ts — cell edit failures, enrichment errors
  • workbook-renderer/use-column-operations.ts — field save/add/delete/duplicate/clear errors

Pattern to follow:

// Before (silent)
catch (error) {
  console.error('Failed to clear column:', error)
}

// After (user-visible)
catch (error) {
  console.error('Failed to clear column:', error)
  toast.error('Failed to clear column. Please try again.')
}

Note: toast is already imported in simple-workbook-table.tsx via @/utils/toast. Add the import to each hook file as needed.

Step 7: Test Coverage for High-Complexity Untested Hooks (Medium Priority)

These hooks are >200 lines with no test coverage:

Hook Lines Key behaviors to test
use-column-actions-with-history.ts ~500 Column add/delete/duplicate/clear with undo/redo, selection tracking after operations
use-column-menu-actions.ts ~490 Field save/add with state management, hide/format/sort/filter/pin column actions
use-formatting.ts ~420 Bold/italic/underline toggle, text color, cell highlight, undo/redo, format persistence
use-workbook-worker.ts ~430 Worker initialization, page fetching, data hydration, search field changes
use-pinned-columns.ts ~300 Pin/unpin, persistence, optimistic updates, boundary crossing
use-toolbar-actions.ts ~260 Column hide/duplicate/clear/delete, movement, sort, unhide

Testing approach: Use renderHook from @testing-library/react with mock dependencies. Focus on:

  1. Happy path for each action
  2. Undo/redo round-trip correctness
  3. Edge cases (empty selection, last column, readonly mode)

Current Architecture Metrics (Post PR #6396)

Metric Before After Target
Orchestrator lines 1,345 984 ~500
Largest hook lines 1,217 796 ~400
Max hook params 28 17 ~10
Callback data-lifting props 3 0 0 ✓
New focused hooks 0 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment