-
Notifications
You must be signed in to change notification settings - Fork 130
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
[Order creation] Update coupons display order details #12855
Merged
samiuelson
merged 20 commits into
trunk
from
issue/12619-adjust-coupons-behavior-in-order-creation
Nov 7, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
28fa782
Add compose implementation of coupons section
malinajirka da97057
Bind model to UI for the coupons section
malinajirka 37f601f
Make changes to coupons list observable
malinajirka 9c6c2e9
Disable coupons section when fetching order or in editing mode
malinajirka 8b0c574
Fix UI glitches when adding shipping and coupons
malinajirka 23d5577
Remove coupon editing from totals bottom sheet
malinajirka fe9f6e9
Update release notes
malinajirka 82ab70a
Fix detekt
malinajirka 96219e8
Merge branch 'refs/heads/trunk' into issue/12619-adjust-coupons-behav…
malinajirka f4f52ca
Fix failing Unit Tests
malinajirka a5d5112
Add unit tests for listed coupons lines
malinajirka 9ecd5d6
Merge branch 'refs/heads/trunk' into issue/12619-adjust-coupons-behav…
malinajirka 43b863b
Rename methods names for better clarity
malinajirka fa50c34
Rename methods names for better clarity
malinajirka 99c5ac1
Fix appearance of long coupons codes
malinajirka 85d244e
Display both dark and light mode previews for coupons section
malinajirka fce8dda
Add content description for remove coupon btn
malinajirka 825b465
Update preview
malinajirka 18e079d
Update coupons line to plural
malinajirka eb1f773
Remove unused imports
malinajirka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/coupon/CouponLineDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.woocommerce.android.ui.orders.creation.coupon | ||
|
||
data class CouponLineDetails( | ||
val code: String | ||
) | ||
|
||
data class CouponSection( | ||
val couponLines: List<CouponLineDetails>, | ||
val isEnabled: Boolean, | ||
) |
143 changes: 143 additions & 0 deletions
143
...rc/main/kotlin/com/woocommerce/android/ui/orders/creation/coupon/CouponLineFormSection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package com.woocommerce.android.ui.orders.creation.coupon | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Add | ||
import androidx.compose.material.icons.outlined.DeleteOutline | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.graphics.RectangleShape | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.PreviewLightDark | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground | ||
|
||
@Composable | ||
fun CouponLineFormSection( | ||
couponLineDetails: List<CouponLineDetails>, | ||
isEnabled: Boolean, | ||
onAddClicked: () -> Unit, | ||
onRemoveClicked: (code: String) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
AnimatedVisibility(couponLineDetails.isNotEmpty()) { | ||
Card(shape = RectangleShape, modifier = modifier) { | ||
Column(modifier = Modifier.padding(16.dp)) { | ||
Row(modifier = Modifier.padding(bottom = 16.dp)) { | ||
Text( | ||
text = stringResource(id = R.string.coupons), | ||
style = MaterialTheme.typography.h6, | ||
modifier = modifier | ||
.weight(2f, true) | ||
.align(Alignment.CenterVertically), | ||
) | ||
Icon( | ||
imageVector = Icons.Default.Add, | ||
contentDescription = stringResource(id = R.string.order_creation_add_coupon), | ||
modifier = Modifier | ||
.align(Alignment.CenterVertically) | ||
.alpha(if (isEnabled) 1f else 0.4f) | ||
.clickable(enabled = isEnabled) { onAddClicked() }, | ||
tint = MaterialTheme.colors.primary | ||
) | ||
} | ||
|
||
samiuelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
couponLineDetails.forEachIndexed { i, couponDetails -> | ||
val itemModifier = if (i == 0) Modifier else Modifier.padding(top = 8.dp) | ||
CouponLineEditCard( | ||
couponLine = couponDetails, | ||
modifier = itemModifier | ||
.alpha(if (isEnabled) 1f else 0.4f) | ||
.clickable(enabled = isEnabled) { onRemoveClicked(couponDetails.code) } | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun CouponLineEditCard( | ||
couponLine: CouponLineDetails, | ||
modifier: Modifier = Modifier | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.border( | ||
brush = SolidColor(MaterialTheme.colors.onSurface.copy(alpha = 0.12f)), | ||
width = 1.dp, | ||
shape = RoundedCornerShape(dimensionResource(id = R.dimen.corner_radius_large)) | ||
) | ||
.padding(dimensionResource(id = R.dimen.major_100)) | ||
) { | ||
Text( | ||
modifier = Modifier.weight(1f), | ||
text = couponLine.code, | ||
style = TextStyle( | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 18.sp | ||
), | ||
color = colorResource(id = R.color.color_on_surface), | ||
maxLines = 1, | ||
overflow = TextOverflow.Ellipsis | ||
) | ||
Icon( | ||
imageVector = Icons.Outlined.DeleteOutline, | ||
contentDescription = stringResource(id = R.string.order_creation_remove_coupon), | ||
modifier = Modifier | ||
.align(Alignment.CenterVertically) | ||
.padding(start = 16.dp) | ||
) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
fun CouponLineDetailsPreview() { | ||
WooThemeWithBackground { | ||
CouponLineDetails( | ||
code = "abcdefg", | ||
) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
fun CouponLineFormSectionPreview() { | ||
val couponLine = List(3) { i -> | ||
CouponLineDetails( | ||
code = "abcdefg_abcdefg_abcdefg_abcdefg_$i", | ||
) | ||
} | ||
WooThemeWithBackground { | ||
CouponLineFormSection( | ||
couponLineDetails = couponLine, | ||
isEnabled = true, | ||
onAddClicked = { }, | ||
onRemoveClicked = { } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,8 @@ import java.math.BigDecimal | |
@Composable | ||
fun ShippingLineFormSection( | ||
shippingLineDetails: List<ShippingLineDetails>, | ||
onAdd: () -> Unit, | ||
onEdit: (id: Long) -> Unit, | ||
onAddClicked: () -> Unit, | ||
onEditClicked: (id: Long) -> Unit, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
formatCurrency: (amount: BigDecimal) -> String, | ||
modifier: Modifier = Modifier | ||
) { | ||
|
@@ -66,7 +66,7 @@ fun ShippingLineFormSection( | |
.clickable( | ||
interactionSource = remember { MutableInteractionSource() }, | ||
indication = null | ||
) { onAdd() }, | ||
) { onAddClicked() }, | ||
tint = MaterialTheme.colors.primary | ||
) | ||
} | ||
|
@@ -75,7 +75,7 @@ fun ShippingLineFormSection( | |
val itemModifier = if (i == 0) Modifier else Modifier.padding(top = 8.dp) | ||
ShippingLineEditCard( | ||
shippingLine = shippingDetails, | ||
onEdit = onEdit, | ||
onEdit = onEditClicked, | ||
formatCurrency = formatCurrency, | ||
modifier = itemModifier | ||
) | ||
|
@@ -182,8 +182,8 @@ fun ShippingLineFormSectionPreview() { | |
ShippingLineFormSection( | ||
shippingLineDetails = shippingDetails, | ||
formatCurrency = { it.toString() }, | ||
onAdd = { }, | ||
onEdit = { } | ||
onAddClicked = { }, | ||
onEditClicked = { } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code would ideally live in the VM so it could be unit tested, however, refactoring it felt like out of scope and bringing inconsistency to the surrounding code feels worse than not having this tested. I'm open to suggestions though.