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

Refactor fetchAllReports in App init #10051

Merged
merged 13 commits into from
Aug 10, 2022
Merged

Conversation

luacmartins
Copy link
Contributor

@luacmartins luacmartins commented Jul 21, 2022

Details

Refactors fetchAllReport

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/213889

Tests

  1. Pull the changes in https://github.com/Expensify/Web-Expensify/pull/34497
  2. Log out and log back in
  3. Verify that OpenApp returns details for your reports report_<id> Onyx keys
  4. Verify that the reports show up in the LHN and that the report names and last messages are correct
  5. Verify that the last read messages are correct.
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (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 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 included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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
  • 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 */
    • Any functional components have the displayName property
    • 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed

  • 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 verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 */
    • Any functional components have the displayName property
    • 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

QA Steps

  • Verify that no errors appear in the JS console

Screenshots

Web

web.mov

Mobile Web

mweb.mov

Desktop

desktop.mov

iOS

ios.mov

Android

android.mov

@luacmartins luacmartins self-assigned this Jul 21, 2022
@luacmartins luacmartins changed the title Refactor fetchAllReports in App init [Hold Web-E #34383] Refactor fetchAllReports in App init Jul 22, 2022
@luacmartins luacmartins marked this pull request as ready for review July 22, 2022 23:18
@luacmartins luacmartins requested a review from a team as a code owner July 22, 2022 23:18
@melvin-bot melvin-bot bot requested review from sketchydroide and removed request for a team July 22, 2022 23:19
@luacmartins luacmartins changed the title [Hold Web-E #34383] Refactor fetchAllReports in App init Refactor fetchAllReports in App init Jul 28, 2022
src/libs/actions/App.js Outdated Show resolved Hide resolved
src/libs/actions/App.js Outdated Show resolved Hide resolved
src/libs/actions/App.js Outdated Show resolved Hide resolved
@luacmartins luacmartins changed the title Refactor fetchAllReports in App init [HOLD] Refactor fetchAllReports in App init Aug 2, 2022
@luacmartins
Copy link
Contributor Author

Need to do more testing. The new waitForCollectionCallback param seems to work, but something is still triggering multiple callbacks. Looking into this next!

@luacmartins
Copy link
Contributor Author

Hmm the logic in the PR is supposedly done, but I'm having some issues testing on android.

Removing this call in getAppData puts us in an infinite spinner at login. More specifically, it seems to be related to this call in fetchChatReportsByIDs 🤔 These are the logs:

 DEBUG  [info] Flushing logs as app is going inactive - {}
 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
 WARN  Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Blob.js -> node_modules/rn-fetch-blob/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/XMLHttpRequest.js -> node_modules/rn-fetch-blob/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Fetch.js -> node_modules/rn-fetch-blob/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
 LOG  Running "NewExpensify" with {"rootTag":61}
 DEBUG  [info] [Migrate Onyx] start - ""
 DEBUG  [info] [Migrate Onyx] Skipped migration MoveToIndexedDB (Not applicable to current platform) - ""
 DEBUG  [info] [Migrate Onyx] Skipped migration RenameActiveClientsKey - ""
 DEBUG  [info] [Migrate Onyx] Skipped migration RenamePriorityModeKey - ""
 DEBUG  [info] [Migrate Onyx] Skipped migration AddEncryptedAuthToken - ""
 DEBUG  [info] [Migrate Onyx] Skipped migration RenameExpensifyNewsStatus - ""
 DEBUG  [info] [Migrate Onyx] finished in 2ms - ""
 DEBUG  [info] [LoadingIndicator] Became visible - {"name":"Navigation Fallback Loader","authenticated":true}
 DEBUG  [info] [LoadingIndicator] Disappeared - {"name":"Navigation Fallback Loader","authenticated":true}
 DEBUG  [info] [NetworkConnection] listenForReconnect called - ""
 DEBUG  [info] [NetworkConnection] NetInfo state change - {"details":{"isConnectionExpensive":false,"subnet":"255.255.255.255","ipAddress":"10.0.2.16","frequency":2447,"strength":99,"bssid":"02:00:00:00:00:00"},"isConnected":true,"type":"wifi","isInternetReachable":true,"isWifiEnabled":true}
 DEBUG  [info] Making API request - {"command":"Get","shouldUseSecure":false,"returnValueList":"userWallet"}
 DEBUG  [info] Making API request - {"command":"OpenApp"}
 DEBUG  [info] Making API request - {"command":"User_FixAccount","shouldUseSecure":false}
 DEBUG  Timing:expensify.cash.homepage_initial_render 64
 DEBUG  [info] [Onyx] set() called for key: network properties: isOffline - ""
 DEBUG  [info] Navigating to route - {"path":"/"}
 DEBUG  [info] [LoadingIndicator] Became visible - {"name":"Main Drawer Loader","initialParams":{"reportID":""}}
 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot convert null value to object
TypeError: Cannot convert null value to object
    at callback (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:222584:37)
    at sendDataToConnection (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:130614:22)
    at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:130647:29)
    at tryCallOne (/tmp/hermes/staging/hermes/cmake/intlDebug/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/tmp/hermes/staging/hermes/cmake/intlDebug/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:30058:26)
    at _callTimer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:29954:17)
    at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:29993:17)
    at callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:30203:44)
    at __callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:5829:46)
    at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:5607:45)
    at __guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:5812:15)
    at flushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:5606:21)
    at invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.expensify.chat&modulesOnly=false&runModule=true:5599:33)
 DEBUG  [hmmm] [Network] Error: Connection interruption likely - {"message":"Network request failed"}
 DEBUG  [info] [NetworkConnection] recheck NetInfo - ""
 DEBUG  [hmmm] [Network] Handled error when making request - {}
 DEBUG  [info] [PusherConnectionManager] unhandled event - {"eventName":"state_change"}
 DEBUG  [info] [PusherConnectionManager] connected event - ""
 DEBUG  [info] [Pusher] Attempting to subscribe to channel - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963","eventName":"reportCommentEdit"}
 DEBUG  [info] [PusherAuthorizer] Attempting to authorize Pusher - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963"}
 DEBUG  [info] Making API request - {"command":"AuthenticatePusher"}
 DEBUG  [info] [Pusher] Attempting to subscribe to channel - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963","eventName":"onyxApiUpdate"}
 DEBUG  [info] [Pusher] Attempting to subscribe to channel - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963","eventName":"preferredLocale"}
 DEBUG  [info] [Pusher] Attempting to subscribe to channel - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963","eventName":"screenshareRequest"}
 DEBUG  [info] Finished API request - {"command":"AuthenticatePusher","jsonCode":200,"requestID":"E5DFlp"}
 DEBUG  [info] [PusherAuthorizer] Pusher authenticated successfully - {"channelName":"private-encrypted-user-accountID-2-22c1653d3f3947f8bef45844d44ae963"}
 DEBUG  [info] Finished API request - {"command":"Get","shouldUseSecure":false,"returnValueList":"userWallet","jsonCode":200,"requestID":"iSe4Pc"}
 DEBUG  [info] [Onyx] set() called for key: userWallet properties: availableBalance,bankAccountID,currentBalance,currentStep,tier,tierName,walletLimit,walletLimitEnforcementPeriod,walletLinkedAccountID,walletLinkedAccountType,shouldShowFailedKYC - ""
 DEBUG  [info] Finished API request - {"command":"User_FixAccount","shouldUseSecure":false,"jsonCode":200,"requestID":"fuwB30"}
 DEBUG  [alrt] ENSURE_BUGBOT [LoadingIndicator] Visible after timeout - {"timeout":15000,"name":"Main Drawer Loader","initialParams":{"reportID":""}}

