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

Added option to get user's current location #26546

Merged
merged 59 commits into from
Oct 5, 2023

Conversation

huzaifa-99
Copy link
Contributor

@huzaifa-99 huzaifa-99 commented Sep 2, 2023

Details

This is a follow-up and builds on top of the reverted PR #25990.

In #25990, we added the feature to get the current location for a user. It was merged but the QA team found some issues while on staging.

These were the issues

  1. [Distance] IOU Distance - Recent list disappears after clearing address field, leaving a big space #26482
  2. [Distance] Distance - 'Use current location' does not invoke error message when clicked offline #26478
  3. [Distance] - Unable to use current location once the site location access is denied #26483
  4. [Distance] Request money - Map box not zooming to current location #26485
  5. [$500] [Desktop ONLY] [Distance] - Current location feature is accessible when location access is disabled #26484

And these were the solutions

  1. This issue was originally introduced in Show recent waypoints when selecting address for distance request #25974, but was not detectable because there was no elements under the AddressSearch component, with out changes it became detectable. Backstory -> We added a predefinedSpaces option to AddressSearch component in Show recent waypoints when selecting address for distance request #25974 to show the recently selected waypoints as suggestions in AddressSearch. When the text input in AddressSearch was empty, we were scaling (transform [{scale: 0}]) the address suggestion popover to 0 but the suggestion list was still taking space, causing the big space b/w AddressSearch and Use Current Location button. In this PR, we are showing the suggestion list even if the text input is empty, this is because we are giving predefined spaces to AddressSearch. (I suggested this here as option 1)
  2. We are now blocking the 'Use current location' button when the user is offline (discussion here)
  3. This is an issue with Chrome, explained in this comment. The original ticket was closed.
  4. Map panning fix (2) #26500 seems to have fixed this (more context) - It was not related to our changes but I have still shown its working in test videos.
  5. We removed the desktop-specific direct API call to geolocation and are now using navigator with the hardcoded token, discussion here

Fixed Issues

$ #25855
PROPOSAL: #25855 (comment)

Tests

  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. Native Android/IOS Only - If the native system GPS/location is disabled, you click on the 'Use current location' button. Verify that you see a system-wide location enable prompt. Accepting it would enable your mobile location/GPS and lead you to either step 8 or 9. Rejecting it would show the error mentioned in step 7.
  5. Native Android Only - Repeated clicks on the "Use current location" button should show the location enable prompt if the system-wide location is disabled
  6. Native IOS Only - After the app install, the initial click on the "Use current location" button should show the location enable prompt if the system-wide location is disabled. Repeated clicks will show the error mentioned in step 7 if the location is disabled.
  7. If app-specific location permission is disabled, 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" text should open https://help.expensify.com/ in a new tab on the web/desktop and open app-specific settings on native iOS/Android.
  8. If location permission is enabled but there is some issue getting the location, verify that you see the error => "We were unable to find your location, please try again or enter an address manually". To emulate this we can make our network speed extremely slow so we get a timeout issue and in turn the error or set the timeout to a lower value manually in code and test.
  9. If location permission is enabled, verify that the address field changes the text to "Your Location", and clears any errors on that page, and navigates you back to the distance page. Verify the waypoint edited with the text 'Your Location' and Mapbox zooming into your location.
  10. Try to get an error as mentioned in steps 7 and 8. After you get that, navigate back, come again to this same waypoint editor page, and verify that the error message gets removed when navigating again.
  11. Again go to a waypoint editor, open the address search, and confirm that the 'Your location' text does not appear in the suggestions.
  12. Go to any waypoint editor, and select an address from the suggestion (you will be navigated to the distance request screen). Now go to the same waypoint again, select the address text, and remove it. Verify that there are no large spaces b/w the address search input and the 'Use current location' button.
  13. Go to any waypoint editor, type some address, and select it from suggestions (you will be navigated back to the distance request screen). Verify that you see the map zooming into the selected location
  14. Go to any waypoint editor and turn off the network. Verify that the 'Use current location' button is grayed out and is not clickable.

