Skip to content

Commit d3645e1

Browse files
committed
Fix more PR comments
1 parent 6a056ca commit d3645e1

File tree

12 files changed

+40
-4844
lines changed

12 files changed

+40
-4844
lines changed

workflow-trace-viewer/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ click to expand/collapse a specific node's children.
2424

2525
<img src="https://github.com/square/workflow-kotlin/raw/wenli/improve-visualizer/workflow-trace-viewer/docs/demo.gif" width="320" alt="Demo" />
2626

27-
#### File Mode
27+
### File Mode
2828

2929
Once a file of the live data is saved, it can easily be uploaded to retrace the steps taken during
3030
the live session. Currently, text/json files that are saved from recordings only contain raw data,
3131
meaning it is simply a list of lists of node renderings.
3232

3333
<img src="https://github.com/square/workflow-kotlin/raw/wenli/improve-visualizer/workflow-trace-viewer/docs/file_mode.gif" width="320" alt="File Mode" />
3434

35-
#### Live Mode
35+
### Live Mode
3636

3737
By hitting the bottom switch, you are able to toggle to live stream mode, where data is directly
3838
pulled from the emulator into the visualizer. To do so:
3939

40-
1. Start the app (on any device)
41-
2. Start the app, and toggle the switch to enter Live mode
42-
3. Select the desired device
40+
- Start the app (on any device)
41+
- Start the app, and toggle the switch to enter Live mode
42+
- Select the desired device
4343

