-
Notifications
You must be signed in to change notification settings - Fork 112
Workflow visualizer prototype #1363
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6bac19
Include new fields in Node class from json and display them
wenli-cai 3cfb832
Change JSON parsing
wenli-cai 7164671
Resolve ktlint violations
wenli-cai 6718c23
Use workflow node sessionId to filter through parent/child structure …
wenli-cai 54bb33b
Fix PR comments
wenli-cai 2f4f69a
Apply changes from apiDump
wenli-cai 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 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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,15 @@ import com.squareup.workflow1.traceviewer.model.Node | |||||||||
| import io.github.vinceglb.filekit.PlatformFile | ||||||||||
| import io.github.vinceglb.filekit.readString | ||||||||||
|
|
||||||||||
| /* | ||||||||||
| The root workflow Node uses an ID of 0, and since we are filtering childrenByParent by the | ||||||||||
| parentId, the root node has a parent of -1 ID. This is reflected seen inside android-register | ||||||||||
| */ | ||||||||||
| const val ROOT_ID: String = "-1" | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Parses a given file's JSON String into [Node] with Moshi adapters. | ||||||||||
| * Parses a given file's JSON String into a list of [Node]s with Moshi adapters. Each of these nodes | ||||||||||
| * count as the root of a tree which forms a Frame. | ||||||||||
| * | ||||||||||
| * @return A [ParseResult] representing result of parsing, either an error related to the | ||||||||||
| * format of the JSON, or a success and a parsed trace. | ||||||||||
|
|
@@ -19,18 +26,63 @@ public suspend fun parseTrace( | |||||||||
| ): ParseResult { | ||||||||||
| return try { | ||||||||||
| val jsonString = file.readString() | ||||||||||
| val moshi = Moshi.Builder() | ||||||||||
| .add(KotlinJsonAdapterFactory()) | ||||||||||
| .build() | ||||||||||
| val workflowList = Types.newParameterizedType(List::class.java, Node::class.java) | ||||||||||
| val workflowAdapter: JsonAdapter<List<Node>> = moshi.adapter(workflowList) | ||||||||||
| val trace = workflowAdapter.fromJson(jsonString) | ||||||||||
| ParseResult.Success(trace) | ||||||||||
| val workflowAdapter = createMoshiAdapter() | ||||||||||
| val parsedRenderPasses = workflowAdapter.fromJson(jsonString) | ||||||||||
|
|
||||||||||
| val parsedFrames = mutableListOf<Node>() | ||||||||||
| parsedRenderPasses?.forEach { renderPass -> | ||||||||||
| val parsed = getFrameFromRenderPass(renderPass) | ||||||||||
| parsedFrames.add(parsed) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| ParseResult.Success(parsedFrames) | ||||||||||
| } catch (e: Exception) { | ||||||||||
| ParseResult.Failure(e) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Creates a Moshi adapter for parsing the JSON trace file. | ||||||||||
| */ | ||||||||||
| private fun createMoshiAdapter(): JsonAdapter<List<List<Node>>> { | ||||||||||
| val moshi = Moshi.Builder() | ||||||||||
| .add(KotlinJsonAdapterFactory()) | ||||||||||
| .build() | ||||||||||
| val workflowList = Types.newParameterizedType( | ||||||||||
| List::class.java, | ||||||||||
| Types.newParameterizedType(List::class.java, Node::class.java) | ||||||||||
| ) | ||||||||||
| val adapter: JsonAdapter<List<List<Node>>> = moshi.adapter(workflowList) | ||||||||||
| return adapter | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * We take an unparsed render pass and build up a tree structure from it to form a Frame. | ||||||||||
|
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.
Suggested change
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. Done |
||||||||||
| * | ||||||||||
| * @return Node the root node of the tree for that specific frame. | ||||||||||
| */ | ||||||||||
| private fun getFrameFromRenderPass(renderPass: List<Node>): Node { | ||||||||||
| val childrenByParent: Map<String, List<Node>> = renderPass.groupBy { it.parentId } | ||||||||||
| val root = childrenByParent[ROOT_ID]?.single() | ||||||||||
| return buildTree(root!!, childrenByParent) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Recursively builds a tree using each node's children. | ||||||||||
| */ | ||||||||||
| private fun buildTree(node: Node, childrenByParent: Map<String, List<Node>>): Node { | ||||||||||
| val children = (childrenByParent[node.id] ?: emptyList()) | ||||||||||
| return Node( | ||||||||||
| name = node.name, | ||||||||||
| id = node.id, | ||||||||||
| parent = node.parent, | ||||||||||
| parentId = node.parentId, | ||||||||||
| props = node.props, | ||||||||||
| state = node.state, | ||||||||||
| children = children.map { buildTree(it, childrenByParent) }, | ||||||||||
| ) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| sealed interface ParseResult { | ||||||||||
| class Success(val trace: List<Node>?) : ParseResult | ||||||||||
| class Failure(val error: Throwable) : ParseResult | ||||||||||
|
|
||||||||||
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.
My guess is when the parent is null in the
WorkflowSessionyou have just given it a default value of -1 in your recording code?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.
Yep! I will make note of this on both PR's in workflow library and register