Skip to content

Commit

Permalink
fix: [ANDROAPP-6418] do not get syncState if there are no conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Manu Muñoz <[email protected]>
  • Loading branch information
mmmateos committed Jan 7, 2025
1 parent 6546046 commit 478b123
Showing 1 changed file with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,63 +618,65 @@ class DataValueRepository(
options,
)

val valueStateSyncState = d2.dataValueModule().dataValues()
.byDataSetUid(dataSetUid)
.byPeriod().eq(periodId)
.byOrganisationUnitUid().eq(orgUnitUid)
.byAttributeOptionComboUid().eq(attributeOptionComboUid)
.byDataElementUid().eq(dataElement.uid())
.byCategoryOptionComboUid().eq(categoryOptionCombo.uid())
.blockingGet()
.find { it.dataElement() == dataElement.uid() }
?.syncState()

val conflictInField =
conflicts.takeIf {
when (valueStateSyncState) {
State.ERROR,
State.WARNING,
-> true

else -> false
}
}?.filter {
"${it.dataElement()}_${it.categoryOptionCombo()}" == fieldViewModel.uid()
}?.takeIf { it.isNotEmpty() }?.map { it.displayDescription() ?: "" }

val error = errors[fieldViewModel.uid()]

val errorList = when {
valueStateSyncState == State.ERROR &&
conflictInField != null &&
error != null ->
conflictInField + listOf(error)
if (conflicts.isNotEmpty()) {
val valueStateSyncState = d2.dataValueModule().dataValues()
.byDataSetUid(dataSetUid)
.byPeriod().eq(periodId)
.byOrganisationUnitUid().eq(orgUnitUid)
.byAttributeOptionComboUid().eq(attributeOptionComboUid)
.byDataElementUid().eq(dataElement.uid())
.byCategoryOptionComboUid().eq(categoryOptionCombo.uid())
.blockingGet()
.find { it.dataElement() == dataElement.uid() }
?.syncState()

val conflictInField =
conflicts.takeIf {
when (valueStateSyncState) {
State.ERROR,
State.WARNING,
-> true

else -> false
}
}?.filter {
"${it.dataElement()}_${it.categoryOptionCombo()}" == fieldViewModel.uid()
}?.takeIf { it.isNotEmpty() }?.map { it.displayDescription() ?: "" }

valueStateSyncState == State.ERROR && conflictInField != null ->
conflictInField
val error = errors[fieldViewModel.uid()]

error != null ->
listOf(error)
val errorList = when {
valueStateSyncState == State.ERROR &&
conflictInField != null &&
error != null ->
conflictInField + listOf(error)

else -> null
}
valueStateSyncState == State.ERROR && conflictInField != null ->
conflictInField

val warningList = when {
valueStateSyncState == State.WARNING &&
conflictInField != null ->
conflictInField
error != null ->
listOf(error)

else ->
null
}
else -> null
}

fieldViewModel = errorList?.let {
fieldViewModel.withError(it.joinToString(".\n"))
} ?: fieldViewModel
val warningList = when {
valueStateSyncState == State.WARNING &&
conflictInField != null ->
conflictInField

fieldViewModel = warningList?.let {
fieldViewModel.withWarning(warningList.joinToString(".\n"))
} ?: fieldViewModel
else ->
null
}

fieldViewModel = errorList?.let {
fieldViewModel.withError(it.joinToString(".\n"))
} ?: fieldViewModel

fieldViewModel = warningList?.let {
fieldViewModel.withWarning(warningList.joinToString(".\n"))
} ?: fieldViewModel
}

fields.add(fieldViewModel)

Expand Down

0 comments on commit 478b123

Please sign in to comment.