Skip to content

Preserve Search context when opening trip previews - #96283

Merged
luacmartins merged 8 commits into
Expensify:mainfrom
marufsharifi:fix/preserve-search-context-for-trip-previews
Aug 7, 2026
Merged

Preserve Search context when opening trip previews#96283
luacmartins merged 8 commits into
Expensify:mainfrom
marufsharifi:fix/preserve-search-context-for-trip-previews

Conversation

@marufsharifi

@marufsharifi marufsharifi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

TripRoomPreview used ROUTES.REPORT_WITH_ID to navigate when a user tapped a trip reservation item or the "View" button. This route always opens in the Inbox navigator, so users on the Search tab were unexpectedly switched to Inbox. This change replaces the hardcoded route with getReportRouteForCurrentContext, which returns the correct Search-owned or Inbox-owned route based on the current fullscreen navigator.

Fixed Issues

$ #85560
PROPOSAL: #85560 (comment)

Tests

  1. Go to Spend > Chats
  2. Open any chat that contains a trip preview (e.g. a booked trip)
  3. Tap any reservation item or the "View" button on the trip card
  4. Verify the trip report opens within the same context (Search or Inbox) without switching tabs
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • 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 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 that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • 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)
  • 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(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-07-21.at.3.07.52.PM.mov
Android: mWeb Chrome
Recording_20260721_144618.mp4
iOS: Native
Screen.Recording.2026-07-21.at.2.55.59.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-07-21.at.2.57.33.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-21.at.2.43.48.PM.mov

@marufsharifi
marufsharifi marked this pull request as ready for review July 21, 2026 10:44
@marufsharifi
marufsharifi requested review from a team as code owners July 21, 2026 10:44
@melvin-bot
melvin-bot Bot requested review from heyjennahay and sobitneupane and removed request for a team July 21, 2026 10:44
@melvin-bot

melvin-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

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

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@sobitneupane, Gentle bump. thanks.

@sobitneupane

Copy link
Copy Markdown
Contributor

Sorry for the delay @marufsharifi I will try to get this done by EOD tomorrow

@sobitneupane

Copy link
Copy Markdown
Contributor

@marufsharifi The changes looks good. How can I create a test trip for testing purposes?

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@sobitneupane, Since I don't have access to a real trip, I used hardcoded mock data to reproduce this. Apply the patch below — it seeds a mock trip preview into the Concierge chat. Then open Concierge from Reports > Chats and tap the reservation / View button.

trip-preview-repro.patch
diff --git a/src/Expensify.tsx b/src/Expensify.tsx
index 463f0d9adc7..30076bbfde7 100644
--- a/src/Expensify.tsx
+++ b/src/Expensify.tsx
@@ -263,6 +263,119 @@ function Expensify() {
         initReconnect();
     }, []);

