Skip to content

Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts (part 4)#90174

Merged
Gonals merged 32 commits into
Expensify:mainfrom
truph01:fix/66416-part-4
Jun 15, 2026
Merged

Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts (part 4)#90174
Gonals merged 32 commits into
Expensify:mainfrom
truph01:fix/66416-part-4

Conversation

@truph01

@truph01 truph01 commented May 11, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

  • This PR is the 4th step to remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT in src/libs/ReportUtils.ts.
    This PR focus on refactoring all places
  1. where getReportOrDraftReport are called directly (We already did a few in 3rd PR)
  2. getReportOrDraftReport -> getTransactionReportName
  3. getReportOrDraftReport -> getTransactionReportName -> computeChatThreadReportName -> computeReportName (ReportNameUtils.ts)

Fixed Issues

$ #66416
PROPOSAL:

Tests

  1. Open policy expense chat. Request 2 expenses.
  2. Open the expense report in step 1.
  3. Choose one expense.
  4. Tab "1 selected" dropdown button > Merge
  5. Verify the header of the list displays "Select an eligible expense to merge with ..." with correct name.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Open policy expense chat. Request 2 expenses.
  2. Open the expense report in step 1.
  3. Choose one expense.
  4. Tab "1 selected" dropdown button > Merge
  5. Verify the header of the list displays "Select an eligible expense to merge with ..." with correct name.
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained ""why"" the code was doing something instead of only explaining ""what"" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named ""index.js"". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-06-04.at.16.02.16.mov

@truph01 truph01 requested review from a team as code owners May 11, 2026 11:58
@melvin-bot melvin-bot Bot requested review from DylanDylann and heyjennahay and removed request for a team May 11, 2026 11:58
@melvin-bot

melvin-bot Bot commented May 11, 2026

Copy link
Copy Markdown

@DylanDylann 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]

@@ -162,7 +162,9 @@ function shouldShowBulkDuplicateOption({
}

const reportID = selectedTransactions[id]?.reportID;

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.

❌ CONSISTENCY-3 (docs)

The expression allReports?.[\${ONYXKEYS.COLLECTION.REPORT}${reportID}`]is repeated across multiple call sites in this file and inuseSelectedTransactionsActions.ts. This boilerplate for looking up a report from the allReportscollection and passing it as the 5th positional argument (with threeundefined` placeholders) is duplicated 6+ times.

Consider extracting a helper function to encapsulate this pattern:

function getReportFromAllReports(reportID: string | undefined) {
    return reportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] : undefined;
}

Then each call site becomes:

getReportOrDraftReport(reportID, searchReports, undefined, undefined, getReportFromAllReports(reportID))

Or better yet, consider whether getReportOrDraftReport itself should accept a named options object instead of positional parameters to avoid the undefined, undefined, undefined pattern entirely.


Reviewed at: a13d9e2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a common pattern used throughout the app for looking up Onyx collection entries. Introducing a helper like:

function getReportFromAllReports(reportID: string | undefined) {
    return reportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] : undefined;
}

would just replace allReports?.[${ONYXKEYS.COLLECTION.REPORT}${reportID}] with getReportFromAllReports(reportID) — it doesn't reduce complexity or improve readability in a meaningful way. The lookup is a single expression and is already self-explanatory. I'll leave this as-is.


// The report must be in Onyx so the pre-inserted screen can render immediately.
const isDestinationReportLoaded = !!destinationReportID && !!getReportOrDraftReport(destinationReportID)?.reportID;
const isDestinationReportLoaded = !!destinationReportID && !!getReportOrDraftReport(destinationReportID, undefined, undefined, undefined, destinationReport)?.reportID;

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.

❌ CONSISTENCY-3 (docs)

The pattern getReportOrDraftReport(reportID, undefined, undefined, undefined, report) with three positional undefined placeholders is duplicated across this file and SubmitExpenseOrchestrator.tsx (which has the same pattern twice). This is the same code smell present in the hooks files.

Since getReportOrDraftReport already has a positional API with 5 parameters, and most callers only need the 1st and 5th, consider refactoring it to accept a named options object:

function getReportOrDraftReport({ reportID, searchReports, fallbackReport, reportDrafts, report }: GetReportOrDraftReportParams)

This would eliminate all the undefined placeholders and make call sites self-documenting.


Reviewed at: a13d9e2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ince getReportOrDraftReport already has a positional API with 5 parameters, and most callers only need the 1st and 5th, consider refactoring it to accept a named options object:

function getReportOrDraftReport({ reportID, searchReports, fallbackReport, reportDrafts, report }: GetReportOrDraftReportParams)

That plan sounds good. However, I think we can do it in another PR.
cc @DylanDylann

