diff --git a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js index 701a9bca70a7..561b8e61bc21 100644 --- a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js @@ -207,10 +207,7 @@ function fetchTag(tag) { console.log(`Running command: ${command}`); execSync(command); } catch (e) { - // This can happen if the tag was only created locally but does not exist in the remote. In this case, we'll fetch history of the staging branch instead - const command = `git fetch origin staging --no-tags --shallow-exclude=${previousPatchVersion}`; - console.log(`Running command: ${command}`); - execSync(command); + console.error(e); } } @@ -301,13 +298,14 @@ function getValidMergedPRs(commits) { * @returns {Promise>} – Pull request numbers */ function getPullRequestsMergedBetween(fromTag, toTag) { + console.log(`Looking for commits made between ${fromTag} and ${toTag}...`); return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => { console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList); // Find which commit messages correspond to merged PR's const pullRequestNumbers = getValidMergedPRs(commitList); console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers); - return pullRequestNumbers; + return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10)); }); } diff --git a/.github/actions/javascript/getDeployPullRequestList/index.js b/.github/actions/javascript/getDeployPullRequestList/index.js index def58d95e846..e42f97508bc5 100644 --- a/.github/actions/javascript/getDeployPullRequestList/index.js +++ b/.github/actions/javascript/getDeployPullRequestList/index.js @@ -170,10 +170,7 @@ function fetchTag(tag) { console.log(`Running command: ${command}`); execSync(command); } catch (e) { - // This can happen if the tag was only created locally but does not exist in the remote. In this case, we'll fetch history of the staging branch instead - const command = `git fetch origin staging --no-tags --shallow-exclude=${previousPatchVersion}`; - console.log(`Running command: ${command}`); - execSync(command); + console.error(e); } } @@ -264,13 +261,14 @@ function getValidMergedPRs(commits) { * @returns {Promise>} – Pull request numbers */ function getPullRequestsMergedBetween(fromTag, toTag) { + console.log(`Looking for commits made between ${fromTag} and ${toTag}...`); return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => { console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList); // Find which commit messages correspond to merged PR's const pullRequestNumbers = getValidMergedPRs(commitList); console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers); - return pullRequestNumbers; + return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10)); }); } diff --git a/.github/libs/GitUtils.js b/.github/libs/GitUtils.js index ba9d7fa2b38a..7bc600470dd1 100644 --- a/.github/libs/GitUtils.js +++ b/.github/libs/GitUtils.js @@ -22,10 +22,7 @@ function fetchTag(tag) { console.log(`Running command: ${command}`); execSync(command); } catch (e) { - // This can happen if the tag was only created locally but does not exist in the remote. In this case, we'll fetch history of the staging branch instead - const command = `git fetch origin staging --no-tags --shallow-exclude=${previousPatchVersion}`; - console.log(`Running command: ${command}`); - execSync(command); + console.error(e); } } @@ -116,13 +113,14 @@ function getValidMergedPRs(commits) { * @returns {Promise>} – Pull request numbers */ function getPullRequestsMergedBetween(fromTag, toTag) { + console.log(`Looking for commits made between ${fromTag} and ${toTag}...`); return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => { console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList); // Find which commit messages correspond to merged PR's const pullRequestNumbers = getValidMergedPRs(commitList); console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers); - return pullRequestNumbers; + return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10)); }); } diff --git a/.github/workflows/finishReleaseCycle.yml b/.github/workflows/finishReleaseCycle.yml index b78a5fac4b69..7b71f6263c88 100644 --- a/.github/workflows/finishReleaseCycle.yml +++ b/.github/workflows/finishReleaseCycle.yml @@ -119,31 +119,3 @@ jobs: uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main with: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - - # Create a new StagingDeployCash for the next release cycle. - createNewStagingDeployCash: - runs-on: ubuntu-latest - needs: [updateStaging, createNewPatchVersion] - steps: - - uses: actions/checkout@v3 - with: - ref: staging - token: ${{ secrets.OS_BOTIFY_TOKEN }} - - # Create a local git tag so that GitUtils.getPullRequestsMergedBetween can use `git log` to generate a - # list of pull requests that were merged between this version tag and another. - # NOTE: This tag is only used locally and shouldn't be pushed to the remote. - # If it was pushed, that would trigger the staging deploy which is handled in a separate workflow (deploy.yml) - - name: Tag version - run: git tag ${{ needs.createNewPatchVersion.outputs.NEW_VERSION }} - - - name: Create new StagingDeployCash - uses: Expensify/App/.github/actions/javascript/createOrUpdateStagingDeploy@main - with: - GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - NPM_VERSION: ${{ needs.createNewPatchVersion.outputs.NEW_VERSION }} - - - if: ${{ failure() }} - uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main - with: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index 84f8373ff247..400a0d4364fe 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -28,6 +28,25 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} + # Note: we're updating the checklist before running the deploys and assuming that it will succeed on at least one platform + deployChecklist: + name: Create or update deploy checklist + runs-on: ubuntu-latest + needs: validateActor + steps: + - uses: actions/checkout@v3 + - uses: Expensify/App/.github/actions/composite/setupNode@main + + - name: Set version + id: getVersion + run: echo "VERSION=$(npm run print-version --silent)" >> "$GITHUB_ENV" + + - name: Create or update staging deploy + uses: Expensify/App/.github/actions/javascript/createOrUpdateStagingDeploy@main + with: + GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} + NPM_VERSION: ${{ steps.getVersion.outputs.VERSION }} + android: name: Build and deploy Android needs: validateActor diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index c9fb636238aa..e3977734fc50 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -98,25 +98,6 @@ jobs: # Force-update the remote staging branch git push --force origin staging - # Create a local git tag on staging so that GitUtils.getPullRequestsMergedBetween can use `git log` to generate a - # list of pull requests that were merged between this version tag and another. - # NOTE: This tag is only used locally and shouldn't be pushed to the remote. - # If it was pushed, that would trigger the staging deploy which is handled in a separate workflow (deploy.yml) - - name: Tag staging - run: git tag ${{ needs.createNewVersion.outputs.NEW_VERSION }} - - - name: Update StagingDeployCash - uses: Expensify/App/.github/actions/javascript/createOrUpdateStagingDeploy@main - with: - GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - NPM_VERSION: ${{ needs.createNewVersion.outputs.NEW_VERSION }} - - - name: Find open StagingDeployCash - id: getStagingDeployCash - run: echo "STAGING_DEPLOY_CASH=$(gh issue list --label StagingDeployCash --json number --jq '.[0].number')" >> "$GITHUB_OUTPUT" - env: - GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - - if: ${{ failure() }} uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main with: diff --git a/android/app/build.gradle b/android/app/build.gradle index 7cba91e7b0a9..bd38d9ebe4ba 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -90,8 +90,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1001036603 - versionName "1.3.66-3" + versionCode 1001036702 + versionName "1.3.67-2" } flavorDimensions "default" diff --git a/ios/NewExpensify/Info.plist b/ios/NewExpensify/Info.plist index e9e9394fcaae..00b380a7d1dc 100644 --- a/ios/NewExpensify/Info.plist +++ b/ios/NewExpensify/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.3.66 + 1.3.67 CFBundleSignature ???? CFBundleURLTypes @@ -40,7 +40,7 @@ CFBundleVersion - 1.3.66.3 + 1.3.67.2 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/ios/NewExpensifyTests/Info.plist b/ios/NewExpensifyTests/Info.plist index 7286b383a0c7..031ce55e7518 100644 --- a/ios/NewExpensifyTests/Info.plist +++ b/ios/NewExpensifyTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.3.66 + 1.3.67 CFBundleSignature ???? CFBundleVersion - 1.3.66.3 + 1.3.67.2 diff --git a/package-lock.json b/package-lock.json index 4128a740b360..cd763dffefbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "new.expensify", - "version": "1.3.66-3", + "version": "1.3.67-2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "new.expensify", - "version": "1.3.66-3", + "version": "1.3.67-2", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -179,7 +179,7 @@ "css-loader": "^6.7.2", "diff-so-fancy": "^1.3.0", "dotenv": "^16.0.3", - "electron": "^25.4.0", + "electron": "^25.8.0", "electron-builder": "24.5.0", "eslint": "^7.6.0", "eslint-config-airbnb-typescript": "^17.1.0", @@ -25005,9 +25005,9 @@ } }, "node_modules/electron": { - "version": "25.4.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.4.0.tgz", - "integrity": "sha512-VLTRxDhL4UvQbqM7pTNENnJo62cdAPZT92N+B7BZQ5Xfok1wuVPEewIjBot4K7U3EpLUuHn1veeLzho3ihiP+Q==", + "version": "25.8.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-25.8.0.tgz", + "integrity": "sha512-T3kC1a/3ntSaYMCVVfUUc9v7myPzi6J2GP0Ad/CyfWKDPp054dGyKxb2EEjKnxQQ7wfjsT1JTEdBG04x6ekVBw==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -65715,9 +65715,9 @@ } }, "electron": { - "version": "25.4.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.4.0.tgz", - "integrity": "sha512-VLTRxDhL4UvQbqM7pTNENnJo62cdAPZT92N+B7BZQ5Xfok1wuVPEewIjBot4K7U3EpLUuHn1veeLzho3ihiP+Q==", + "version": "25.8.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-25.8.0.tgz", + "integrity": "sha512-T3kC1a/3ntSaYMCVVfUUc9v7myPzi6J2GP0Ad/CyfWKDPp054dGyKxb2EEjKnxQQ7wfjsT1JTEdBG04x6ekVBw==", "dev": true, "requires": { "@electron/get": "^2.0.0", diff --git a/package.json b/package.json index 25718357b151..6666fd19cf7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new.expensify", - "version": "1.3.66-3", + "version": "1.3.67-2", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "New Expensify is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.", @@ -219,7 +219,7 @@ "css-loader": "^6.7.2", "diff-so-fancy": "^1.3.0", "dotenv": "^16.0.3", - "electron": "^25.4.0", + "electron": "^25.8.0", "electron-builder": "24.5.0", "eslint": "^7.6.0", "eslint-config-airbnb-typescript": "^17.1.0", diff --git a/src/App.js b/src/App.js index c432a0b666c8..7ec82b9a4f8a 100644 --- a/src/App.js +++ b/src/App.js @@ -24,6 +24,7 @@ import {CurrentReportIDContextProvider} from './components/withCurrentReportID'; import {EnvironmentProvider} from './components/withEnvironment'; import * as Session from './libs/actions/Session'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; +import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; // For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx if (window && Environment.isDevelopment()) { @@ -42,6 +43,7 @@ const fill = {flex: 1}; function App() { useDefaultDragAndDrop(); + OnyxUpdateManager(); return ( ; [ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report; diff --git a/src/ROUTES.js b/src/ROUTES.ts similarity index 64% rename from src/ROUTES.js rename to src/ROUTES.ts index b38ce25f590f..3ea8bd868d6a 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.ts @@ -1,10 +1,16 @@ -import lodashGet from 'lodash/get'; +import {ValueOf} from 'type-fest'; import * as Url from './libs/Url'; +import CONST from './CONST'; /** * This is a file containing constants for all of the routes we want to be able to go to */ +type ParseReportRouteParams = { + reportID: string; + isSubReportPageRoute: boolean; +}; + const REPORT = 'r'; const IOU_REQUEST = 'request/new'; const IOU_BILL = 'split/new'; @@ -20,7 +26,7 @@ export default { BANK_ACCOUNT_NEW: 'bank-account/new', BANK_ACCOUNT_WITH_STEP_TO_OPEN: 'bank-account/:stepToOpen?', BANK_ACCOUNT_PERSONAL: 'bank-account/personal', - getBankAccountRoute: (stepToOpen = '', policyID = '', backTo = '') => { + getBankAccountRoute: (stepToOpen = '', policyID = '', backTo = ''): string => { const backToParam = backTo ? `&backTo=${encodeURIComponent(backTo)}` : ''; return `bank-account/${stepToOpen}?policyID=${policyID}${backToParam}`; }, @@ -47,7 +53,7 @@ export default { SETTINGS_ADD_DEBIT_CARD: 'settings/wallet/add-debit-card', SETTINGS_ADD_BANK_ACCOUNT: 'settings/wallet/add-bank-account', SETTINGS_ENABLE_PAYMENTS: 'settings/wallet/enable-payments', - getSettingsAddLoginRoute: (type) => `settings/addlogin/${type}`, + getSettingsAddLoginRoute: (type: string) => `settings/addlogin/${type}`, SETTINGS_WALLET_TRANSFER_BALANCE: 'settings/wallet/transfer-balance', SETTINGS_WALLET_CHOOSE_TRANSFER_ACCOUNT: 'settings/wallet/choose-transfer-account', SETTINGS_PERSONAL_DETAILS, @@ -56,7 +62,7 @@ export default { SETTINGS_PERSONAL_DETAILS_ADDRESS: `${SETTINGS_PERSONAL_DETAILS}/address`, SETTINGS_CONTACT_METHODS, SETTINGS_CONTACT_METHOD_DETAILS: `${SETTINGS_CONTACT_METHODS}/:contactMethod/details`, - getEditContactMethodRoute: (contactMethod) => `${SETTINGS_CONTACT_METHODS}/${encodeURIComponent(contactMethod)}/details`, + getEditContactMethodRoute: (contactMethod: string) => `${SETTINGS_CONTACT_METHODS}/${encodeURIComponent(contactMethod)}/details`, SETTINGS_NEW_CONTACT_METHOD: `${SETTINGS_CONTACT_METHODS}/new`, SETTINGS_2FA: 'settings/security/two-factor-auth', SETTINGS_STATUS, @@ -67,14 +73,14 @@ export default { REPORT, REPORT_WITH_ID: 'r/:reportID/:reportActionID?', EDIT_REQUEST: 'r/:threadReportID/edit/:field', - getEditRequestRoute: (threadReportID, field) => `r/${threadReportID}/edit/${field}`, + getEditRequestRoute: (threadReportID: string, field: ValueOf) => `r/${threadReportID}/edit/${field}`, EDIT_CURRENCY_REQUEST: 'r/:threadReportID/edit/currency', - getEditRequestCurrencyRoute: (threadReportID, currency, backTo) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`, - getReportRoute: (reportID) => `r/${reportID}`, + getEditRequestCurrencyRoute: (threadReportID: string, currency: string, backTo: string) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`, + getReportRoute: (reportID: string) => `r/${reportID}`, REPORT_WITH_ID_DETAILS_SHARE_CODE: 'r/:reportID/details/shareCode', - getReportShareCodeRoute: (reportID) => `r/${reportID}/details/shareCode`, + getReportShareCodeRoute: (reportID: string) => `r/${reportID}/details/shareCode`, REPORT_ATTACHMENTS: 'r/:reportID/attachment', - getReportAttachmentRoute: (reportID, source) => `r/${reportID}/attachment?source=${encodeURI(source)}`, + getReportAttachmentRoute: (reportID: string, source: string) => `r/${reportID}/attachment?source=${encodeURI(source)}`, /** This is a utility route used to go to the user's concierge chat, or the sign-in page if the user's not authenticated */ CONCIERGE: 'concierge', @@ -100,64 +106,61 @@ export default { IOU_SEND_ADD_BANK_ACCOUNT: `${IOU_SEND}/add-bank-account`, IOU_SEND_ADD_DEBIT_CARD: `${IOU_SEND}/add-debit-card`, IOU_SEND_ENABLE_PAYMENTS: `${IOU_SEND}/enable-payments`, - getMoneyRequestRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}`, - getMoneyRequestAmountRoute: (iouType, reportID = '') => `${iouType}/new/amount/${reportID}`, - getMoneyRequestParticipantsRoute: (iouType, reportID = '') => `${iouType}/new/participants/${reportID}`, - getMoneyRequestConfirmationRoute: (iouType, reportID = '') => `${iouType}/new/confirmation/${reportID}`, - getMoneyRequestCreatedRoute: (iouType, reportID = '') => `${iouType}/new/date/${reportID}`, - getMoneyRequestCurrencyRoute: (iouType, reportID = '', currency, backTo) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`, - getMoneyRequestDescriptionRoute: (iouType, reportID = '') => `${iouType}/new/description/${reportID}`, - getMoneyRequestCategoryRoute: (iouType, reportID = '') => `${iouType}/new/category/${reportID}`, - getMoneyRequestMerchantRoute: (iouType, reportID = '') => `${iouType}/new/merchant/${reportID}`, - getMoneyRequestDistanceTabRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}/distance`, - getMoneyRequestWaypointRoute: (iouType, waypointIndex) => `${iouType}/new/waypoint/${waypointIndex}`, + getMoneyRequestRoute: (iouType: string, reportID = '') => `${iouType}/new/${reportID}`, + getMoneyRequestAmountRoute: (iouType: string, reportID = '') => `${iouType}/new/amount/${reportID}`, + getMoneyRequestParticipantsRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}`, + getMoneyRequestConfirmationRoute: (iouType: string, reportID = '') => `${iouType}/new/confirmation/${reportID}`, + getMoneyRequestCreatedRoute: (iouType: string, reportID = '') => `${iouType}/new/date/${reportID}`, + getMoneyRequestCurrencyRoute: (iouType: string, reportID: string, currency: string, backTo: string) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`, + getMoneyRequestDescriptionRoute: (iouType: string, reportID = '') => `${iouType}/new/description/${reportID}`, + getMoneyRequestCategoryRoute: (iouType: string, reportID = '') => `${iouType}/new/category/${reportID}`, SPLIT_BILL_DETAILS: `r/:reportID/split/:reportActionID`, - getSplitBillDetailsRoute: (reportID, reportActionID) => `r/${reportID}/split/${reportActionID}`, - getNewTaskRoute: (reportID) => `${NEW_TASK}/${reportID}`, + getSplitBillDetailsRoute: (reportID: string, reportActionID: string) => `r/${reportID}/split/${reportActionID}`, + getNewTaskRoute: (reportID: string) => `${NEW_TASK}/${reportID}`, NEW_TASK_WITH_REPORT_ID: `${NEW_TASK}/:reportID?`, TASK_TITLE: 'r/:reportID/title', TASK_DESCRIPTION: 'r/:reportID/description', TASK_ASSIGNEE: 'r/:reportID/assignee', - getTaskReportTitleRoute: (reportID) => `r/${reportID}/title`, - getTaskReportDescriptionRoute: (reportID) => `r/${reportID}/description`, - getTaskReportAssigneeRoute: (reportID) => `r/${reportID}/assignee`, + getTaskReportTitleRoute: (reportID: string) => `r/${reportID}/title`, + getTaskReportDescriptionRoute: (reportID: string) => `r/${reportID}/description`, + getTaskReportAssigneeRoute: (reportID: string) => `r/${reportID}/assignee`, NEW_TASK_ASSIGNEE: `${NEW_TASK}/assignee`, NEW_TASK_SHARE_DESTINATION: `${NEW_TASK}/share-destination`, NEW_TASK_DETAILS: `${NEW_TASK}/details`, NEW_TASK_TITLE: `${NEW_TASK}/title`, NEW_TASK_DESCRIPTION: `${NEW_TASK}/description`, FLAG_COMMENT: `flag/:reportID/:reportActionID`, - getFlagCommentRoute: (reportID, reportActionID) => `flag/${reportID}/${reportActionID}`, + getFlagCommentRoute: (reportID: string, reportActionID: string) => `flag/${reportID}/${reportActionID}`, SEARCH: 'search', SAVE_THE_WORLD: 'save-the-world', I_KNOW_A_TEACHER: 'save-the-world/i-know-a-teacher', INTRO_SCHOOL_PRINCIPAL: 'save-the-world/intro-school-principal', I_AM_A_TEACHER: 'save-the-world/i-am-a-teacher', DETAILS: 'details', - getDetailsRoute: (login) => `details?login=${encodeURIComponent(login)}`, + getDetailsRoute: (login: string) => `details?login=${encodeURIComponent(login)}`, PROFILE: 'a/:accountID', - getProfileRoute: (accountID, backTo = '') => { + getProfileRoute: (accountID: string | number, backTo = '') => { const backToParam = backTo ? `?backTo=${encodeURIComponent(backTo)}` : ''; return `a/${accountID}${backToParam}`; }, REPORT_PARTICIPANTS: 'r/:reportID/participants', - getReportParticipantsRoute: (reportID) => `r/${reportID}/participants`, + getReportParticipantsRoute: (reportID: string) => `r/${reportID}/participants`, REPORT_WITH_ID_DETAILS: 'r/:reportID/details', - getReportDetailsRoute: (reportID) => `r/${reportID}/details`, + getReportDetailsRoute: (reportID: string) => `r/${reportID}/details`, REPORT_SETTINGS: 'r/:reportID/settings', - getReportSettingsRoute: (reportID) => `r/${reportID}/settings`, + getReportSettingsRoute: (reportID: string) => `r/${reportID}/settings`, REPORT_SETTINGS_ROOM_NAME: 'r/:reportID/settings/room-name', - getReportSettingsRoomNameRoute: (reportID) => `r/${reportID}/settings/room-name`, + getReportSettingsRoomNameRoute: (reportID: string) => `r/${reportID}/settings/room-name`, REPORT_SETTINGS_NOTIFICATION_PREFERENCES: 'r/:reportID/settings/notification-preferences', - getReportSettingsNotificationPreferencesRoute: (reportID) => `r/${reportID}/settings/notification-preferences`, + getReportSettingsNotificationPreferencesRoute: (reportID: string) => `r/${reportID}/settings/notification-preferences`, REPORT_WELCOME_MESSAGE: 'r/:reportID/welcomeMessage', - getReportWelcomeMessageRoute: (reportID) => `r/${reportID}/welcomeMessage`, + getReportWelcomeMessageRoute: (reportID: string) => `r/${reportID}/welcomeMessage`, REPORT_SETTINGS_WRITE_CAPABILITY: 'r/:reportID/settings/who-can-post', - getReportSettingsWriteCapabilityRoute: (reportID) => `r/${reportID}/settings/who-can-post`, + getReportSettingsWriteCapabilityRoute: (reportID: string) => `r/${reportID}/settings/who-can-post`, TRANSITION_BETWEEN_APPS: 'transition', VALIDATE_LOGIN: 'v/:accountID/:validateCode', GET_ASSISTANCE: 'get-assistance/:taskID', - getGetAssistanceRoute: (taskID) => `get-assistance/${taskID}`, + getGetAssistanceRoute: (taskID: string) => `get-assistance/${taskID}`, UNLINK_LOGIN: 'u/:accountID/:validateCode', APPLE_SIGN_IN: 'sign-in-with-apple', @@ -168,7 +171,7 @@ export default { // when linking users from e.com in order to share a session in this app. ENABLE_PAYMENTS: 'enable-payments', WALLET_STATEMENT_WITH_DATE: 'statements/:yearMonth', - getWalletStatementWithDateRoute: (yearMonth) => `statements/${yearMonth}`, + getWalletStatementWithDateRoute: (yearMonth: string) => `statements/${yearMonth}`, WORKSPACE_NEW: 'workspace/new', WORKSPACE_INITIAL: 'workspace/:policyID', WORKSPACE_INVITE: 'workspace/:policyID/invite', @@ -182,27 +185,23 @@ export default { WORKSPACE_TRAVEL: 'workspace/:policyID/travel', WORKSPACE_MEMBERS: 'workspace/:policyID/members', WORKSPACE_NEW_ROOM: 'workspace/new-room', - getWorkspaceInitialRoute: (policyID) => `workspace/${policyID}`, - getWorkspaceInviteRoute: (policyID) => `workspace/${policyID}/invite`, - getWorkspaceInviteMessageRoute: (policyID) => `workspace/${policyID}/invite-message`, - getWorkspaceSettingsRoute: (policyID) => `workspace/${policyID}/settings`, - getWorkspaceCardRoute: (policyID) => `workspace/${policyID}/card`, - getWorkspaceReimburseRoute: (policyID) => `workspace/${policyID}/reimburse`, - getWorkspaceRateAndUnitRoute: (policyID) => `workspace/${policyID}/rateandunit`, - getWorkspaceBillsRoute: (policyID) => `workspace/${policyID}/bills`, - getWorkspaceInvoicesRoute: (policyID) => `workspace/${policyID}/invoices`, - getWorkspaceTravelRoute: (policyID) => `workspace/${policyID}/travel`, - getWorkspaceMembersRoute: (policyID) => `workspace/${policyID}/members`, + getWorkspaceInitialRoute: (policyID: string) => `workspace/${policyID}`, + getWorkspaceInviteRoute: (policyID: string) => `workspace/${policyID}/invite`, + getWorkspaceInviteMessageRoute: (policyID: string) => `workspace/${policyID}/invite-message`, + getWorkspaceSettingsRoute: (policyID: string) => `workspace/${policyID}/settings`, + getWorkspaceCardRoute: (policyID: string) => `workspace/${policyID}/card`, + getWorkspaceReimburseRoute: (policyID: string) => `workspace/${policyID}/reimburse`, + getWorkspaceRateAndUnitRoute: (policyID: string) => `workspace/${policyID}/rateandunit`, + getWorkspaceBillsRoute: (policyID: string) => `workspace/${policyID}/bills`, + getWorkspaceInvoicesRoute: (policyID: string) => `workspace/${policyID}/invoices`, + getWorkspaceTravelRoute: (policyID: string) => `workspace/${policyID}/travel`, + getWorkspaceMembersRoute: (policyID: string) => `workspace/${policyID}/members`, // These are some on-off routes that will be removed once they're no longer needed (see GH issues for details) SAASTR: 'saastr', SBE: 'sbe', - /** - * @param {String} route - * @returns {Object} - */ - parseReportRouteParams: (route) => { + parseReportRouteParams: (route: string): ParseReportRouteParams => { let parsingRoute = route; if (parsingRoute.at(0) === '/') { // remove the first slash @@ -215,9 +214,9 @@ export default { const pathSegments = parsingRoute.split('/'); return { - reportID: lodashGet(pathSegments, 1), + reportID: pathSegments[1], isSubReportPageRoute: pathSegments.length > 2, }; }, SIGN_IN_MODAL: 'sign-in-modal', -}; +} as const; diff --git a/src/components/Composer/index.js b/src/components/Composer/index.js index d29e89452e30..44075a4ec1eb 100755 --- a/src/components/Composer/index.js +++ b/src/components/Composer/index.js @@ -418,7 +418,6 @@ function Composer({ { const selectedItem = props.menuItems[index]; props.onItemSelected(selectedItem, index); - setSelectedItemIndex(index); + selectedItemIndex.current = index; }; useKeyboardShortcut( @@ -78,9 +78,9 @@ function PopoverMenu(props) { isVisible={props.isVisible} onModalHide={() => { setFocusedIndex(-1); - if (selectedItemIndex !== null) { - props.menuItems[selectedItemIndex].onSelected(); - setSelectedItemIndex(null); + if (selectedItemIndex.current !== null) { + props.menuItems[selectedItemIndex.current].onSelected(); + selectedItemIndex.current = null; } }} animationIn={props.animationIn} diff --git a/src/languages/en.ts b/src/languages/en.ts index af7957e1a560..f52848589663 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -68,6 +68,9 @@ import type { OOOEventSummaryPartialDayParams, ParentNavigationSummaryParams, ManagerApprovedParams, + SetTheRequestParams, + UpdatedTheRequestParams, + RemovedTheRequestParams, } from './types'; import * as ReportActionsUtils from '../libs/ReportActionsUtils'; @@ -523,6 +526,11 @@ export default { paidUsingExpensifyWithAmount: ({amount}: PaidUsingExpensifyWithAmountParams) => `paid ${amount} using Expensify`, noReimbursableExpenses: 'This report has an invalid amount', pendingConversionMessage: "Total will update when you're back online", + changedTheRequest: 'changed the request', + setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `set the ${valueName} to ${newValueToDisplay}`, + removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) => `removed the ${valueName} (previously ${oldValueToDisplay})`, + updatedTheRequest: ({valueName, newValueToDisplay, oldValueToDisplay}: UpdatedTheRequestParams) => + `changed the ${valueName} to ${newValueToDisplay} (previously ${oldValueToDisplay})`, threadRequestReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`, threadSentMoneyReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`, error: { @@ -1345,6 +1353,7 @@ export default { fastReimbursementsVBACopy: "You're all set to reimburse receipts from your bank account!", updateCustomUnitError: "Your changes couldn't be saved. The workspace was modified while you were offline, please try again.", invalidRateError: 'Please enter a valid rate', + lowRateError: 'Rate must be greater than 0', }, bills: { manageYourBills: 'Manage your bills', diff --git a/src/languages/es.ts b/src/languages/es.ts index f950733b005c..8610f41308e1 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -68,6 +68,9 @@ import type { OOOEventSummaryPartialDayParams, ParentNavigationSummaryParams, ManagerApprovedParams, + SetTheRequestParams, + UpdatedTheRequestParams, + RemovedTheRequestParams, } from './types'; /* eslint-disable max-len */ @@ -524,6 +527,12 @@ export default { paidUsingExpensifyWithAmount: ({amount}: PaidUsingExpensifyWithAmountParams) => `pagó ${amount} con Expensify`, noReimbursableExpenses: 'El importe de este informe no es válido', pendingConversionMessage: 'El total se actualizará cuando estés online', + changedTheRequest: 'cambió la solicitud', + setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `estableció ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay}`, + removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) => + `eliminó ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} (previamente ${oldValueToDisplay})`, + updatedTheRequest: ({valueName, newValueToDisplay, oldValueToDisplay}: UpdatedTheRequestParams) => + `cambío ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay} (previamente ${oldValueToDisplay})`, threadRequestReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, threadSentMoneyReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`, error: { @@ -1373,6 +1382,7 @@ export default { fastReimbursementsVBACopy: '¡Todo listo para reembolsar recibos desde tu cuenta bancaria!', updateCustomUnitError: 'Los cambios no han podido ser guardados. El espacio de trabajo ha sido modificado mientras estabas desconectado. Por favor, inténtalo de nuevo.', invalidRateError: 'Por favor, introduce una tarifa válida', + lowRateError: 'La tarifa debe ser mayor que 0', }, bills: { manageYourBills: 'Gestiona tus facturas', diff --git a/src/languages/types.ts b/src/languages/types.ts index 50290fb5776c..059d944fd4ba 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -184,6 +184,12 @@ type OOOEventSummaryPartialDayParams = {summary: string; timePeriod: string; dat type ParentNavigationSummaryParams = {rootReportName: string; workspaceName: string}; +type SetTheRequestParams = {valueName: string; newValueToDisplay: string}; + +type RemovedTheRequestParams = {valueName: string; oldValueToDisplay: string}; + +type UpdatedTheRequestParams = {valueName: string; newValueToDisplay: string; oldValueToDisplay: string}; + export type { AddressLineParams, CharacterLimitParams, @@ -252,4 +258,7 @@ export type { OOOEventSummaryFullDayParams, OOOEventSummaryPartialDayParams, ParentNavigationSummaryParams, + SetTheRequestParams, + UpdatedTheRequestParams, + RemovedTheRequestParams, }; diff --git a/src/libs/API.js b/src/libs/API.js index 9405fb8f3a51..491503f07381 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -21,7 +21,8 @@ Request.use(Middleware.RecheckConnection); // Reauthentication - Handles jsonCode 407 which indicates an expired authToken. We need to reauthenticate and get a new authToken with our stored credentials. Request.use(Middleware.Reauthentication); -// SaveResponseInOnyx - Merges either the successData or failureData into Onyx depending on if the call was successful or not +// SaveResponseInOnyx - Merges either the successData or failureData into Onyx depending on if the call was successful or not. This needs to be the LAST middleware we use, don't add any +// middlewares after this, because the SequentialQueue depends on the result of this middleware to pause the queue (if needed) to bring the app to an up-to-date state. Request.use(Middleware.SaveResponseInOnyx); /** diff --git a/src/libs/EmojiTrie.js b/src/libs/EmojiTrie.js index c5448c340d81..b0bd0d5eec5d 100644 --- a/src/libs/EmojiTrie.js +++ b/src/libs/EmojiTrie.js @@ -18,26 +18,40 @@ function createTrie(lang = CONST.LOCALES.DEFAULT) { return; } - const name = isDefaultLocale ? item.name : _.get(langEmojis, [item.code, 'name']); - const names = isDefaultLocale ? [name] : [...new Set([name, item.name])]; - _.forEach(names, (nm) => { - const node = trie.search(nm); - if (!node) { - trie.add(nm, {code: item.code, types: item.types, name: nm, suggestions: []}); - } else { - trie.update(nm, {code: item.code, types: item.types, name: nm, suggestions: node.metaData.suggestions}); - } - }); + const englishName = item.name; + const localeName = _.get(langEmojis, [item.code, 'name'], englishName); + const node = trie.search(localeName); + if (!node) { + trie.add(localeName, {code: item.code, types: item.types, name: localeName, suggestions: []}); + } else { + trie.update(localeName, {code: item.code, types: item.types, name: localeName, suggestions: node.metaData.suggestions}); + } + + // Add keywords for both the locale language and English to enable users to search using either language. const keywords = _.get(langEmojis, [item.code, 'keywords'], []).concat(isDefaultLocale ? [] : _.get(localeEmojis, [CONST.LOCALES.DEFAULT, item.code, 'keywords'], [])); for (let j = 0; j < keywords.length; j++) { const keywordNode = trie.search(keywords[j]); if (!keywordNode) { - trie.add(keywords[j], {suggestions: [{code: item.code, types: item.types, name}]}); + trie.add(keywords[j], {suggestions: [{code: item.code, types: item.types, name: localeName}]}); } else { trie.update(keywords[j], { ...keywordNode.metaData, - suggestions: [...keywordNode.metaData.suggestions, {code: item.code, types: item.types, name}], + suggestions: [...keywordNode.metaData.suggestions, {code: item.code, types: item.types, name: localeName}], + }); + } + } + + // If current language isn't the default, prepend the English name of the emoji in the suggestions as well. + // We do this because when the user types the english name of the emoji, we want to show the emoji in the suggestions before all the others. + if (!isDefaultLocale) { + const englishNode = trie.search(englishName); + if (!englishNode) { + trie.add(englishName, {suggestions: [{code: item.code, types: item.types, name: localeName}]}); + } else { + trie.update(englishName, { + ...englishNode.metaData, + suggestions: [{code: item.code, types: item.types, name: localeName}, ...englishNode.metaData.suggestions], }); } } diff --git a/src/libs/EmojiUtils.js b/src/libs/EmojiUtils.js index df00418b7524..80665541e24b 100644 --- a/src/libs/EmojiUtils.js +++ b/src/libs/EmojiUtils.js @@ -319,7 +319,16 @@ function replaceEmojis(text, preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE, } for (let i = 0; i < emojiData.length; i++) { const name = emojiData[i].slice(1, -1); - const checkEmoji = trie.search(name); + let checkEmoji = trie.search(name); + // If the user has selected a language other than English, and the emoji doesn't exist in that language, + // we will check if the emoji exists in English. + if (lang !== CONST.LOCALES.DEFAULT && (!checkEmoji || !checkEmoji.metaData.code)) { + const englishTrie = emojisTrie[CONST.LOCALES.DEFAULT]; + if (englishTrie) { + const englishEmoji = englishTrie.search(name); + checkEmoji = englishEmoji; + } + } if (checkEmoji && checkEmoji.metaData.code) { let emojiReplacement = getEmojiCodeWithSkinColor(checkEmoji.metaData, preferredSkinTone); emojis.push({ diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index 28b8a93fb585..8cb66c0c10d0 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -1,34 +1,32 @@ -import Onyx from 'react-native-onyx'; import _ from 'underscore'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; -import * as QueuedOnyxUpdates from '../actions/QueuedOnyxUpdates'; import * as MemoryOnlyKeys from '../actions/MemoryOnlyKeys/MemoryOnlyKeys'; import * as OnyxUpdates from '../actions/OnyxUpdates'; +// If we're executing any of these requests, we don't need to trigger our OnyxUpdates flow to update the current data even if our current value is out of +// date because all these requests are updating the app to the most current state. +const requestsToIgnoreLastUpdateID = ['OpenApp', 'ReconnectApp', 'GetMissingOnyxMessages']; + /** - * @param {Promise} response + * @param {Promise} requestResponse * @param {Object} request * @returns {Promise} */ -function SaveResponseInOnyx(response, request) { - return response.then((responseData) => { - // Make sure we have response data (i.e. response isn't a promise being passed down to us by a failed retry request and responseData undefined) - if (!responseData) { +function SaveResponseInOnyx(requestResponse, request) { + return requestResponse.then((response) => { + // Make sure we have response data (i.e. response isn't a promise being passed down to us by a failed retry request and response undefined) + if (!response) { return; } + const onyxUpdates = response.onyxData; - // The data for this response comes in two different formats: - // 1. Original format - this is what was sent before the RELIABLE_UPDATES project and will go away once RELIABLE_UPDATES is fully complete - // - The data is an array of objects, where each object is an onyx update - // Example: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}] - // 1. Reliable updates format - this is what was sent with the RELIABLE_UPDATES project and will be the format from now on - // - The data is an object, containing updateIDs from the server and an array of onyx updates (this array is the same format as the original format above) - // Example: {lastUpdateID: 1, previousUpdateID: 0, onyxData: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]} - // NOTE: This is slightly different than the format of the pusher event data, where pusher has "updates" and HTTPS responses have "onyxData" (long story) + // Sometimes we call requests that are successfull but they don't have any response or any success/failure data to set. Let's return early since + // we don't need to store anything here. + if (!onyxUpdates && !request.successData && !request.failureData) { + return Promise.resolve(response); + } - // Supports both the old format and the new format - const onyxUpdates = _.isArray(responseData) ? responseData : responseData.onyxData; // If there is an OnyxUpdate for using memory only keys, enable them _.find(onyxUpdates, ({key, value}) => { if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { @@ -39,30 +37,26 @@ function SaveResponseInOnyx(response, request) { return true; }); - // Save the update IDs to Onyx so they can be used to fetch incremental updates if the client gets out of sync from the server - OnyxUpdates.saveUpdateIDs(Number(responseData.lastUpdateID || 0), Number(responseData.previousUpdateID || 0)); + const responseToApply = { + type: CONST.ONYX_UPDATE_TYPES.HTTPS, + lastUpdateID: Number(response.lastUpdateID || 0), + previousUpdateID: Number(response.previousUpdateID || 0), + request, + response, + }; - // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in - // the UI. See https://github.com/Expensify/App/issues/12775 for more info. - const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; + if (_.includes(requestsToIgnoreLastUpdateID, request.command) || !OnyxUpdates.doesClientNeedToBeUpdated(Number(response.previousUpdateID || 0))) { + return OnyxUpdates.apply(responseToApply); + } - // First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then - // apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained - // in successData/failureData until after the component has received and API data. - const onyxDataUpdatePromise = responseData.onyxData ? updateHandler(responseData.onyxData) : Promise.resolve(); + // Save the update IDs to Onyx so they can be used to fetch incremental updates if the client gets out of sync from the server + OnyxUpdates.saveUpdateInformation(responseToApply); - return onyxDataUpdatePromise - .then(() => { - // Handle the request's success/failure data (client-side data) - if (responseData.jsonCode === 200 && request.successData) { - return updateHandler(request.successData); - } - if (responseData.jsonCode !== 200 && request.failureData) { - return updateHandler(request.failureData); - } - return Promise.resolve(); - }) - .then(() => responseData); + // Ensure the queue is paused while the client resolves the gap in onyx updates so that updates are guaranteed to happen in a specific order. + return Promise.resolve({ + ...response, + shouldPauseQueue: true, + }); }); } diff --git a/src/libs/Network/SequentialQueue.js b/src/libs/Network/SequentialQueue.js index f8ea396663a5..e53515fb5e87 100644 --- a/src/libs/Network/SequentialQueue.js +++ b/src/libs/Network/SequentialQueue.js @@ -21,6 +21,30 @@ let isSequentialQueueRunning = false; let currentRequest = null; let isQueuePaused = false; +/** + * Puts the queue into a paused state so that no requests will be processed + */ +function pause() { + if (isQueuePaused) { + return; + } + + console.debug('[SequentialQueue] Pausing the queue'); + isQueuePaused = true; +} + +/** + * Gets the current Onyx queued updates, apply them and clear the queue if the queue is not paused. + */ +function flushOnyxUpdatesQueue() { + // The only situation where the queue is paused is if we found a gap between the app current data state and our server's. If that happens, + // we'll trigger async calls to make the client updated again. While we do that, we don't want to insert anything in Onyx. + if (isQueuePaused) { + return; + } + QueuedOnyxUpdates.flushQueue(); +} + /** * Process any persisted requests, when online, one at a time until the queue is empty. * @@ -44,7 +68,12 @@ function process() { // Set the current request to a promise awaiting its processing so that getCurrentRequest can be used to take some action after the current request has processed. currentRequest = Request.processWithMiddleware(requestToProcess, true) - .then(() => { + .then((response) => { + // A response might indicate that the queue should be paused. This happens when a gap in onyx updates is detected between the client and the server and + // that gap needs resolved before the queue can continue. + if (response.shouldPauseQueue) { + pause(); + } PersistedRequests.remove(requestToProcess); RequestThrottle.clear(); return process(); @@ -94,12 +123,27 @@ function flush() { isSequentialQueueRunning = false; resolveIsReadyPromise(); currentRequest = null; - Onyx.update(QueuedOnyxUpdates.getQueuedUpdates()).then(QueuedOnyxUpdates.clear); + flushOnyxUpdatesQueue(); }); }, }); } +/** + * Unpauses the queue and flushes all the requests that were in it or were added to it while paused + */ +function unpause() { + if (!isQueuePaused) { + return; + } + + const numberOfPersistedRequests = PersistedRequests.getAll().length || 0; + console.debug(`[SequentialQueue] Unpausing the queue and flushing ${numberOfPersistedRequests} requests`); + isQueuePaused = false; + flushOnyxUpdatesQueue(); + flush(); +} + /** * @returns {Boolean} */ @@ -149,30 +193,4 @@ function waitForIdle() { return isReadyPromise; } -/** - * Puts the queue into a paused state so that no requests will be processed - */ -function pause() { - if (isQueuePaused) { - return; - } - - console.debug('[SequentialQueue] Pausing the queue'); - isQueuePaused = true; -} - -/** - * Unpauses the queue and flushes all the requests that were in it or were added to it while paused - */ -function unpause() { - if (!isQueuePaused) { - return; - } - - const numberOfPersistedRequests = PersistedRequests.getAll().length || 0; - console.debug(`[SequentialQueue] Unpausing the queue and flushing ${numberOfPersistedRequests} requests`); - isQueuePaused = false; - flush(); -} - export {flush, getCurrentRequest, isRunning, push, waitForIdle, pause, unpause}; diff --git a/src/libs/PusherUtils.js b/src/libs/PusherUtils.js index 9d84bd4012fe..b4615d3c7d8b 100644 --- a/src/libs/PusherUtils.js +++ b/src/libs/PusherUtils.js @@ -18,12 +18,13 @@ function subscribeToMultiEvent(eventType, callback) { /** * @param {String} eventType * @param {Mixed} data + * @returns {Promise} */ function triggerMultiEventHandler(eventType, data) { if (!multiEventCallbackMapping[eventType]) { - return; + return Promise.resolve(); } - multiEventCallbackMapping[eventType](data); + return multiEventCallbackMapping[eventType](data); } /** diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 9cbc414bf582..9bb365c0f42a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -105,11 +105,15 @@ function isWhisperAction(action) { } /** + * Returns whether the comment is a thread parent message/the first message in a thread + * * @param {Object} reportAction + * @param {String} reportID * @returns {Boolean} */ -function hasCommentThread(reportAction) { - return lodashGet(reportAction, 'childType', '') === CONST.REPORT.TYPE.CHAT && lodashGet(reportAction, 'childVisibleActionCount', 0) > 0; +function isThreadParentMessage(reportAction = {}, reportID) { + const {childType, childVisibleActionCount = 0, childReportID} = reportAction; + return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID); } /** @@ -628,7 +632,7 @@ export { getLastClosedReportAction, getLatestReportActionFromOnyxData, isMoneyRequestAction, - hasCommentThread, + isThreadParentMessage, getLinkedTransactionID, getMostRecentReportActionLastModified, getReportPreviewAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 53423e8deaf2..6167a04ada2f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1478,14 +1478,15 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName, valueInQuotes) { const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue; const oldValueToDisplay = valueInQuotes ? `"${oldValue}"` : oldValue; + const displayValueName = valueName.toLowerCase(); if (!oldValue) { - return `set the ${valueName} to ${newValueToDisplay}`; + return Localize.translateLocal('iou.setTheRequest', {valueName: displayValueName, newValueToDisplay}); } if (!newValue) { - return `removed the ${valueName} (previously ${oldValueToDisplay})`; + return Localize.translateLocal('iou.removedTheRequest', {valueName: displayValueName, oldValueToDisplay}); } - return `changed the ${valueName} to ${newValueToDisplay} (previously ${oldValueToDisplay})`; + return Localize.translateLocal('iou.updatedTheRequest', {valueName: displayValueName, newValueToDisplay, oldValueToDisplay}); } /** @@ -1497,7 +1498,7 @@ function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName, function getModifiedExpenseMessage(reportAction) { const reportActionOriginalMessage = lodashGet(reportAction, 'originalMessage', {}); if (_.isEmpty(reportActionOriginalMessage)) { - return `changed the request`; + return Localize.translateLocal('iou.changedTheRequest'); } const hasModifiedAmount = @@ -1512,12 +1513,12 @@ function getModifiedExpenseMessage(reportAction) { const currency = reportActionOriginalMessage.currency; const amount = CurrencyUtils.convertToDisplayString(reportActionOriginalMessage.amount, currency); - return getProperSchemaForModifiedExpenseMessage(amount, oldAmount, 'amount', false); + return getProperSchemaForModifiedExpenseMessage(amount, oldAmount, Localize.translateLocal('iou.amount'), false); } const hasModifiedComment = _.has(reportActionOriginalMessage, 'oldComment') && _.has(reportActionOriginalMessage, 'newComment'); if (hasModifiedComment) { - return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.newComment, reportActionOriginalMessage.oldComment, 'description', true); + return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.newComment, reportActionOriginalMessage.oldComment, Localize.translateLocal('common.description'), true); } const hasModifiedCreated = _.has(reportActionOriginalMessage, 'oldCreated') && _.has(reportActionOriginalMessage, 'created'); @@ -1525,12 +1526,12 @@ function getModifiedExpenseMessage(reportAction) { // Take only the YYYY-MM-DD value as the original date includes timestamp let formattedOldCreated = parseISO(reportActionOriginalMessage.oldCreated); formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING); - return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, 'date', false); + return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, Localize.translateLocal('common.date'), false); } const hasModifiedMerchant = _.has(reportActionOriginalMessage, 'oldMerchant') && _.has(reportActionOriginalMessage, 'merchant'); if (hasModifiedMerchant) { - return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, 'merchant', true); + return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, Localize.translateLocal('common.merchant'), true); } } diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 6028e0468696..90c2a9ec4f16 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -18,7 +18,6 @@ import * as Session from './Session'; import * as ReportActionsUtils from '../ReportActionsUtils'; import Timing from './Timing'; import * as Browser from '../Browser'; -import * as SequentialQueue from '../Network/SequentialQueue'; let currentUserAccountID; let currentUserEmail; @@ -208,6 +207,35 @@ function reconnectApp(updateIDFrom = 0) { }); } +/** + * Fetches data when the app will call reconnectApp without params for the last time. This is a separate function + * because it will follow patterns that are not recommended so we can be sure we're not putting the app in a unusable + * state because of race conditions between reconnectApp and other pusher updates being applied at the same time. + * @return {Promise} + */ +function finalReconnectAppAfterActivatingReliableUpdates() { + console.debug(`[OnyxUpdates] Executing last reconnect app with promise`); + return getPolicyParamsForOpenOrReconnect().then((policyParams) => { + const params = {...policyParams}; + + // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. + // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. + // + // - Look through the local report actions and reports to find the most recently modified report action or report. + // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. + Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); + params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); + Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); + + // It is SUPER BAD FORM to return promises from action methods. + // DO NOT FOLLOW THIS PATTERN!!!!! + // It was absolutely necessary in order to not break the app while migrating to the new reliable updates pattern. This method will be removed + // as soon as we have everyone migrated to the reliableUpdate beta. + // eslint-disable-next-line rulesdir/no-api-side-effects-method + return API.makeRequestWithSideEffects('ReconnectApp', params, getOnyxDataForOpenOrReconnect()); + }); +} + /** * Fetches data when the client has discovered it missed some Onyx updates from the server * @param {Number} [updateIDFrom] the ID of the Onyx update that we want to start fetching from @@ -231,48 +259,6 @@ function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo = 0) { ); } -// The next 40ish lines of code are used for detecting when there is a gap of OnyxUpdates between what was last applied to the client and the updates the server has. -// When a gap is detected, the missing updates are fetched from the API. - -// These key needs to be separate from ONYXKEYS.ONYX_UPDATES_FROM_SERVER so that it can be updated without triggering the callback when the server IDs are updated -let lastUpdateIDAppliedToClient = 0; -Onyx.connect({ - key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, - callback: (val) => (lastUpdateIDAppliedToClient = val), -}); - -Onyx.connect({ - key: ONYXKEYS.ONYX_UPDATES_FROM_SERVER, - callback: (val) => { - if (!val) { - return; - } - - const {lastUpdateIDFromServer, previousUpdateIDFromServer} = val; - console.debug('[OnyxUpdates] Received lastUpdateID from server', lastUpdateIDFromServer); - console.debug('[OnyxUpdates] Received previousUpdateID from server', previousUpdateIDFromServer); - console.debug('[OnyxUpdates] Last update ID applied to the client', lastUpdateIDAppliedToClient); - - // If the previous update from the server does not match the last update the client got, then the client is missing some updates. - // getMissingOnyxUpdates will fetch updates starting from the last update this client got and going to the last update the server sent. - if (lastUpdateIDAppliedToClient && previousUpdateIDFromServer && lastUpdateIDAppliedToClient < previousUpdateIDFromServer) { - console.debug('[OnyxUpdates] Gap detected in update IDs so fetching incremental updates'); - Log.info('Gap detected in update IDs from server so fetching incremental updates', true, { - lastUpdateIDFromServer, - previousUpdateIDFromServer, - lastUpdateIDAppliedToClient, - }); - SequentialQueue.pause(); - getMissingOnyxUpdates(lastUpdateIDAppliedToClient, lastUpdateIDFromServer).finally(SequentialQueue.unpause); - } - - if (lastUpdateIDFromServer > lastUpdateIDAppliedToClient) { - // Update this value so that it matches what was just received from the server - Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, lastUpdateIDFromServer || 0); - } - }, -}); - /** * This promise is used so that deeplink component know when a transition is end. * This is necessary because we want to begin deeplink redirection after the transition is end. @@ -484,4 +470,6 @@ export { beginDeepLinkRedirect, beginDeepLinkRedirectAfterTransition, createWorkspaceAndNavigateToIt, + getMissingOnyxUpdates, + finalReconnectAppAfterActivatingReliableUpdates, }; diff --git a/src/libs/actions/AppUpdate.js b/src/libs/actions/AppUpdate.ts similarity index 78% rename from src/libs/actions/AppUpdate.js rename to src/libs/actions/AppUpdate.ts index 502ef9762252..f0e3c1c3da20 100644 --- a/src/libs/actions/AppUpdate.js +++ b/src/libs/actions/AppUpdate.ts @@ -5,10 +5,7 @@ function triggerUpdateAvailable() { Onyx.set(ONYXKEYS.UPDATE_AVAILABLE, true); } -/** - * @param {Boolean} isBeta - */ -function setIsAppInBeta(isBeta) { +function setIsAppInBeta(isBeta: boolean) { Onyx.set(ONYXKEYS.IS_BETA, isBeta); } diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js new file mode 100644 index 000000000000..f0051b85f302 --- /dev/null +++ b/src/libs/actions/OnyxUpdateManager.js @@ -0,0 +1,81 @@ +import Onyx from 'react-native-onyx'; +import ONYXKEYS from '../../ONYXKEYS'; +import Log from '../Log'; +import * as SequentialQueue from '../Network/SequentialQueue'; +import * as App from './App'; +import * as OnyxUpdates from './OnyxUpdates'; + +// This file is in charge of looking at the updateIDs coming from the server and comparing them to the last updateID that the client has. +// If the client is behind the server, then we need to +// 1. Pause all sequential queue requests +// 2. Pause all Onyx updates from Pusher +// 3. Get the missing updates from the server +// 4. Apply those updates +// 5. Apply the original update that triggered this request (it could have come from either HTTPS or Pusher) +// 6. Restart the sequential queue +// 7. Restart the Onyx updates from Pusher +// This will ensure that the client is up-to-date with the server and all the updates have been applied in the correct order. +// It's important that this file is separate and not imported by OnyxUpdates.js, so that there are no circular dependencies. Onyx +// is used as a pub/sub mechanism to break out of the circular dependency. +// The circular dependency happens because this file calls API.GetMissingOnyxUpdates() which uses the SaveResponseInOnyx.js file +// (as a middleware). Therefore, SaveResponseInOnyx.js can't import and use this file directly. + +let lastUpdateIDAppliedToClient = 0; +Onyx.connect({ + key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, + callback: (val) => (lastUpdateIDAppliedToClient = val), +}); + +export default () => { + console.debug('[OnyxUpdateManager] Listening for updates from the server'); + Onyx.connect({ + key: ONYXKEYS.ONYX_UPDATES_FROM_SERVER, + callback: (val) => { + if (!val) { + return; + } + + const updateParams = val; + const lastUpdateIDFromServer = val.lastUpdateID; + const previousUpdateIDFromServer = val.previousUpdateID; + + // In cases where we received a previousUpdateID and it doesn't match our lastUpdateIDAppliedToClient + // we need to perform one of the 2 possible cases: + // + // 1. This is the first time we're receiving an lastUpdateID, so we need to do a final reconnectApp before + // fully migrating to the reliable updates mode. + // 2. This client already has the reliable updates mode enabled, but it's missing some updates and it + // needs to fetch those. + // + // For both of those, we need to pause the sequential queue. This is important so that the updates are + // applied in their correct and specific order. If this queue was not paused, then there would be a lot of + // onyx data being applied while we are fetching the missing updates and that would put them all out of order. + SequentialQueue.pause(); + let canUnpauseQueuePromise; + + // The flow below is setting the promise to a reconnect app to address flow (1) explained above. + if (!lastUpdateIDAppliedToClient) { + Log.info('Client has not gotten reliable updates before so reconnecting the app to start the process'); + + // Since this is a full reconnectApp, we'll not apply the updates we received - those will come in the reconnect app request. + canUnpauseQueuePromise = App.finalReconnectAppAfterActivatingReliableUpdates(); + } else { + // The flow below is setting the promise to a getMissingOnyxUpdates to address flow (2) explained above. + console.debug(`[OnyxUpdateManager] Client is behind the server by ${previousUpdateIDFromServer - lastUpdateIDAppliedToClient} so fetching incremental updates`); + Log.info('Gap detected in update IDs from server so fetching incremental updates', true, { + lastUpdateIDFromServer, + previousUpdateIDFromServer, + lastUpdateIDAppliedToClient, + }); + canUnpauseQueuePromise = App.getMissingOnyxUpdates(lastUpdateIDAppliedToClient, lastUpdateIDFromServer); + } + + canUnpauseQueuePromise.finally(() => { + OnyxUpdates.apply(updateParams).finally(() => { + console.debug('[OnyxUpdateManager] Done applying all updates'); + SequentialQueue.unpause(); + }); + }); + }, + }); +}; diff --git a/src/libs/actions/OnyxUpdates.js b/src/libs/actions/OnyxUpdates.js index e582016f0109..8e45e7dd2e66 100644 --- a/src/libs/actions/OnyxUpdates.js +++ b/src/libs/actions/OnyxUpdates.js @@ -1,22 +1,123 @@ import Onyx from 'react-native-onyx'; +import _ from 'underscore'; +import PusherUtils from '../PusherUtils'; import ONYXKEYS from '../../ONYXKEYS'; +import * as QueuedOnyxUpdates from './QueuedOnyxUpdates'; +import CONST from '../../CONST'; + +// This key needs to be separate from ONYXKEYS.ONYX_UPDATES_FROM_SERVER so that it can be updated without triggering the callback when the server IDs are updated. If that +// callback were triggered it would lead to duplicate processing of server updates. +let lastUpdateIDAppliedToClient = 0; +Onyx.connect({ + key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, + callback: (val) => (lastUpdateIDAppliedToClient = val), +}); /** - * - * @param {Number} [lastUpdateID] - * @param {Number} [previousUpdateID] + * @param {Object} request + * @param {Object} response + * @returns {Promise} */ -function saveUpdateIDs(lastUpdateID = 0, previousUpdateID = 0) { - // Return early if there were no updateIDs - if (!lastUpdateID) { - return; - } +function applyHTTPSOnyxUpdates(request, response) { + console.debug('[OnyxUpdateManager] Applying https update'); + // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in + // the UI. See https://github.com/Expensify/App/issues/12775 for more info. + const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; - Onyx.merge(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, { - lastUpdateIDFromServer: lastUpdateID, - previousUpdateIDFromServer: previousUpdateID, + // First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then + // apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained + // in successData/failureData until after the component has received and API data. + const onyxDataUpdatePromise = response.onyxData ? updateHandler(response.onyxData) : Promise.resolve(); + + return onyxDataUpdatePromise + .then(() => { + // Handle the request's success/failure data (client-side data) + if (response.jsonCode === 200 && request.successData) { + return updateHandler(request.successData); + } + if (response.jsonCode !== 200 && request.failureData) { + return updateHandler(request.failureData); + } + return Promise.resolve(); + }) + .then(() => { + console.debug('[OnyxUpdateManager] Done applying HTTPS update'); + return Promise.resolve(response); + }); +} + +/** + * @param {Array} updates + * @returns {Promise} + */ +function applyPusherOnyxUpdates(updates) { + console.debug('[OnyxUpdateManager] Applying pusher update'); + const pusherEventPromises = _.map(updates, (update) => PusherUtils.triggerMultiEventHandler(update.eventType, update.data)); + return Promise.all(pusherEventPromises).then(() => { + console.debug('[OnyxUpdateManager] Done applying Pusher update'); }); } +/** + * @param {Object[]} updateParams + * @param {String} updateParams.type + * @param {Number} updateParams.lastUpdateID + * @param {Object} [updateParams.request] Exists if updateParams.type === 'https' + * @param {Object} [updateParams.response] Exists if updateParams.type === 'https' + * @param {Object} [updateParams.updates] Exists if updateParams.type === 'pusher' + * @returns {Promise} + */ +function apply({lastUpdateID, type, request, response, updates}) { + console.debug(`[OnyxUpdateManager] Applying update type: ${type} with lastUpdateID: ${lastUpdateID}`, {request, response, updates}); + + if (lastUpdateID && lastUpdateID < lastUpdateIDAppliedToClient) { + console.debug('[OnyxUpdateManager] Update received was older than current state, returning without applying the updates'); + return Promise.resolve(); + } + if (lastUpdateID && lastUpdateID > lastUpdateIDAppliedToClient) { + Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, lastUpdateID); + } + if (type === CONST.ONYX_UPDATE_TYPES.HTTPS) { + return applyHTTPSOnyxUpdates(request, response); + } + if (type === CONST.ONYX_UPDATE_TYPES.PUSHER) { + return applyPusherOnyxUpdates(updates); + } +} + +/** + * @param {Object[]} updateParams + * @param {String} updateParams.type + * @param {Object} [updateParams.request] Exists if updateParams.type === 'https' + * @param {Object} [updateParams.response] Exists if updateParams.type === 'https' + * @param {Object} [updateParams.updates] Exists if updateParams.type === 'pusher' + * @param {Number} [updateParams.lastUpdateID] + * @param {Number} [updateParams.previousUpdateID] + */ +function saveUpdateInformation(updateParams) { + // Always use set() here so that the updateParams are never merged and always unique to the request that came in + Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, updateParams); +} + +/** + * This function will receive the previousUpdateID from any request/pusher update that has it, compare to our current app state + * and return if an update is needed + * @param {Number} previousUpdateID The previousUpdateID contained in the response object + * @returns {Boolean} + */ +function doesClientNeedToBeUpdated(previousUpdateID = 0) { + // If no previousUpdateID is sent, this is not a WRITE request so we don't need to update our current state + if (!previousUpdateID) { + return false; + } + + // If we don't have any value in lastUpdateIDAppliedToClient, this is the first time we're receiving anything, so we need to do a last reconnectApp + if (!lastUpdateIDAppliedToClient) { + return true; + } + + return lastUpdateIDAppliedToClient < previousUpdateID; +} + // eslint-disable-next-line import/prefer-default-export -export {saveUpdateIDs}; +export {saveUpdateInformation, doesClientNeedToBeUpdated, apply}; diff --git a/src/libs/actions/QueuedOnyxUpdates.js b/src/libs/actions/QueuedOnyxUpdates.js index 486108dd56cf..06f15be1340f 100644 --- a/src/libs/actions/QueuedOnyxUpdates.js +++ b/src/libs/actions/QueuedOnyxUpdates.js @@ -22,10 +22,10 @@ function clear() { } /** - * @returns {Array} + * @returns {Promise} */ -function getQueuedUpdates() { - return queuedOnyxUpdates; +function flushQueue() { + return Onyx.update(queuedOnyxUpdates).then(clear); } -export {queueOnyxUpdates, clear, getQueuedUpdates}; +export {queueOnyxUpdates, flushQueue}; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 881615948a38..85552fa14a56 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -528,12 +528,12 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p onyxData.optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`, - value: {[parentReportActionID]: {childReportID: reportID}}, + value: {[parentReportActionID]: {childReportID: reportID, childType: CONST.REPORT.TYPE.CHAT}}, }); onyxData.failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`, - value: {[parentReportActionID]: {childReportID: '0'}}, + value: {[parentReportActionID]: {childReportID: '0', childType: ''}}, }); } } @@ -926,7 +926,7 @@ function deleteReportComment(reportID, reportAction) { html: '', text: '', isEdited: true, - isDeletedParentAction: ReportActionsUtils.hasCommentThread(reportAction), + isDeletedParentAction: ReportActionsUtils.isThreadParentMessage(reportAction, reportID), }, ]; const optimisticReportActions = { diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index b77c5b278bc9..ee93c6acb1e5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -546,8 +546,6 @@ function subscribeToUserEvents() { // Handles the mega multipleEvents from Pusher which contains an array of single events. // Each single event is passed to PusherUtils in order to trigger the callbacks for that event PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.MULTIPLE_EVENTS, currentUserAccountID, (pushJSON) => { - let updates; - // The data for this push event comes in two different formats: // 1. Original format - this is what was sent before the RELIABLE_UPDATES project and will go away once RELIABLE_UPDATES is fully complete // - The data is an array of objects, where each object is an onyx update @@ -556,28 +554,44 @@ function subscribeToUserEvents() { // - The data is an object, containing updateIDs from the server and an array of onyx updates (this array is the same format as the original format above) // Example: {lastUpdateID: 1, previousUpdateID: 0, updates: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]} if (_.isArray(pushJSON)) { - updates = pushJSON; - } else { - updates = pushJSON.updates; - OnyxUpdates.saveUpdateIDs(Number(pushJSON.lastUpdateID || 0), Number(pushJSON.previousUpdateID || 0)); + _.each(pushJSON, (multipleEvent) => { + PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); + }); + return; + } + + const updates = { + type: CONST.ONYX_UPDATE_TYPES.PUSHER, + lastUpdateID: Number(pushJSON.lastUpdateID || 0), + updates: pushJSON.updates, + previousUpdateID: Number(pushJSON.previousUpdateID || 0), + }; + if (!OnyxUpdates.doesClientNeedToBeUpdated(Number(pushJSON.previousUpdateID || 0))) { + OnyxUpdates.apply(updates); + return; } - _.each(updates, (multipleEvent) => { - PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); - }); + + // If we reached this point, we need to pause the queue while we prepare to fetch older OnyxUpdates. + SequentialQueue.pause(); + OnyxUpdates.saveUpdateInformation(updates); }); // Handles Onyx updates coming from Pusher through the mega multipleEvents. - PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON) => { + PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON) => SequentialQueue.getCurrentRequest().then(() => { // If we don't have the currentUserAccountID (user is logged out) we don't want to update Onyx with data from Pusher if (!currentUserAccountID) { return; } - Onyx.update(pushJSON); + const onyxUpdatePromise = Onyx.update(pushJSON); triggerNotifications(pushJSON); - }); - }); + + // Return a promise when Onyx is done updating so that the OnyxUpdatesManager can properly apply all + // the onyx updates in order + return onyxUpdatePromise; + }), + ); } /** diff --git a/src/libs/canFocusInputOnScreenFocus/index.js b/src/libs/canFocusInputOnScreenFocus/index.js deleted file mode 100644 index c930c0d944ec..000000000000 --- a/src/libs/canFocusInputOnScreenFocus/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as DeviceCapabilities from '../DeviceCapabilities'; - -export default () => !DeviceCapabilities.canUseTouchScreen(); diff --git a/src/libs/canFocusInputOnScreenFocus/index.native.js b/src/libs/canFocusInputOnScreenFocus/index.native.js deleted file mode 100644 index eae5767cffbc..000000000000 --- a/src/libs/canFocusInputOnScreenFocus/index.native.js +++ /dev/null @@ -1 +0,0 @@ -export default () => false; diff --git a/src/libs/canFocusInputOnScreenFocus/index.native.ts b/src/libs/canFocusInputOnScreenFocus/index.native.ts new file mode 100644 index 000000000000..79d711c49fa6 --- /dev/null +++ b/src/libs/canFocusInputOnScreenFocus/index.native.ts @@ -0,0 +1,5 @@ +import CanFocusInputOnScreenFocus from './types'; + +const canFocusInputOnScreenFocus: CanFocusInputOnScreenFocus = () => false; + +export default canFocusInputOnScreenFocus; diff --git a/src/libs/canFocusInputOnScreenFocus/index.ts b/src/libs/canFocusInputOnScreenFocus/index.ts new file mode 100644 index 000000000000..be500074d7e3 --- /dev/null +++ b/src/libs/canFocusInputOnScreenFocus/index.ts @@ -0,0 +1,6 @@ +import * as DeviceCapabilities from '../DeviceCapabilities'; +import CanFocusInputOnScreenFocus from './types'; + +const canFocusInputOnScreenFocus: CanFocusInputOnScreenFocus = () => !DeviceCapabilities.canUseTouchScreen(); + +export default canFocusInputOnScreenFocus; diff --git a/src/libs/canFocusInputOnScreenFocus/types.ts b/src/libs/canFocusInputOnScreenFocus/types.ts new file mode 100644 index 000000000000..5a65e5e7d198 --- /dev/null +++ b/src/libs/canFocusInputOnScreenFocus/types.ts @@ -0,0 +1,3 @@ +type CanFocusInputOnScreenFocus = () => boolean; + +export default CanFocusInputOnScreenFocus; diff --git a/src/libs/shouldRenderOffscreen/index.android.js b/src/libs/shouldRenderOffscreen/index.android.js deleted file mode 100644 index c91ffa15894d..000000000000 --- a/src/libs/shouldRenderOffscreen/index.android.js +++ /dev/null @@ -1,2 +0,0 @@ -// Rendering offscreen on Android allows it to apply opacity to stacked components correctly. -export default true; diff --git a/src/libs/shouldRenderOffscreen/index.android.ts b/src/libs/shouldRenderOffscreen/index.android.ts new file mode 100644 index 000000000000..bf2d9837086f --- /dev/null +++ b/src/libs/shouldRenderOffscreen/index.android.ts @@ -0,0 +1,6 @@ +import ShouldRenderOffscreen from './types'; + +// Rendering offscreen on Android allows it to apply opacity to stacked components correctly. +const shouldRenderOffscreen: ShouldRenderOffscreen = true; + +export default shouldRenderOffscreen; diff --git a/src/libs/shouldRenderOffscreen/index.js b/src/libs/shouldRenderOffscreen/index.js deleted file mode 100644 index 33136544dba2..000000000000 --- a/src/libs/shouldRenderOffscreen/index.js +++ /dev/null @@ -1 +0,0 @@ -export default false; diff --git a/src/libs/shouldRenderOffscreen/index.ts b/src/libs/shouldRenderOffscreen/index.ts new file mode 100644 index 000000000000..eadcc44814f9 --- /dev/null +++ b/src/libs/shouldRenderOffscreen/index.ts @@ -0,0 +1,5 @@ +import ShouldRenderOffscreen from './types'; + +const shouldRenderOffscreen: ShouldRenderOffscreen = false; + +export default shouldRenderOffscreen; diff --git a/src/libs/shouldRenderOffscreen/types.ts b/src/libs/shouldRenderOffscreen/types.ts new file mode 100644 index 000000000000..63cd98eec31b --- /dev/null +++ b/src/libs/shouldRenderOffscreen/types.ts @@ -0,0 +1,3 @@ +type ShouldRenderOffscreen = boolean; + +export default ShouldRenderOffscreen; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 6daa15785921..5d0cb5ab9bf6 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -37,6 +37,7 @@ import ReportScreenContext from './ReportScreenContext'; import TaskHeaderActionButton from '../../components/TaskHeaderActionButton'; import DragAndDropProvider from '../../components/DragAndDrop/Provider'; import usePrevious from '../../hooks/usePrevious'; +import withCurrentReportID, {withCurrentReportIDPropTypes, withCurrentReportIDDefaultProps} from '../../components/withCurrentReportID'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -88,6 +89,7 @@ const propTypes = { ...windowDimensionsPropTypes, ...viewportOffsetTopPropTypes, + ...withCurrentReportIDPropTypes, }; const defaultProps = { @@ -102,6 +104,7 @@ const defaultProps = { policies: {}, accountManagerReportID: null, personalDetails: {}, + ...withCurrentReportIDDefaultProps, }; /** @@ -131,6 +134,7 @@ function ReportScreen({ viewportOffsetTop, isComposerFullSize, errors, + currentReportID, }) { const firstRenderRef = useRef(true); const flatListRef = useRef(); @@ -157,7 +161,7 @@ function ReportScreen({ const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; - const isTopMostReportId = Navigation.getTopmostReportId() === getReportID(route); + const isTopMostReportId = currentReportID === getReportID(route); let headerView = ( _.size(reportActions) === 1, [reportActions]); - const shouldAutoFocus = !modal.isVisible && (shouldFocusInputOnScreenFocus || isEmptyChat) && shouldShowComposeInput; + const parentAction = ReportActionsUtils.getParentReportAction(report); + const shouldAutoFocus = !modal.isVisible && (shouldFocusInputOnScreenFocus || (isEmptyChat && !ReportActionsUtils.isTransactionThread(parentAction))) && shouldShowComposeInput; const valueRef = useRef(value); valueRef.current = value; diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index c7517977aa27..3ad92fa5c769 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -285,6 +285,15 @@ function ReportActionCompose({ setIsFocused(true); }, []); + // resets the composer to normal size when + // the send button is pressed. + const resetFullComposerSize = useCallback(() => { + if (isComposerFullSize) { + Report.setIsComposerFullSize(reportID, false); + } + setIsFullComposerAvailable(false); + }, [isComposerFullSize, reportID]); + // We are returning a callback here as we want to incoke the method on unmount only useEffect( () => () => { @@ -338,7 +347,7 @@ function ReportActionCompose({ reportID={reportID} report={report} reportParticipantIDs={reportParticipantIDs} - isFullComposerAvailable={isFullComposerAvailable} + isFullComposerAvailable={isFullComposerAvailable && !isCommentEmpty} isComposerFullSize={isComposerFullSize} updateShouldShowSuggestionMenuToFalse={updateShouldShowSuggestionMenuToFalse} isBlockedFromConcierge={isBlockedFromConcierge} @@ -400,6 +409,7 @@ function ReportActionCompose({ diff --git a/src/pages/home/report/ReportActionCompose/SendButton.js b/src/pages/home/report/ReportActionCompose/SendButton.js index 4f1dc5fff191..8128b5a6b39d 100644 --- a/src/pages/home/report/ReportActionCompose/SendButton.js +++ b/src/pages/home/report/ReportActionCompose/SendButton.js @@ -23,11 +23,14 @@ const propTypes = { /** Sets the isCommentEmpty flag to true */ setIsCommentEmpty: PropTypes.func.isRequired, + /** resets the composer to normal size */ + resetFullComposerSize: PropTypes.func.isRequired, + /** Submits the form */ submitForm: PropTypes.func.isRequired, }; -function SendButton({isDisabled: isDisabledProp, animatedRef, setIsCommentEmpty, submitForm}) { +function SendButton({isDisabled: isDisabledProp, animatedRef, setIsCommentEmpty, resetFullComposerSize, submitForm}) { const {translate} = useLocalize(); const Tap = Gesture.Tap() @@ -40,6 +43,7 @@ function SendButton({isDisabled: isDisabledProp, animatedRef, setIsCommentEmpty, const updates = {text: ''}; // We are setting the isCommentEmpty flag to true so the status of it will be in sync of the native text input state runOnJS(setIsCommentEmpty)(true); + runOnJS(resetFullComposerSize)(); updatePropsPaperWorklet(viewTag, viewName, updates); // clears native text input on the UI thread runOnJS(submitForm)(); }); diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 22ded971898f..8425f78a3a10 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -344,6 +344,7 @@ function ReportActionItem(props) { {!props.draftMessage ? ( ReportActions.clearReportActionErrors(props.report.reportID, props.action)} pendingAction={props.draftMessage ? null : props.action.pendingAction} - shouldHideOnDelete={!ReportActionsUtils.hasCommentThread(props.action)} + shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(props.action, props.report.reportID)} errors={props.action.errors} errorRowStyles={[styles.ml10, styles.mr2]} needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(props.action)} diff --git a/src/pages/home/report/ReportActionItemFragment.js b/src/pages/home/report/ReportActionItemFragment.js index 91ee8f7531da..d768fcacd5b7 100644 --- a/src/pages/home/report/ReportActionItemFragment.js +++ b/src/pages/home/report/ReportActionItemFragment.js @@ -67,6 +67,9 @@ const propTypes = { /** icon */ actorIcon: avatarPropTypes, + /** Whether the comment is a thread parent message/the first message in a thread */ + isThreadParentMessage: PropTypes.bool, + ...windowDimensionsPropTypes, /** localization props */ @@ -88,6 +91,7 @@ const defaultProps = { style: [], delegateAccountID: 0, actorIcon: {}, + isThreadParentMessage: false, }; function ReportActionItemFragment(props) { @@ -113,7 +117,7 @@ function ReportActionItemFragment(props) { // While offline we display the previous message with a strikethrough style. Once online we want to // immediately display "[Deleted message]" while the delete action is pending. - if ((!props.network.isOffline && props.hasCommentThread && props.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) || props.fragment.isDeletedParentAction) { + if ((!props.network.isOffline && props.isThreadParentMessage && props.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) || props.fragment.isDeletedParentAction) { return ${props.translate('parentReportAction.deletedMessage')}`} />; } diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 40d2d5e6d89c..bc92889158d0 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -23,6 +23,9 @@ const propTypes = { /** Whether or not the message is hidden by moderation */ isHidden: PropTypes.bool, + /** The ID of the report */ + reportID: PropTypes.string.isRequired, + /** localization props */ ...withLocalizePropTypes, }; @@ -53,7 +56,7 @@ function ReportActionItemMessage(props) { fragment={fragment} isAttachment={props.action.isAttachment} iouMessage={iouMessage} - hasCommentThread={ReportActionsUtils.hasCommentThread(props.action)} + isThreadParentMessage={ReportActionsUtils.isThreadParentMessage(props.action, props.reportID)} attachmentInfo={props.action.attachmentInfo} pendingAction={props.action.pendingAction} source={lodashGet(props.action, 'originalMessage.source')} diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index da475e61f749..a694c4996438 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -275,6 +275,10 @@ function arePropsEqual(oldProps, newProps) { return false; } + if (lodashGet(newProps, 'report.participantAccountIDs', 0) !== lodashGet(oldProps, 'report.participantAccountIDs', 0)) { + return false; + } + return _.isEqual(lodashGet(newProps.report, 'icons', []), lodashGet(oldProps.report, 'icons', [])); } diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 6db3a20a3e4a..b7a1986c06e6 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -186,7 +186,7 @@ function WorkspaceInvitePage(props) { ); const headerMessage = useMemo(() => { - const searchValue = searchTerm.trim(); + const searchValue = searchTerm.trim().toLowerCase(); if (!userToInvite && CONST.EXPENSIFY_EMAILS.includes(searchValue)) { return translate('messages.errorMessageInvalidEmail'); } diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js index e72b02e18696..e551e0d6d1b9 100644 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js +++ b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js @@ -93,9 +93,11 @@ class WorkspaceRateAndUnitPage extends React.Component { validate(values) { const errors = {}; const decimalSeparator = this.props.toLocaleDigit('.'); - const rateValueRegex = RegExp(String.raw`^\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,3})?$`, 'i'); + const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,3})?$`, 'i'); if (!rateValueRegex.test(values.rate) || values.rate === '') { errors.rate = 'workspace.reimburse.invalidRateError'; + } else if (parseFloat(values.rate) <= 0) { + errors.rate = 'workspace.reimburse.lowRateError'; } return errors; } diff --git a/src/types/onyx/OnyxUpdatesFromServer.ts b/src/types/onyx/OnyxUpdatesFromServer.ts new file mode 100644 index 000000000000..02a96d4ce230 --- /dev/null +++ b/src/types/onyx/OnyxUpdatesFromServer.ts @@ -0,0 +1,14 @@ +import {OnyxUpdate} from 'react-native-onyx'; +import Request from './Request'; +import Response from './Response'; + +type OnyxUpdatesFromServer = { + type: 'https' | 'pusher'; + lastUpdateID: number | string; + previousUpdateID: number | string; + request?: Request; + response?: Response; + updates?: OnyxUpdate[]; +}; + +export default OnyxUpdatesFromServer; diff --git a/src/types/onyx/RecentlyUsedCategories.ts b/src/types/onyx/RecentlyUsedCategories.ts new file mode 100644 index 000000000000..d251b16f8667 --- /dev/null +++ b/src/types/onyx/RecentlyUsedCategories.ts @@ -0,0 +1,3 @@ +type RecentlyUsedCategories = string[]; + +export default RecentlyUsedCategories; diff --git a/src/types/onyx/Request.ts b/src/types/onyx/Request.ts index e730dfd807fb..1df20cfb28fe 100644 --- a/src/types/onyx/Request.ts +++ b/src/types/onyx/Request.ts @@ -1,8 +1,12 @@ +import {OnyxUpdate} from 'react-native-onyx'; + type Request = { command?: string; data?: Record; type?: string; shouldUseSecure?: boolean; + successData?: OnyxUpdate[]; + failureData?: OnyxUpdate[]; }; export default Request; diff --git a/src/types/onyx/Response.ts b/src/types/onyx/Response.ts new file mode 100644 index 000000000000..c501034e971c --- /dev/null +++ b/src/types/onyx/Response.ts @@ -0,0 +1,11 @@ +import {OnyxUpdate} from 'react-native-onyx'; + +type Response = { + previousUpdateID?: number | string; + lastUpdateID?: number | string; + jsonCode?: number; + onyxData?: OnyxUpdate[]; + requestID?: string; +}; + +export default Response; diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index 9e6cd603472f..4326920ab51f 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -6,6 +6,18 @@ type Comment = { comment?: string; }; +type Geometry = { + coordinates: number[][]; + type: 'LineString'; +}; + +type Route = { + distance: number; + geometry: Geometry; +}; + +type Routes = Record; + type Transaction = { transactionID: string; amount: number; @@ -25,6 +37,7 @@ type Transaction = { source?: string; state?: ValueOf; }; + routes?: Routes; }; export default Transaction; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 039448fac531..d908c0b36ce1 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -33,6 +33,7 @@ import ReimbursementAccountDraft from './ReimbursementAccountDraft'; import WalletTransfer from './WalletTransfer'; import ReceiptModal from './ReceiptModal'; import MapboxAccessToken from './MapboxAccessToken'; +import OnyxUpdatesFromServer from './OnyxUpdatesFromServer'; import Download from './Download'; import PolicyMember from './PolicyMember'; import Policy from './Policy'; @@ -43,6 +44,7 @@ import SecurityGroup from './SecurityGroup'; import Transaction from './Transaction'; import Form, {AddDebitCardForm} from './Form'; import RecentWaypoints from './RecentWaypoints'; +import RecentlyUsedCategories from './RecentlyUsedCategories'; export type { Account, @@ -90,5 +92,7 @@ export type { Transaction, Form, AddDebitCardForm, + OnyxUpdatesFromServer, RecentWaypoints, + RecentlyUsedCategories, }; diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 6fbbe19cec8e..afb06cdb6fb3 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -9,6 +9,7 @@ import DateUtils from '../../src/libs/DateUtils'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as ReportActions from '../../src/libs/actions/ReportActions'; import * as Report from '../../src/libs/actions/Report'; +import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; const CARLOS_EMAIL = 'cmartins@expensifail.com'; const CARLOS_ACCOUNT_ID = 1; @@ -19,6 +20,7 @@ const RORY_ACCOUNT_ID = 3; const VIT_EMAIL = 'vit@expensifail.com'; const VIT_ACCOUNT_ID = 4; +OnyxUpdateManager(); describe('actions/IOU', () => { beforeAll(() => { Onyx.init({ diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index c06d3bc83766..978186fcf9c4 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -14,6 +14,7 @@ import * as PersistedRequests from '../../src/libs/actions/PersistedRequests'; import * as User from '../../src/libs/actions/User'; import * as ReportUtils from '../../src/libs/ReportUtils'; import DateUtils from '../../src/libs/DateUtils'; +import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; jest.mock('../../src/libs/actions/Report', () => { const originalModule = jest.requireActual('../../src/libs/actions/Report'); @@ -24,6 +25,7 @@ jest.mock('../../src/libs/actions/Report', () => { }; }); +OnyxUpdateManager(); describe('actions/Report', () => { beforeAll(() => { PusherHelper.setup(); diff --git a/tests/actions/SessionTest.js b/tests/actions/SessionTest.js index d8bfa144e358..59a7441679ea 100644 --- a/tests/actions/SessionTest.js +++ b/tests/actions/SessionTest.js @@ -7,6 +7,7 @@ import * as TestHelper from '../utils/TestHelper'; import CONST from '../../src/CONST'; import PushNotification from '../../src/libs/Notification/PushNotification'; import * as App from '../../src/libs/actions/App'; +import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; // This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection // eslint-disable-next-line no-unused-vars @@ -24,6 +25,7 @@ Onyx.init({ registerStorageEventListener: () => {}, }); +OnyxUpdateManager(); beforeEach(() => Onyx.clear().then(waitForPromisesToResolve)); describe('Session', () => { diff --git a/tests/unit/NetworkTest.js b/tests/unit/NetworkTest.js index c8dcda0e2af5..7d8c4f23197c 100644 --- a/tests/unit/NetworkTest.js +++ b/tests/unit/NetworkTest.js @@ -14,6 +14,7 @@ import Log from '../../src/libs/Log'; import * as MainQueue from '../../src/libs/Network/MainQueue'; import * as App from '../../src/libs/actions/App'; import NetworkConnection from '../../src/libs/NetworkConnection'; +import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; jest.mock('../../src/libs/Log'); jest.useFakeTimers(); @@ -22,6 +23,7 @@ Onyx.init({ keys: ONYXKEYS, }); +OnyxUpdateManager(); const originalXHR = HttpUtils.xhr; beforeEach(() => {