Repository navigation
Add JSON export and import for portable graphs - #5
Merged
Merged
Conversation
PNG export captures a picture of a graph, but there was no way to get the graph itself out of one browser and into another. This adds a portable JSON path: - Download: a header button serializes the active document to <graph-name>.json (pretty-printed, application/json) through the existing downloadBlob helper. - Import: a header button opens a file picker; the file is parsed with parseDocumentJson, which reuses sanitizeDocument — the same integrity boundary persisted state goes through — and returns null on malformed JSON or non-graph JSON instead of throwing. - importGraph lands the imported document as a NEW graph in the active project and switches to it, so importing never clobbers the graph you were looking at. History starts clean, mirroring createGraph. Tests cover the round-trip through the integrity boundary, malformed and non-document rejection, filename slugging, and the store-level import. Note: the two storage failure tests in store.test.ts fail on main before this change (see the separate fix PR); no new failures are introduced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PNG export captures a picture of a graph, but there was no way to get the graph itself out of one browser and into another (or share one with a friend, or keep a versioned copy in a repo). This adds a portable JSON path, two icon buttons in the header:
<graph-name>.json(pretty-printed,application/json), reusing the existingdownloadBlobhelper. Filenames are slugged from the graph name ("Retrieval — v2"→retrieval-v2.json).parseDocumentJson, which reusessanitizeDocument— the same integrity boundary persisted state already goes through — and returnsnullon malformed JSON or JSON that isn't a graph document, surfaced as a toast instead of a crash.Design choice: import never clobbers
importGraphlands the imported document as a new graph in the active project and switches to it (mirroringcreateGraph: clean history, selection cleared). Importing can't destroy the graph you were looking at, and a bad file changes nothing.Tests
documentToJsonBlob→parseDocumentJson→normalizeDocumentequality).Note: the two storage-failure tests in
store.test.tsfail onmainbefore this branch — that's #3, independent of this change.