const {targetTransaction, sourceTransaction, targetTransactionReport, sourceTransactionReport, targetTransactionPolicy, sourceTransactionPolicy} = useMergeTransactions({
mergeTransaction,
});
const [targetTransactionReportByID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${targetTransaction?.reportID}`);

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.

❌ PERF-11 (docs)

This useOnyx call subscribes to targetTransactionReportByID using targetTransaction?.reportID, but targetTransactionReport is already available from useMergeTransactions() on line 51 and represents the same report (for reported expenses, getReportIDForExpense returns transaction.reportID). This creates a redundant Onyx subscription that will cause unnecessary re-renders.

Consider passing the already-available targetTransactionReport as the transactionReport parameter instead of creating a new subscription:

getTransactionReportName({
    translate,
    reportAction: undefined,
    transaction: targetTransaction,
    transactions: [targetTransaction],
    reports: targetTransactionReport ? [targetTransactionReport] : [],
    transactionReport: targetTransactionReport,
})

This eliminates the extra useOnyx subscription entirely.


Reviewed at: a13d9e2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved it

@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/hooks/useSearchBulkActions.ts 50.65% <100.00%> (+0.05%) ⬆️
src/hooks/useSelectedTransactionsActions.ts 76.63% <100.00%> (ø)
src/libs/ReportNameUtils.ts 82.32% <100.00%> (+0.04%) ⬆️
src/libs/ReportUtils.ts 84.83% <ø> (+0.01%) ⬆️
...es/iou/request/step/IOURequestStepConfirmation.tsx 64.55% <100.00%> (+0.11%) ⬆️
.../TransactionMerge/MergeTransactionsListContent.tsx 0.00% <0.00%> (ø)
...st/step/confirmation/SubmitExpenseOrchestrator.tsx 61.97% <66.66%> (+0.54%) ⬆️
... and 11 files with indirect coverage changes

@heyjennahay heyjennahay 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.

No product review required

@DylanDylann

Copy link
Copy Markdown
Contributor

@truph01 Could you check the AI review and fix the failed check?

@truph01

truph01 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@DylanDylann All comments are resolved

Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
transaction?: OnyxEntry<Transaction>;
transactions?: Transaction[];
reports?: Report[];
transactionReport?: OnyxEntry<Report>;

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.

Do we plan to remove "?" in the next PRs? If yes, please leave a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added 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.

@truph01 Please add issue link

Comment thread src/libs/ReportUtils.ts Outdated
* @deprecated Moved to src/libs/ReportNameUtils.ts.
*/
function getReportName(reportNameInformation: GetReportNameParams): string {
const {report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy, reportAttributes, transactions, isReportArchived, reports, conciergeReportID} =

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.

Are you planning to refactor getReportName in the next PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@DylanDylann Yes, I will refactor getReportName in the next PR

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.

@truph01 Could you merge the latest main again? Now this getReportName function can only be used in Search page. Could you verify again if it's necessary to refactor this function anymore

@truph01 truph01 May 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could you verify again if it's necessary to refactor this function anymore

@DylanDylann The getReportName is still called in getSearchReportName function, so I think we still need to refactor this function (getReportName).

@truph01

truph01 commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

@DylanDylann I resolved your comments

Comment thread src/libs/ReportUtils.ts Outdated
transaction?: OnyxEntry<Transaction>;
transactions?: Transaction[];
reports?: Report[];
transactionReport?: OnyxEntry<Report>;

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.

@truph01 Please add issue link

Comment thread src/libs/ReportUtils.ts Outdated
/** Used to identify the Concierge chat so its name can be set to the Concierge display name */
conciergeReportID?: string;
/** The transaction linked to the report action */
transaction?: OnyxEntry<Transaction>;

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.

Please add a comment to remind us to remove ? later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It isn't scope of this PR anymore based on #90174 (comment)

Comment on lines +133 to +136
transaction: targetTransaction,
transactions: [targetTransaction],
reports: targetTransactionReport ? [targetTransactionReport] : [],
transactionReport: targetTransactionReport,

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.

@truph01 These looks like redundant parameters. Could we make it cleaner?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I resolved it

@melvin-bot melvin-bot Bot requested a review from Gonals June 4, 2026 09:39
@DylanDylann

Copy link
Copy Markdown
Contributor

The test failure is due to a timeout. @truph01 Could you merge main again to re-run the test?

@DylanDylann

Copy link
Copy Markdown
Contributor

@truph01 Could you resolve the conflict?

@DylanDylann

Copy link
Copy Markdown
Contributor

@truph01 one failed check, could you solve it?

@truph01

truph01 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

The lint failure isn't related to this PR.

@Gonals

Gonals commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The lint failure isn't related to this PR.

Let's merge main. It should be good now

@DylanDylann

Copy link
Copy Markdown
Contributor

@Gonals Kindly bump

@Gonals Gonals merged commit f8283ec into Expensify:main Jun 15, 2026
32 checks passed
@OSBotify

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.

@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/Gonals in version: 9.4.8-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes required.

This PR is part 4 of an internal refactor to remove Onyx.connect() for ONYXKEYS.COLLECTION.REPORT in ReportUtils.ts. The changes are limited to:

  • Passing the report/allReports data explicitly as function arguments instead of reading it via a direct Onyx connection (getReportOrDraftReport, getTransactionReportName, computeChatThreadReportName).
  • Refactoring the getTransactionReportName signature from reports?: Report[] to report: OnyxEntry<Report>.
  • Adding useOnyx subscriptions in IOURequestStepConfirmation and SubmitExpenseOrchestrator to source report data.
  • Unit tests for getTransactionReportName.

There are no user-facing changes — no new features, UI elements, tabs, settings, or button labels are introduced or modified. Nothing under App/docs/articles describes this internal data-flow plumbing, so no documentation update is warranted and no draft help site PR was created.

@truph01, since no help site changes were required, there is no linked help site PR to review. If you believe a documentation update is needed, let me know what behavior changed and I'll draft one.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/Gonals in version: 9.4.8-0 🚀

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

Bundle Size Analysis (Sentry):

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.4.8-3 🚀

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants