Skip to content

Commit 6334452

Browse files
committed
Edits made for PR comments
1 parent 03d7784 commit 6334452

File tree

9 files changed

+35
-29
lines changed

9 files changed

+35
-29
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
agpVersion = "8.8.0"
44

55
compileSdk = "34"
6-
filekitDialogsComposeVersion = "0.10.0-beta04"
6+
filekitDialogsComposeVersion = "0.10.0-beta03"
77
minSdk = "24"
88
moshiKotlinVersion = "1.15.2"
99
targetSdk = "33"

workflow-trace-viewer/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ It can be run via Gradle using:
99
```shell
1010
./gradlew :workflow-trace-viewer:run
1111
```
12+
13+
14+
### External Libraries
15+
16+
[FileKit](https://github.com/vinceglb/FileKit) is an external library made to apply file operations
17+
on Kotlin and KMP projects. It's purpose in this app is to allow developers to upload their own
18+
json trace files. The motivation for its use is to quickly implement a file picker.

workflow-trace-viewer/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kotlin {
2424
implementation(libs.kotlinx.coroutines.swing)
2525
implementation(compose.materialIconsExtended)
2626
implementation(libs.moshi.kotlin)
27-
implementation("io.github.vinceglb:filekit-dialogs-compose:0.10.0-beta03")
27+
implementation(libs.filekit.dialogs.compose)
2828
}
2929
}
3030
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import androidx.compose.ui.Modifier
1010
import io.github.vinceglb.filekit.PlatformFile
1111
import io.github.vinceglb.filekit.readString
1212

13+
/**
14+
* Main composable that provides the different layers of UI.
15+
*/
1316
@Composable
1417
public fun App(
1518
modifier: Modifier = Modifier
@@ -31,7 +34,7 @@ private fun WorkflowContent(file: PlatformFile?) {
3134
LaunchedEffect(file) {
3235
jsonString.value = file?.readString()
3336
}
34-
val root = jsonString.value?.let { fetchRoot(it) }
37+
val root = jsonString.value?.let { parseTrace(it) }
3538

3639
if (root != null) {
3740
DrawWorkflowTree(root)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package com.squareup.workflow1.traceviewer
22

33
import androidx.compose.ui.window.singleWindowApplication
44

5+
/**
6+
* Main entry point for the desktop application, see [README.md] for more details.
7+
*/
58
fun main() {
69
singleWindowApplication(title = "Workflow Trace Viewer") {
710
App()

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

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

33
import androidx.compose.foundation.gestures.awaitEachGesture
4+
import androidx.compose.foundation.gestures.detectDragGestures
45
import androidx.compose.foundation.layout.Box
56
import androidx.compose.foundation.layout.fillMaxSize
67
import androidx.compose.foundation.layout.wrapContentSize
@@ -36,34 +37,22 @@ public fun SandboxBackground(
3637
modifier
3738
.fillMaxSize()
3839
.pointerInput(Unit) {
39-
// this allows for user's panning to view different parts of content
40+
// Panning capabilities: watches for drag gestures and applies the translation
41+
detectDragGestures { _, translation->
42+
offset += translation
43+
}
44+
}
45+
.pointerInput(Unit) {
46+
// Zooming capabilities: watches for any scroll events and immediately consumes changes.
47+
// - This is AI generated.
4048
awaitEachGesture {
4149
val event = awaitPointerEvent()
42-
43-
// zooming
4450
if (event.type == PointerEventType.Scroll) {
4551
val scrollDelta = event.changes.first().scrollDelta.y
4652
scale *= if (scrollDelta < 0) 1.1f else 0.9f
4753
scale = scale.coerceIn(0.1f, 10f)
4854
event.changes.forEach { it.consume() }
4955
}
50-
51-
// panning: this tracks multiple events within one gesture to see what the user is doing,
52-
// then calculates the offset and pans the screen accordingly
53-
val drag = event.changes.firstOrNull()
54-
if (drag != null && drag.pressed) {
55-
var prev = drag.position
56-
while (true) {
57-
val nextEvent = awaitPointerEvent()
58-
val nextDrag = nextEvent.changes.firstOrNull() ?: break
59-
if (!nextDrag.pressed) break
60-
61-
val delta = nextDrag.position - prev
62-
offset += delta
63-
prev = nextDrag.position
64-
nextDrag.consume()
65-
}
66-
}
6756
}
6857
}
6958
) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import io.github.vinceglb.filekit.PlatformFile
1717
import io.github.vinceglb.filekit.dialogs.FileKitType
1818
import io.github.vinceglb.filekit.dialogs.compose.rememberFilePickerLauncher
1919

20+
/**
21+
* Provides functionality for user to upload a JSON or .txt file from their local devices, which
22+
* contains information pulled from workflow traces
23+
*/
2024
@Composable
2125
public fun UploadFile(
2226
onFileSelect: (PlatformFile?) -> Unit,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
66
import java.io.IOException
77

88
/**
9-
* Parses a JSON string into [WorkflowNode] with Moshi adapters
9+
* Parses a JSON string into [WorkflowNode] with Moshi adapters.
1010
*
1111
* All the caught exceptions should be handled by the caller, and appropriate UI feedback should be
12-
* provided to user
12+
* provided to user.
1313
*/
14-
public fun fetchRoot(
14+
public fun parseTrace(
1515
json: String
1616
): WorkflowNode? {
1717
return try {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public data class WorkflowNode(
3131
)
3232

3333
/**
34-
* Since the workflow nodes present a tree structure, we utilize a recursive function to draw the tree
35-
* The Column holds a subtree of nodes, and the Row holds all the children of the current node
34+
* Since the workflow nodes present a tree structure, we utilize a recursive function to draw the tree.
35+
* The Column holds a subtree of nodes, and the Row holds all the children of the current node.
3636
*/
3737
@Composable
3838
public fun DrawWorkflowTree(
@@ -62,7 +62,7 @@ public fun DrawWorkflowTree(
6262
}
6363

6464
/**
65-
* A basic box that represents a workflow node
65+
* A basic box that represents a workflow node.
6666
*/
6767
@Composable
6868
private fun DrawNode(

0 commit comments

Comments
 (0)