Skip to content

refactor(ui): modularize seat grid layout math and cell components - #72

Merged
Youchenjiang merged 6 commits into
mainfrom
refactor/seat-grid-modular
Nov 1, 2026
Merged

Youchenjiang merged 6 commits into
mainfrom
refactor/seat-grid-modular

Conversation

@Youchenjiang

@Youchenjiang Youchenjiang commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

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 into seat-layout-math.ts. Dedicated cell and facility elements are extracted into SeatGridCells.tsx, and aisle walkway dividers are extracted into AisleTrack.tsx. This reduces SeatGrid.tsx from 556 lines to 158 lines while maintaining 100% visual and behavioral parity.

Key Changes

  1. Architecture & Scope:
    • 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.
  2. Behavior & Contracts:
    • Maintained full visual and behavioral equivalence across all room layouts (209, 310, and 313).
    • Independent testability for coordinate and track math without DOM rendering overhead.
    • Added src/test/seat-modular.test.tsx with 24 comprehensive unit tests verifying math functions, component states, and room layout assemblies.

Verification

  • npx tsc -b passes with 0 errors
  • npm test — all 33 test files (305 tests) pass
  • No sensitive data committed
  • Clickra branch naming and Conventional Commit policies verified

Notes

Summary by Sourcery

Modularize the seat grid implementation to improve separation of concerns and independent testability without changing rendered layouts or interactions.

Enhancements:

  • Separate seat-grid layout calculations, cell rendering, facility elements, and aisle tracks into focused modules while preserving existing visual and behavioral behavior.

Tests:

  • Add unit, component, and integration coverage for seat-layout math, extracted grid elements, aisle tracks, and room layouts.

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
@sourcery-ai

sourcery-ai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 composition

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Extract layout geometry and cell-position calculations into independently testable pure helpers.
  • Moved coordinate resolution, grid-track construction, flat-cell generation, row counting, and door alignment logic out of the main component.
  • Preserved handling for aisles, walkways, solo corridors, spans, facility tracks, and room-specific layouts.
src/components/seats/seat-layout-math.ts
src/components/seats/SeatGrid.tsx
Extract seat, facility, boundary, and aisle rendering into focused React components.
  • Added dedicated renderers for seats, doors, printers, special blocks, and top/side room facilities.
  • Added reusable horizontal walkway, row spacer, and vertical aisle track components.
  • Reduced SeatGrid to layout orchestration and composition while retaining existing styling and occupancy behavior.
src/components/seats/SeatGridCells.tsx
src/components/seats/AisleTrack.tsx
src/components/seats/SeatGrid.tsx
Add coverage for the modularized math, rendering components, and supported room assemblies.
  • Unit-tested geometry thresholds, column/span calculations, template tracks, flattened items, and total rows.
  • Tested component states, facility rendering, walkway behavior, and integrations for rooms 209, 310, and 313.
src/test/seat-modular.test.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepsource-io

deepsource-io Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in be5bbac...4f9f084 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/components/seats/SeatGridCells.tsx Resolved
Comment thread src/test/seat-modular.test.tsx Resolved
Comment thread src/test/seat-modular.test.tsx Resolved
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
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

@Youchenjiang
Youchenjiang merged commit 3b9983f into main Nov 1, 2026
10 checks passed
@Youchenjiang
Youchenjiang deleted the refactor/seat-grid-modular branch November 1, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant