Skip to content

Add new capability to set tracking rate and unit#6839

Merged
deetergp merged 10 commits into
Expensify:mainfrom
marktoman:add-tracking-unit-capability
Feb 3, 2022
Merged

Add new capability to set tracking rate and unit#6839
deetergp merged 10 commits into
Expensify:mainfrom
marktoman:add-tracking-unit-capability

Conversation

@marktoman

@marktoman marktoman commented Dec 20, 2021

Copy link
Copy Markdown
Contributor

Details

Fixed Issues

$ #6213

Tests and QA Steps

Action 1

Steps
  1. Click the profile icon
  2. Go to Workspace
Result

The menu item is named "Reimburse expenses"

Action 2

Steps
  1. Click the profile icon
  2. Go to Workspace
  3. Go to Reimburse expenses
  4. Change Rate and Unit
  5. Reload
Result

Values are preserved

Action 3

Steps
  1. Repeat Action 2
  2. Log out and delete local storage
  3. Log in and go to Reimburse expenses
Result

Values are preserved

Action 4

Steps
  1. Log in to an account that has no custom Unit or Rate set
  2. Go to Reimburse expenses
Result

Miles is the value in Unit

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

image

Mobile Web

Screenshot_1641563068

Desktop

iOS

Android

@marktoman marktoman requested a review from a team as a code owner December 20, 2021 18:26
@MelvinBot MelvinBot requested review from deetergp and removed request for a team December 20, 2021 18:26
@deetergp

Copy link
Copy Markdown
Contributor

Hey @marktoman 👋 Just want to point out there's a merge conflict and I'm waiting on testing instructions. Once you've added those I will review it. I also know it's the holidays, so no worries if you don't get to it till afterwards.

@trjExpensify

Copy link
Copy Markdown
Contributor

Hi @marktoman - happy new year! Can you provide us with an ETA on fixing the merge conflict and adding the testing steps for @deetergp, please? It would be great to have this squared away this week if we can!

@marktoman

Copy link
Copy Markdown
Contributor Author

Happy new year to you guys as well!

I have updated the instruction and QA steps. Unfortunately, it does not build on windows for some reason, so I am not able to provide more platforms.

@deetergp

deetergp commented Jan 13, 2022

Copy link
Copy Markdown
Contributor

Heya Mark, thank you for adding the instructions and screenshots, it makes life easier for everyone.

Going through the testing steps, I'm experiencing issues with the settings persistence. If I Change the rate to 68 and units to kilometers the settings will persist after page refreshes. But if I log out and then back in and go back to the settings, the rate defaults to 0 and the units back to Miles. This is on web. The results are the same if I clear out local storage between logging out and then back in.

@marktoman

Copy link
Copy Markdown
Contributor Author

Hi Scott, thank you for the review. I can replicate the problem.

The issue is caused by withFullPolicy not calling Policy.loadFullPolicy when you log in. The following check returns false: !isPreviousRouteInSameWorkspace(currentRoute.name, policyID).

All other scenarios seem to work, e.g.: Log out & in > refresh the page > navigate to Reimburse expenses. (It fetches the latest values and displays them correctly.)

Do you think I should find a workaround like calling Policy.loadFullPolicy directly from Reimburse expenses, or should this be somehow solved in withFullPolicy itself, given the name does not represent its behavior for this scenario?

@deetergp

Copy link
Copy Markdown
Contributor

@marktoman Great questions! Since it looks like you've got some merge conflicts around Policy.js, let's resolve those first and re-test to see we don't get lucky and fix our problem.

@marktoman

Copy link
Copy Markdown
Contributor Author

@deetergp Merged and tested again — sadly no luck.

@marktoman

Copy link
Copy Markdown
Contributor Author

@deetergp I have made it work the following way:

  1. Set a flag in SignInRedirect.js > clearStorageAndRedirect > Onyx.clear().then: Onyx.merge(ONYXKEYS.SESSION, {myFlag: true});
  2. In WithFullPolicy, changed the condition to: ... (props.session.myFlag || !isPreviousRouteInSameWorkspace(currentRoute.name, policyID))
  3. If true, reset: Onyx.merge(ONYXKEYS.SESSION, {myFlag: false});

@marktoman

Copy link
Copy Markdown
Contributor Author

Hi Scott, curious about your opinion. I consider the second solution cleaner because it does not require adding sessions to withFullPolicy and solves the general policy problem for future use cases as well. Both solutions work.

@deetergp deetergp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall it looks good and passes tests, thanks for sorting it out. I had a few minor requests mostly around variable declarations that only get used once and are unnecessary.

