Skip to content

[Due for payment 2026-03-24] Migrate ModifiedExpenseMessage.ts from Onyx.connect to useOnyx pattern #80263

@marcochavezf

Description

@marcochavezf

Coming from Coming from here

Overview

The ModifiedExpenseMessage.ts file uses Onyx.connectWithoutView to maintain module-level state for allPolicyTags and currentUserLogin.

Current Architecture

The file uses module-level Onyx connections:

let allPolicyTags: OnyxCollection<PolicyTagLists> = {};
Onyx.connectWithoutView({
    key: ONYXKEYS.COLLECTION.POLICY_TAGS,
    // ...
});

let currentUserLogin = '';
Onyx.connectWithoutView({
    key: ONYXKEYS.SESSION,
    // ...
});

These are used by getForReportAction() which is called from:

  • ReportActionItem.tsx
  • ContextMenuActions.tsx
  • BrowserNotifications.ts
  • OptionsListUtils/index.ts
  • ReportNameUtils.ts
  • ReportUtils.ts

Migration Plan

The goal is to make getForReportAction a pure function that receives policyTags and currentUserLogin as parameters from the call site.

PR 1: ReportActionItem.tsx + ContextMenuActions.tsx ✅

Status: In Progress (#80258)

  • Add useOnyx hooks to fetch policyTags and session in React components
  • Use getForReportActionTemp which accepts all required parameters
  • Pass translate, policy, policyTags, and currentUserLogin from components

PR 2: BrowserNotifications.ts

Scope: 1 file, straightforward

Browser notifications are non-UI code. We can pass empty/undefined values for parameters that aren't needed in notification context, or thread the values from where notifications are triggered.

PR 3: OptionsListUtils getLastMessageTextForReport

Scope: ~4-5 files

This function already accepts some parameters. We need to:

  1. Add policyTags and currentUserLogin parameters
  2. Switch to the pure function version
  3. Update the 5 callers

PR 4: ReportNameUtils computeReportName

Scope: ~8-9 files

Similar approach:

  1. Add parameters to computeChatThreadReportName and computeReportName
  2. Update 12 callers across 8 files

PR 5: Final Cleanup

Scope: 1 file

Once PRs 2-4 are complete:

  1. Remove getForReportAction (old function)
  2. Rename getForReportActionTempgetForReportAction
  3. Remove the module-level Onyx connections
  4. Remove eslint-disable comments

What about ReportUtils.getReportName?

The deprecated getReportName function in ReportUtils.ts has 42 callers. Since it's already marked as deprecated (developers should use computeReportName instead), we don't need to actively migrate all those callers. Once PR 4 is done, the recommended function will be fully migrated.

Related PRs

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions