Skip to content

Commit 570ff49

Browse files
committed
fix progress bar during precompute stage
1 parent a83e815 commit 570ff49

File tree

4 files changed

+50
-19
lines changed

4 files changed

+50
-19
lines changed

service/src/main/kotlin/app/cash/backfila/ui/components/BackfillsTable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fun TagConsumer<*>.BackfillsTable(
8080
td(
8181
"whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-0",
8282
) {
83-
ProgressBar(it.backfilled_matching_record_count, it.computed_matching_record_count)
83+
ProgressBar(it.backfilled_matching_record_count, it.computed_matching_record_count, it.precomputing_done)
8484
}
8585
listOf(it.created_by_user, it.created_at, it.last_active_at).map {
8686
td(

service/src/main/kotlin/app/cash/backfila/ui/components/ProgressBar.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ import kotlinx.html.TagConsumer
55
import kotlinx.html.div
66
import kotlinx.html.style
77

8-
fun TagConsumer<*>.ProgressBar(numerator: Number, denominator: Number) {
8+
fun TagConsumer<*>.ProgressBar(
9+
numerator: Number,
10+
denominator: Number,
11+
precomputingDone: Boolean = true,
12+
) {
913
div("w-full bg-gray-200 rounded-full dark:bg-gray-700") {
10-
val percentComplete = if (numerator.toInt() == 0) 0 else round((numerator.toDouble() / denominator.toDouble()) * 100)
11-
// Don't show blue sliver for 0%, just show the gray empty bar
12-
val showPartialBarStyle = if (percentComplete.toInt() != 0) "bg-blue-600" else ""
13-
div(
14-
"$showPartialBarStyle text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full",
15-
) {
16-
style = "width: ${if (percentComplete.toInt() == 0) 100 else percentComplete}%"
17-
+"""$percentComplete%"""
14+
val percentComplete = when {
15+
!precomputingDone -> null // Show indeterminate during precomputing
16+
denominator.toDouble() <= 0 -> 0.0 // Handle zero denominator
17+
else -> round((numerator.toDouble() / denominator.toDouble()) * 100)
18+
}
19+
20+
// Show indeterminate progress bar during precomputing
21+
if (percentComplete == null) {
22+
div("animate-pulse bg-gray-300 text-xs font-medium text-center p-0.5 leading-none rounded-full") {
23+
style = "width: 100%"
24+
+"Computing..."
25+
}
26+
} else {
27+
// Don't show blue sliver for 0%, just show the gray empty bar
28+
val showPartialBarStyle = if (percentComplete > 0) "bg-blue-600" else ""
29+
div("$showPartialBarStyle text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full") {
30+
style = "width: $percentComplete%"
31+
+"${percentComplete.toInt()}%"
32+
}
1833
}
1934
}
2035
}

service/src/main/kotlin/app/cash/backfila/ui/components/ProgressBarReloader.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ import kotlinx.html.TagConsumer
55
import kotlinx.html.div
66
import kotlinx.html.style
77

8-
fun TagConsumer<*>.ProgressBarReloader(numerator: Number, denominator: Number) {
8+
fun TagConsumer<*>.ProgressBarReloader(
9+
numerator: Number,
10+
denominator: Number,
11+
precomputingDone: Boolean = true,
12+
) {
913
div("w-full bg-gray-200 rounded-full dark:bg-gray-700") {
10-
val percentComplete = if (numerator.toInt() == 0) 0 else round((numerator.toDouble() / denominator.toDouble()) * 100)
11-
// Don't show blue sliver for 0%, just show the gray empty bar
12-
val showPartialBarStyle = if (percentComplete.toInt() != 0) "bg-blue-600" else ""
13-
div(
14-
"$showPartialBarStyle text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full",
15-
) {
16-
style = "width: ${if (percentComplete.toInt() == 0) 100 else percentComplete}%"
17-
+"""$percentComplete%"""
14+
val percentComplete = when {
15+
!precomputingDone -> null // Show indeterminate during precomputing
16+
denominator.toDouble() <= 0 -> 0.0 // Handle zero denominator
17+
else -> round((numerator.toDouble() / denominator.toDouble()) * 100)
18+
}
19+
20+
// Show indeterminate progress bar during precomputing
21+
if (percentComplete == null) {
22+
div("animate-pulse bg-gray-300 text-xs font-medium text-center p-0.5 leading-none rounded-full") {
23+
style = "width: 100%"
24+
+"Computing..."
25+
}
26+
} else {
27+
// Don't show blue sliver for 0%, just show the gray empty bar
28+
val showPartialBarStyle = if (percentComplete > 0) "bg-blue-600" else ""
29+
div("$showPartialBarStyle text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full") {
30+
style = "width: $percentComplete%"
31+
+"${percentComplete.toInt()}%"
32+
}
1833
}
1934
}
2035
}

service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class BackfillShowAction @Inject constructor(
187187
ProgressBar(
188188
partition.backfilled_matching_record_count,
189189
partition.computed_matching_record_count,
190+
partition.precomputing_done,
190191
)
191192
}
192193
td("hidden py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700 sm:table-cell") {

0 commit comments

Comments
 (0)