Repository navigation
refactor(ui): modularize seat grid layout math and cell components - #72
Conversation
1. Extract buildTemplateColumns, buildFlatItems, and span math to seat-layout-math.ts 2. Decouple mathematical layout algorithms from React rendering components 3. Import math helpers in SeatGrid while preserving all layout outputs
1. Extract SeatCellElement, DoorCellElement, and SpecialBlockCell to SeatGridCells 2. Extract AisleTrack component for vertical and horizontal walkways 3. Simplify SeatGrid main JSX render tree
1. Add unit tests for seat-layout-math track calculations and flat item generation 2. Add unit tests for special cell rendering and door alignment 3. Verify room layouts 209, 310, and 313 pass all layout tests
Reviewer's GuideThe PR refactors SeatGrid into a thin composition layer by separating pure seat-layout mathematics and reusable rendering components, while adding focused unit and integration coverage to verify behavior across the supported room layouts. Sequence diagram for seat grid compositionsequenceDiagram
participant Layout as RoomLayout
participant Grid as SeatGrid
participant Math as seat-layout-math
participant Cells as SeatGridCells
participant Aisles as AisleTrack
Layout->>Grid: render(layout)
Grid->>Math: buildTemplateColumns(layout, ...)
Grid->>Math: buildFlatItems(layout, ...)
Grid->>Math: resolveTotalGridRows(flat, layout)
Grid->>Cells: GridCellElement(item, sizes, layout, ...)
Grid->>Cells: TopDoorElement / facility elements
Grid->>Aisles: HorizontalWalkway / RowGapSpacer
Grid->>Aisles: VerticalAisleTrack
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Secrets | Nov 1, 2026 4:41p.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/components/seats/seat-layout-math.ts" line_range="64" />
<code_context>
-
-const resolvePhysicalSpan = (
- isSoloCorridor: boolean,
- hasAisles: boolean,
- logical: number,
- colSpan: number,
</code_context>
<issue_to_address>
**Mismatched layout flags place seats incorrectly**
When a caller passes aisle flags that disagree with the layout or with each other, `buildTemplateColumns` and `resolveSeatColumn` use independent aisle flags, so inconsistent arguments produce a track template that does not match the calculated seat columns; seats land in implicit grid tracks and the caller sees a misaligned grid.
Derive these flags from `RoomLayout` inside the helpers or pass a single validated layout-options object to all related calculations.
Also at `src/components/seats/seat-layout-math.ts:36`.
</issue_to_address>
### Comment 2
<location path="src/components/seats/SeatGridCells.tsx" line_range="53" />
<code_context>
- itemStyle,
-}: Readonly<{
- cell: Extract<GridCell, { type: "seat" }>;
- sizes: SeatSizes;
- layoutId: string;
- itemStyle: React.CSSProperties;
</code_context>
<issue_to_address>
**Non-door cells render as doors**
When a caller uses either exported renderer with a different special-cell variant, `DoorCellElement` accepts any `SpecialCell` and renders its label as a door; `PrinterCellElement` has the same overly broad cell type. A caller can pass a corridor or sofa without a type error and get the wrong facility rendered.
Narrow each renderer's cell prop to the corresponding discriminated variant, such as `Extract<SpecialCell, { type: "door" }>`.
Also at `src/components/seats/SeatGridCells.tsx:100`.
</issue_to_address>
### Comment 3
<location path="src/test/seat-modular.test.tsx" line_range="126-127" />
<code_context>
+
+ it("builds correct grid template for room 310 with left aisle", () => {
+ const cols = buildTemplateColumns(room310, false, true, true, false);
+ expect(cols[0]).toBe("minmax(24px, auto)");
+ expect(cols).toHaveLength(12); // left aisle + 6 seat cols + 5 gap tracks
+ });
+ });
</code_context>
<issue_to_address>
**Incorrect aisle tracks pass**
When the room-310 builder returns 12 tracks with the correct first track but incorrect remaining tracks, the “builds correct grid template for room 310 with left aisle” test checks only the first track and total length at line 127, so incorrect seat or gap tracks still pass.
Assert the full expected track array for room 310.
</issue_to_address>
### Comment 4
<location path="src/test/seat-modular.test.tsx" line_range="136-138" />
<code_context>
+ const seatColumn = (logical: number) => resolveSeatColumn(logical, true, 0);
+ const flat = buildFlatItems(room209, true, false, 2, seatColumn);
+ expect(flat.length).toBe(20); // 5 rows * 4 cols
+ expect(flat[0].row).toBe(2);
+ expect(flat[0].col).toBe(1);
+ expect(flat[0].cell.type).toBe("seat");
+
+ const totalRows = resolveTotalGridRows(flat, room209);
</code_context>
<issue_to_address>
**Wrong seat columns pass flatten test**
When the flattener preserves the item count and first item but assigns later cells to incorrect columns, the “flattens room 209 rows and maps correct row and col tracks” test checks only the first item’s coordinates at lines 136–137, so incorrect column mappings for later cells pass.
Assert expected coordinates for cells across the flattened rows.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/components/seats/seat-layout-math.ts:64, src/test/seat-modular.test.tsx:127, src/test/seat-modular.test.tsx:138
1. Replace generic length equality checks with toHaveLength matcher 2. Resolve SonarCloud typescript:S5906 rule findings
1. Introduce resolveLayoutFlags to unify aisle and track option derivation 2. Narrow DoorCell and PrinterCell element props to exact cell variants 3. Address review feedback for layout flag consistency and type safety
1. Assert full track array for room 310 grid template 2. Assert cell coordinates across all columns in flattened room 209 rows 3. Add unit test for resolveLayoutFlags
|



Summary
Modularize the seat grid visualization (
SeatGrid.tsx) by separating mathematical layout algorithms from React rendering concerns. Pure coordinate resolvers, track builders, and cell flattening are decoupled intoseat-layout-math.ts. Dedicated cell and facility elements are extracted intoSeatGridCells.tsx, and aisle walkway dividers are extracted intoAisleTrack.tsx. This reducesSeatGrid.tsxfrom 556 lines to 158 lines while maintaining 100% visual and behavioral parity.Key Changes
src/components/seats/seat-layout-math.ts: Decoupled pure geometry and layout math algorithms (buildTemplateColumns,buildFlatItems,resolveSeatColumn,resolvePhysicalSpan,resolveTotalGridRows,resolveDoorJustify,resolveLeftAisleTrack,resolveRowOffset,resolveFont).src/components/seats/SeatGridCells.tsx: Modularized cell renderers (SeatCellElement,DoorCellElement,PrinterCellElement,SpecialBlockCell,GridCellElement) and room boundary facility elements (TopDoorElement,TopWhiteboardElement,SideDoorElement,SideWhiteboardElement,SidePrinterElement).src/components/seats/AisleTrack.tsx: Modularized aisle walkway dividers (HorizontalWalkway,RowGapSpacer,VerticalAisleTrack).src/components/seats/SeatGrid.tsx: Streamlined main grid component to pure composition, shrinking from 556 to 158 lines.src/test/seat-modular.test.tsxwith 24 comprehensive unit tests verifying math functions, component states, and room layout assemblies.Verification
npx tsc -bpasses with 0 errorsnpm test— all 33 test files (305 tests) passNotes
DepartmentNewsModal).Summary by Sourcery
Modularize the seat grid implementation to improve separation of concerns and independent testability without changing rendered layouts or interactions.
Enhancements:
Tests: