Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-6703] refresh selected item when inputCardData list is modified #3921

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading