Skip to content

[Part 2] Onyx.connect() removal for ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS in ReportUtils.ts#79832

Open
ShridharGoel wants to merge 89 commits into
Expensify:mainfrom
ShridharGoel:onyxConnect2.2
Open

[Part 2] Onyx.connect() removal for ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS in ReportUtils.ts#79832
ShridharGoel wants to merge 89 commits into
Expensify:mainfrom
ShridharGoel:onyxConnect2.2

Conversation

@ShridharGoel
Copy link
Copy Markdown
Contributor

@ShridharGoel ShridharGoel commented Jan 18, 2026

Explanation of Change

Here, we are passing archived‑report info into IOU/report selection and edit logic, and into search selection, so archived chats are consistently filtered and edit actions don’t target archived reports. We also remove the old Onyx.connect call since now all callers use the new hook‑based data.

Fixed Issues

$ #66422
PROPOSAL:

Tests

  1. Create a workspace.
  2. Go to #admins chat.
  3. Send a few messages.
  4. Go to workspace settings.
  5. Delete the workspace.
  6. Go to inbox.
  7. Go to the archived admins chat (might need to search for it).
  8. Ensure the chat shows as archived.
  9. There should be no chat input box.

  1. Create a new account.
  2. In the onboarding flow, select "Manage my team's expenses"
  3. Then, select 11-50 employees.
  4. Select "None" in accounting software.
  5. Select a few extra features in the next step (like tags).
  6. Complete the flow.
  7. Should be redirected to #admins and the tasks should show.

  1. Archive atleast one report.
  2. Go to any expense's details.
  3. Click on the report row to edit the report.
  4. Ensure it only shows non-archived report options.

  1. Go to search.
  2. Select any movable expense.
  3. Go to dropdown.
  4. Select "Move expenses".
  5. Ensure only non-archived reports show.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Sanity testing should be enough. Everything should work as before.

  • 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
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified 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-02-21.at.3.20.08.PM.mov

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 18, 2026

Codecov Report

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

Files with missing lines Coverage Δ
...eyRequestConfirmationList/sections/ReportField.tsx 85.10% <100.00%> (ø)
src/hooks/useArchivedReportsIDSet.ts 100.00% <100.00%> (ø)
src/hooks/useAutoCreateTrackWorkspace.ts 40.00% <100.00%> (ø)
src/hooks/useOutstandingReports.ts 93.75% <100.00%> (ø)
src/hooks/useSearchSections.ts 100.00% <100.00%> (ø)
src/hooks/useSelectedTransactionsActions.ts 76.44% <100.00%> (+0.09%) ⬆️
.../AppNavigator/Navigators/ReportsSplitNavigator.tsx 92.59% <100.00%> (ø)
src/libs/ReportSecondaryActionUtils.ts 94.63% <100.00%> (ø)
src/libs/actions/Report/MarkAllMessageAsRead.tsx 90.00% <100.00%> (ø)
src/libs/navigateAfterOnboarding.ts 79.16% <100.00%> (ø)
... and 13 more
... and 5 files with indirect coverage changes

@ShridharGoel ShridharGoel marked this pull request as ready for review February 22, 2026 06:44
@ShridharGoel ShridharGoel requested review from a team as code owners February 22, 2026 06:44
@melvin-bot melvin-bot Bot requested review from a team, DylanDylann and JmillsExpensify and removed request for a team February 22, 2026 06:44
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Feb 22, 2026

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

@melvin-bot melvin-bot Bot requested review from heyjennahay and removed request for a team February 22, 2026 06:44
@ShridharGoel ShridharGoel requested a review from DylanDylann May 15, 2026 08:57
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportSecondaryActionUtils.ts
…ect2.2

# Conflicts:
#	src/components/Search/index.tsx
#	src/hooks/useDeleteTransactions.ts
#	src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
#	src/pages/OnboardingWorkspaces/BaseOnboardingWorkspaces.tsx
@ShridharGoel ShridharGoel requested a review from DylanDylann May 22, 2026 07:10
@DylanDylann
Copy link
Copy Markdown
Contributor

Kindly bump on #79832 (comment)

@ShridharGoel
Copy link
Copy Markdown
Contributor Author

Updated

Comment thread src/components/Search/index.tsx Outdated
Comment thread src/libs/ReportSecondaryActionUtils.ts
Comment thread src/libs/ReportSecondaryActionUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/hooks/useDeleteTransactions.ts Outdated
Comment thread src/hooks/useAutoCreateTrackWorkspace.ts Outdated
Comment thread src/components/Search/index.tsx
…ect2.2

# Conflicts:
#	src/components/MoneyRequestHeaderSecondaryActions.tsx
#	src/components/Search/index.tsx
#	src/hooks/useDeleteTransactions.ts
#	src/libs/ReportSecondaryActionUtils.ts
#	tests/unit/ReportSecondaryActionUtilsTest.ts
selectedTransactions,
email ?? '',
accountID,
archivedReportsIDSet,
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.

Why do we need to pass archivedReportsIDSet here?

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 is used downstream by mapTransactionItemToSelectedEntry when calculating canChangeReport. That calls canEditFieldOfMoneyRequest, which needs archivedReportsIDSet to exclude archived reports from outstanding report checks without using Onyx.connect.

@DylanDylann
Copy link
Copy Markdown
Contributor

@ShridharGoel Could you review the change again before requesting review?

@ShridharGoel
Copy link
Copy Markdown
Contributor Author

@DylanDylann It's ready for review

@DylanDylann
Copy link
Copy Markdown
Contributor

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f17391f966

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/ReportUtils.ts Outdated

// Unreported transaction from OldDot can have the reportID as an empty string
const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
const archivedReportIDs = archivedReportsIDSet ?? buildArchivedReportsIDSet(allReportNameValuePair);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid rebuilding archived sets for unrelated edits

When archivedReportsIDSet is omitted, this scans the entire report-name-value-pairs collection before knowing whether archive status is needed. Callers such as canEditMultipleTransactions() still invoke canEditFieldOfMoneyRequest() without the set while checking AMOUNT/MERCHANT/etc., so bulk-selecting many expenses can now do an O(number of selected transactions × number of reports) rebuild even though those fields never use archivedReportIDs. Move this fallback into the REPORT branch (or pass a prebuilt set from the caller) so non-report edit checks keep their previous constant-time behavior.

Useful? React with 👍 / 👎.

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.

@MelvinBot Are we necessary to pass the full archivedReportsIDSet in the canEditFieldOfMoneyRequest function?

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.

@ShridharGoel Could you check this codex's 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.

Updated

@MelvinBot
Copy link
Copy Markdown
Contributor

Yes, the full archivedReportsIDSet is needed here. The function doesn't just check the current report — it also iterates across policies to count outstanding reports (lines 5044–5052), calling getOutstandingReportsForUser and isReportOutstanding for potentially many different reports. Each of those calls checks whether a given report is archived via isReportArchivedByID(archivedReportsIDSet, reportID), so a single report's archived status wouldn't be sufficient.

@DylanDylann
Copy link
Copy Markdown
Contributor

@MelvinBot Could you also review this PR?

@MelvinBot
Copy link
Copy Markdown
Contributor

Here's my review of the PR:

Overall: The migration from Onyx.connect() to hook-based archivedReportsIDSet is well-structured, and the naming fix (IdID) is a good consistency improvement. A few concerns:


1. Missing useMemo in useArchivedReportsIDSet — potential perf issue

useArchivedReportsIDSet calls buildArchivedReportsIDSet() on every render, creating a new Set reference each time. This means every component consuming this hook gets a fresh object, which breaks memoization in downstream useMemo/useCallback dependency arrays.

This is especially concerning in Search/index.tsx where archivedReportsIDSet is added to multiple useCallback deps — those callbacks will be recreated on every render.

Suggestion: Wrap the return in useMemo:

return useMemo(() => buildArchivedReportsIDSet(reportNameValuePairs), [reportNameValuePairs]);

2. Optional archivedReportsIDSet params + fallback pattern

The ? on canEditFieldOfMoneyRequest, isReportOutstanding, and getOutstandingReportsForUser with a fallback to buildArchivedReportsIDSet(allReportNameValuePair) means callers that forget to pass the set silently rebuild it from the module-level Onyx connection — which is the old pattern this PR is trying to remove.

The "temporarily optional" comments with the issue link are good. I'd echo DylanDylann's feedback: making these required now (where callers already have the set) prevents regressions where someone adds a new call site without passing it.

3. getOutstandingReportsForUser — parameter reorder is risky

The signature changed from (policyID, ownerAccountID, reports, reportNameValuePairs, allowSubmitted) to (policyID, ownerAccountID, archivedReportsIDSet?, reports, allowSubmitted). Since archivedReportsIDSet is optional and reports has a default value, a caller passing positional args in the old order would silently compile but pass the wrong values. Any callers outside this PR would break silently.

4. Inconsistent required vs optional

getSecondaryTransactionThreadActions has archivedReportsIDSet as required, while getSecondaryReportActions has it as optional. If both are being migrated in this PR, they should ideally be consistent.

5. Tests look good

The test updates correctly pass new Set<string>() for the new parameter, and the hook test renames are clean.


Summary: The main actionable item is adding useMemo to the hook to avoid unnecessary re-renders across the many components that consume it. The rest aligns with DylanDylann's existing feedback about making params required and using the hook directly rather than prop-drilling.

@DylanDylann
Copy link
Copy Markdown
Contributor

@ShridharGoel Kindly bump on #79832 (comment)

@ShridharGoel
Copy link
Copy Markdown
Contributor Author

Kindly bump on #79832 (comment)

@DylanDylann Which comment is that? No comment is getting highlighted on clicking the link

Comment thread src/libs/ReportUtils.ts
function getOutstandingReportsForUser(
policyID: string | undefined,
reportOwnerAccountID: number | undefined,
archivedReportsIDSet?: ArchivedReportsIDSet,
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.

@ShridharGoel if this is temporary, please comment that it should be removed in the next PRs (also note the link to the issue)

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.

The ref link didn't work 😄 I commented gain

@DylanDylann
Copy link
Copy Markdown
Contributor

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35524bf13f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

function useArchivedReportsIDSet(): ArchivedReportsIDSet {
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);

return buildArchivedReportsIDSet(reportNameValuePairs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid treating unloaded archive data as empty

When useOnyx has not delivered REPORT_NAME_VALUE_PAIRS yet, this returns an empty Set instead of an unloaded/undefined value. New callers pass that set into isReportOutstanding, whose fallback to the module-scoped allReportNameValuePair only runs when the set argument is omitted, so archived expense reports can be treated as outstanding in initial renders such as the report picker or move-expense eligibility until this hook catches up.

Useful? React with 👍 / 👎.

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.

4 participants