Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ function appendSetupCategoriesOnboardingData(
function buildOptimisticPolicyWithExistingCategories(policyID: string, categories: PolicyCategories) {
const categoriesValues = Object.values(categories);
const optimisticCategoryMap = categoriesValues.reduce<Record<string, Partial<PolicyCategory>>>((acc, category) => {
if (category.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return acc;
}
acc[category.name] = {
...category,
errors: null,
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
};

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 241 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand All @@ -254,7 +254,7 @@
});

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 257 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -264,7 +264,7 @@

let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({

Check warning on line 267 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
Expand All @@ -273,7 +273,7 @@
});

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 276 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (deprecatedAllPersonalDetails = val),
});
Expand Down Expand Up @@ -3087,6 +3087,11 @@
const optimisticCategoriesData =
policyCategories && isCategoriesOptionSelected ? buildOptimisticPolicyWithExistingCategories(targetPolicyID, policyCategories) : defaultOptimisticCategoriesData;

const visibleCodingRules = Object.fromEntries(Object.entries(policy?.rules?.codingRules ?? {}).filter(([, rule]) => rule.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE));
const visibleEmployeeList = Object.fromEntries(
Object.entries(policy?.employeeList ?? {}).filter(([, employee]) => employee.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE),
);

// WARNING: The data below should be kept in sync with the API so we create the policy with the correct configuration.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const optimisticData: Array<
Expand Down Expand Up @@ -3119,14 +3124,14 @@
travelSettings: undefined,
workspaceAccountID: undefined,
tax: isTaxesOptionSelected ? policy?.tax : undefined,
employeeList: isMemberOptionSelected ? policy.employeeList : {[policy.owner]: policy?.employeeList?.[policy.owner]},
employeeList: isMemberOptionSelected ? visibleEmployeeList : {[policy.owner]: policy?.employeeList?.[policy.owner]},
id: targetPolicyID,
name: policyName,
fieldList: isReportsOptionSelected ? policy?.fieldList : undefined,
connections: isConnectionsOptionSelected ? policy?.connections : undefined,
customUnits: getCustomUnitsForDuplication(policy, isDistanceRatesOptionSelected, isPerDiemOptionSelected, {distanceCustomUnitID, perDiemCustomUnitID}),
taxRates: isTaxesOptionSelected ? policy?.taxRates : undefined,
rules: isCodingRulesOptionSelected ? {codingRules: policy?.rules?.codingRules} : undefined,
rules: isCodingRulesOptionSelected ? {codingRules: visibleCodingRules} : undefined,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
pendingFields: {
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function WorkspaceDuplicateSelectFeaturesForm({policyID}: WorkspaceDuplicateForm
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
const taxesLength = Object.keys(policy?.taxRates?.taxes ?? {}).length ?? 0;
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const categoriesCount = Object.keys(policyCategories ?? {}).length;
const codingRulesCount = Object.keys(policy?.rules?.codingRules ?? {}).length;
const categoriesCount = Object.values(policyCategories ?? {}).filter((category) => category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length;
const codingRulesCount = Object.values(policy?.rules?.codingRules ?? {}).filter((rule) => rule.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length;
Comment on lines +46 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude pending-deleted members from the duplicate feature counts

This change filters pending-deleted categories and merchant rules, but the members count in this form still comes from getMemberAccountIDsForWorkspace(policy?.employeeList) with its default includeMemberWithPendingDelete = true. In the offline flow this PR targets, a removed member is still counted in the “Members” row and confirmation modal even though buildDuplicatePolicyData() now drops that member from the duplicated employeeList, so the UI still overstates how many people will be copied.

Useful? React with 👍 / 👎.

const [selectedItems, setSelectedItems] = useState<string[]>([]);
const reportFields = Object.keys(getReportFieldsByPolicyID(policyID)).length ?? 0;
const customUnits = getPerDiemCustomUnit(policy);
Expand Down
5 changes: 4 additions & 1 deletion tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ describe('actions/Policy', () => {
it('duplicate workspace', async () => {
(fetch as MockFetch)?.pause?.();
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
const fakePolicy = createRandomPolicy(10, CONST.POLICY.TYPE.PERSONAL);
const fakePolicy = {
...createRandomPolicy(10, CONST.POLICY.TYPE.PERSONAL),
employeeList: {},
};
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
await Onyx.set(`${ONYXKEYS.NVP_ACTIVE_POLICY_ID}`, fakePolicy.id);
await Onyx.set(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM});
Expand Down
Loading