1
1
package com.squareup.workflow1.traceviewer.ui
2
2
3
3
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
5
6
import androidx.compose.foundation.layout.Column
6
7
import androidx.compose.foundation.layout.Row
8
+ import androidx.compose.foundation.layout.Spacer
7
9
import androidx.compose.foundation.layout.fillMaxHeight
8
10
import androidx.compose.foundation.layout.fillMaxWidth
11
+ import androidx.compose.foundation.layout.height
9
12
import androidx.compose.foundation.layout.padding
10
13
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
11
17
import androidx.compose.material.Icon
12
18
import androidx.compose.material.IconButton
19
+ import androidx.compose.material.MaterialTheme
13
20
import androidx.compose.material.Text
14
21
import androidx.compose.material.icons.Icons.AutoMirrored.Filled
15
22
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
@@ -22,11 +29,8 @@ import androidx.compose.runtime.setValue
22
29
import androidx.compose.ui.Alignment
23
30
import androidx.compose.ui.Modifier
24
31
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
28
33
import androidx.compose.ui.unit.dp
29
- import androidx.compose.ui.unit.sp
30
34
import com.squareup.workflow1.traceviewer.model.Node
31
35
32
36
/* *
@@ -49,7 +53,7 @@ internal fun RightInfoPanel(
49
53
onClick = { panelOpen = ! panelOpen },
50
54
modifier = Modifier
51
55
.padding(8 .dp)
52
- .size(30 .dp)
56
+ .size(40 .dp)
53
57
.align(Alignment .Top )
54
58
) {
55
59
Icon (
@@ -68,41 +72,89 @@ internal fun RightInfoPanel(
68
72
}
69
73
}
70
74
75
+ /* *
76
+ * Displays specific details about the opened workflow node.
77
+ */
71
78
@Composable
72
79
private fun NodePanelDetails (
73
80
node : Node ? ,
74
81
modifier : Modifier = Modifier
75
82
) {
76
- Column (
83
+ LazyColumn (
77
84
modifier = modifier
78
85
.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)
85
89
) {
86
90
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
89
95
}
90
96
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 (
94
98
" Name" to node.name,
95
99
" ID" to node.id,
96
100
" Props" to node.props,
97
101
" State" to node.state,
98
102
" Rendering" to node.rendering
99
103
)
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 }
100
153
101
- fields.forEach { (label, value) ->
154
+ Spacer (modifier = Modifier .height( 4 .dp))
102
155
Text (
103
- text = " $label : $value " ,
104
- modifier = textModifier,
105
- style = textStyle
156
+ text = value,
157
+ style = MaterialTheme .typography.body1
106
158
)
107
159
}
108
160
}
0 commit comments