-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic navigation #92
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6baa808
feat: basic navigation
KarlHeitmann 367db62
Merge branch 'main' into add_nav
AykutSarac b26d950
conventional improvements
AykutSarac ab0e7dc
feat: added basic tests for extractTree, flattenTree and generateChil…
KarlHeitmann 76c73b8
feat: added parent_id data each node of the tree representation of th…
KarlHeitmann 0d0977c
feat: flattenTree function adds a parent node if needed, parent node …
KarlHeitmann dee65ea
chore: tests updated
KarlHeitmann c66651c
refactor: function generateChildren uses .flatMap again
KarlHeitmann c81d54f
Merge branch 'main' into add_nav
AykutSarac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
190 changes: 190 additions & 0 deletions
190
src/components/__tests__/utils/json-editor-parser/extractTree.test.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import { extractTree } from "src/utils/json-editor-parser" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test files |
||
|
||
describe("extractTree", () => { | ||
it("takes a parsed JSON and extracts a tree representation of the JSON", () => { | ||
const parsedJson = [ | ||
{ | ||
"name": "root", | ||
"colors": [ | ||
"red", | ||
"green", | ||
"blue" | ||
] | ||
} | ||
] | ||
const tree = [ | ||
{ | ||
"id": "1", | ||
"text": { | ||
"name": "root" | ||
}, | ||
"children": [ | ||
{ | ||
"id": "2", | ||
"text": "colors", | ||
"parent": true, | ||
"parent_id": "1", | ||
"children": [ | ||
{ | ||
"id": "3", | ||
"text": "red", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
}, | ||
{ | ||
"id": "4", | ||
"text": "green", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
}, | ||
{ | ||
"id": "5", | ||
"text": "blue", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
} | ||
] | ||
} | ||
], | ||
"parent": false, | ||
"parent_id": null | ||
} | ||
] | ||
expect(extractTree(parsedJson)).toStrictEqual(tree) | ||
}) | ||
|
||
it("simple object with two sibblings arrays", () => { | ||
const simpleObject = { | ||
"name": "root", | ||
"colors": [ | ||
"red", | ||
"blue," | ||
], | ||
"tags": [ | ||
"good-first-issue", | ||
"bug" | ||
] | ||
} | ||
const result = [ | ||
{ | ||
"id": "1", | ||
"text": { | ||
"name": "root" | ||
}, | ||
"children": [ | ||
{ | ||
"id": "2", | ||
"text": "colors", | ||
"parent": true, | ||
"parent_id": "1", | ||
"children": [ | ||
{ | ||
"id": "4", | ||
"text": "red", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
}, | ||
{ | ||
"id": "5", | ||
"text": "blue,", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "3", | ||
"text": "tags", | ||
"parent": true, | ||
"parent_id": "1", | ||
"children": [ | ||
{ | ||
"id": "6", | ||
"text": "good-first-issue", | ||
"children": [], | ||
"parent_id": "3", | ||
"parent": false | ||
}, | ||
{ | ||
"id": "7", | ||
"text": "bug", | ||
"children": [], | ||
"parent_id": "3", | ||
"parent": false | ||
} | ||
] | ||
} | ||
], | ||
"parent_id": null, | ||
"parent": false | ||
} | ||
] | ||
expect(extractTree(simpleObject)).toStrictEqual(result) | ||
}) | ||
|
||
it("simple object with no children", () => { | ||
const simpleObject = [ | ||
{ | ||
"first_name": "jane", | ||
"last_name": "doe" | ||
} | ||
] | ||
const result = [ | ||
{ | ||
"id": "1", | ||
"text": { | ||
"first_name": "jane", | ||
"last_name": "doe" | ||
}, | ||
"children": [], | ||
"parent_id": null, | ||
"parent": false | ||
} | ||
] | ||
expect(extractTree(simpleObject)).toStrictEqual(result) | ||
}) | ||
|
||
it("simple object with only one element inside array in children", () => { | ||
const simpleObject = [ | ||
{ | ||
"name": "root", | ||
"colors": [ | ||
"red", | ||
] | ||
} | ||
] | ||
const result = [ | ||
{ | ||
"id": "1", | ||
"text": { | ||
"name": "root" | ||
}, | ||
"children": [ | ||
{ | ||
"id": "2", | ||
"text": "colors", | ||
"parent": true, | ||
"parent_id": "1", | ||
"children": [ | ||
{ | ||
"id": "3", | ||
"text": "red", | ||
"children": [], | ||
"parent_id": "2", | ||
"parent": false | ||
} | ||
] | ||
} | ||
], | ||
"parent": false, | ||
"parent_id": null | ||
} | ||
] | ||
expect(extractTree(simpleObject)).toStrictEqual(result) | ||
}) | ||
}) |
56 changes: 56 additions & 0 deletions
56
src/components/__tests__/utils/json-editor-parser/flattenTree.test.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { flattenTree } from "src/utils/json-editor-parser" | ||
|
||
describe("flattenTree", () => { | ||
it("takes a tree representation of a JSON and flattens it into a set of nodes and edges", () => { | ||
const tree = [ | ||
{ | ||
"id": "2", | ||
"text": "colors", | ||
"parent": true, | ||
"parent_id": "1", | ||
"children": [ | ||
{ | ||
"id": "3", | ||
"text": "red", | ||
"parent_id": "2", | ||
"children": [], | ||
"parent": false | ||
} | ||
] | ||
} | ||
] | ||
|
||
const flatTree = [ | ||
{ | ||
"id": "1", | ||
"text": "parent", | ||
"parent": true | ||
}, | ||
{ | ||
"id": "2", | ||
"text": "colors", | ||
"parent": true, | ||
"parent_id": "1" | ||
}, | ||
{ | ||
"id": "3", | ||
"text": "red", | ||
"parent_id": "2", | ||
"parent": false | ||
}, | ||
{ | ||
"id": "e2-1", | ||
"from": "2", | ||
"to": "1" | ||
}, | ||
{ | ||
"id": "e2-3", | ||
"from": "2", | ||
"to": "3" | ||
} | ||
] | ||
|
||
expect(flattenTree(tree)).toStrictEqual(flatTree) | ||
}) | ||
}) | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flattenTree from
json-editor-parser.ts
is applied to the sub tree whose node is clicked by the user. Here you apply the same function applied on line 64 of this file into a subtree. FRACTAL.