-
Notifications
You must be signed in to change notification settings - Fork 3k
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
debounce rate input in reimburse expenses #11967
Conversation
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.
@aimane-chnaif, I found that the user can add non numeric values to the input. Can we fix that?
@thesahindia I don't think it's possible to prevent non-numeric input with debounce. setRate(value) {
const decimalSeparator = this.props.toLocaleDigit('.');
const rateValueRegex = RegExp(String.raw`^\d{1,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{0,3})?$`, 'i');
const isInvalidRateValue = value !== '' && !rateValueRegex.test(value);
+ if (this.props.isShown) {
+ const updatedValue = !isInvalidRateValue ? this.getRateDisplayValue(value) : this.state.unitRateValue;
+ this.setState({unitRateValue: value}, () => {
+ // Set the corrected value with a delay and sync to the server
+ this.updateRateValueDebounced(updatedValue);
+ });
+ } else {
this.setState(prevState => ({
unitRateValue: !isInvalidRateValue ? this.getRateDisplayValue(value) : prevState.unitRateValue,
}), () => {
// Set the corrected value with a delay and sync to the server
this.updateRateValueDebounced(this.state.unitRateValue);
});
+ }
} export default compose(
withLocalize,
+ withKeyboardState,
withNetwork(),
)(WorkspaceReimburseView); So on web/desktop (that doesn't show keyboard), use original logic that don't use debounce. How do you think? |
@aimane-chnaif, I don't like the idea of using two logics just to prevent users from entering non numeric characters. Let me know if you have any other idea. @AndrewGable, what do you think, do we wanna prevent user from entering non numeric characters? After this PR the user will be able to type non numeric chars. If the user refreshes the page or closes the page and comes back then they will see the previous valid value. |
|
Let's wait for @AndrewGable's opinion at #11967 (comment), because I am not 100% sure if we should prevent the user from adding non numeric characters because we also try to not restrict the user from typing something. |
Bump @AndrewGable ^ |
Thanks for the bump, currently we do not allow non-numerical characters to be inserted, so I do not think we should "go back" in a sense. So I think only numbers should allowed to be inserted. |
Let's do it @aimane-chnaif |
@thesahindia one more thing when apply regex:
Which one do you recommend? |
@aimane-chnaif, can you share the screen recording? |
@thesahindia I updated comment above. So allowing multiple dots ( |
Cool, let's move forward with it. |
@@ -236,12 +235,13 @@ class WorkspaceReimburseView extends React.Component { | |||
<TextInput | |||
label={this.props.translate('workspace.reimburse.trackDistanceRate')} | |||
placeholder={this.state.outputCurrency} | |||
onChangeText={value => this.setRate(value)} | |||
onChangeText={value => this.setRate(value.replace(/[^0-9.]/g, ''))} |
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.
I think we should move this logic inside setRate
or let's create a new method where we will replace the non numeric chars and call setRate
inside it with the new value?
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.
I added that logic inline because setRate is called only here. But yes it's better to move this logic inside setRate
After debounce timeout, what output we expect? |
I think the output should be |
@thesahindia ready for review |
Looks good but we have one problem. We are removing Screen.Recording.2022-11-03.at.1.08.31.AM.mov |
@thesahindia Good catch. It was original issue before this PR and now good time to fix it here. |
There's |
The issue is becoming more complex. |
Good point. I think the other option is to use the previous valid value after the debounce timeout. |
This is what I implemented already, isn't it? |
If I only add |
This happens because empty value (after removing dots) is considered as valid rate.
- const isInvalidRateValue = value !== '' && !rateValueRegex.test(value);
+ const isInvalidRateValue = !rateValueRegex.test(value); |
I think it can be a problem, e.g. A user clears the default value and pauses before adding the new value, now the user will have to clear the value again because the previous value will be added again after the timeout. |
@thesahindia ready for review |
ScreenshotsWeb Screen.Recording.2022-11-04.at.3.52.26.PM.movMobile Web - Chrome Screen.Recording.2022-11-04.at.3.45.28.PM.movMobile Web - Safari Screen.Recording.2022-11-04.at.3.51.28.PM.movDesktop Screen.Recording.2022-11-04.at.3.48.00.PM.moviOS Screen.Recording.2022-11-04.at.3.50.02.PM.movAndroid Screen.Recording.2022-11-04.at.3.58.13.PM.movLooks good and tests well! cc: @AndrewGable C+ reviewed 🎀👀🎀
|
@aimane-chnaif, thanks for the changes! |
Bump @AndrewGable |
This comment was marked as off-topic.
This comment was marked as off-topic.
✋ 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 @AndrewGable in version: 1.2.25-0 🚀
|
🚀 Deployed to production by @yuwenmemon in version: 1.2.25-0 🚀
|
Details
Let user keep typing and show raw input value until debounce timeout.
After timeout, fix value and show corrected value accordingly, along with syncing to server
And limit characters length to 12
Fixed Issues
$ #11352
PROPOSAL: #11352 (comment)
Tests
PR Review Checklist
PR Author Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
have been tested & I retested again)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
web.mov
Mobile Web - Chrome
mchrome.mp4
Mobile Web - Safari
msafari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mp4