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

Allow user to get current location #25990

Merged
merged 29 commits into from
Aug 31, 2023

Conversation

huzaifa-99
Copy link
Contributor

@huzaifa-99 huzaifa-99 commented Aug 26, 2023

Details

Fixed Issues

$ #25855
$ #22707
PROPOSAL: #25855 (comment)

Tests

Prerequisite: Distance request beta must be enabled

  1. Click on Fab -> Request Money -> Press Distance Tab
  2. Click on any waypoint
  3. On the waypoint editor page, click on the "Use current location" button
  4. If location permission is turned off, verify that you see the error -> "It looks like you have denied permission to your location. Please allow location permission in settings and then try again.". Clicking on the "allow location permission in settings" should open https://help.expensify.com/ on web and desktop and app settings on ios/android native.
  5. If location permission is turned on but there is some issue getting location (you can turn off the wifi to emulate this), verify that you see the error => "We were unable to find your location, please try again or enter an address manually".
  6. If location permission is enabled, verify that the address field changes text to "Your Location" and clears any errors on that page and navigates you back to distance page. There you will see the waypoint edited with text 'Your Location' and Mapbox zooming into your location.
  7. Now go to another waypoint editor and try to display the error i.e turn off network then reload page and then click on get current location (you will see the error). Now navigate back and come again to this same page and verify that the error message gets removed when navigated to waypoint editor page.
  • Verify that no errors appear in the JS console

Offline tests

Only step 6 from the "Tests" section above doesn't apply in offline tests. All other steps are same as "Tests" section.

QA Steps

Same as "Tests" section above.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

Chrome:

Web.Chrome.mp4

Safari:

Web.Safari.mp4
Mobile Web - Chrome
mWeb.Chrome.mp4
Mobile Web - Safari
mWeb.Safari.mp4
Desktop
Desktop.mp4
iOS
IOS.Native.mp4
Android
Android.Native.mp4

@huzaifa-99 huzaifa-99 requested a review from a team as a code owner August 26, 2023 11:48
@melvin-bot melvin-bot bot requested review from narefyev91 and removed request for a team August 26, 2023 11:48
@melvin-bot
Copy link

melvin-bot bot commented Aug 26, 2023

@narefyev91 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Aug 26, 2023

@hayata-suenaga @narefyev91 PR is up.

I have some UX questions.

  1. Do we want to clear the location error when the user starts typing in the address search?
  2. When the user sets location with the 'Use current location' button, the address field changes text to "Your Location". When the user revisits the waypoint editor, and presses save, the lat/lng for the waypoint will be changed but the address text will be 'Your Location'. What should be the correct flow in this case? Should we get the current location again and save it?
  3. Similar to 2, if the user changes the "Your Location" text in the address search. What should we do in this case?

To simplify 2 and 3, should we show a form error when the address input has "Your Location" text set manually by the user?