Important:

  • On Chrome after disabling and then re-enabling location permission, the browser might still say that you have location permission disabled, in this case you would have to either close and reopen the tab or reset website permissions.

  • We have to reload the page, whenever we change location permissions in Web/mWeb Chrome/Safari.

  • If testing mWeb Safari in an IOS stimulator, when you disable the location permissions then it's very hard to get safari in the stimulator to allow location permissions (changing the settings does nothing most of the time). A reliable way is to reset the stimulator (I have shown this in the mWeb Safari test video). However, on a real iOS device with Safari, changing the settings works and we don't have to do extreme steps for it to work.

  • For iOS/Android, please test on a physical device.

  • Verify that no errors appear in the JS console

Offline tests

Only steps 9, 11, 12, and 13 don't apply to offline behaviour. All other steps are the same as in the "Tests" section above.

QA Steps

Same as the "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
    • 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.Native.mp4
iOS
IOS.Native.mp4
Android
Android.Native.mp4

@huzaifa-99 huzaifa-99 requested a review from a team as a code owner September 2, 2023 02:03
@melvin-bot melvin-bot bot removed the request for review from a team September 2, 2023 02:03
@melvin-bot
Copy link

melvin-bot bot commented Sep 2, 2023

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@melvin-bot
Copy link

melvin-bot bot commented Sep 2, 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]

@melvin-bot melvin-bot bot requested a review from narefyev91 September 2, 2023 02:03
@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Sep 2, 2023

Some questions:

  1. In Show recent waypoints when selecting address for distance request #25974, we added the feature to display recently selected waypoint in the AddressSearch component, but in the PR, we are supporting the current location, so when ever current location is used, the address search will show 'Your Location' as a suggested option, Should we filter it form the suggestion list?
Screenshots image
  1. Should we display a "You appear to be offline" message on this page?
Screenshots image
  1. How do we want the error text size/color to be displayed?
Screenshots image image
  1. This one about getCurrentLocation() config.
  2. This one about the getCurrentLocation.desktop.ts implementation.

cc: @hayata-suenaga

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Sep 2, 2023

@huzaifa-99 Great clarifying questions and hard work 🚀 I answered your questions below 🙇

  1. In Show recent waypoints when selecting address for distance request #25974, we added the feature to display recently selected waypoint in the AddressSearch component, but in the PR, we are supporting the current location, so when ever current location is used, the address search will show 'Your Location' as a suggested option, Should we filter it form the suggestion list?

Is the location associated with "Your Location" suggestion is the location when the user last used the current location option?
Yes I think we need to either filter out that option or make sure that current location is not saved as a recently-used address.

  1. Should we display a "You appear to be offline" message on this page?

I'm asking the internal product team about this. I'll get back to you once they decide on this 🙇

  1. How do we want the error text size/color to be displayed?

I believe the left one is the current one? Where did you come up with the right choice / text?

  1. This one about getCurrentLocation() config.
  2. This one about the getCurrentLocation.desktop.ts implementation.

I answered questions in the respective comments 🙇

@huzaifa-99
Copy link
Contributor Author

Is the location associated with "Your Location" suggestion is the location when the user last used the current location option?

Yes

I think we need to either filter out that option or make sure that current location is not saved as a recently-used address.

We can do any of that, I think not saving it as a recently used address might be better if that sounds good?. To do this we have to avoid running this logic when the user is using the current location

const recentWaypointAlreadyExists = _.find(recentWaypoints, (recentWaypoint) => recentWaypoint.address === waypoint.address);
if (!recentWaypointAlreadyExists) {
const clonedWaypoints = _.clone(recentWaypoints);
clonedWaypoints.unshift(waypoint);
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, clonedWaypoints.slice(0, 5));
}

If we want to filter it, its also simple and we can do it here.

I will wait for your suggestion here to proceed. @hayata-suenaga

Where did you come up with the right choice / text?

I actually copied it from the OfflineWithFeedback text. Apologies for asking this, but i don't have access to the docs file, so manually confirming details from you.

src/ONYXKEYS.ts Outdated Show resolved Hide resolved
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.

A few comments.