4444
Once in Live mode, frames will appear as you interact with the app. You may also save the current
4545
data into a file saved in `~/Downloads` to be used later (this action will take some time, so it may
@@ -58,10 +58,10 @@ A connection can only happen once. There is currently no support for a recording
5858
due to the fact that an open socket will consume all render pass data when a connection begins. To
5959
restart the recording:
6060

61-
1. (optional) Save the current trace
62-
2. Switch out of Live mode
63-
3. Restart the app
64-
4. Switch back to Live mode, and the
61+
- (optional) Save the current trace
62+
- Switch out of Live mode
63+
- Restart the app
64+
- Switch back to Live mode, and the
6565

6666
### Terminology
6767

@@ -83,4 +83,4 @@ on Kotlin and KMP projects. This simplified the development process of allowing
8383
## Future
8484

8585
This app can be integrated into the process of anyone working with Workflow, so it's highly
86-
encouraged for anyone to make improvements that makes their life a little easier using this app.
86+
encouraged for anyone to make improvements that makes their life a little easier using this app.

workflow-trace-viewer/docs/demo.gif

-730 KB
Binary file not shown.
-431 KB
Binary file not shown.
-217 KB
Binary file not shown.

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/App.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.runtime.LaunchedEffect
99
import androidx.compose.runtime.getValue
1010
import androidx.compose.runtime.mutableFloatStateOf
1111
import androidx.compose.runtime.mutableIntStateOf
12+
import androidx.compose.runtime.mutableStateListOf
1213
import androidx.compose.runtime.mutableStateMapOf
1314
import androidx.compose.runtime.mutableStateOf
1415
import androidx.compose.runtime.remember
@@ -18,11 +19,9 @@ import androidx.compose.runtime.snapshots.SnapshotStateMap
1819
import androidx.compose.ui.Alignment
1920
import androidx.compose.ui.Modifier
2021
import androidx.compose.ui.geometry.Offset
21-
import androidx.compose.ui.layout.onGloballyPositioned
2222
import androidx.compose.ui.layout.onSizeChanged
2323
import androidx.compose.ui.unit.IntSize
2424
import androidx.compose.ui.unit.dp
25-
import androidx.compose.ui.window.WindowPosition.PlatformDefault.x
2625
import com.squareup.workflow1.traceviewer.model.Node
2726
import com.squareup.workflow1.traceviewer.model.NodeUpdate
2827
import com.squareup.workflow1.traceviewer.ui.RightInfoPanel
@@ -49,7 +48,7 @@ internal fun App(
4948
var rawRenderPass by remember { mutableStateOf("") }
5049
var frameIndex by remember { mutableIntStateOf(0) }
5150
val sandboxState = remember { SandboxState() }
52-
val nodeLocations = remember { mutableListOf<SnapshotStateMap<Node, Offset>>() }
51+
val nodeLocations = remember { mutableStateListOf<SnapshotStateMap<Node, Offset>>() }
5352

5453
// Default to File mode, and can be toggled to be in Live mode.
5554
var active by remember { mutableStateOf(false) }
@@ -110,7 +109,9 @@ internal fun App(
110109
horizontalAlignment = Alignment.CenterHorizontally
111110
) {
112111
if (active) {
113-
// Since we can jump from frame to frame, we fill in the map during each recomposition
112+
// Frames that appear in composition may not happen sequentially, so when the current frame
113+
// locations is null, that means we've skipped frames and need to fill all the intermediate
114+
// ones. e.g. Frame 1 to Frame 10
114115
if (nodeLocations.getOrNull(frameInd) == null) {
115116
// frameSize has not been updated yet, so on the first frame, frameSize = nodeLocations.size = 0,
116117
// and it will append a new map

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/model/NodeUpdate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal data class NodeUpdate(
2121
past == null -> NodeState.NEW
2222
current.props != past.props -> NodeState.PROPS_CHANGED
2323
current.state != past.state -> NodeState.STATE_CHANGED
24-
else -> NodeState.CHILDREN_CHANGED
24+
else -> NodeState.RENDERED
2525
}
2626

2727
return NodeUpdate(current, past, state)
@@ -33,6 +33,6 @@ internal enum class NodeState(val color: Color) {
3333
NEW(Color(0x804CAF50)), // green
3434
STATE_CHANGED(Color(0xFFE57373)), // red
3535
PROPS_CHANGED(Color(0xFFFF8A65)), // orange
36-
CHILDREN_CHANGED(Color(0x802196F3)), // blue
36+
RENDERED(Color(0x802196F3)), // blue
3737
UNCHANGED(Color.LightGray.copy(alpha = 0.3f)),
3838
}

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/WorkflowInfoPanel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ internal fun RightInfoPanel(
6262
.clip(CircleShape)
6363
.background(Color.White)
6464
.padding(8.dp)
65-
.size(40.dp)
6665
.align(Alignment.Top)
6766
) {
6867
Icon(

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/WorkflowTree.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ private fun DrawNode(
306306
)
307307

308308
Box {
309-
Box(
309+
Column(
310+
horizontalAlignment = Alignment.CenterHorizontally,
310311
modifier = Modifier
312+
.wrapContentSize()
311313
.hoverable(interactionSource)
312314
.background(nodeUpdate.state.color)
313315
.clickable {
@@ -328,21 +330,16 @@ private fun DrawNode(
328330
storeNodeLocation(node, offsetToCenter)
329331
}
330332
) {
331-
Column(
332-
horizontalAlignment = Alignment.CenterHorizontally,
333-
modifier = Modifier.wrapContentSize()
333+
Row(
334+
verticalAlignment = Alignment.CenterVertically,
335+
horizontalArrangement = Arrangement.spacedBy(4.dp)
334336
) {
335-
Row(
336-
verticalAlignment = Alignment.CenterVertically,
337-
horizontalArrangement = Arrangement.spacedBy(4.dp)
338-
) {
339-
if (node.children.isNotEmpty()) {
340-
Text(text = if (isExpanded) "" else "")
341-
}
342-
Text(text = node.name)
337+
if (node.children.isNotEmpty()) {
338+
Text(text = if (isExpanded) "" else "")
343339
}
344-
Text(text = "ID: ${node.id}")
340+
Text(text = node.name)
345341
}
342+
Text(text = "ID: ${node.id}")
346343
}
347344

348345
if (isHovered) {

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/control/FileDump.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.squareup.workflow1.traceviewer.ui.control
22

33
import androidx.compose.foundation.layout.padding
4+
import androidx.compose.foundation.layout.widthIn
45
import androidx.compose.foundation.shape.CircleShape
56
import androidx.compose.material.Button
67
import androidx.compose.material.ButtonDefaults.buttonColors
@@ -24,29 +25,34 @@ internal fun FileDump(
2425
trace: String,
2526
modifier: Modifier = Modifier
2627
) {
28+
var filePath by remember { mutableStateOf("") }
2729
var clicked by remember { mutableStateOf(false) }
2830
Button(
29-
modifier = modifier.padding(16.dp),
31+
modifier = modifier
32+
.padding(16.dp)
33+
.widthIn(max = 300.dp),
3034
shape = CircleShape,
3135
colors = buttonColors(Color.Black),
3236
onClick = {
3337
clicked = true
34-
writeToFile(trace)
38+
filePath = writeToFile(trace)
3539
}
3640
) {
3741
val text = if (clicked) {
38-
"Trace saved to Downloads"
42+
"Trace saved to $filePath"
3943
} else {
4044
"Save trace to file"
4145
}
4246
Text(
4347
text = text,
44-
color = Color.White
48+
color = Color.White,
49+
maxLines = 3,
50+
softWrap = true
4551
)
4652
}
4753
}
4854

49-
private fun writeToFile(trace: String) {
55+
private fun writeToFile(trace: String): String{
5056
val timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))
5157
val home = System.getProperty("user.home")
5258
val path = "$home/Downloads/workflow-trace_$timestamp.json".toPath()
@@ -58,4 +64,6 @@ private fun writeToFile(trace: String) {
5864
bufferedSink.writeUtf8("]")
5965
}
6066
}
67+
68+
return path.toString()
6169
}

workflow-trace-viewer/src/jvmMain/resources/workflow-20.json

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)