Skip to content

FE-502, H-6330: Improve SDCPN file import/export and file save/open behaviour#8536

Merged
kube merged 12 commits intomainfrom
cf/petrinaut-better-export-import
Mar 18, 2026
Merged

FE-502, H-6330: Improve SDCPN file import/export and file save/open behaviour#8536
kube merged 12 commits intomainfrom
cf/petrinaut-better-export-import

Conversation

@kube
Copy link
Collaborator

@kube kube commented Mar 12, 2026

🌟 What is the purpose of this PR?

Fixes the bug where importing an SDCPN file exported without visual info breaks the editor. Also improves the file format with Zod validation and a versioned envelope. Additionally improves the File menu save/open behaviour.

🔗 Related links

🔍 What does this change?

  • Moves file format code into src/file-format/ (export-sdcpn, import-sdcpn, remove-visual-info)
  • Removes old-format (before November 2025)
  • Replaces manual type guards with Zod schemas for import validation, matching the pattern used for clipboard in clipboard/types.ts
  • Adds versioned file format envelope (version, meta.generator) to exported files
  • Fixes layout on import: when nodes are missing x/y, runs ELK layout before calling createNewNet (avoids a stale closure bug where positions were applied to the wrong net)
  • Adds onlyMissingPositions option to calculateGraphLayout for partial re-layout of imported nodes
  • Adds ImportErrorDialog showing Zod validation errors with a "Create empty net" fallback
  • Caps Open submenu height so it doesn't go off-screen with many files (scrollable, max 400px / viewport-relative)
  • Sorts Open menu by most recently updated net first
  • Cleans up empty nets — empty, unmodified nets are removed from storage when the user switches away or creates a new net
  • Updates lastUpdated on mutation so the sort order reflects actual edit activity

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

❓ How to test this?

  1. Export a net as "JSON without visual info"
  2. Import the exported file back
  3. Confirm all nodes are laid out by ELK (not stacked at origin)
  4. Import a malformed JSON file and confirm the error dialog appears
  5. Create several nets via File → New, verify empty ones are cleaned up when switching away
  6. Open the File → Open menu with many nets, confirm it scrolls instead of going off-screen
  7. Edit a net, then check that it appears at the top of the Open menu

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Mar 17, 2026 11:36pm
petrinaut Ready Ready Preview Mar 17, 2026 11:36pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview Mar 17, 2026 11:36pm
hashdotdesign-tokens Ignored Ignored Preview Mar 17, 2026 11:36pm

@github-actions github-actions bot added area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Mar 12, 2026
Copy link
Collaborator Author

kube commented Mar 12, 2026

@kube kube marked this pull request as ready for review March 12, 2026 23:15
@cursor
Copy link

cursor bot commented Mar 12, 2026

PR Summary

Medium Risk
Moderate risk: changes SDCPN file import/export format/validation and editor import flow (including auto-layout), which could break backward compatibility or edge-case files if schemas/layout assumptions are wrong.

Overview
Improves Petrinaut SDCPN import/export by introducing a versioned file envelope (version, meta.generator) on export and a new Zod-validated import pipeline (parseSDCPNFile) that supports both versioned and legacy files, with clearer error reporting.

Fixes imports of files missing visual info by defaulting absent arrays/visual fields (including missing x/y) and, when positions are missing, running ELK layout before createNewNet to avoid loading a broken/stacked graph. Import failures now surface via a new ImportErrorDialog with a “Create empty net” fallback.

Improves net switching UX by adding lastUpdated to MinimalNetMetadata/persisted nets, showing relative timestamps in the Open submenu, making submenus scrollable, sorting nets by most-recently-updated, updating lastUpdated on edits, and cleaning up empty unmodified local nets when switching/creating new nets. Hash frontend now includes lastUpdated from entity metadata when listing persisted nets.

Written by Cursor Bugbot for commit e31b652. This will update automatically on new commits. Configure here.

@augmentcode
Copy link

augmentcode bot commented Mar 12, 2026

🤖 Augment PR Summary

Summary: This PR refactors Petrinaut’s SDCPN JSON import/export to be versioned and Zod-validated, and improves the import experience when node positions are missing.

Changes:

  • Moved SDCPN file I/O helpers into src/file-format/ (export, import, remove-visual-info, old-format converters).
  • Introduced a v1 on-disk JSON envelope with version and meta.generator metadata on export.
  • Added Zod schemas for both the versioned format and a legacy (unversioned) format, using defaults for optional sections.
  • Reworked import to return a structured result (success/error) and to detect missing x/y coordinates.
  • On import, fills missing coordinates and (when needed) runs ELK layout before calling createNewNet to avoid stale-closure issues.
  • Extended calculateGraphLayout with an onlyMissingPositions option to support partial re-layout.
  • Added an ImportErrorDialog to display validation/read errors with a “Create empty net” fallback.

Technical Notes: The new importer prefers the versioned schema first, falls back to the legacy schema, and uses user settings (compact vs classic node dimensions) when computing ELK layout.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@kube kube changed the title Improve SDCPN file import/export with Zod validation and layout fix FE-502: Improve SDCPN file import/export with Zod validation and layout fix Mar 13, 2026
@kube kube changed the base branch from cf/petrinaut-copy-paste to graphite-base/8536 March 14, 2026 19:32
@kube kube force-pushed the cf/petrinaut-better-export-import branch from 82c0b1c to 5cb778f Compare March 14, 2026 19:48
@kube kube force-pushed the graphite-base/8536 branch from 7889b18 to 1a404fc Compare March 14, 2026 19:48
@kube kube changed the base branch from graphite-base/8536 to cf/petrinaut-copy-paste March 14, 2026 19:48
@kube kube marked this pull request as draft March 14, 2026 19:57
@kube kube marked this pull request as ready for review March 14, 2026 19:57
@kube kube force-pushed the cf/petrinaut-better-export-import branch from 5cb778f to 9d9196d Compare March 14, 2026 20:01
Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

- Fix export spread order so explicit title cannot be overwritten
- Fix stale closure in loadPetriNet by moving check inside updater
- Show actual Zod errors for supported version with invalid structure
- Split hasMissingPositions from type visual info check
- Remove pre-2025-11-28 old format import support
- Add 19 unit tests for parseSDCPNFile

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot removed area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) labels Mar 17, 2026
- Remove old-formats directory and all related exports/types
- Simplify localStorage types (no more OldFormat union)
- Remove old format conversion logic from init effect
- Remove onlyMissingPositions from calculateGraphLayout, always do full layout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@kube kube enabled auto-merge March 17, 2026 23:43
@kube kube added this pull request to the merge queue Mar 18, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 18, 2026
@kube kube added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit 0a3ddc3 Mar 18, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash* Affects HASH (a `hash-*` app) area/apps area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

2 participants