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

Release 3.1.0.1 #3916

Merged
merged 15 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: [ANDROAPP-6703] refresh selected item when inputCardData list is…
… modified
xavimolloy committed Dec 5, 2024
commit b72122ff8fa8a47b90353aa47602d5562165299b
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
@@ -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
@@ -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) }
@@ -112,7 +109,6 @@ fun FieldProvider(
inputStyle = inputStyle,
fieldUiModel = fieldUiModel,
intentHandler = intentHandler,
context = context,
fetchOptions = {
intentHandler(
FormIntent.FetchOptions(
@@ -484,7 +480,6 @@ fun ProvideByOptionSet(
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
intentHandler: (FormIntent) -> Unit,
context: Context,
fetchOptions: () -> Unit,
) {
when (fieldUiModel.renderingType) {
@@ -516,7 +511,6 @@ fun ProvideByOptionSet(
inputStyle = inputStyle,
fieldUiModel = fieldUiModel,
intentHandler = intentHandler,
context = context,
)
}

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

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
@@ -21,7 +20,6 @@ internal fun ProvideMatrixInput(
modifier: Modifier,
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
context: Context,
intentHandler: (FormIntent) -> Unit,
) {
val inputCardDataList: MutableList<ImageCardData> = mutableListOf()
Original file line number Diff line number Diff line change
@@ -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,
@@ -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 },
)
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
@@ -21,7 +20,6 @@ internal fun ProvideSequentialInput(
modifier: Modifier,
inputStyle: InputStyle,
fieldUiModel: FieldUiModel,
context: Context,
intentHandler: (FormIntent) -> Unit,
) {
val inputCardDataList: MutableList<ImageCardData> = mutableListOf()
@@ -38,7 +36,6 @@ internal fun ProvideSequentialInput(
)
}
}

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