Skip to content

Commit 32c5b9f

Browse files
committed
Improve UI for detailed node panel
1 parent 69d9c27 commit 32c5b9f

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

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

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.squareup.workflow1.traceviewer.ui
22

33
import androidx.compose.foundation.background
4-
import androidx.compose.foundation.gestures.detectTapGestures
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Column
67
import androidx.compose.foundation.layout.Row
8+
import androidx.compose.foundation.layout.Spacer
79
import androidx.compose.foundation.layout.fillMaxHeight
810
import androidx.compose.foundation.layout.fillMaxWidth
11+
import androidx.compose.foundation.layout.height
912
import androidx.compose.foundation.layout.padding
1013
import androidx.compose.foundation.layout.size
14+
import androidx.compose.foundation.lazy.LazyColumn
15+
import androidx.compose.foundation.lazy.items
16+
import androidx.compose.material.Card
1117
import androidx.compose.material.Icon
1218
import androidx.compose.material.IconButton
19+
import androidx.compose.material.MaterialTheme
1320
import androidx.compose.material.Text
1421
import androidx.compose.material.icons.Icons.AutoMirrored.Filled
1522
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
@@ -22,11 +29,8 @@ import androidx.compose.runtime.setValue
2229
import androidx.compose.ui.Alignment
2330
import androidx.compose.ui.Modifier
2431
import androidx.compose.ui.graphics.Color
25-
import androidx.compose.ui.input.pointer.pointerInput
26-
import androidx.compose.ui.text.TextStyle
27-
import androidx.compose.ui.text.style.TextAlign
32+
import androidx.compose.ui.text.font.FontWeight
2833
import androidx.compose.ui.unit.dp
29-
import androidx.compose.ui.unit.sp
3034
import com.squareup.workflow1.traceviewer.model.Node
3135

3236
/**
@@ -49,7 +53,7 @@ internal fun RightInfoPanel(
4953
onClick = { panelOpen = !panelOpen },
5054
modifier = Modifier
5155
.padding(8.dp)
52-
.size(30.dp)
56+
.size(40.dp)
5357
.align(Alignment.Top)
5458
) {
5559
Icon(
@@ -68,41 +72,89 @@ internal fun RightInfoPanel(
6872
}
6973
}
7074

75+
/**
76+
* Displays specific details about the opened workflow node.
77+
*/
7178
@Composable
7279
private fun NodePanelDetails(
7380
node: Node?,
7481
modifier: Modifier = Modifier
7582
) {
76-
Column(
83+
LazyColumn(
7784
modifier = modifier
7885
.fillMaxHeight()
79-
.background(Color.LightGray)
80-
.padding(8.dp)
81-
.pointerInput(Unit) {
82-
detectTapGestures { }
83-
},
84-
horizontalAlignment = Alignment.CenterHorizontally
86+
.background(Color.White)
87+
.padding(8.dp),
88+
verticalArrangement = Arrangement.spacedBy(16.dp)
8589
) {
8690
if (node == null) {
87-
Text("No node selected")
88-
return@Column
91+
item {
92+
Text("Select a node to view details")
93+
}
94+
return@LazyColumn
8995
}
9096

91-
val textModifier = Modifier.padding(8.dp)
92-
val textStyle = TextStyle(fontSize = 16.sp, textAlign = TextAlign.Center)
93-
val fields = mapOf(
97+
val fields = listOf(
9498
"Name" to node.name,
9599
"ID" to node.id,
96100
"Props" to node.props,
97101
"State" to node.state,
98102
"Rendering" to node.rendering
99103
)
104+
item {
105+
Text(
106+
text = "Workflow Details",
107+
style = MaterialTheme.typography.h6,
108+
modifier = Modifier.padding(top = 8.dp, bottom = 8.dp)
109+
)
110+
}
111+
112+
items(fields) { (label, value) ->
113+
DetailCard(
114+
label = label,
115+
value = value
116+
)
117+
}
118+
}
119+
}
120+
121+
/**
122+
* Card component that represents each item for the nodes.
123+
*
124+
* Can be open/closed to show/hide details.
125+
*/
126+
@Composable
127+
private fun DetailCard(
128+
label: String,
129+
value: String,
130+
) {
131+
var open by remember { mutableStateOf(true) }
132+
Card(
133+
modifier = Modifier
134+
.fillMaxWidth()
135+
.padding(8.dp)
136+
.clickable {
137+
open = !open
138+
},
139+
elevation = 3.dp,
140+
) {
141+
Column(
142+
modifier = Modifier
143+
.fillMaxWidth()
144+
.padding(16.dp)
145+
) {
146+
Text(
147+
text = label,
148+
style = MaterialTheme.typography.subtitle1,
149+
color = Color.Black,
150+
fontWeight = FontWeight.Medium
151+
)
152+
if (!open) { return@Card }
100153

101-
fields.forEach { (label, value) ->
154+
Spacer(modifier = Modifier.height(4.dp))
102155
Text(
103-
text = "$label: $value",
104-
modifier = textModifier,
105-
style = textStyle
156+
text = value,
157+
style = MaterialTheme.typography.body1
106158
)
107159
}
108160
}

0 commit comments

Comments
 (0)