Skip to content

Commit

Permalink
feat: add expired tag
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Dec 18, 2024
1 parent c26ff4b commit 483eba7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class TestDescriptorRepository(
private val json: Json,
private val backgroundContext: CoroutineContext,
) {
fun list() =
fun list(isExpired: Boolean? = null) =
database.testDescriptorQueries
.selectAll()
.selectAll(isExpired = isExpired?.let { if (it) 1 else 0 })
.asFlow()
.mapToList(backgroundContext)
.map { list -> list.mapNotNull { it.toModel() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import org.ooni.probe.data.models.toDescriptor

class GetTestDescriptors(
private val getDefaultTestDescriptors: () -> List<DefaultTestDescriptor>,
private val listInstalledTestDescriptors: () -> Flow<List<InstalledTestDescriptorModel>>,
private val listInstalledTestDescriptors: (Boolean?) -> Flow<List<InstalledTestDescriptorModel>>,
private val descriptorUpdates: () -> Flow<DescriptorUpdatesStatus>,
private val getPreferenceValues: (List<SettingsKey>) -> Flow<Map<SettingsKey, Any?>>,
) {
operator fun invoke(): Flow<List<Descriptor>> {
operator fun invoke(isExpired: Boolean? = null): Flow<List<Descriptor>> {
return combine(
listInstalledTestDescriptors(),
listInstalledTestDescriptors(isExpired),
descriptorUpdates(),
flowOf(getDefaultTestDescriptors()),
isWebsitesDescriptorEnabled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.ic_chevron_right
import org.jetbrains.compose.resources.painterResource
import org.ooni.probe.data.models.Descriptor
import org.ooni.probe.ui.shared.ExpiredChip
import org.ooni.probe.ui.shared.UpdatesChip

@Composable
Expand Down Expand Up @@ -56,6 +57,9 @@ fun TestDescriptorItem(
if (descriptor.updatable) {
UpdatesChip(onClick = updateDescriptor)
}
if (descriptor.isExpired) {
ExpiredChip()
}
Icon(
painter = painterResource(Res.drawable.ic_chevron_right),
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.ooni.probe.config.OrganizationConfig
import org.ooni.probe.config.TestDisplayMode
import org.ooni.probe.data.models.Descriptor
import org.ooni.probe.data.models.NetTest
import org.ooni.probe.ui.shared.ExpiredChip
import org.ooni.probe.ui.shared.MarkdownViewer
import org.ooni.probe.ui.shared.SelectableItem
import org.ooni.probe.ui.shared.TopBar
Expand Down Expand Up @@ -263,6 +264,11 @@ private fun DescriptorDetails(
if (descriptor.updatable) {
UpdatesChip(onClick = { }, modifier = Modifier.padding(top = 8.dp))
}

if (descriptor.isExpired) {
ExpiredChip()
}

state.updatedDescriptor?.let {
OutlinedButton(
onClick = { onEvent(DescriptorViewModel.Event.UpdateDescriptor) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.ooni.probe.ui.shared.SelectableItem

class RunViewModel(
onBack: () -> Unit,
getTestDescriptors: () -> Flow<List<Descriptor>>,
getTestDescriptors: (Boolean?) -> Flow<List<Descriptor>>,
shouldShowVpnWarning: suspend () -> Boolean,
private val preferenceRepository: PreferenceRepository,
startBackgroundRun: (RunSpecification) -> Unit,
Expand All @@ -45,7 +45,7 @@ class RunViewModel(

init {
combine(
getTestDescriptors(),
getTestDescriptors(false),
collapsedDescriptorsKeys,
::Pair,
).flatMapLatest { (descriptors, collapsedDescriptorsKeys) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.ooni.probe.ui.shared

import androidx.compose.material3.SuggestionChip
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import ooniprobe.composeapp.generated.resources.Dashboard_RunV2_ExpiredTag
import ooniprobe.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.stringResource

@Composable
fun ExpiredChip(modifier: Modifier = Modifier) {
SuggestionChip(
onClick = { },
enabled = false,
label = { Text(stringResource(Res.string.Dashboard_RunV2_ExpiredTag)) },
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ setAutoUpdate:
UPDATE TestDescriptor SET auto_update = ? WHERE runId = ?;

selectAll:
SELECT * FROM TestDescriptor;
SELECT * FROM TestDescriptor WHERE (is_expired IS NULL OR is_expired = :isExpired) OR (:isExpired IS NULL);

selectByRunIds:
SELECT * FROM TestDescriptor WHERE runId IN ?;
Expand Down

0 comments on commit 483eba7

Please sign in to comment.