src/components/LocationErrorMessage/index.js Outdated Show resolved Hide resolved
src/components/LocationErrorMessage/index.native.js Outdated Show resolved Hide resolved
src/components/UserCurrentLocationButton.js Outdated Show resolved Hide resolved
src/components/UserCurrentLocationButton.js Outdated Show resolved Hide resolved
src/components/UserCurrentLocationButton.js Outdated Show resolved Hide resolved
src/libs/getCurrentPosition/getCurrentPosition.native.ts Outdated Show resolved Hide resolved
@huzaifa-99
Copy link
Contributor Author

Thank you for the feedback @parasharrajat. I have addressed your comments above and also left some questions here 1, 2 and 3.

src/libs/actions/Transaction.ts Show resolved Hide resolved
src/libs/getCurrentPosition/index.android.ts Outdated Show resolved Hide resolved
@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Oct 2, 2023

There was a package-lock conflict again. To be sure, I merged and retested Android again, and it still works. Bumping for final review @hayata-suenaga.

@hayata-suenaga
Copy link
Contributor

Testing on chrome

Screen.Recording.2023-10-03.at.9.15.51.AM.mov

@huzaifa-99 I thought the design decision was not to use the whole page blocking loader

@hayata-suenaga
Copy link
Contributor

@huzaifa-99 while testing on desktop, I realized that I cannot click the "+" icon in the text composer.

The issue is also present on chrome. Can you retest and confirm? Maybe pulling the latest main will fix it?

Screen.Recording.2023-10-03.at.9.19.47.AM.mov

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Oct 3, 2023

I'm having trouble testing on iOS (the app thinks the device is offline when it's not), but I was at least able to confirm that I can click the "+" icon of the text composer on iOS

Screen.Recording.2023-10-03.at.9.45.31.AM.mov

@huzaifa-99
Copy link
Contributor Author

@huzaifa-99 I thought the design decision was not to use the whole page blocking loader

Yes, originally it was suggested but i think we ignored it in favour of merging,
#26546 (comment), #26546 (comment), #26546 (comment)

@huzaifa-99 while testing on desktop, I realized that I cannot click the "+" icon in the text composer. The issue is also present on chrome. Can you retest and confirm? Maybe pulling the latest main will fix it?

Hm, I think it was an issue on main, I merged main and tested on web chrome / desktop / android native / ios native and the "+" icon in composer works there.

cc: @hayata-suenaga

@huzaifa-99
Copy link
Contributor Author

@hayata-suenaga gentle bump for review.

@parasharrajat
Copy link
Member

Can we please merge this PR before there are more conflicts? We can create follow-up PRs if something gets missed which I think is very unlikely.

onPress={onAllowLocationLinkPress}
style={styles.locationErrorLinkText}
>
{` ${translate('location.allowPermission')} `}
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: we should use padding instead of spaces

Copy link
Member

Choose a reason for hiding this comment

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

Spaces work better when text wraps the next lines as they can be collapsed.


// If current location is used, we would want to avoid saving it as a recent waypoint. This prevents the 'Your Location'
// text from showing up in the address search suggestions
if (isEqual(waypoint?.address, CONST.YOUR_LOCATION_TEXT)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Why is lodash used here? Wouldn't === work just as well? It's only comparing two strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, don't we have an eslint rule for TS that says we prefer not to use lodash or underscore?

@tgolen
Copy link
Contributor

tgolen commented Oct 5, 2023

I will approve and merge this as-is. If you choose to correct the few things I pointed out, please submit a follow-up PR to fix them.

@tgolen tgolen dismissed pecanoro’s stale review October 5, 2023 15:09

To get this merged

@tgolen tgolen merged commit 1c1d8b1 into Expensify:main Oct 5, 2023
16 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Oct 5, 2023

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

@DylanDylann
Copy link
Contributor

@huzaifa-99 I think the "Use your location" button should display in the above suggestion list as designed here: #27165 (comment)

cc @trjExpensify

@OSBotify
Copy link
Contributor

OSBotify commented Oct 6, 2023

🚀 Deployed to staging by https://github.com/tgolen in version: 1.3.79-0 🚀

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

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Oct 6, 2023

@DylanDylann lets followup in the ticket here

@OSBotify
Copy link
Contributor

OSBotify commented Oct 9, 2023

🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Oct 9, 2023

🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 cancelled 🔪
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Oct 9, 2023

🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 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.

10 participants