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

Androapp 6474 mobile UI update org tree bottom sheet button configuration #299

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,12 +1,15 @@
package org.hisp.dhis.common.screens.bottomSheets

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.MoveDown
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.style.TextAlign
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -30,6 +33,7 @@ fun OrgTreeBottomSheetScreen() {
var showTwoOrgTreeBottomSheet by rememberSaveable { mutableStateOf(false) }
var showMediumOrgTreeBottomSheet by rememberSaveable { mutableStateOf(false) }
var showLargeOrgTreeBottomSheet by rememberSaveable { mutableStateOf(false) }
var showTransferOrgBottomSheet by rememberSaveable { mutableStateOf(false) }

if (showOneOrgTreeBottomSheet) {
val orgTreeItemsRepo = remember { OrgTreeItemsFakeRepo() }
Expand Down Expand Up @@ -115,6 +119,31 @@ fun OrgTreeBottomSheetScreen() {
)
}

if (showTransferOrgBottomSheet) {
val orgTreeItemsRepo = remember { OrgTreeItemsFakeRepo() }
val oneOrgTreeItem by orgTreeItemsRepo.state.collectAsState(emptyList())

OrgBottomSheet(
title = "Transfer [tracked entity type]",
description = "From [current owner org. unit] to...",
orgTreeItems = oneOrgTreeItem,
doneButtonText = "Transfer",
doneButtonIcon = Icons.Outlined.MoveDown,
headerTextAlignment = TextAlign.Left,
onDismiss = {
showTransferOrgBottomSheet = false
},
onSearch = orgTreeItemsRepo::search,
onItemClick = orgTreeItemsRepo::toggleItemExpansion,
onItemSelected = { uid, checked ->
orgTreeItemsRepo.toggleItemSelection(uid, checked)
},
onDone = {
// no-op
},
)
}

ColumnScreenContainer(title = BottomSheets.ORG_TREE_BOTTOM_SHEET.label) {
ColumnComponentContainer("Org Tree Bottom Sheet with single item") {
Button(
Expand Down Expand Up @@ -155,6 +184,16 @@ fun OrgTreeBottomSheetScreen() {
showLargeOrgTreeBottomSheet = !showLargeOrgTreeBottomSheet
}
}

ColumnComponentContainer("Transfer Org Tree Bottom Sheet") {
Button(
enabled = true,
ButtonStyle.FILLED,
text = "Show Transfer Org Tree Bottom Sheet",
) {
showTransferOrgBottomSheet = !showTransferOrgBottomSheet
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
Expand Down Expand Up @@ -58,7 +59,9 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor
* @param description: optional description.
* @param clearAllButtonText: text for clear all button.
* @param doneButtonText: text for accept button.
* @param doneButtonIcon: icon for accept button.
* @param noResultsFoundText: text for no results found.
* @param headerTextAlignment [Alignment] for header text.
* @param icon: optional icon to be shown above the header .
* @param onSearch: access to the on search event.
* @param onDismiss: access to the on dismiss event.
Expand All @@ -76,14 +79,16 @@ fun OrgBottomSheet(
subtitle: String? = null,
description: String? = null,
clearAllButtonText: String = provideStringResource("clear_all"),
doneButtonText: String = provideStringResource("done"),
doneButtonText: String? = null,
doneButtonIcon: ImageVector = Icons.Filled.Check,
noResultsFoundText: String = provideStringResource("no_results_found"),
headerTextAlignment: TextAlign = TextAlign.Center,
icon: @Composable (() -> Unit)? = null,
onSearch: ((String) -> Unit)? = null,
onDismiss: () -> Unit,
onItemClick: (uid: String) -> Unit,
onItemSelected: (uid: String, checked: Boolean) -> Unit,
onClearAll: () -> Unit,
onClearAll: (() -> Unit)? = null,
onDone: () -> Unit,
) {
var searchQuery by remember { mutableStateOf("") }
Expand All @@ -95,6 +100,7 @@ fun OrgBottomSheet(
title = title,
subtitle = subtitle,
description = description,
headerTextAlignment = headerTextAlignment,
icon = icon,
searchQuery = searchQuery,
onSearchQueryChanged = { query ->
Expand Down Expand Up @@ -124,33 +130,35 @@ fun OrgBottomSheet(
Row(
verticalAlignment = Alignment.CenterVertically,
) {
Button(
modifier = Modifier.weight(1f)
.testTag("CLEAR_ALL_BUTTON"),
onClick = onClearAll,
icon = {
Icon(
imageVector = Icons.Filled.ClearAll,
contentDescription = null,
)
},
text = clearAllButtonText,
enabled = orgTreeItems.any { it.selected },
)
if (onClearAll != null) {
Button(
modifier = Modifier.weight(1f)
.testTag("CLEAR_ALL_BUTTON"),
onClick = onClearAll,
icon = {
Icon(
imageVector = Icons.Filled.ClearAll,
contentDescription = null,
)
},
text = clearAllButtonText,
enabled = orgTreeItems.any { it.selected },
)

Spacer(Modifier.requiredWidth(Spacing.Spacing16))
Spacer(Modifier.requiredWidth(Spacing.Spacing16))
}

Button(
modifier = Modifier.weight(1f),
onClick = onDone,
icon = {
Icon(
imageVector = Icons.Filled.Check,
imageVector = doneButtonIcon,
contentDescription = null,
)
},
enabled = orgTreeItems.any { it.selected },
text = doneButtonText,
text = doneButtonText ?: provideStringResource("done"),
style = ButtonStyle.FILLED,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,38 @@ class OrgBottomSheetTest {
rule.onNodeWithTag("ORG_TREE_ITEM_CHECKBOX_Item 1").assertExists()
rule.onNodeWithTag("ORG_TREE_ITEM_CHECKBOX_Item 2").assertDoesNotExist()
}

@Test
fun shouldHideClearButtonWhenOnClearAllMethodIsNotProvided() {
rule.setContent {
OrgBottomSheet(
orgTreeItems = listOf(
OrgTreeItem(
uid = "1",
label = "Item 1",
canBeSelected = true,
),
OrgTreeItem(
uid = "2",
label = "Item 2",
canBeSelected = false,
),
),
onDismiss = {
// no-op
},
onItemClick = {
// no-op
},
onItemSelected = { _, _ ->
// no-op
},
onDone = {
// no-op
},
)
}

rule.onNodeWithTag("CLEAR_ALL_BUTTON").assertDoesNotExist()
}
}
Loading