-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: negative amount in settlement button when the unheld expense comes from self #51209
Conversation
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeMacOS: Chrome / Safari51209-web.mp4 |
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.
LGTM.
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.
Hmm I really don't think this new variable is intuitive.... The name is clear but reading this PR I as myself "Why" everywhere - I think we need a lot more comments 🙏
Do y'all think it's super clear why we pass this everywhere we added it? If not, it's def going to make everyone confused
@Beamanator Can you elaborate which confusion did you face? I think these changes are straight-forward and comments might be redundant. |
@@ -230,7 +230,7 @@ function ReportPreview({ | |||
return ''; | |||
} | |||
|
|||
if (ReportUtils.hasHeldExpenses(iouReport?.reportID) && canAllowSettlement) { | |||
if (ReportUtils.hasHeldExpenses(iouReport?.reportID) && canAllowSettlement && !isNonHeldAmountNegative) { |
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.
Here's an example of something not clear. Why don't we return nonHeldAmount
here if ! isNonHeldAmountNegative
?
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.
@Beamanator As the original issue states, the nonHeldAmount
amount can be negative if we hold a transaction. Since we cannot pay partially in this case, we shouldn't display the nonHeldAmount
as the default option.
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.
That's a great comment for this PR 🙏 Can you please add a comment like that here? & think about the other places you made similar changes - the point is so that other people can read the code & understand why isNonHeldAmountNegative
is needed so they don't have to find the PR that made the change, then find the issue, then read to figure out the context
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.
Added comments.
@mkzie2 Any updates here? |
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.
@mkzie2 A couple of changes required with respect to variable naming which would make it easier to understand the code in context. Thanks.
@@ -122,7 +122,7 @@ function ReportPreview({ | |||
const [isPaidAnimationRunning, setIsPaidAnimationRunning] = useState(false); | |||
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); | |||
const [requestType, setRequestType] = useState<ActionHandledType>(); | |||
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, policy); | |||
const {nonHeldAmount, fullAmount, isNonHeldAmountNegative} = ReportUtils.getNonHeldAndFullAmount(iouReport, policy); |
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.
@mkzie2 Please rename isNonHeldAmountNegative
to hasValidNonHeldAmount
, as this makes more sense in the contexts where the boolean value is being checked.
hasValidNonHeldAmount
should be true
if the nonHeldAmount
value is not negative and is greater than 0
.
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.
Thanks for the great suggestion. I updated.
src/libs/ReportUtils.ts
Outdated
return { | ||
nonHeldAmount: CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * coefficient, iouReport?.currency), | ||
fullAmount: CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), | ||
isNonHeldAmountNegative: (iouReport?.unheldTotal ?? 0) * coefficient < 0, |
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.
Let's rename this to hasValidNonHeldAmount
and add a comment explaining what the value is for. To reiterate, hasValidNonHeldAmount
should be true if the nonHeldAmount
value is not negative and is greater than 0
.
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.
Updated.
I renamed the variable and added comments. |
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.
Thanks for updating to the new variable name (hat top to @akinwale for that idea) - though I think you didn't consider how that affects the rest of the code.
@Beamanator I updated. |
@Beamanator, I tested it when pushing the code. All yours @akinwale. |
@Beamanator Re-tested and confirmed working as expected. |
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.
LGTM.
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.
LGTM
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/Beamanator in version: 9.0.62-0 🚀
|
I tested and it works well. Can you please double-check @akinwale ? Screen.Recording.2024-11-15.at.15.57.02.mov |
🚀 Deployed to production by https://github.com/mountiny in version: 9.0.62-4 🚀
|
Details
Fixed Issues
$ #50497
PROPOSAL: #50497 (comment)
Tests
Total
These expenses are on hold. Do you want to pay anyway?
modal displaysOffline tests
NA
QA Steps
See Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop