From 549e4e3796db60fbe5ebe288d7b78a7a3dd2f1ae Mon Sep 17 00:00:00 2001 From: andresmr Date: Mon, 13 Jan 2025 16:21:48 +0100 Subject: [PATCH] feat: [ANDROAPP-6693] multiplatform resources code refactor --- .../component/table/ui/CellLegend.kt | 7 ++ .../component/table/ui/CellStyle.kt | 60 +++++++++++++++-- .../component/table/ui/DataTable.kt | 6 ++ .../component/table/ui/DropDownOptions.kt | 10 ++- .../component/table/ui/ExtendDivider.kt | 11 +++- .../component/table/ui/HeaderCell.kt | 13 +++- .../component/table/ui/ItemValues.kt | 14 +++- .../component/table/ui/MultiOptionSelector.kt | 11 +++- .../designsystem/component/table/ui/Table.kt | 11 +++- .../component/table/ui/TableActions.kt | 11 +++- .../component/table/ui/TableCell.kt | 12 +++- .../component/table/ui/TableColors.kt | 36 ++++++++++ .../component/table/ui/TableConfiguration.kt | 10 +++ .../component/table/ui/TableCorner.kt | 8 +++ .../component/table/ui/TableDimensions.kt | 65 ++++++++++++------- .../component/table/ui/TableItemRow.kt | 14 +++- 16 files changed, 258 insertions(+), 41 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellLegend.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellLegend.kt index fe91e3185..74e8d7b0f 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellLegend.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellLegend.kt @@ -12,6 +12,13 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color +/** + * Composable function to display a cell with a legend color. + * + * @param modifier The modifier to be applied to the layout. + * @param legendColor The color of the legend to be displayed. + * @param content The content to be displayed inside the box. + */ @Composable internal fun CellLegendBox( modifier: Modifier = Modifier, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellStyle.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellStyle.kt index f122cf321..d0ba012d0 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellStyle.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/CellStyle.kt @@ -3,23 +3,55 @@ package org.hisp.dhis.mobile.ui.designsystem.component.table.ui import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color -sealed class CellStyle { +internal sealed class CellStyle { + + /** + * Style for header cells. + * + * @property backgroundColor The background color of the header cell. + * @property textColor The text color of the header cell. + */ data class HeaderStyle(val backgroundColor: Color, val textColor: Color) : CellStyle() + + /** + * Style for cells with borders. + * + * @property backgroundColor The background color of the cell. + * @property borderColor The border color of the cell. + */ data class CellBorderStyle(val backgroundColor: Color, val borderColor: Color) : CellStyle() + /** + * Returns the background color of the cell. + * + * @return The background color. + */ fun backgroundColor() = when (this) { is CellBorderStyle -> backgroundColor is HeaderStyle -> backgroundColor } + /** + * Returns the main color of the cell (text or border color). + * + * @return The main color. + */ fun mainColor() = when (this) { is CellBorderStyle -> borderColor is HeaderStyle -> textColor } } +/** + * Returns the style for column header cells based on their selection state and index. + * + * @param isSelected Indicates if the column header is selected. + * @param isParentSelected Indicates if the parent column header is selected. + * @param columnIndex The index of the column. + * @return The style for the column header cell. + */ @Composable -fun styleForColumnHeader( +internal fun styleForColumnHeader( isSelected: Boolean, isParentSelected: Boolean, columnIndex: Int, @@ -43,8 +75,16 @@ fun styleForColumnHeader( ) } +/** + * Returns the style for column header cells based on their selection state and index. + * + * @param isSelected Indicates if the column header is selected. + * @param isParentSelected Indicates if the parent column header is selected. + * @param columnIndex The index of the column. + * @return The style for the column header cell. + */ @Composable -fun styleForRowHeader(isSelected: Boolean, isOtherRowSelected: Boolean): CellStyle = when { +internal fun styleForRowHeader(isSelected: Boolean, isOtherRowSelected: Boolean): CellStyle = when { isSelected -> CellStyle.HeaderStyle( TableTheme.colors.primary, TableTheme.colors.onPrimary, @@ -59,7 +99,19 @@ fun styleForRowHeader(isSelected: Boolean, isOtherRowSelected: Boolean): CellSty ) } -fun styleForCell( +/** + * Returns the style for table cells based on various states and properties. + * + * @param tableColorProvider A function providing the table colors. + * @param isSelected Indicates if the cell is selected. + * @param isParentSelected Indicates if the parent cell is selected. + * @param hasError Indicates if the cell has an error. + * @param hasWarning Indicates if the cell has a warning. + * @param isEditable Indicates if the cell is editable. + * @param legendColor The color of the legend, if any. + * @return The style for the table cell. + */ +internal fun styleForCell( tableColorProvider: () -> TableColors, isSelected: Boolean, isParentSelected: Boolean, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DataTable.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DataTable.kt index 5cf8c22b0..2a6196086 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DataTable.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DataTable.kt @@ -18,6 +18,12 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.TableTheme.tableS import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.compositions.LocalInteraction import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.compositions.LocalTableResizeActions +/** + * Composable function to display a data table. + * + * @param tableList The list of table models to be displayed. + * @param bottomContent Optional composable content to be displayed at the bottom of the table. + */ @Composable fun DataTable(tableList: List, bottomContent: @Composable (() -> Unit)? = null) { val tableResizeActions = LocalTableResizeActions.current diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DropDownOptions.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DropDownOptions.kt index 3c9254d4e..ad3aa2241 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DropDownOptions.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/DropDownOptions.kt @@ -6,8 +6,16 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import org.hisp.dhis.mobile.ui.designsystem.component.table.model.DropdownOption +/** + * Composable function to display a dropdown menu with options. + * + * @param expanded Indicates whether the dropdown menu is expanded. + * @param options The list of options to be displayed in the dropdown menu. + * @param onDismiss The callback to be invoked when the dropdown menu is dismissed. + * @param onSelected The callback to be invoked when an option is selected, with the option's code and label. + */ @Composable -fun DropDownOptions( +internal fun DropDownOptions( expanded: Boolean, options: List, onDismiss: () -> Unit, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ExtendDivider.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ExtendDivider.kt index 2a01a0c65..ee68f39c5 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ExtendDivider.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ExtendDivider.kt @@ -14,9 +14,16 @@ import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp -// todo review dividers + +// TODO review dividers +/** + * Composable function to display an extended divider for table rows. + * + * @param tableId The ID of the table. + * @param selected Indicates if the divider is selected. + */ @Composable -fun ExtendDivider(tableId: String, selected: Boolean) { +internal fun ExtendDivider(tableId: String, selected: Boolean) { val background = TableTheme.colors.primary Row(modifier = Modifier.fillMaxWidth()) { Box( diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/HeaderCell.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/HeaderCell.kt index c2c18e156..a0ee38ede 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/HeaderCell.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/HeaderCell.kt @@ -24,8 +24,17 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.columnI import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.rowIndexHeader import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.tableIdColumnHeader +/** + * Composable function to display a header cell. + * + * @param itemHeaderUiState The state of the header cell. + * @param modifier The modifier to be applied to the cell. + */ @Composable -internal fun HeaderCell(itemHeaderUiState: ItemColumnHeaderUiState, modifier: Modifier = Modifier) { +internal fun HeaderCell( + itemHeaderUiState: ItemColumnHeaderUiState, + modifier: Modifier = Modifier, +) { Box( modifier = modifier .width(with(LocalDensity.current) { itemHeaderUiState.headerMeasures.width.toDp() }) @@ -57,7 +66,7 @@ internal fun HeaderCell(itemHeaderUiState: ItemColumnHeaderUiState, modifier: Mo maxLines = 3, softWrap = true, ) - // todo ensure new dividers are implemented correctly + // TODO ensure new dividers are implemented correctly HorizontalDivider( color = TableTheme.colors.primary, modifier = Modifier diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ItemValues.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ItemValues.kt index 2910a6317..7973f4e0b 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ItemValues.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/ItemValues.kt @@ -13,8 +13,20 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableCell import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableHeader import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.CELL_TEST_TAG +/** + * Composable function to display item values in a table row. + * + * @param tableId The ID of the table. + * @param horizontalScrollState The state of the horizontal scroll. + * @param maxLines The maximum number of lines to display in each cell. + * @param cellValues A map of column indices to table cells representing the cell values. + * @param overridenValues A map of column indices to table cells representing the overridden cell values. + * @param tableHeaderModel The model representing the table header. + * @param options The list of dropdown options available for the cells. + * @param headerLabel The label for the header. + */ @Composable -fun ItemValues( +internal fun ItemValues( tableId: String, horizontalScrollState: ScrollState, maxLines: Int, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/MultiOptionSelector.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/MultiOptionSelector.kt index a3e4866b3..e1a8fad65 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/MultiOptionSelector.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/MultiOptionSelector.kt @@ -7,8 +7,17 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.model.DropdownOption import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableCell import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource +/** + * Composable function to display a multi-option selector. + * + * @param options The list of dropdown options available for selection. + * @param cell The table cell containing the current value and editability state. + * @param title The title of the multi-option selector. + * @param onSave The callback to be invoked when the selected options are saved, with the selected codes and values. + * @param onDismiss The callback to be invoked when the selector is dismissed. + */ @Composable -fun MultiOptionSelector( +internal fun MultiOptionSelector( options: List, cell: TableCell, title: String, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/Table.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/Table.kt index e55f5315d..764464506 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/Table.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/Table.kt @@ -36,9 +36,18 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.TableTheme.tableS import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.compositions.LocalTableResizeActions import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.extensions.fixedStickyHeader +/** + * Composable function to display a table. + * + * @param tableList The list of table models to be displayed. + * @param tableHeaderRow Optional composable function to display the header row of the table. + * @param tableItemRow Optional composable function to display the item row of the table. + * @param verticalResizingView Optional composable function to display the vertical resizing view. + * @param bottomContent Optional composable content to be displayed at the bottom of the table. + */ @OptIn(ExperimentalFoundationApi::class) @Composable -fun Table( +internal fun Table( tableList: List, tableHeaderRow: @Composable ((index: Int, tableModel: TableModel) -> Unit)? = null, tableItemRow: @Composable ( diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableActions.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableActions.kt index 721a7955b..d863754e4 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableActions.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableActions.kt @@ -15,14 +15,21 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +/** + * Composable function to display table actions with a title and action icons. + * + * @param modifier The modifier to be applied to the layout. + * @param title The title of the table actions. + * @param actionIcons A composable function to display the action icons. + */ @Composable -fun TableActions(modifier: Modifier, title: String, actionIcons: @Composable () -> Unit) { +internal fun TableActions(modifier: Modifier, title: String, actionIcons: @Composable () -> Unit) { Row( modifier = modifier, horizontalArrangement = Arrangement.Absolute.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, ) { - // todo verify icon is correct + // TODO verify icon is correct Icon( imageVector = Icons.Outlined.TableView, contentDescription = "", diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCell.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCell.kt index 0308109b5..0548a2109 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCell.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCell.kt @@ -53,9 +53,19 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.hasErro import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.isBlocked import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.rowBackground +/** + * Composable function to display a table cell. + * + * @param tableId The ID of the table. + * @param cell The cell to be displayed. + * @param maxLines The maximum number of lines to be displayed in the cell. + * @param headerExtraSize The extra size to be added to the header. + * @param options The list of dropdown options. + * @param headerLabel The label of the header. + */ @OptIn(ExperimentalFoundationApi::class) @Composable -fun TableCell( +internal fun TableCell( tableId: String, cell: TableCell, maxLines: Int, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableColors.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableColors.kt index f470088a8..6e18fc5ac 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableColors.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableColors.kt @@ -4,6 +4,24 @@ import androidx.compose.runtime.Immutable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color +/** + * Data class representing the colors used in the table component. + * + * @property primary The primary color. + * @property primaryLight The light variant of the primary color. + * @property headerText The color of the header text. + * @property headerBackground1 The first background color for the header. + * @property headerBackground2 The second background color for the header. + * @property cellText The color of the cell text. + * @property disabledCellText The color of the text in disabled cells. + * @property disabledCellBackground The background color of disabled cells. + * @property disabledSelectedBackground The background color of selected disabled cells. + * @property errorColor The color used to indicate errors. + * @property warningColor The color used to indicate warnings. + * @property tableBackground The background color of the table. + * @property iconColor The color of icons. + * @property onPrimary The color used for text/icons on primary color. + */ @Immutable data class TableColors( val primary: Color = Color(0xFF2C98F0), @@ -21,6 +39,15 @@ data class TableColors( val iconColor: Color = Color.LightGray, val onPrimary: Color = Color.White, ) { + + /** + * Returns the appropriate cell text color based on error, warning, and editability states. + * + * @param hasError Indicates if the cell has an error. + * @param hasWarning Indicates if the cell has a warning. + * @param isEditable Indicates if the cell is editable. + * @return The color to be used for the cell text. + */ fun cellTextColor(hasError: Boolean, hasWarning: Boolean, isEditable: Boolean) = when { hasError -> errorColor hasWarning -> warningColor @@ -28,10 +55,19 @@ data class TableColors( else -> cellText } + /** + * Returns the appropriate color for the mandatory icon based on the cell value state. + * + * @param hasValue Indicates if the cell has a value. + * @return The color to be used for the mandatory icon. + */ fun cellMandatoryIconColor(hasValue: Boolean) = when (hasValue) { true -> iconColor false -> errorColor } } +/** + * CompositionLocal to provide [TableColors] throughout the Compose hierarchy. + */ val LocalTableColors = staticCompositionLocalOf { TableColors() } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableConfiguration.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableConfiguration.kt index 76ff908ca..6c089b9d6 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableConfiguration.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableConfiguration.kt @@ -3,6 +3,13 @@ package org.hisp.dhis.mobile.ui.designsystem.component.table.ui import androidx.compose.runtime.Immutable import androidx.compose.runtime.staticCompositionLocalOf +/** + * Data class representing the configuration settings for the table component. + * + * @property headerActionsEnabled Indicates if header actions are enabled. + * @property editable Indicates if the table cells are editable. + * @property textInputViewMode Indicates if the text input view mode is enabled. + */ @Immutable data class TableConfiguration( val headerActionsEnabled: Boolean = true, @@ -10,4 +17,7 @@ data class TableConfiguration( val textInputViewMode: Boolean = true, ) +/** + * CompositionLocal to provide [TableConfiguration] throughout the Compose hierarchy. + */ val LocalTableConfiguration = staticCompositionLocalOf { TableConfiguration() } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCorner.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCorner.kt index 7040a7965..bafc584f6 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCorner.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableCorner.kt @@ -14,6 +14,14 @@ import androidx.compose.ui.zIndex import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableCornerUiState import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.modifiers.cornerBackground +/** + * Composable function to display the table corner. + * + * @param modifier The modifier to be applied to the layout. + * @param tableCornerUiState The state of the table corner. + * @param tableId The ID of the table. + * @param onClick The action to be executed + */ @Composable internal fun TableCorner( modifier: Modifier = Modifier, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableDimensions.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableDimensions.kt index d567aa3a0..6f7bcd43a 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableDimensions.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableDimensions.kt @@ -7,8 +7,35 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import org.jetbrains.annotations.VisibleForTesting +/** + * Data class representing the dimensions of the table component. + * + * @property tableHorizontalPadding The horizontal padding of the table. + * @property tableVerticalPadding The vertical padding of the table. + * @property defaultCellWidth The default width of the table cells. + * @property defaultCellHeight The default height of the table cells. + * @property defaultRowHeaderWidth The default width of the row header. + * @property defaultHeaderHeight The default height of the header. + * @property defaultLegendCornerSize The default size of the legend corner. + * @property defaultLegendBorderWidth The default width of the legend border. + * @property defaultHeaderTextSize The default size of the header text. + * @property defaultRowHeaderTextSize The default size of the row header text. + * @property defaultCellTextSize The default size of the cell text. + * @property totalWidth The total width of the table. + * @property cellVerticalPadding The vertical padding of the table cells. + * @property cellHorizontalPadding The horizontal padding of the table cells. + * @property headerCellPaddingValues The padding values of the header cells. + * @property tableBottomPadding The bottom padding of the table. + * @property extraWidths The extra widths of the table. + * @property rowHeaderWidths The widths of the row headers. + * @property columnWidth The widths of the columns. + * @property minRowHeaderWidth The minimum width of the row header. + * @property minColumnWidth The minimum width of the column. + * @property maxRowHeaderWidth The maximum width of the row header. + * @property maxColumnWidth The maximum width of the column. + * @property tableEndExtraScroll The extra scroll of the table end. + */ @Immutable data class TableDimensions( val tableHorizontalPadding: Dp = 16.dp, @@ -46,17 +73,18 @@ data class TableDimensions( return (rowHeaderWidths[tableId] ?: defaultRowHeaderWidth) + extraWidthInTable(tableId) } - fun defaultCellWidthWithExtraSize( + internal fun defaultCellWidthWithExtraSize( tableId: String, totalColumns: Int, hasExtra: Boolean = false, ): Int = defaultCellWidth + extraSize(tableId, totalColumns, hasExtra) + extraWidthInTable(tableId) - fun columnWidthWithTableExtra(tableId: String, column: Int? = null): Int = + + internal fun columnWidthWithTableExtra(tableId: String, column: Int? = null): Int = (columnWidth[tableId]?.get(column) ?: defaultCellWidth) + extraWidthInTable(tableId) - fun headerCellWidth( + internal fun headerCellWidth( tableId: String, column: Int, headerRowColumns: Int, @@ -80,14 +108,7 @@ data class TableDimensions( return result } - // todo review testing usages for this class - @VisibleForTesting() - fun headerCellWidth(headerRowColumns: Int, totalColumns: Int): Int { - val fullWidth = defaultCellWidth * totalColumns - return fullWidth / headerRowColumns - } - - fun extraSize(tableId: String, totalColumns: Int, hasTotal: Boolean, column: Int? = null): Int { + internal fun extraSize(tableId: String, totalColumns: Int, hasTotal: Boolean, column: Int? = null): Int { val screenWidth = totalWidth val tableWidth = tableWidth(tableId, totalColumns, hasTotal) val columnHasResizedValue = column?.let { @@ -105,28 +126,26 @@ data class TableDimensions( } } - // todo review testing usages for this class - @VisibleForTesting() - fun tableWidth(tableId: String, totalColumns: Int, hasTotal: Boolean): Int { + private fun tableWidth(tableId: String, totalColumns: Int, hasTotal: Boolean): Int { val totalCellWidth = defaultCellWidth.takeIf { hasTotal } ?: 0 return rowHeaderWidth(tableId) + defaultCellWidth * totalColumns + totalCellWidth } - fun updateAllWidthBy(tableId: String, widthOffset: Float): TableDimensions { + private fun updateAllWidthBy(tableId: String, widthOffset: Float): TableDimensions { val newWidth = (extraWidths[tableId] ?: 0) + widthOffset - 11 val newMap = extraWidths.toMutableMap() newMap[tableId] = newWidth.toInt() return copy(extraWidths = newMap) } - fun updateHeaderWidth(tableId: String, widthOffset: Float): TableDimensions { + private fun updateHeaderWidth(tableId: String, widthOffset: Float): TableDimensions { val newWidth = (rowHeaderWidths[tableId] ?: defaultRowHeaderWidth) + widthOffset - 11 val newMap = rowHeaderWidths.toMutableMap() newMap[tableId] = newWidth.toInt() return copy(rowHeaderWidths = newMap) } - fun updateColumnWidth(tableId: String, column: Int, widthOffset: Float): TableDimensions { + private fun updateColumnWidth(tableId: String, column: Int, widthOffset: Float): TableDimensions { val newWidth = ( columnWidth[tableId]?.get(column) ?: (defaultCellWidth + (currentExtraSize[tableId] ?: 0)) @@ -145,7 +164,6 @@ data class TableDimensions( extraWidths.containsKey(tableId) } - // todo review whether this method is still needed fun resetWidth(tableId: String): TableDimensions { val newExtraWidths = extraWidths.toMutableMap() val newColumnMap = columnWidth.toMutableMap() @@ -160,12 +178,12 @@ data class TableDimensions( ) } - fun canUpdateRowHeaderWidth(tableId: String, widthOffset: Float): Boolean { + internal fun canUpdateRowHeaderWidth(tableId: String, widthOffset: Float): Boolean { val desiredDimension = updateHeaderWidth(tableId = tableId, widthOffset = widthOffset) return desiredDimension.rowHeaderWidth(tableId) in minRowHeaderWidth..maxRowHeaderWidth } - fun canUpdateColumnHeaderWidth( + internal fun canUpdateColumnHeaderWidth( tableId: String, currentOffsetX: Float, columnIndex: Int, @@ -188,7 +206,7 @@ data class TableDimensions( ) in minColumnWidth..maxColumnWidth } - fun canUpdateAllWidths(tableId: String, widthOffset: Float): Boolean { + internal fun canUpdateAllWidths(tableId: String, widthOffset: Float): Boolean { val desiredDimension = updateAllWidthBy(tableId = tableId, widthOffset = widthOffset) return desiredDimension.rowHeaderWidth(tableId) in minRowHeaderWidth..maxRowHeaderWidth && desiredDimension.columnWidthWithTableExtra(tableId) in minColumnWidth..maxColumnWidth && @@ -199,17 +217,14 @@ data class TableDimensions( ) in minColumnWidth..maxColumnWidth } ?: true } - // todo review whether this method is still needed fun getRowHeaderWidth(tableId: String): Int { return rowHeaderWidths[tableId] ?: defaultRowHeaderWidth } - // todo review whether this method is still needed fun getColumnWidth(tableId: String, column: Int): Int { return columnWidth[tableId]?.get(column) ?: defaultCellWidth } - // todo review whether this method is still needed fun getExtraWidths(tableId: String): Int { return extraWidths[tableId] ?: 0 diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableItemRow.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableItemRow.kt index fa0df1eac..22d647575 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableItemRow.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/table/ui/TableItemRow.kt @@ -23,6 +23,18 @@ import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableModel import org.hisp.dhis.mobile.ui.designsystem.component.table.model.TableRowModel import org.hisp.dhis.mobile.ui.designsystem.component.table.ui.semantics.ROW_TEST_TAG +/** + * Composable function to display a table item row. + * + * @param tableModel The model containing the table data. + * @param horizontalScrollState The scroll state for horizontal scrolling. + * @param rowModel The model containing the row data. + * @param rowHeaderCellStyle A composable function to provide the style for the row header cell. + * @param onRowHeaderClick Callback function invoked when the row header is clicked. + * @param onDecorationClick Callback function invoked when a decoration is clicked. + * @param onHeaderResize Callback function invoked when the header is resized. + * @param onResizing Callback function invoked during the resizing of the header. + */ @Composable internal fun TableItemRow( tableModel: TableModel, @@ -74,7 +86,7 @@ internal fun TableItemRow( ) } if (!rowModel.isLastRow) { - // todo review if new divider is implemented correctly + // TODO review if new divider is implemented correctly HorizontalDivider( modifier = Modifier .fillMaxWidth()