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

IOU - Localize amount text input #7221

Merged
merged 7 commits into from
Jan 19, 2022

Conversation

songlang1994
Copy link
Contributor

@songlang1994 songlang1994 commented Jan 14, 2022

Details

IOU - Localize amount text input. Users will be able to type/paste localized amount format in amount input. See also: #6427 (comment)

Fixed Issues

$ #6427

Tests

  1. Go to preference set language to "Español"
  2. Request money from chats list
  3. Verify that the virtual keypad on mobile shows localized digits.
  4. Verify that localized amount text can be typed with virtual keypad on mobile.
  5. Verify that localized amount text can be typed with hardware keyboard on desktop.
  6. Verify that localized amount text can be pasted.

QA Steps

Same as above.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web-1

web-2

web-3

Mobile Web

mobile-web-1

mobile-web-2

mobile-web-3

Desktop

desktop-1

desktop-2

desktop-3

iOS

ios-1

ios-2

ios-3

Android

android-1

android-2

android-3

@songlang1994 songlang1994 requested a review from a team as a code owner January 14, 2022 11:59
@MelvinBot MelvinBot requested review from Luke9389 and parasharrajat and removed request for a team January 14, 2022 11:59
@songlang1994 songlang1994 force-pushed the iou-amount-localization branch from 59b21ae to 55b2372 Compare January 15, 2022 06:06
Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good so far. Giving some styling suggestions.

src/libs/LocaleDigitUtils.js Outdated Show resolved Hide resolved
src/libs/LocaleDigitUtils.js Outdated Show resolved Hide resolved
src/libs/LocaleDigitUtils.js Outdated Show resolved Hide resolved
src/libs/NumberFormatUtils/index.native.js Outdated Show resolved Hide resolved
Comment on lines 131 to 142
isValidLocaleDigit(digit) {
return LocaleDigitUtils.isValidLocaleDigit(this.props.preferredLocale, digit);
}

toLocaleDigit(digit) {
return LocaleDigitUtils.toLocaleDigit(this.props.preferredLocale, digit);
}

fromLocaleDigit(localeDigit) {
return LocaleDigitUtils.fromLocaleDigit(this.props.preferredLocale, localeDigit);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of any other place in the app that will use these functions so I don't think it is a good idea to pollute the WithLocalize context at this time. Maybe directly use them in the IOUAmountPage for now and pass the locale from this.props.preferredLocale. We can refactor these in future if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently toLocaleDigit is also used by BigNumberPad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I cleaned up the isValidLocaleDigit function because it's not used. So only toLocaleDigit and fromLocaleDigit is added in that context.

src/pages/iou/steps/IOUAmountPage.js Outdated Show resolved Hide resolved
src/pages/iou/steps/IOUAmountPage.js Show resolved Hide resolved
@songlang1994 songlang1994 changed the title [WIP] IOU - Localize amount text input IOU - Localize amount text input Jan 15, 2022
src/pages/iou/steps/IOUAmountPage.js Outdated Show resolved Hide resolved
src/pages/iou/steps/IOUAmountPage.js Outdated Show resolved Hide resolved
}

render() {
const formattedAmount = this.replaceAllDigits(this.state.amount, this.props.toLocaleDigit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just use, numberFormat prop directly for the whole input value?

Copy link
Contributor Author

@songlang1994 songlang1994 Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't. Because the amount might not be a valid number yet while inputing (e.g. "12.").

If we do need to use numberFormat the code will be

get formattedInputingAmount() {
    if (!this.state.amount) {
        return '';
    }

    const endsWithDecimalPoint = this.state.amount.endsWith('.');
    if (endsWithDecimalPoint) {
        const localized = this.props.numberFormat(this.state.amount, {useGrouping: false, minimumFractionDigits: 1});
        return localized.slice(0, -1);
    }

    const fraction = this.state.amount.split('.')[1];
    const fractionDigits = fraction ? fraction.length : 0;
    return this.props.numberFormat(this.state.amount, {useGrouping: false, minimumFractionDigits: fractionDigits});
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. What is more performant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no performance issue here since the max length of amount is just 8. But replaceAllDigits here is more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds, good. I will give it a go.

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Looks good.
But when I selected Spanish, I have to type , on my keyboard. Is this behavior correct? or should it be like.. you type . and , is shown to the user when the selected language is Spanish.

@songlang1994
Copy link
Contributor Author

But when I selected Spanish, I have to type , on my keyboard.

@parasharrajat That's the expected behavior of current implementation. Maybe you would like to double check it by asking a native Spanish user.

@parasharrajat
Copy link
Member

ok. Thanks. I will ask @Luke9389 to test it and then decide.

@parasharrajat
Copy link
Member

@Luke9389 I have a question above. Thanks.

@Luke9389
Copy link
Contributor

I think needing to type , is totally fine. That's what you'd do if you were expecting a comma, right?

@Luke9389
Copy link
Contributor

I think it'd be really frustrating for users to by typing one thing, and then have a totally different character show up.

@parasharrajat
Copy link
Member

@songlang1994 You got some conflicts to resolve.

@songlang1994
Copy link
Contributor Author

Should I use git rebase then force-push or git merge to resolve the conflicts?

@parasharrajat
Copy link
Member

Git merge and resolve conflicts manually.

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. LGTM. Good work @songlang1994 .

cc: @Luke9389
🎀 👀 🎀 C+ reviewed

Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I was about to approve this yesterday but wanted to adhere to the Contributor+ structure. Great work both of you @songlang1994 @parasharrajat. 👍

@Luke9389 Luke9389 merged commit dcd2882 into Expensify:main Jan 19, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @Luke9389 in version: 1.1.31-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @AndrewGable in version: 1.1.32-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants