Skip to content

feat: remember the schema visualizer's manual table layout - #1555

Merged
sorenbs merged 1 commit into
mainfrom
feat/1397-visualizer-layout
Jul 18, 2026
Merged

feat: remember the schema visualizer's manual table layout#1555
sorenbs merged 1 commit into
mainfrom
feat/1397-visualizer-layout

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #1397

Dragged table positions in the schema visualizer previously survived view switches (in-memory collection) but were lost on page reload. Following the repo's UI-state architecture:

  • New localStorage-backed uiPersistentStateCollection (TanStack DB localStorageCollectionOptions, key prisma-studio-persistent-ui-state-v1), with useUiState gaining a persistent: true option.
  • Dragging a node writes its position to a persisted map keyed schema-visualizer:<schemaName>:manual-layout:node-positions; on mount, ELK auto-layout runs and saved manual positions are merged over it — remembered tables restore exactly, new tables fall back to auto-layout.
  • The existing "Reset layout" button also clears the persisted layout — no new chrome.

Verification

  • Acceptance tests codified first: persistence survives simulated reload, auto-layout fallback for unsaved tables, reset clears, per-schema key scoping. Full pnpm test: 913 passing.
  • Verified end-to-end in the live demo: drag → localStorage written → full page reload → position restored; reset restores auto layout and clears the persisted value.
  • Typecheck/lint clean; Architecture/ui-state.md + FEATURES.md updated; changeset included (minor).

Known limitation: two databases exposing the same schema name and identical table names share a saved layout — Studio's navigation metadata has no stable database identifier to key on.

🤖 Generated with Claude Code

Dragged node positions are now persisted in a localStorage-backed
TanStack DB collection (uiPersistentStateCollection) scoped per schema,
so a manual arrangement survives leaving the visualizer and full page
reloads. Saved positions are merged over the ELK auto-layout on mount,
so tables without a remembered position (for example newly created
ones) still fall back to auto-layout, and the existing Reset layout
header action now also clears the remembered manual layout.

Closes #1397

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Schema visualizer node positions now persist across view changes and page reloads.
    • Layouts are saved separately for each schema.
    • Unpositioned tables continue using automatic layout.
    • Added a Reset layout action that restores automatic positioning and clears saved placements.
  • Documentation

    • Updated feature and UI state documentation to describe layout persistence and reset behavior.

Walkthrough

The change adds a localStorage-backed persistent UI state collection and a persistent option to useUiState. Schema visualizer node positions are stored under schema-scoped keys, merged over ELK auto-layout positions, and restored after in-memory state resets. Reset layout clears persisted manual positions. Tests, architecture documentation, feature documentation, and a changeset describe and verify the new behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: persisting manual schema visualizer layout.
Description check ✅ Passed The description matches the PR's layout persistence work and related docs/tests.
Linked Issues check ✅ Passed The PR fulfills #1397 by remembering manual visualizer layout across reloads and reset.
Out of Scope Changes check ✅ Passed The added docs, tests, and changeset all support the same layout-persistence objective.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/1397-visualizer-layout
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/1397-visualizer-layout

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Compute preview deployed.

Branch: feat/1397-visualizer-layout
Service: feat-1397-visualizer-layout
Preview: https://p3pggn43j3orfqar1zhz9rf8.cdg.prisma.build

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 34 minutes.

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui/studio/views/schema/Visualiser.tsx (1)

324-385: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Merge late manual position hydration into the visualizer state (ui/studio/views/schema/Visualiser.tsx:324-385).

manualNodePositions only updates the ref here, so if the persistent row arrives after the first auto-layout pass, those coordinates never get merged into nodePositions. Either merge the hydrated positions into nodePositions here or make the layout effect react to manualNodePositions. Add a test for late persistence hydration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/studio/views/schema/Visualiser.tsx` around lines 324 - 385, Update the
manualNodePositions synchronization effect to merge newly hydrated positions
into nodePositions, using the current auto-layout positions as the base and
preserving manual overrides. Ensure late persistence hydration updates the
rendered visualizer state without requiring another layout pass, and add a test
covering manual positions arriving after the initial auto-layout.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@ui/studio/views/schema/Visualiser.tsx`:
- Around line 324-385: Update the manualNodePositions synchronization effect to
merge newly hydrated positions into nodePositions, using the current auto-layout
positions as the base and preserving manual overrides. Ensure late persistence
hydration updates the rendered visualizer state without requiring another layout
pass, and add a test covering manual positions arriving after the initial
auto-layout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1b56fc54-6c9b-452b-a09b-6c1437a7d7f3

📥 Commits

Reviewing files that changed from the base of the PR and between 81354ff and f176238.

📒 Files selected for processing (12)
  • .changeset/schema-visualizer-remember-layout.md
  • Architecture/ui-state.md
  • FEATURES.md
  • ui/hooks/use-ui-state.context.test.tsx
  • ui/hooks/use-ui-state.ts
  • ui/studio/context.tsx
  • ui/studio/views/schema/SchemaView.test.tsx
  • ui/studio/views/schema/SchemaView.tsx
  • ui/studio/views/schema/Visualiser.test.tsx
  • ui/studio/views/schema/Visualiser.tsx
  • ui/studio/views/schema/schema-layout.test.ts
  • ui/studio/views/schema/schema-layout.ts

@sorenbs
sorenbs merged commit dc44731 into main Jul 18, 2026
3 checks passed
@sorenbs
sorenbs deleted the feat/1397-visualizer-layout branch July 18, 2026 13:02
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.

Remember visualizer manual layout.

1 participant