-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
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.tsxContextMenuActions.tsxBrowserNotifications.tsOptionsListUtils/index.tsReportNameUtils.tsReportUtils.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
useOnyxhooks to fetchpolicyTagsandsessionin React components - Use
getForReportActionTempwhich accepts all required parameters - Pass
translate,policy,policyTags, andcurrentUserLoginfrom 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:
- Add
policyTagsandcurrentUserLoginparameters - Switch to the pure function version
- Update the 5 callers
PR 4: ReportNameUtils computeReportName
Scope: ~8-9 files
Similar approach:
- Add parameters to
computeChatThreadReportNameandcomputeReportName - Update 12 callers across 8 files
PR 5: Final Cleanup
Scope: 1 file
Once PRs 2-4 are complete:
- Remove
getForReportAction(old function) - Rename
getForReportActionTemp→getForReportAction - Remove the module-level Onyx connections
- 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
- fix: migrate ReportActionItem to useOnyx for policyTags #80258 - PR 1: ReportActionItem.tsx + ContextMenuActions.tsx migration