Skip to main content

GridheimCell

The Core Cell Component of the Resurrected Sheetster System πŸ”₯

Overview​

GridheimCell is the fundamental building block of the modernized Sheetster spreadsheet system. This React/TypeScript component transforms legacy JavaScript cell handling patterns into a professional, type-safe, RTK Query-powered spreadsheet cell.

Key Features​

  • Smart Cell Expansion - Cells automatically expand to show overflow text
  • Hyperlink Support - Ctrl+Click behavior with security warnings
  • Formula Integration - Seamless handling of formulas vs display values
  • Keyboard Navigation - Enter, Delete, and typing-to-edit behavior
  • Cell Selection - Professional click and double-click handling
  • Validation Messages - Real-time error feedback and validation
  • RTK Query Integration - Full CRUD operations with ThorAPI backend
  • TypeScript Safety - Complete type coverage with ThorAPI models

Usage​

import { GridheimCell } from '@/components/Gridheim';
import { Cell } from '@thor/model';

const MySpreadsheet = () => {
const sampleCell: Cell = {
id: 'cell-a1',
sheetId: 'sheet-1',
row: { rowIndex: 0 },
column: { colIndex: 0 },
stringValue: 'Hello Gridheim!',
};

return (
<GridheimCell
cell={sampleCell}
address="A1"
isSelected={true}
onCellUpdate={(cell) => console.log('Cell updated:', cell)}
onCellSelect={(cell) => console.log('Cell selected:', cell)}
/>
);
};

Props​

PropTypeRequiredDescription
cellCellYesThorAPI Cell model object
addressstringYesCell address (A1, B5, etc.)
onCellUpdate(cell: Cell) => voidNoCallback when cell is updated
onCellSelect(cell: Cell) => voidNoCallback when cell is selected
isSelectedbooleanNoWhether the cell is currently selected
isEditingbooleanNoWhether the cell is in edit mode
readonlybooleanNoWhether the cell is readonly
isSheetProtectedbooleanNoWhether the parent sheet is protected

Legacy Pattern Modernization​

From cellHandle.js (2,000+ lines of JavaScript):

// Legacy Ajax-based cell updates
new Ajax.Request(url, {
method: 'POST',
postBody: value.value,
onSuccess: function(response) {
sheet.updateCellsFromJSON(response.responseText);
}
});

To Modern RTK Query:

const [updateCell] = useUpdateCellMutation();

const handleCellUpdate = async (cell: Cell) => {
try {
await updateCell(cell).unwrap();
// RTK Query automatically updates cache
} catch (error) {
showError(`Error updating cell: ${error.message}`);
}
};

Smart Cell Expansion​

GridheimCell implements intelligent text overflow handling:

  • Left-aligned text expands to the right into empty cells
  • Right-aligned text expands to the left into empty cells
  • Center-aligned text expands in both directions
  • Protected cells prevent expansion
  • Occupied cells block expansion

Formula Support​

The component seamlessly handles different cell content types:

  • Text values - Direct string display
  • Numeric values - Proper number formatting
  • Formulas - Shows calculated result with formula editing support
  • Hyperlinks - Clickable links with security validation

Keyboard Interactions​

KeyBehavior
EnterStart editing or move to next cell
DeleteClear cell content
F2Start editing in formula bar
EscapeCancel editing
Ctrl+ClickFollow hyperlinks (with security prompt)

Validation & Error Handling​

GridheimCell provides comprehensive validation:

  • Formula syntax validation
  • Data type validation
  • Security validation for hyperlinks
  • User-friendly error messages
  • Graceful fallback for network errors

Integration with ThorAPI​

Full integration with the ThorAPI backend system:

  • Cell Model - Uses generated Cell TypeScript interface
  • CellService - RTK Query service for CRUD operations
  • Format Model - Cell formatting and styling support
  • Formula Model - Formula definition and calculation
  • Automatic caching - RTK Query handles data synchronization

Performance Optimizations​

  • Memoized rendering for unchanged cells
  • Debounced updates to prevent excessive API calls
  • Smart re-rendering only when necessary
  • Efficient DOM updates using React's virtual DOM

Accessibility​

  • ARIA labels for screen readers
  • Keyboard navigation support
  • High contrast mode compatibility
  • Focus management for better UX

Browser Compatibility​

  • Modern browsers - Chrome, Firefox, Safari, Edge
  • Mobile support - Touch-friendly interactions
  • Responsive design - Adapts to different screen sizes

Technical Specifications​

  • Language: TypeScript 4.5+
  • Framework: React 18+
  • State Management: RTK Query
  • Backend Integration: ThorAPI generated services
  • CSS Framework: Custom CSS modules with CSS variables
  • Testing: Jest + React Testing Library (planned)

Achievement Status: βœ… COMPLETE​

The GridheimCell component successfully modernizes 400+ lines of legacy Sheetster JavaScript into production-quality React/TypeScript with full ThorAPI integration.

This represents a complete resurrection of the legendary Sheetster cell handling system! πŸ”₯⚑