@luacmartins
Copy link
Contributor Author

Merging main seems to have resolved the issue with android 😕 This is ready for another review!

@luacmartins luacmartins requested a review from tgolen August 8, 2022 18:50
@luacmartins luacmartins changed the title [HOLD] Refactor fetchAllReports in App init Refactor fetchAllReports in App init Aug 8, 2022
src/libs/actions/App.js Outdated Show resolved Hide resolved
@luacmartins
Copy link
Contributor Author

Updated onyx! Ready for another review!

@luacmartins luacmartins requested a review from tgolen August 9, 2022 20:00
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

Are all those changes to the lockfile OK? It's only hashes being updated, which is I think related to m1 macs. It's probably OK?

src/libs/actions/App.js Outdated Show resolved Hide resolved
@luacmartins luacmartins requested a review from tgolen August 9, 2022 22:16
@luacmartins
Copy link
Contributor Author

Updated!

@luacmartins
Copy link
Contributor Author

Are all those changes to the lockfile OK? It's only hashes being updated, which is I think related to m1 macs. It's probably OK?

Yea, I think as long as we are updating from sha1 to sha512 we are good!

@tgolen tgolen merged commit 02f8376 into main Aug 10, 2022
@tgolen tgolen deleted the cmartins-refactorFetchAllReports branch August 10, 2022 15:44
@OSBotify
Copy link
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.

@marcaaron
Copy link
Contributor

Added a comment here, but I think this is introducing a 🐛 when updating policies after the initial load.

To reproduce...

  1. Load all the policies
  2. Create a workspace
  3. Log out value of policyIDList
  4. It will end up as []

Screen Shot 2022-08-10 at 2 00 29 PM


// We should update the syncing indicator when personal details and reports are both done fetching.
return Promise.all([
Report.fetchAllReports(true),
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 #32658

Not loading all reports broke the IOU report previews.

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