Other considerations

  1. We must add process.env.GOOGLE_API_KEY for the desktop app. This is required to use the navigator.geolocation, docs here. I tested with a token I created and it works there (didn't add the token config in PR, plz lmk if i should)
  2. I think we can just use Linking.openSettings() for ios/android native instead of the getPermissionDeniedHelpLink function from the react-native-x-geolocation lib. I don't think we can get both the ios/android settings links from getPermissionDeniedHelpLink but curious for your suggestions. Addressed here

I will add all test videos soon after these questions are addressed. Just for a reference, this is how it looks like in chrome

Web Chrome
Web.Chrome.mp4

src/libs/actions/User.js Outdated Show resolved Hide resolved
src/ONYXKEYS.ts Outdated Show resolved Hide resolved
@hayata-suenaga
Copy link
Contributor

We must add process.env.GOOGLE_API_KEY for the desktop app. This is required to use the navigator.geolocation, docs here. I tested with a token I created and it works there (didn't add the token config in PR, plz lmk if i should) link

@huzaifa-99 Is this only for desktops?

@hayata-suenaga
Copy link
Contributor

When the user sets location with the 'Use current location' button, the address field changes text to "Your Location". When the user revisits the waypoint editor, and presses save, the lat/lng for the waypoint will be changed but the address text will be 'Your Location'. What should be the correct flow in this case? Should we get the current location again and save it?
Similar to 2, if the user changes the "Your Location" text in the address search. What should we do in this case?

@huzaifa-99 I couldn't quite understand these questions (I'm sorry 😓 ), could you provide videos showing the flow you're describing 🙇 🙇 🙇

@huzaifa-99
Copy link
Contributor Author

We must add process.env.GOOGLE_API_KEY for the desktop app. This is required to use the navigator.geolocation, docs here. I tested with a token I created and it works there (didn't add the token config in PR, plz lmk if i should) link

@huzaifa-99 Is this only for desktops?

Yes the API key is only needed for desktop @hayata-suenaga.

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Aug 26, 2023

When the user sets location with the 'Use current location' button, the address field changes text to "Your Location". When the user revisits the waypoint editor, and presses save, the lat/lng for the waypoint will be changed but the address text will be 'Your Location'. What should be the correct flow in this case? Should we get the current location again and save it?
Similar to 2, if the user changes the "Your Location" text in the address search. What should we do in this case?

@huzaifa-99 I couldn't quite understand these questions (I'm sorry 😓 ), could you provide videos showing the flow you're describing 🙇 🙇 🙇

Apologies, it was for UX and for both 2 and 3 I meant it would look something like the video below. Notice the back-and-forth navigation, and the form error when we try to save the "Your Location" text manually instead of clicking the 'Use Current Location' button.

Video
Screen.Recording.2023-08-27.at.2.40.28.AM.mov

Just wanted to confirm if we should show a form error when the address input has "Your Location" text set manually by the user (again apologies for making it wordy 😅)

cc: @hayata-suenaga

@hayata-suenaga
Copy link
Contributor

thank you @huzaifa-99 for the PR so far. I gonna address your questions on the UX shortly.

I'm working on figuring out the Google API key stuff right now

It's weird that Electron calls the Google geolocation API to get the current location. Do you know why it cannot get the location from the OS directly?

@narefyev91
Copy link
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
8mb.video-ThL-w0cMhEHD.mp4
8mb.video-GOv-6pYhU7kg.mp4
Mobile Web - Chrome
8mb.video-bdE-PCYvj3WV.mp4
Mobile Web - Safari
ios-web1.mov
8mb.video-oIH-0qUvVOse.mp4
Desktop
8mb.video-Qzm-1zM0vjPu.mp4
8mb.video-Djc-8ZLhBau3.mp4
iOS
8mb.video-r0v-sV44FVVD.mp4
Android
8mb.video-OEH-7pFpveOm.mp4

Copy link
Contributor

@narefyev91 narefyev91 left a comment

Choose a reason for hiding this comment

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

LGTM!
I mostly worried about crash - but if it should not be a part of this PR - and all other items are not so important - than we can move forward - in any case get location is working correctly on all platforms
🎀 👀 🎀 C+ reviewed

@melvin-bot melvin-bot bot requested a review from hayata-suenaga August 31, 2023 13:21
@hayata-suenaga
Copy link
Contributor

  • I'd say that this is expected
  • Map is cut on Android WEB -> this is happening on web in general under certain conditions (not specific to this PR)
  • Using the same location will show warning about keys in react -> this is known
  • Even after reloading the app - i still see addresses which i choose - should it be cleared if i move away from request money flow? -> this should be fixed in another PR

Looking good. I'll ask another internal engineer's review just in case 👍

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Aug 31, 2023

Thank you for the feedback @hayata-suenaga.

Using the same location will show warning about keys in react -> this is known

Apologies i didn't knew that, i created a PR for that Expensify/react-native-x-maps#35. I think i oversteped and maybe we can close that PR.

  • I haven't added test videos myself. Will add shortly.

There is one last concern I have. What if someone lives outside of US and uses their current location? Currently we can only add US locations from the search dropdown. So if a user is from outside US and uses their current location and a US location for waypoints, the distance would be big. In certain cases, a user can get "Route exceeds maximum distance limitation" error.

@hayata-suenaga
Copy link
Contributor

There is one last concern I have. What if someone lives outside of US and uses their current location? Currently we can only add US locations from the search dropdown.

This issue is being fixed now and now you can choose address outside US, but I love your attention to details ❤️

Copy link
Contributor

@stitesExpensify stitesExpensify left a comment

Choose a reason for hiding this comment

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

Looking good! Just a couple of questions

.env.production Show resolved Hide resolved
desktop/main.js Outdated Show resolved Hide resolved
@stitesExpensify
Copy link
Contributor

@huzaifa-99 everything is looking good, but I need you to fill out the checklist, and add videos for all platforms please!

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Aug 31, 2023

NAB: I remember there was a discussion somewhere why we cannot use useLocalize. Can someone link to that discussion? (something related to the use of Form component or something)?

ah found this: #25990 (comment)

@huzaifa-99 could you give me more detailed summary of the reason why we couldn't use the HOC after the PR is merged (let's prioritize the merge of the PR first)

@huzaifa-99
Copy link
Contributor Author

@huzaifa-99 everything is looking good, but I need you to fill out the checklist, and add videos for all platforms please!

yes, I am adding those right now @stitesExpensify

@huzaifa-99 could you give me more detailed summary of the reason why we couldn't use the HOC after the PR is merged (let's prioritize the merge of the PR first)

sure. I will add a comment soon after adding videos.

@huzaifa-99
Copy link
Contributor Author

Checklist completed and videos added.

cc: @hayata-suenaga @stitesExpensify

@stitesExpensify stitesExpensify merged commit f604e90 into Expensify:main Aug 31, 2023
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 1.3.61-1 🚀

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

@pecanoro
Copy link
Contributor

pecanoro commented Sep 1, 2023

I am looking into a deploy blocker linked to this but I am just here to note that Spanish translations were not approved by anyone and they are not right 😢

@OSBotify
Copy link
Contributor

OSBotify commented Sep 1, 2023

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.61-3 🚀

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

<View>
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={dismissError}
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #29433.

If the address input is focused, pressing the mouse on this button will trigger blur and hide the autocomplete component, causing this button to move up (layout shift), thus causing the click event to fail to be triggered on this button.

We add onMouseDown={e => e.preventDefault()} to prevent blur event.

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.

8 participants