Comment thread src/libs/actions/Policy.js Outdated
updateLocalPolicyValues(policyID, {customUnit: localCustomUnit});
}).catch(() => {
// Show the user feedback
const errorMessage = Localize.translateLocal('workspace.editor.genericFailureMessage');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The errorMessage variable isn't really necessary, just call Localize.translateLocal inside the growl error.

Comment thread src/libs/actions/Policy.js Outdated
* @param {Object} values
*/
function setCustomUnit(policyID, values) {
const payload = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No real need for this variable, just define this object inside the call to API.Policy_CustomUnit_Update.

Comment thread src/libs/actions/Policy.js Outdated
throw new Error();
}

const localCustomUnit = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary variable, define in the function call.

Comment thread src/libs/actions/Policy.js Outdated
* @param {Object} values
*/
function setCustomUnitRate(policyID, customUnitID, values) {
const payload = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary variable declaration

Comment thread src/libs/actions/Policy.js Outdated
throw new Error();
}

const localCustomUnitRate = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary variable declaration

Comment thread src/libs/actions/Policy.js Outdated
updateLocalPolicyValues(policyID, {customUnit: {rate: localCustomUnitRate}});
}).catch(() => {
// Show the user feedback
const errorMessage = Localize.translateLocal('workspace.editor.genericFailureMessage');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary variable declaration


this.setState({rateValue: numValue.toString()});

const values = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You only use this once, you don't need it.

setUnit(value) {
this.setState({unitValue: value});

const values = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same

@deetergp

Copy link
Copy Markdown
Contributor

Oh, and one other thing, let's make sure we are showing the second 0 when displaying the rates. 3.50 showed up as 3.5
Screen Shot 2022-01-28 at 3 14 59 PM

deetergp
deetergp previously approved these changes Feb 3, 2022

@deetergp deetergp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Thanks for the changes!

@deetergp

deetergp commented Feb 3, 2022

Copy link
Copy Markdown
Contributor

@marktoman Your changes look good, but there's one slight snag: two of your four most recent commits (04bac5c & 93a37f2) contain unverified signatures which prevent me from being able to merge it.
Screen Shot 2022-02-03 at 11 29 10 AM

I think the right way to fix this will be to do the following (I HIGHLY recommend testing it on a copy of your branch first just to be safe):

  1. Make a backup branch!
  2. Do a hard reset back to 1b398a5, your last commit before these changes
  3. Merge main back into your branch with a signed & verified account
  4. Cherry pick 0857ed6 from your backup branch (You shouldn't need to CP 56832ee)
  5. Force push the changes.

Because the changes are after the last review, it shouldn't mess with the PR history adversely.

@marktoman

Copy link
Copy Markdown
Contributor Author

@deetergp Thank you for all your help on this issue!

@deetergp deetergp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! Thanks for sticking with it, @marktoman!

@deetergp deetergp merged commit 16d38de into Expensify:main Feb 3, 2022
@OSBotify

OSBotify commented Feb 3, 2022

Copy link
Copy Markdown
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

OSBotify commented Feb 4, 2022

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by @deetergp in version: 1.1.36-0 🚀

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

@OSBotify

OSBotify commented Feb 7, 2022

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.36-0 🚀

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

@trjExpensify

Copy link
Copy Markdown
Contributor

Added a comment to the linked issue here, but I think we're displaying the decimals in the wrong place in the workspace editor setting.

Comment thread src/languages/es.js
Comment on lines +767 to +774
kilometers: '',
miles: '',
viewAllReceipts: 'Ver todos los recibos',
reimburseReceipts: 'Reembolsar recibos',
trackDistance: '',
trackDistanceCopy: '',
trackDistanceRate: '',
trackDistanceUnit: '',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is wrong, you need to complete the translations for this language.
Since it was not done, it generated a few alerts. I am going to post them in the original issue so you can get them fixed @marktoman.
@deetergp you should've not merged this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lo siento! 😬 Not sure how I missed that but will get some translations to Mark Toman, so he can add them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the translations have already been added in main
Screen Shot 2022-02-17 at 9 22 00 AM

Is that all that was missing to fix those BugBot issues?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh did not see that, I just saw the bugbot issues and assumed it was still happening. Curious where were they added?
And yes, that's all we need to do to fix the issues.

@deetergp deetergp Feb 17, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll close them as my penance. The changes were added in this commit by @PrashantMangukiya, whom I now owe a 🍺.

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.

5 participants