feat: remember the schema visualizer's manual table layout - #1555
Conversation
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>
Summary by CodeRabbit
WalkthroughThe change adds a localStorage-backed persistent UI state collection and a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
Compute preview deployed. Branch: |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull 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. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
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 winMerge late manual position hydration into the visualizer state (
ui/studio/views/schema/Visualiser.tsx:324-385).
manualNodePositionsonly updates the ref here, so if the persistent row arrives after the first auto-layout pass, those coordinates never get merged intonodePositions. Either merge the hydrated positions intonodePositionshere or make the layout effect react tomanualNodePositions. 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
📒 Files selected for processing (12)
.changeset/schema-visualizer-remember-layout.mdArchitecture/ui-state.mdFEATURES.mdui/hooks/use-ui-state.context.test.tsxui/hooks/use-ui-state.tsui/studio/context.tsxui/studio/views/schema/SchemaView.test.tsxui/studio/views/schema/SchemaView.tsxui/studio/views/schema/Visualiser.test.tsxui/studio/views/schema/Visualiser.tsxui/studio/views/schema/schema-layout.test.tsui/studio/views/schema/schema-layout.ts
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:
uiPersistentStateCollection(TanStack DBlocalStorageCollectionOptions, keyprisma-studio-persistent-ui-state-v1), withuseUiStategaining apersistent: trueoption.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.Verification
pnpm test: 913 passing.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