Skip to content

Commit

Permalink
Show errors on result list
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Oct 9, 2024
1 parent 34ed78d commit 1264d80
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class RunNetTest(
it.copy(
failureMessage =
if (it.failureMessage != null) {
"${it.failureMessage}\n\n$message"
"${it.failureMessage}\n$message"
} else {
message
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import org.jetbrains.compose.resources.painterResource
import org.ooni.probe.data.models.Descriptor

@Composable
fun TestDescriptorLabel(descriptor: Descriptor) {
fun TestDescriptorLabel(
descriptor: Descriptor,
modifier: Modifier = Modifier,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(bottom = 2.dp),
modifier = modifier.padding(bottom = 2.dp),
) {
Icon(
painter = painterResource(descriptor.icon ?: Res.drawable.ooni_empty_state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import ooniprobe.composeapp.generated.resources.Res
Expand All @@ -36,8 +37,10 @@ fun ResultCell(
item: ResultListItem,
onResultClick: () -> Unit,
) {
val hasError = item.result.isDone && item.measurementsCount == 0L

Surface(
color = if (item.result.isViewed) {
color = if (item.result.isViewed || hasError) {
MaterialTheme.colorScheme.surface
} else {
MaterialTheme.colorScheme.surfaceVariant
Expand All @@ -47,13 +50,16 @@ fun ResultCell(
verticalAlignment = Alignment.Bottom,
modifier = Modifier
.fillMaxWidth()
.clickable { onResultClick() }
.run { if (!hasError) clickable { onResultClick() } else this }
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
Column(
modifier = Modifier.weight(0.66f),
) {
TestDescriptorLabel(item.descriptor)
TestDescriptorLabel(
item.descriptor,
modifier = if (hasError) Modifier.alpha(0.5f) else Modifier,
)

item.network?.networkName?.let { networkName ->
Text(
Expand All @@ -64,13 +70,21 @@ fun ResultCell(
)
}

val asn = item.network?.asn ?: stringResource(Res.string.TestResults_UnknownASN)
Text(
"($asn)",
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (hasError) {
Text(
item.result.failureMessage.orEmpty().lines().first(),
maxLines = 2,
color = MaterialTheme.colorScheme.error,
)
} else {
val asn = item.network?.asn ?: stringResource(Res.string.TestResults_UnknownASN)
Text(
"($asn)",
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}

Text(
item.result.startTime.relativeDateTime(),
Expand All @@ -97,15 +111,17 @@ fun ResultCell(
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(bottom = 2.dp),
)
Text(
pluralStringResource(
Res.plurals.measurements_count,
item.measurementsCount.toInt(),
item.measurementsCount,
),
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(bottom = 2.dp),
)
if (!hasError) {
Text(
pluralStringResource(
Res.plurals.measurements_count,
item.measurementsCount.toInt(),
item.measurementsCount,
),
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(bottom = 2.dp),
)
}
if (!item.allMeasurementsUploaded) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand Down

0 comments on commit 1264d80

Please sign in to comment.