Skip to content

Commit

Permalink
Hide adhoc job cards if AddLoiTask is missing (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 authored Feb 2, 2024
1 parent f68ba6d commit b566168
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ data class Job(

fun getTask(id: String): Task = tasks[id] ?: error("Unknown task id $id")

fun getAddLoiTask(): Task? = tasks.values.firstOrNull { it.isAddLoiTask }
/** Job must contain at-most 1 `AddLoiTask`. */
fun getAddLoiTask(): Task? =
tasks.values
.filter { it.isAddLoiTask }
.apply { check(size <= 1) { "Expected 0 or 1, found $size AddLoiTasks" } }
.firstOrNull()

/** Returns true if the job has one or more tasks. */
fun hasTasks() = tasks.values.isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,10 @@ internal constructor(
.stateIn(viewModelScope, SharingStarted.Lazily, listOf())

adHocLoiJobs =
activeSurvey
.combine(isZoomedInFlow) { survey, isZoomedIn -> Pair(survey, isZoomedIn) }
.flatMapLatest { (survey, isZoomedIn) ->
flowOf(
if (survey == null || !isZoomedIn) listOf()
else survey.jobs.filter { it.canDataCollectorsAddLois }
)
}
activeSurvey.combine(isZoomedInFlow) { survey, isZoomedIn ->
if (survey == null || !isZoomedIn) listOf()
else survey.jobs.filter { it.canDataCollectorsAddLois && it.getAddLoiTask() != null }
}
}

private fun updatedLoiSelectedStates(
Expand Down

0 comments on commit b566168

Please sign in to comment.