Skip to content

Commit b30a565

Browse files
committed
Include a detailed view of node via side panel
- This will provide a lot more information about each workflow node that's clicked, especially when it could contain a lot of information
1 parent e36ca77 commit b30a565

File tree

2 files changed

+89
-13
lines changed

2 files changed

+89
-13
lines changed
Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
package com.squareup.workflow1.traceviewer
22

3+
import androidx.compose.foundation.background
34
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.fillMaxHeight
8+
import androidx.compose.foundation.layout.fillMaxSize
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
12+
import androidx.compose.foundation.layout.width
13+
import androidx.compose.foundation.layout.widthIn
14+
import androidx.compose.material.Icon
15+
import androidx.compose.material.IconButton
416
import androidx.compose.material.Text
517
import androidx.compose.runtime.Composable
618
import androidx.compose.runtime.LaunchedEffect
@@ -19,28 +31,90 @@ import io.github.vinceglb.filekit.readString
1931
public fun App(
2032
modifier: Modifier = Modifier
2133
) {
22-
Box {
23-
var selectedFile by remember { mutableStateOf<PlatformFile?>(null) }
34+
var selectedFile by remember { mutableStateOf<PlatformFile?>(null) }
35+
var selectedNode by remember { mutableStateOf<WorkflowNode?>(null) }
36+
// Used when user selects a new file in [UploadFile]
37+
val resetSelectedNode = { selectedNode = null }
2438

39+
Box {
40+
// Main content
2541
if (selectedFile != null) {
26-
SandboxBackground { WorkflowContent(selectedFile!!) }
42+
SandboxBackground {
43+
LoadWorkflowContent(selectedFile) {
44+
selectedNode = it
45+
}
46+
}
2747
}
2848

29-
UploadFile(onFileSelect = { selectedFile = it })
49+
// Left side information panel
50+
InfoPanel(
51+
selectedNode.value
52+
)
53+
54+
// Bottom right upload button
55+
UploadFile(resetSelectedNode, { selectedFile.value = it })
3056
}
3157
}
3258

59+
60+
3361
@Composable
34-
private fun WorkflowContent(file: PlatformFile) {
35-
var jsonString by remember { mutableStateOf<String?>(null) }
36-
LaunchedEffect(file) {
37-
jsonString = file.readString()
62+
private fun InfoPanel(
63+
selectedNode: WorkflowNode?
64+
) {
65+
Row {
66+
val panelOpen = remember { mutableStateOf(false) }
67+
68+
// based on open/close, display the node details (Column)
69+
if (panelOpen.value) {
70+
PanelDetails(
71+
selectedNode,
72+
Modifier.fillMaxWidth(.35f)
73+
)
74+
}
75+
76+
IconButton(
77+
onClick = { panelOpen.value = !panelOpen.value },
78+
modifier = Modifier
79+
.padding(8.dp)
80+
.size(30.dp)
81+
.align(Alignment.Top)
82+
) {
83+
Icon(
84+
imageVector = if (panelOpen.value) Filled.KeyboardArrowLeft else Filled.KeyboardArrowRight,
85+
contentDescription = if (panelOpen.value) "Close Panel" else "Open Panel",
86+
modifier = Modifier
87+
)
88+
}
3889
}
39-
val root = jsonString?.let { parseTrace(it) }
90+
}
91+
92+
@Composable
93+
private fun PanelDetails(
94+
node: WorkflowNode?,
95+
modifier: Modifier = Modifier
96+
) {
97+
Column(
98+
modifier
99+
.fillMaxHeight()
100+
.background(Color.LightGray)
101+
) {
102+
if (node == null) {
103+
Text("No node selected")
104+
return@Column
105+
}
40106

41-
if (root != null) {
42-
DrawWorkflowTree(root)
43-
} else {
44-
Text("Empty data or failed to parse data") // TODO: proper handling of error
107+
Column(
108+
modifier = Modifier
109+
.padding(8.dp),
110+
horizontalAlignment = Alignment.CenterHorizontally
111+
) {
112+
Text("only visible with a node selected")
113+
Text(
114+
text = "This is a node panel for ${node.name}",
115+
fontSize = 20.sp,
116+
modifier = Modifier.padding(8.dp)
117+
)
118+
}
45119
}
46120
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.github.vinceglb.filekit.dialogs.compose.rememberFilePickerLauncher
2323
*/
2424
@Composable
2525
public fun UploadFile(
26+
resetSelectedNode: () -> Unit,
2627
onFileSelect: (PlatformFile?) -> Unit,
2728
modifier: Modifier = Modifier,
2829
) {
@@ -35,6 +36,7 @@ public fun UploadFile(
3536
type = FileKitType.File(listOf("json", "txt")),
3637
title = "Select Workflow Trace File"
3738
) {
39+
resetSelectedNode()
3840
onFileSelect(it)
3941
}
4042
Button(

0 commit comments

Comments
 (0)