Repository navigation
Revert "fix: Offline deleted rules reappear after reconnecting until cache is cleared" #87675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3097,98 +3097,6 @@ function createDraftWorkspace( | |
| return params; | ||
| } | ||
|
|
||
| function buildOptimisticDuplicatePolicy(sourcePolicy: Policy, policyOptions: DuplicatePolicyDataOptions) { | ||
| const { | ||
| policyName: duplicatedPolicyName = '', | ||
| targetPolicyID: duplicatedPolicyID, | ||
| file: duplicatedPolicyFile, | ||
| parts: duplicatedParts, | ||
| localCurrency: duplicatedLocalCurrency, | ||
| } = policyOptions; | ||
|
|
||
| const isMemberFeatureSelected = duplicatedParts?.people; | ||
| const isReportsFeatureSelected = duplicatedParts?.reports; | ||
| const isConnectionsFeatureSelected = duplicatedParts?.connections; | ||
| const isTaxesFeatureSelected = duplicatedParts?.taxes; | ||
| const isTagsFeatureSelected = duplicatedParts?.tags; | ||
| const isInvoicesFeatureSelected = duplicatedParts?.invoices; | ||
| const isDistanceRatesFeatureSelected = duplicatedParts?.distance; | ||
| const isRulesFeatureSelected = duplicatedParts?.expenses; | ||
| const isWorkflowsFeatureSelected = duplicatedParts?.exportLayouts; | ||
| const isPerDiemFeatureSelected = duplicatedParts?.perDiem; | ||
| const isOverviewFeatureSelected = duplicatedParts?.overview; | ||
| const isTravelFeatureSelected = duplicatedParts?.travel; | ||
| const isCodingRulesFeatureSelected = duplicatedParts?.codingRules; | ||
| const duplicatedOutputCurrency = isOverviewFeatureSelected ? sourcePolicy?.outputCurrency : duplicatedLocalCurrency; | ||
| const {customUnitID: duplicatedDistanceCustomUnitID} = buildOptimisticDistanceRateCustomUnits(duplicatedOutputCurrency); | ||
| const duplicatedPerDiemCustomUnitID = generateCustomUnitID(); | ||
|
|
||
| const filterPendingDeleteData = <T>(data?: Record<string, T>): Record<string, T> | undefined => | ||
| data | ||
| ? (Object.fromEntries( | ||
| Object.entries(data).filter(([, value]) => { | ||
| if (!value || typeof value !== 'object' || !('pendingAction' in value)) { | ||
| return true; | ||
| } | ||
| return value.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; | ||
| }), | ||
| ) as Record<string, T>) | ||
| : undefined; | ||
|
|
||
| const codingRulesWithoutPendingDelete = filterPendingDeleteData(sourcePolicy?.rules?.codingRules); | ||
| const employeeListWithoutPendingDelete = filterPendingDeleteData(sourcePolicy?.employeeList); | ||
| const fieldListWithoutPendingDelete = filterPendingDeleteData(sourcePolicy?.fieldList); | ||
| const connectionsWithoutPendingDelete = filterPendingDeleteData(sourcePolicy?.connections); | ||
| const taxRatesWithoutPendingDelete = { | ||
| ...sourcePolicy?.taxRates, | ||
| taxes: filterPendingDeleteData(sourcePolicy?.taxRates?.taxes), | ||
| }; | ||
|
|
||
| return { | ||
| ...sourcePolicy, | ||
| areCategoriesEnabled: true, | ||
| areTagsEnabled: isTagsFeatureSelected, | ||
| areDistanceRatesEnabled: isDistanceRatesFeatureSelected, | ||
| areInvoicesEnabled: isInvoicesFeatureSelected, | ||
| areRulesEnabled: isRulesFeatureSelected, | ||
| areWorkflowsEnabled: isWorkflowsFeatureSelected, | ||
| areReportFieldsEnabled: isReportsFeatureSelected, | ||
| areConnectionsEnabled: isConnectionsFeatureSelected, | ||
| arePerDiemRatesEnabled: isPerDiemFeatureSelected, | ||
| isTravelEnabled: isTravelFeatureSelected ? sourcePolicy?.isTravelEnabled : undefined, | ||
| travelSettings: undefined, | ||
| workspaceAccountID: undefined, | ||
| tax: isTaxesFeatureSelected ? sourcePolicy?.tax : undefined, | ||
| employeeList: isMemberFeatureSelected ? employeeListWithoutPendingDelete : {[sourcePolicy.owner]: sourcePolicy?.employeeList?.[sourcePolicy.owner]}, | ||
| id: duplicatedPolicyID, | ||
| name: duplicatedPolicyName, | ||
| fieldList: isReportsFeatureSelected ? fieldListWithoutPendingDelete : undefined, | ||
| connections: isConnectionsFeatureSelected ? connectionsWithoutPendingDelete : undefined, | ||
| customUnits: getCustomUnitsForDuplication(sourcePolicy, isDistanceRatesFeatureSelected, isPerDiemFeatureSelected, { | ||
| distanceCustomUnitID: duplicatedDistanceCustomUnitID, | ||
| perDiemCustomUnitID: duplicatedPerDiemCustomUnitID, | ||
| }), | ||
| taxRates: isTaxesFeatureSelected ? taxRatesWithoutPendingDelete : undefined, | ||
| rules: isCodingRulesFeatureSelected ? {codingRules: codingRulesWithoutPendingDelete} : undefined, | ||
| pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| pendingFields: { | ||
| autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| name: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| outputCurrency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| address: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| type: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| areReportFieldsEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| }, | ||
| avatarURL: duplicatedPolicyFile?.uri, | ||
| originalFileName: duplicatedPolicyFile?.name, | ||
| outputCurrency: duplicatedOutputCurrency, | ||
| address: isOverviewFeatureSelected ? sourcePolicy?.address : undefined, | ||
| }; | ||
| } | ||
|
|
||
| function buildDuplicatePolicyData(policy: Policy, options: DuplicatePolicyDataOptions) { | ||
| const {policyName = '', policyID = generatePolicyID(), file, welcomeNote, parts, targetPolicyID = generatePolicyID(), policyCategories, localCurrency} = options; | ||
|
|
||
|
|
@@ -3204,8 +3112,19 @@ function buildDuplicatePolicyData(policy: Policy, options: DuplicatePolicyDataOp | |
| pendingChatMembers, | ||
| } = ReportUtils.buildOptimisticWorkspaceChats(targetPolicyID, policyName); | ||
| const isMemberOptionSelected = parts?.people; | ||
| const isReportsOptionSelected = parts?.reports; | ||
| const isConnectionsOptionSelected = parts?.connections; | ||
| const isCategoriesOptionSelected = parts?.categories; | ||
| const isTaxesOptionSelected = parts?.taxes; | ||
| const isTagsOptionSelected = parts?.tags; | ||
| const isInvoicesOptionSelected = parts?.invoices; | ||
| const isDistanceRatesOptionSelected = parts?.distance; | ||
| const isRulesOptionSelected = parts?.expenses; | ||
| const isWorkflowsOptionSelected = parts?.exportLayouts; | ||
| const isPerDiemOptionSelected = parts?.perDiem; | ||
| const isOverviewOptionSelected = parts?.overview; | ||
| const isTravelOptionSelected = parts?.travel; | ||
| const isCodingRulesOptionSelected = parts?.codingRules; | ||
|
|
||
| const outputCurrency = isOverviewOptionSelected ? policy?.outputCurrency : localCurrency; | ||
|
|
||
|
|
@@ -3238,7 +3157,46 @@ function buildDuplicatePolicyData(policy: Policy, options: DuplicatePolicyDataOp | |
| { | ||
| onyxMethod: Onyx.METHOD.SET, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${targetPolicyID}`, | ||
| value: buildOptimisticDuplicatePolicy(policy, {...options, targetPolicyID}), | ||
| value: { | ||
| ...policy, | ||
| areCategoriesEnabled: true, | ||
| areTagsEnabled: isTagsOptionSelected, | ||
| areDistanceRatesEnabled: isDistanceRatesOptionSelected, | ||
| areInvoicesEnabled: isInvoicesOptionSelected, | ||
| areRulesEnabled: isRulesOptionSelected, | ||
| areWorkflowsEnabled: isWorkflowsOptionSelected, | ||
| areReportFieldsEnabled: isReportsOptionSelected, | ||
| areConnectionsEnabled: isConnectionsOptionSelected, | ||
| arePerDiemRatesEnabled: isPerDiemOptionSelected, | ||
| isTravelEnabled: isTravelOptionSelected ? policy?.isTravelEnabled : undefined, | ||
| travelSettings: undefined, | ||
| workspaceAccountID: undefined, | ||
| tax: isTaxesOptionSelected ? policy?.tax : undefined, | ||
| employeeList: isMemberOptionSelected ? policy.employeeList : {[policy.owner]: policy?.employeeList?.[policy.owner]}, | ||
| id: targetPolicyID, | ||
| name: policyName, | ||
| fieldList: isReportsOptionSelected ? policy?.fieldList : undefined, | ||
| connections: isConnectionsOptionSelected ? policy?.connections : undefined, | ||
|
Comment on lines
+3175
to
+3179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Useful? React with 👍 / 👎. |
||
| customUnits: getCustomUnitsForDuplication(policy, isDistanceRatesOptionSelected, isPerDiemOptionSelected, {distanceCustomUnitID, perDiemCustomUnitID}), | ||
| taxRates: isTaxesOptionSelected ? policy?.taxRates : undefined, | ||
| rules: isCodingRulesOptionSelected ? {codingRules: policy?.rules?.codingRules} : undefined, | ||
| pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| pendingFields: { | ||
| autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| name: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| outputCurrency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| address: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| type: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| areReportFieldsEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
| }, | ||
| avatarURL: file?.uri, | ||
| originalFileName: file?.name, | ||
| outputCurrency, | ||
| address: isOverviewOptionSelected ? policy?.address : undefined, | ||
| }, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildOptimisticPolicyWithExistingCategoriesnow processes every category and forcespendingAction: ADD, including categories that were already marked for deletion. In offline flows, duplicating a workspace after deleting categories will recreate those deleted categories in the target workspace instead of excluding them. The reducer should continue skipping categories withpendingAction: DELETE.Useful? React with 👍 / 👎.