Skip to content

Commit

Permalink
Merge pull request #3921 from dhis2/ANDROAPP-6703-Option-is-not-marke…
Browse files Browse the repository at this point in the history
…d-as-selected-after-saving-the-event

fix: [ANDROAPP-6703] refresh selected item when inputCardData list is modified
  • Loading branch information
xavimolloy authored Dec 5, 2024
2 parents 5786295 + b72122f commit f4d6779
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dhis2.form.ui.provider.inputfield

import android.content.Context
import android.content.Intent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.focusable
Expand All @@ -23,7 +22,6 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.TextFieldValue
Expand Down Expand Up @@ -68,7 +66,6 @@ fun FieldProvider(
focusManager: FocusManager,
onNextClicked: () -> Unit,
) {
val context = LocalContext.current
val bringIntoViewRequester = remember { BringIntoViewRequester() }
val focusRequester = remember { FocusRequester() }
var visibleArea by remember { mutableStateOf(Rect.Zero) }
Expand Down Expand Up @@ -112,7 +109,6 @@ fun FieldProvider(
inputStyle = inputStyle,
fieldUiModel = fieldUiModel,
intentHandler = intentHandler,
context = context,
fetchOptions = {
intentHandler(
FormIntent.FetchOptions(
Expand Down Expand Up @@ -484,7 +480,6 @@ fun ProvideByOptionSet(
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
intentHandler: (FormIntent) -> Unit,
context: Context,
fetchOptions: () -> Unit,
) {
when (fieldUiModel.renderingType) {
Expand Down Expand Up @@ -516,7 +511,6 @@ fun ProvideByOptionSet(
inputStyle = inputStyle,
fieldUiModel = fieldUiModel,
intentHandler = intentHandler,
context = context,
)
}

Expand All @@ -526,7 +520,6 @@ fun ProvideByOptionSet(
inputStyle = inputStyle,
fieldUiModel = fieldUiModel,
intentHandler = intentHandler,
context = context,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dhis2.form.ui.provider.inputfield

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
Expand All @@ -21,7 +20,6 @@ internal fun ProvideMatrixInput(
modifier: Modifier,
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
context: Context,
intentHandler: (FormIntent) -> Unit,
) {
val inputCardDataList: MutableList<ImageCardData> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import org.dhis2.form.model.FieldUiModel
import org.dhis2.ui.MetadataIconData
import org.hisp.dhis.android.core.option.Option
import org.hisp.dhis.mobile.ui.designsystem.component.ImageCardData

@Composable
fun rememberInputCardList(
options: List<Option>?,
optionMetadataIconMap: Map<String, MetadataIconData>?,
) = remember(options) {
options?.map { option ->
val metadataIconData =
optionMetadataIconMap?.get(option.uid()) ?: throw IllegalArgumentException()

var icon = option.style().icon() ?: "dhis2_dhis2_logo_positive"
if (!icon.startsWith("dhis2_")) {
icon = "dhis2_$icon"
}
imageCardDataWithUidAndLabel(
metadataIconData.imageCardData,
option.code() ?: "",
option.displayName() ?: "",
)
} ?: emptyList()
}

fun imageCardDataWithUidAndLabel(
imageCardData: ImageCardData,
optionCode: String,
Expand All @@ -42,7 +19,7 @@ fun imageCardDataWithUidAndLabel(

@Composable
fun rememberSelectedOption(fieldUiModel: FieldUiModel, inputCardDataList: List<ImageCardData>) =
remember(fieldUiModel.displayName) {
remember(inputCardDataList, fieldUiModel.displayName) {
mutableStateOf(
inputCardDataList.find { it.uid == fieldUiModel.displayName || it.label == fieldUiModel.displayName },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dhis2.form.ui.provider.inputfield

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
Expand All @@ -21,7 +20,6 @@ internal fun ProvideSequentialInput(
modifier: Modifier,
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
context: Context,
intentHandler: (FormIntent) -> Unit,
) {
val inputCardDataList: MutableList<ImageCardData> = mutableListOf()
Expand All @@ -38,7 +36,6 @@ internal fun ProvideSequentialInput(
)
}
}

var matrixSelectedItem by rememberSelectedOption(
fieldUiModel = fieldUiModel,
inputCardDataList = inputCardDataList,
Expand Down

0 comments on commit f4d6779

Please sign in to comment.