Refactor Policy_CustomUnit_Update#10374
Conversation
|
Updated and ready for re-reviews |
chiragsalian
left a comment
There was a problem hiding this comment.
-
When i refresh and then open settings -> reimburse expenses i see this error which you might want to address.

-
Can you make a follow up to remove
CustomUnitfrom onyx, this way we only keep CustomUnits. It can be confusing to have both.

-
There is problem with
WorkspaceReimburseViewrender. So this is how i tested. I have one regular chrome window signed into my account. I have another incognito window signed into the same account. So now from my first window when i change some value i would expect the same update in the incognito window (because its a push notification to both accounts). So for the incognito window i see the onyx value updating which means web-e works well but the UI didn't update to match the same.

(Notice attributes unit is "km" but in the UI its showing "miles")
Done! I had the wrong syntax for defining the
Good idea - https://github.com/Expensify/Expensify/issues/224464
Good catch. When I was initially testing, I noticed the API was being called twice so I put in if (value === this.state.unitValue) {
return;
}to stop that from happening. However, I forgot that React double invokes functions in Strict Mode, so that is actually expected in local dev. So I've removed that early return and I'm seeing the UI update correctly now. |
| <Picker | ||
| label={this.props.translate('workspace.reimburse.trackDistanceUnit')} | ||
| items={this.unitItems} | ||
| value={this.state.unitValue} |
There was a problem hiding this comment.
Talking about point 3 from your response
There is problem with WorkspaceReimburseView render.
Its still not resolved. I believe its because you have a state variable here. So when the value is updated in props the constructor is not rerun to update this unitValue.
Check out this video to see if it helps,
I have newDot open in two windows, i update the custom unit value in one window and while its onyx is updating in the second window its UI is not.
Screen.Recording.2022-08-24.at.11.05.03.AM.mov
I think you might need to use getDerivedStateFromProps for your usecase where you update this state value only if lodashGet(distanceCustomUnit, 'attributes.unit') has changed.
There was a problem hiding this comment.
Okay, got it for real for real this time. Thanks for explaining that further and pointing me in the right direction.
10374-custom-unit.mov
chiragsalian
left a comment
There was a problem hiding this comment.
LGTM and works well. Left one question for you.
| const distanceCustomUnit = _.find(lodashGet(props, 'policy.customUnits', {}), unit => unit.name === 'Distance'); | ||
| const unitValue = lodashGet(distanceCustomUnit, 'attributes.unit', 'mi'); | ||
|
|
||
| if (!state.unitValue || (unitValue !== state.unitValue)) { |
There was a problem hiding this comment.
This !state.unitValue doesn't look right. How can state.unitValue not have a value? I don't think this is run before constructor but correct me if i'm mistaken.
There was a problem hiding this comment.
Mm yeah good callout. I was being overly cautious but yeah thinking about it further it isn't needed, as getDerivedStateFromProps runs before the render method, and we've got a fallback value for state.unitValue. I'll create a quick PR to remove it
|
✋ 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 @chiragsalian in version: 1.1.92-0 🚀
|
Was held on the production deploy of the Web-E PR (https://github.com/Expensify/Web-Expensify/pull/34587), which has now been deployed.
Details
Refactor of Policy_CustomUnit_Update
Fixed Issues
https://github.com/Expensify/Expensify/issues/215182
Tests
Success case
Error case (with RBR)
This requires a bit of manual work for testing:
Onyx.merge('policy_B7F58A2F61A9389C', {customUnits: {'628e77618f113': {errors: {1: "Your changes couldn't be saved. The workspace was modified while you were offline, please try again."}}}});(whereB7F58A2F61A9389Cis the name of the policy you're testing and628e77618f113is the ID of the Distance custom unit - you can obtain these by going in Dev Tools to Application > Onyx > keyvaluepairs > find the policy data for the workspace ID that is in your URL)PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*filesSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)PR Reviewer Checklist
The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed
### Fixed Issuessection aboveTestssectionQA stepssectiontoggleReportand notonIconClick).src/languages/*filesSTYLE.md) were followedAvatar, I verified the components usingAvatarhave been tested & I retested again)/** comment above it */displayNamepropertythisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)QA Steps
Screenshots
Web
Mobile Web
Desktop
10374-desktop.mov
iOS
10374-ios.mp4
Android
10374-android.mov