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:
setCopyPolicySettingsData(data: Partial<CopyPolicySettings>) — merge helper for the COPY_POLICY_SETTINGS Onyx key.
clearCopyPolicySettings() — clears the key when the flow exits.
requestCopyPolicySettingsNotification() — fires CopyPolicySettings_Notify via API.write.
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.
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
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 Owner
Current Issue Owner: @ShridharGoel
Add Bulk Workspace EditsTask
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:
setCopyPolicySettingsData(data: Partial<CopyPolicySettings>)— merge helper for theCOPY_POLICY_SETTINGSOnyx key.clearCopyPolicySettings()— clears the key when the flow exits.requestCopyPolicySettingsNotification()— firesCopyPolicySettings_NotifyviaAPI.write.PARTS_TO_POLICY_FIELDS— the map of part key → list ofPolicyfield names (see Step 1 table in the design doc). This powerspendingFieldsexpansion.buildCopyPolicySettingsData(sourcePolicy, targetPolicies, parts, allPolicyCategories, allPolicyTags)— returns{optimisticData, successData, failureData}following the 4-step algorithm in the design doc:partsusing the mapping tablependingFieldskeyed by the expandedPolicyfield names (not by part names — see the reviewer comment resolved in the doc)POLICY_CATEGORIESandPOLICY_TAGScollection keys, with failure data restoring the snapshotisLoadingflag onCOPY_POLICY_SETTINGSitselfcopyPolicySettings(...)— entry point: callsbuildCopyPolicySettingsData, thenAPI.write(WRITE_COMMANDS.COPY_POLICY_SETTINGS, params, {optimisticData, successData, failureData}).Include unit tests for
buildCopyPolicySettingsDatacovering:categoriesandtagscustomUnitspreservation (use target's existing unit ID; generate a new one only when absent)Relevant design doc sections: "[App] Actions", including the
PARTS_TO_POLICY_FIELDShelper block and all four steps underbuildCopyPolicySettingsData.Depends on Issue 1.
Issue Owner
Current Issue Owner: @ShridharGoel