Skip to content

Commit 9c1fc6a

Browse files
committed
Enumerate the specific changes for each node and color them accordingly
1 parent cbcea20 commit 9c1fc6a

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ internal fun App(
7878
traceSource = traceMode,
7979
frameInd = frameIndex,
8080
onFileParse = { workflowFrames.addAll(it) },
81-
onNodeSelect = { node, prevNode ->
82-
selectedNode = NodeUpdate(node, prevNode)
83-
},
81+
onNodeSelect = { selectedNode = it },
8482
onNewFrame = { frameIndex += 1 }
8583
)
8684
}
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
package com.squareup.workflow1.traceviewer.model
22

3+
import androidx.compose.ui.graphics.Color
4+
35
/**
46
* Represents the difference between the current and previous state of a node in the workflow trace.
5-
* This will be what is passed as a state between UI to display the diff.
7+
* This will be what is passed as a state between UI to display the diff. The states all have an
8+
* associated color
69
*
7-
* If it's the first node in the frame, [previous] will be null and there is no difference to show.
10+
* If it's the first node in the frame, [past] will be null and there is no difference to show.
811
*/
9-
internal class NodeUpdate(
12+
internal data class NodeUpdate(
1013
val current: Node,
11-
val previous: Node?,
12-
)
14+
val past: Node?,
15+
val state: NodeState
16+
) {
17+
companion object {
18+
fun create(current: Node, past: Node?, isAffected: Boolean): NodeUpdate {
19+
val state = when {
20+
!isAffected -> NodeState.UNCHANGED
21+
past == null -> NodeState.NEW
22+
current.props != past.props -> NodeState.PROPS_CHANGED
23+
current.state != past.state -> NodeState.STATE_CHANGED
24+
else -> NodeState.CHILDREN_CHANGED
25+
}
26+
27+
return NodeUpdate(current, past, state)
28+
}
29+
}
30+
}
31+
32+
enum class NodeState(val color: Color) {
33+
NEW(Color(0x804CAF50)), // green
34+
STATE_CHANGED(Color(0xFFE57373)), // red
35+
PROPS_CHANGED(Color(0xFFFF8A65)), // orange
36+
CHILDREN_CHANGED(Color(0x802196F3)), // blue
37+
UNCHANGED(Color.Transparent),
38+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private fun NodePanelDetails(
107107
val fields = Node::class.memberProperties
108108
for (field in fields) {
109109
val currVal = field.get(node.current).toString()
110-
val pastVal = if (node.previous != null) field.get(node.previous).toString() else null
110+
val pastVal = if (node.past != null) field.get(node.past).toString() else null
111111
item {
112112
DetailCard(
113113
label = field.name,

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.ui.unit.dp
2929
import com.squareup.moshi.JsonAdapter
3030
import com.squareup.workflow1.traceviewer.TraceMode
3131
import com.squareup.workflow1.traceviewer.model.Node
32+
import com.squareup.workflow1.traceviewer.model.NodeUpdate
3233
import com.squareup.workflow1.traceviewer.util.ParseResult
3334
import com.squareup.workflow1.traceviewer.util.createMoshiAdapter
3435
import com.squareup.workflow1.traceviewer.util.parseFileTrace
@@ -47,7 +48,7 @@ internal fun RenderTrace(
4748
traceSource: TraceMode,
4849
frameInd: Int,
4950
onFileParse: (List<Node>) -> Unit,
50-
onNodeSelect: (Node, Node?) -> Unit,
51+
onNodeSelect: (NodeUpdate) -> Unit,
5152
onNewFrame: () -> Unit,
5253
modifier: Modifier = Modifier
5354
) {
@@ -145,7 +146,7 @@ private fun DrawTree(
145146
previousFrameNode: Node?,
146147
affectedNodes: Set<Node>,
147148
expandedNodes: MutableMap<String, Boolean>,
148-
onNodeSelect: (Node, Node?) -> Unit,
149+
onNodeSelect: (NodeUpdate) -> Unit,
149150
modifier: Modifier = Modifier,
150151
) {
151152
Column(
@@ -207,15 +208,21 @@ private fun DrawNode(
207208
nodePast: Node?,
208209
isAffected: Boolean,
209210
isExpanded: Boolean,
210-
onNodeSelect: (Node, Node?) -> Unit,
211+
onNodeSelect: (NodeUpdate) -> Unit,
211212
onExpandToggle: (Node) -> Unit,
212213
) {
214+
val nodeUpdate = NodeUpdate.create(
215+
current = node,
216+
past = nodePast,
217+
isAffected = isAffected
218+
)
219+
213220
Box(
214221
modifier = Modifier
215-
.background(if (isAffected) Color.Green else Color.Transparent)
222+
.background(nodeUpdate.state.color)
216223
.onPointerEvent(PointerEventType.Press) {
217224
if (it.buttons.isPrimaryPressed) {
218-
onNodeSelect(node, nodePast)
225+
onNodeSelect(nodeUpdate)
219226
} else if (it.buttons.isSecondaryPressed) {
220227
onExpandToggle(node)
221228
}

0 commit comments

Comments
 (0)