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-5249] resizing button over cell #3421

Merged
merged 5 commits into from
Dec 20, 2023
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
Expand Up @@ -71,22 +71,32 @@ class TableDataToTableModelMapper(val mapFieldValueToUser: MapFieldValueToUser)
rows = listOf(
TableHeaderRow(
cells = listOf(
TableHeaderCell(value = "Value"),
TableHeaderCell(mapFieldValueToUser.resources.getString(R.string.value)),
),
),
),
)
val tableRows = tableData.map { (indicatorName, indicatorValue) ->
TableRowModel(
rowHeader = RowHeader(id = indicatorName, title = indicatorName!!),
rowHeader = RowHeader(
id = indicatorName,
title = indicatorName!!,
row = tableData.keys.indexOf(indicatorName),
),
values = mapOf(
0 to TableCell(id = indicatorName, value = indicatorValue, editable = false),
0 to TableCell(
id = indicatorName,
column = 0,
value = indicatorValue,
editable = false,
),
),
)
}

return TableModel(
title = "Indicators",
id = "indicators",
title = mapFieldValueToUser.resources.getString(R.string.dashboard_indicators),
tableHeaderModel = tableHeader,
tableRows = tableRows,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import org.hisp.dhis.android.core.dataelement.DataElement
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

const val DATAELEMENT_FORM_NAME = "dataElement_formName"
const val DATAELEMENT_DESCRIPTION = "dataElement_description"
Expand All @@ -28,6 +31,9 @@ class TableDataToTableModelMapperTest {

@Test
fun `Should Map Indicators`() {
whenever(mapFieldValueToUser.resources) doReturn mock()
whenever(mapFieldValueToUser.resources.getString(any())) doReturn "Value"

val map = mapOf<String?, String>(
Pair("Indicator 1", "2"),
Pair("Indicator 2", "1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
data class RowHeader(
val id: String? = null,
val title: String,
val row: Int? = null,
val row: Int,
val showDecoration: Boolean = false,
val description: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package org.dhis2.composetable.model

import kotlinx.serialization.Serializable
import org.dhis2.composetable.ui.SelectionState

@Serializable
data class TableCell(
val id: String? = null,
val row: Int? = null,
val column: Int? = null,
val column: Int,
val value: String?,
val editable: Boolean = true,
val mandatory: Boolean? = false,
val error: String? = null,
val warning: String? = null,
val legendColor: Int? = null,
) {
fun isSelected(selectionState: SelectionState): Boolean {
return selectionState.cellOnly &&
selectionState.row == row &&
selectionState.column == column
}

fun hasErrorOrWarning() = errorOrWarningMessage() != null
fun errorOrWarningMessage() = error ?: warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import org.dhis2.composetable.ui.semantics.rowIndexHeader
import org.dhis2.composetable.ui.semantics.tableIdColumnHeader

@Composable
fun HeaderCell(itemHeaderUiState: ItemColumnHeaderUiState) {
fun HeaderCell(itemHeaderUiState: ItemColumnHeaderUiState, modifier: Modifier = Modifier) {
Box(
modifier = Modifier
modifier = modifier
.width(with(LocalDensity.current) { itemHeaderUiState.headerMeasures.width.toDp() })
.fillMaxHeight()
.background(itemHeaderUiState.cellStyle.backgroundColor())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun ItemValues(
overridenValues[columnIndex]
} else {
cellValues[columnIndex]
} ?: TableCell(value = "")
} ?: TableCell(value = "", column = columnIndex)

key("$tableId$CELL_TEST_TAG${cellValue.row}${cellValue.column}") {
TableCell(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ fun TableHeader(
action = { columnIndex ->
val cellIndex = columnIndex % rowOptions
HeaderCell(
ItemColumnHeaderUiState(
modifier = Modifier.zIndex((totalColumns - columnIndex) * 1f),
itemHeaderUiState = ItemColumnHeaderUiState(
tableId = tableId,
rowIndex = rowIndex,
columnIndex = columnIndex,
Expand Down Expand Up @@ -84,36 +85,36 @@ fun TableHeader(
)
},
)
if (tableHeaderModel.hasTotals) {
HeaderCell(
ItemColumnHeaderUiState(
tableId = tableId,
rowIndex = 0,
columnIndex = tableHeaderModel.rows.size,
headerCell = TableHeaderCell("Total"),
HeaderMeasures(
dimensions.defaultCellWidthWithExtraSize(
tableId = tableId ?: "",
totalColumns = tableHeaderModel.tableMaxColumns(),
hasExtra = true,
),
dimensions.defaultHeaderHeight * tableHeaderModel.rows.size,
),
cellStyle = cellStyle(
tableHeaderModel.numberOfColumns(tableHeaderModel.rows.size - 1),
tableHeaderModel.rows.size - 1,
),
onCellSelected = {},
onHeaderResize = { _, _ -> },
onResizing = {},
isLastRow = false,
checkMaxCondition = { _, _ -> false },
),
)
}
}
}
}
if (tableHeaderModel.hasTotals) {
HeaderCell(
ItemColumnHeaderUiState(
tableId = tableId,
rowIndex = 0,
columnIndex = tableHeaderModel.rows.size,
headerCell = TableHeaderCell("Total"),
HeaderMeasures(
dimensions.defaultCellWidthWithExtraSize(
tableId = tableId ?: "",
totalColumns = tableHeaderModel.tableMaxColumns(),
hasExtra = tableHeaderModel.hasTotals,
),
dimensions.defaultHeaderHeight * tableHeaderModel.rows.size,
),
cellStyle = cellStyle(
tableHeaderModel.numberOfColumns(tableHeaderModel.rows.size - 1),
tableHeaderModel.rows.size - 1,
),
onCellSelected = {},
onHeaderResize = { _, _ -> },
onResizing = {},
isLastRow = false,
checkMaxCondition = { _, _ -> false },
),
)
}
Spacer(Modifier.size(dimensions.tableEndExtraScroll))
}
}
Loading