+    // ------------------------------------------------------------------
+    // Mock trip data for testing PR #96283 — REMOVE AFTER TESTING.
+    // Seeds a mock trip room + a TRIPPREVIEW action in the Concierge chat
+    // so the real TripRoomPreview renders through the normal pipeline.
+    // ------------------------------------------------------------------
+    /* eslint-disable @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/naming-convention -- temporary local fixture for PR #96283 testing */
+    const [session] = useOnyx(ONYXKEYS.SESSION);
+    const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
+    useEffect(() => {
+        if (!session?.accountID || !conciergeReportID) {
+            return;
+        }
+        const accountID = session.accountID;
+        const tripReportID = '99990002';
+
+        const mockTripRoom = {
+            reportID: tripReportID,
+            type: CONST.REPORT.TYPE.CHAT,
+            reportName: 'NYC Business Trip',
+            chatType: CONST.REPORT.CHAT_TYPE.TRIP_ROOM,
+            ownerAccountID: accountID,
+            currency: 'USD',
+            participants: {[accountID]: {notificationPreference: 'always'}},
+            lastMessageText: 'Trip to Los Angeles',
+            lastActorAccountID: accountID,
+            lastVisibleActionCreated: '2026-07-13 10:00:00.000',
+            tripData: {
+                startDate: '2026-07-15',
+                endDate: '2026-07-20',
+                tripID: 'trip_mock_1',
+                payload: {
+                    tripId: 'trip_mock_1',
+                    tripName: 'NYC Business Trip',
+                    startDateTime: {iso8601: '2026-07-15T08:00:00Z'},
+                    endDateTime: {iso8601: '2026-07-20T18:00:00Z'},
+                    tripPaymentInfo: {totalFare: {amount: 350, currencyCode: 'USD'}},
+                    pnrs: [
+                        {
+                            pnrId: 'pnr_mock_1',
+                            data: {
+                                bookingStatus: 'CONFIRMED',
+                                pnrTravelers: [],
+                                additionalMetadata: {
+                                    airportInfo: [
+                                        {airportCode: 'JFK', airportName: 'John F. Kennedy International Airport', cityName: 'New York', stateCode: 'NY', countryName: 'USA'},
+                                        {airportCode: 'LAX', airportName: 'Los Angeles International Airport', cityName: 'Los Angeles', stateCode: 'CA', countryName: 'USA'},
+                                    ],
+                                    airlineInfo: [{airlineCode: 'AA', airlineName: 'American Airlines'}],
+                                },
+                                airPnr: {
+                                    legs: [
+                                        {
+                                            legStatus: 'CONFIRMED_STATUS',
+                                            flights: [
+                                                {
+                                                    origin: 'JFK',
+                                                    destination: 'LAX',
+                                                    departureDateTime: {iso8601: '2026-07-15T08:00:00'},
+                                                    arrivalDateTime: {iso8601: '2026-07-15T11:30:00'},
+                                                    marketing: {airlineCode: 'AA', num: '123'},
+                                                    cabin: 'ECONOMY',
+                                                    flightStatus: 'CONFIRMED',
+                                                    vendorConfirmationNumber: 'MOCK123',
+                                                    duration: {iso8601: 'PT5H30M'},
+                                                },
+                                            ],
+                                        },
+                                    ],
+                                    travelerInfos: [
+                                        {
+                                            userId: {id: 'traveler_mock_1'},
+                                            tickets: [{flightCoupons: [{legIdx: 0, flightIdx: 0}]}],
+                                        },
+                                    ],
+                                },
+                            },
+                        },
+                    ],
+                },
+            },
+        };
+
+        // eslint-disable-next-line rulesdir/prefer-actions-set-data -- temporary local fixture for PR #96283 testing
+        Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${tripReportID}`, mockTripRoom as never);
+
+        // eslint-disable-next-line rulesdir/prefer-actions-set-data -- temporary local fixture for PR #96283 testing
+        Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${tripReportID}`, {
+            '8000000000001': {
+                reportActionID: '8000000000001',
+                actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
+                actorAccountID: accountID,
+                created: '2026-07-13 10:00:00.000',
+                message: [{type: 'COMMENT', html: 'Trip created', text: 'Trip created'}],
+            },
+        } as never);
+
+        // eslint-disable-next-line rulesdir/prefer-actions-set-data -- temporary local fixture for PR #96283 testing
+        Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${conciergeReportID}`, {
+            '8000000000002': {
+                reportActionID: '8000000000002',
+                actionName: CONST.REPORT.ACTIONS.TYPE.TRIP_PREVIEW,
+                actorAccountID: accountID,
+                created: '2026-07-13 10:00:05.000',
+                message: [{type: 'COMMENT', html: 'Trip preview', text: 'Trip preview'}],
+                originalMessage: {linkedReportID: tripReportID},
+            },
+        } as never);
+    }, [session?.accountID, conciergeReportID]);
+    /* eslint-enable @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/naming-convention */
+    // ------------------------------------------------------------------
+    // End of mock trip data — REMOVE AFTER TESTING.
+    // ------------------------------------------------------------------
+
     useLayoutEffect(() => {
         if (!isNavigationReady || !lastRoute) {
             return;

@sobitneupane sobitneupane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that 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 that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • 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)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • 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
    • 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(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
Screen.Recording.2026-07-27.at.23.28.26.mov
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-07-27.at.23.19.52.mov

@melvin-bot
melvin-bot Bot requested a review from luacmartins July 27, 2026 17:53
@marufsharifi

Copy link
Copy Markdown
Contributor Author

@luacmartins, could you please hold off on merging this for now? I’ll run another round of testing and let you know once it’s ready. Thanks!

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@sobitneupane, During testing, I found one more edge case in the trip preview flow.

Repro steps:

  1. Open a trip preview from Spend > Chats / Search while the linked trip report is still loading.
  2. Click the trip preview before the linked report has a valid reportID.
  3. Verify the app navigates to an empty report route and can redirect to Home.
Screen.Recording.2026-07-29.at.2.28.10.PM.mov

I’m working on a fix for this case too. Thanks!

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@sobitneupane, During testing, I found one more edge case in the trip preview flow.

@sobitneupane Addressed this case too. Could you please take another look? Thanks!

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@sobitneupane, Gentle bump. thanks.

@sobitneupane

Copy link
Copy Markdown
Contributor

Reviewing the updates.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@luacmartins, could you please take a look at this, when you get a chance. thanks.

@marufsharifi

Copy link
Copy Markdown
Contributor Author

@luacmartins, Gentle bump. thanks.

@luacmartins

Copy link
Copy Markdown
Contributor

Sorry, I was OOO. Approved.

@luacmartins luacmartins closed this Aug 6, 2026
@luacmartins luacmartins reopened this Aug 6, 2026
@luacmartins

Copy link
Copy Markdown
Contributor

@marufsharifi can you merge main please? One workflow seems stuck

@luacmartins
luacmartins merged commit 3aaea6c into Expensify:main Aug 7, 2026
34 checks passed
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🚧 luacmartins has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
Built from App PR #96283.

Android 🤖 iOS 🍎
❌ FAILED ❌ https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-ios-device-AdHoc-3aaea6c-f1b9fa4-758bb92c321f49887819dafe6c7af98f894da28f/index.html
The QR code can't be generated, because the Android build failed iOS
Web 🕸️
https://96283.pr-testing.expensify.com
Web

👀 View the workflow run that generated this build 👀

@OSBotify

OSBotify commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.4.52-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 cancelled 🔪

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed this PR against the help site articles in App/docs/articles and no help site changes are required.

Why: This is an internal navigation bug fix. It swaps the hardcoded ROUTES.REPORT_WITH_ID for getReportRouteForCurrentContext in src/components/ReportActionItem/TripRoomPreview.tsx so tapping a reservation item or View keeps the user in their current tab context (Search vs. Inbox) instead of always jumping to Inbox. There is no new feature, no new UI label, and no change to any documented, user-facing workflow.

The travel help articles (e.g. View-Upcoming-and-Past-Trips.md, Creating-Trips.md) describe how to view and manage trips, but none document which app navigator tab a trip preview opens in — so the fix doesn't contradict or require updates to any published content.

No draft docs PR was created since there's nothing to document.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.52-11 🚀

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

Bundle Size Analysis (Sentry):

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