Skip to content

[Due for payment 2026-05-28] [Bulk workspace edits] Actions: buildCopyPolicySettingsData + helpers + entry point [2] #88668

Description

@francoisl

Task

Create src/libs/actions/Policy/CopyPolicySettings.ts. This file owns all logic that talks to Onyx and the API for the copy flow.

It should export:

  1. setCopyPolicySettingsData(data: Partial<CopyPolicySettings>) — merge helper for the COPY_POLICY_SETTINGS Onyx key.
  2. clearCopyPolicySettings() — clears the key when the flow exits.
  3. requestCopyPolicySettingsNotification() — fires CopyPolicySettings_Notify via API.write.
  4. PARTS_TO_POLICY_FIELDS — the map of part key → list of Policy field names (see Step 1 table in the design doc). This powers pendingFields expansion.
  5. buildCopyPolicySettingsData(sourcePolicy, targetPolicies, parts, allPolicyCategories, allPolicyTags) — returns {optimisticData, successData, failureData} following the 4-step algorithm in the design doc:
    • Step 1: build the field patch from parts using the mapping table
    • Step 2: for each target policy, push optimistic/success/failure updates with pendingFields keyed by the expanded Policy field names (not by part names — see the reviewer comment resolved in the doc)
    • Step 3: SET-level overwrite of POLICY_CATEGORIES and POLICY_TAGS collection keys, with failure data restoring the snapshot
    • Step 4: drive the isLoading flag on COPY_POLICY_SETTINGS itself
  6. copyPolicySettings(...) — entry point: calls buildCopyPolicySettingsData, then API.write(WRITE_COMMANDS.COPY_POLICY_SETTINGS, params, {optimisticData, successData, failureData}).

Include unit tests for buildCopyPolicySettingsData covering:

  • Each part key in isolation (correct fields marked pending, correct values patched)
  • Collection key overwrite for categories and tags
  • Failure data fully restores the target's pre-copy state
  • customUnits preservation (use target's existing unit ID; generate a new one only when absent)

Relevant design doc sections: "[App] Actions", including the PARTS_TO_POLICY_FIELDS helper block and all four steps under buildCopyPolicySettingsData.

Depends on Issue 1.

Issue OwnerCurrent Issue Owner: @ShridharGoel

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2InternalRequires API changes or must be handled by Expensify staffTask

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions