Skip to content

Remove Onyx.connect() usage for ONYXKEYS.COLLECTION.REPORTS from src/libs/actions/IOU/Transaction.ts - #93734

Open
Guccio163 wants to merge 33 commits into
Expensify:mainfrom
software-mansion-labs:Guccio163/onyx-connect/transaction/report
Open

Remove Onyx.connect() usage for ONYXKEYS.COLLECTION.REPORTS from src/libs/actions/IOU/Transaction.ts#93734
Guccio163 wants to merge 33 commits into
Expensify:mainfrom
software-mansion-labs:Guccio163/onyx-connect/transaction/report

Conversation

@Guccio163

@Guccio163 Guccio163 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR is part of a refactor to remove Onyx.connect for the keys: ONYXKEYS.COLLECTION.REPORT from the src/libs/actions/IOU/Transation.ts file and replace it with useOnyx.

It adds the reports argument to the changeTransactionsReport function, extracted and filtered from the ONYXKEYS.COLLECTION.REPORT Onyx.connect key .

Fixed Issues

$ #67779
PROPOSAL:

Tests

Prerequisites

  • 1 workspace where you can create expense reports
  • An open expense report on the workspace, called Report A
  • Expense 1 on Report A with amount, date, merchant and a category set.
  • Expense 2 on Report A with the same values as Expense 1
  • Both expenses show a red brick road (RBR) with "Duplicate transaction" violation

Steps

  1. Go to Search (left nav → Search) and filter by type Expense.
  2. Select Expense 1 via its checkbox.
  3. Click bulk action → "Remove from report".
  4. Verify: Expense 1 is now unreported (no parent report); Expense 2 on Report A no longer shows the "Duplicate transaction" violation; if Expense 2 had any other (non-duplicate) violations, those are
    preserved.
  5. Reload the page.
  6. Verify: The state from step 4 persists after reload.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as tests

  • 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 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-22.at.12.50.34.mov

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/hooks/useUndeleteTransactions.ts 80.00% <100.00%> (ø)
src/libs/actions/Report/index.ts 71.52% <100.00%> (ø)
src/libs/actions/Transaction.ts 76.44% <ø> (-0.10%) ⬇️
src/components/AddExistingExpenseFooter.tsx 0.00% <0.00%> (ø)
src/hooks/useChangeTransactionsReportReports.ts 95.45% <95.45%> (ø)
...c/pages/DynamicNewReportWorkspaceSelectionPage.tsx 86.00% <50.00%> (-0.87%) ⬇️
...questStepReport/hooks/useReportSelectionActions.ts 62.74% <50.00%> (-0.53%) ⬇️
...s/iou/request/step/DynamicIOURequestEditReport.tsx 0.00% <0.00%> (ø)
...c/pages/iou/request/step/IOURequestStepUpgrade.tsx 0.00% <0.00%> (ø)
...rc/pages/Search/SearchTransactionsChangeReport.tsx 0.00% <0.00%> (ø)
... and 86 files with indirect coverage changes

@Guccio163
Guccio163 marked this pull request as ready for review June 22, 2026 10:53
@Guccio163
Guccio163 requested review from a team as code owners June 22, 2026 10:53
@melvin-bot
melvin-bot Bot requested review from DylanDylann and joekaufmanexpensify and removed request for a team June 22, 2026 10:53
@melvin-bot

melvin-bot Bot commented Jun 22, 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]

Comment thread src/hooks/useChangeTransactionsReportReports.ts Outdated

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

Copy link
Copy Markdown

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: e5a7cc16a6

ℹ️ 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/pages/Search/SearchTransactionsChangeReport.tsx Outdated
@joekaufmanexpensify

Copy link
Copy Markdown
Contributor

No product review needed

@joekaufmanexpensify
joekaufmanexpensify removed their request for review June 22, 2026 21:30
…-fork into Guccio163/onyx-connect/transaction/report
…-fork into Guccio163/onyx-connect/transaction/report
@Guccio163

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: c70ce5a0bd

ℹ️ 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/pages/DynamicNewReportWorkspaceSelectionPage.tsx Outdated
Guccio163 and others added 2 commits June 25, 2026 18:07
Resolved conflicts:
- Kept onyx-connect changes (reports param / removed global allReports Onyx.connect)
- Took main's version for files only carried as stale-main snapshots
- Restored GroupCurrencyPopup.tsx from main
- Consolidated DynamicIOURequestStepUpgradePage.tsx -> IOURequestStepUpgrade.tsx (main's name)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Guccio163

Copy link
Copy Markdown
Contributor Author

@DylanDylann kindly bump here 👀

Comment thread src/libs/actions/Transaction.ts
…-fork into Guccio163/onyx-connect/transaction/report
@Guccio163

Copy link
Copy Markdown
Contributor Author

@DylanDylann fixed, ready for a re-review

@DylanDylann

Copy link
Copy Markdown
Contributor

@Guccio163 This current code looks wrong to me. Why do we use reportActionID to get the report object?

policyID: reports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldIOUAction.reportActionID}`]?.policyID,

Are you okay if we adjust this before refactoring?

Comment thread src/hooks/useChangeTransactionsReportReports.ts Outdated
Comment thread src/hooks/useChangeTransactionsReportReports.ts Outdated
Comment thread src/hooks/useChangeTransactionsReportReports.ts Outdated
…-fork into Guccio163/onyx-connect/transaction/report
@DylanDylann

Copy link
Copy Markdown
Contributor

@Guccio163 Kindly bump

@Guccio163

Copy link
Copy Markdown
Contributor Author

Hi, I was OOO for the past week, that's why I didn't complete this one ✈️ I'll get it done soon

…-fork into Guccio163/onyx-connect/transaction/report
waitForCollectionCallback no longer exists on ConnectOptions (collection
vs entry is now inferred from the key type), and two changeTransactionsReport
calls had a reports/allReports typo.
… merges

buildOptimisticEmptyReport doesn't set these two fields, so the freshly
created report merged into reportsForCall was missing them, leaving
failure-rollback unable to reset them (Onyx merge ignores undefined).
Covers source selection (reported vs unreported transaction), skipping
the IOU action lookup for deleted transactions, and that the result is
narrowed to only the computed ids.
@Guccio163

Copy link
Copy Markdown
Contributor Author

I fixed the logic, patched for failureData and added new tests file for this hook, please take a look @DylanDylann 👀

@DylanDylann

Copy link
Copy Markdown
Contributor

@Guccio163 Regarding this problem, I asked the author who introduced it here, but got no response. Still, we need to fix it here too, to avoid spreading the problem to the new hook. This is my suggestion, could you check and update the PR?

index b0fd166f203..7008b4a0dde 100644
--- a/src/hooks/useChangeTransactionsReportReports.ts
+++ b/src/hooks/useChangeTransactionsReportReports.ts
@@ -50,9 +50,6 @@ function useChangeTransactionsReportReports(transactionIDs: string[], allTransac
         if (iouAction?.childReportID) {
             ids.add(iouAction.childReportID);
         }
-        if (iouAction?.reportActionID) {
-            ids.add(iouAction.reportActionID);
-        }
     }
     const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {
         selector: (allReports) => {
diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts
index 115b4651a72..4857b4bf977 100644
--- a/src/libs/actions/Transaction.ts
+++ b/src/libs/actions/Transaction.ts
@@ -1575,7 +1575,7 @@ function getChangeTransactionsReportOnyxData({
                 value: {
                     parentReportID: isUnreportedExpense ? selfDMReportID : oldReportID,
                     parentReportActionID: oldIOUAction.reportActionID,
-                    policyID: reports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldIOUAction.reportActionID}`]?.policyID,
+                    policyID: reports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldIOUAction.childReportID}`]?.policyID,
                 },
             });
         }

@Guccio163

Copy link
Copy Markdown
Contributor Author

Ah yes, I must've missed that comment - I thought about the same issue, but decided that I'll leave it like that so we avoid regression, but since you've noticed it too I'll apply your proposed changes, they look good to me 👍

oldIOUAction.reportActionID was used as a REPORT key, which never
matches a real report, so the restored policyID was always undefined.
Use oldIOUAction.childReportID (the thread's own key) instead, and drop
the now-unnecessary reportActionID entry from the hook's id set.

Per DylanDylann's review on Expensify#93734.
…-fork into Guccio163/onyx-connect/transaction/report
Two reportNextStep tests never refreshed the reports snapshot after
merging their own report data, so they asserted against stale data and
threw before mockAPIWrite.mockRestore() ran — leaving the spy active
and corrupting the two sibling-duplicate-violation tests that ran
after them. Also fixes an allReports/reports typo in tests newly
merged from main.
…-fork into Guccio163/onyx-connect/transaction/report
…-fork into Guccio163/onyx-connect/transaction/report
…-fork into Guccio163/onyx-connect/transaction/report
The feature they tested (moving all matching expenses via jsonQuery +
hash) was reverted from Transaction.ts on main in d51ada0, but the
merge into this branch left the tests behind, referencing fields
(jsonQuery, hash) that no longer exist on ChangeTransactionsReportProps.
@Guccio163

Copy link
Copy Markdown
Contributor Author

@DylanDylann ready ✅

Comment thread src/hooks/useChangeTransactionsReportReports.ts Outdated
Comment thread src/hooks/useChangeTransactionsReportReports.ts

if (isEditing) {
const policyTagList = item?.policyID ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${item.policyID}`] : {};
const reportsForCall = report?.reportID ? {[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, ...reports} : reports;

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 update the reports 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.

We need it because the hook here doesn't know the destination report yet when it runs — report is only picked later, inside this callback, so reports never contains it.

changeTransactionsReport's failure-rollback path reads the target report straight from reports, with no fallback to the newReport param (unlike the optimistic-update path, which does have that fallback). So if reports is missing the destination report, the rollback value on API failure is undefined — and since Onyx.merge ignores undefined, a failed request would leave the destination report's total/transactionCount stuck at the optimistic (wrong) value instead of rolling back.

Merging report in here fixes that. It's the same thing other callers of this hook already do for the same reason (SearchTransactionsChangeReport.tsx, DynamicIOURequestEditReport.tsx, IOURequestStepUpgrade.tsx, DynamicNewReportWorkspaceSelectionPage.tsx).

…RT_ID lookups

Accept the resolved transactions and destination reportID directly instead of a
transactionIDs/allTransactions pair, dropping the per-caller collection-building
boilerplate. Also always include CONST.REPORT.UNREPORTED_REPORT_ID in the resolved
report ids, matching what getChangeTransactionsReportOnyxData looks up for
unreported transactions.
@Guccio163

Copy link
Copy Markdown
Contributor Author

@DylanDylann applied the changes/replied to the comment, please take a look

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