Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cead22 committed Mar 8, 2024
1 parent 32e20ed commit e77b01a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function getTagViolationsForSingleLevelTags(
const policyTagListName = policyTagKeys[0];
const policyTags = policyTagList[policyTagListName]?.tags;
const hasTagOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY);
let newTransactionViolations = [...transactionViolations];
const hasMissingTagViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_TAG);
const isTagInPolicy = policyTags ? !!policyTags[updatedTransaction.tag ?? '']?.enabled : false;
let newTransactionViolations = [...transactionViolations];

// Add 'tagOutOfPolicy' violation if tag is not in policy
if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy) {
Expand All @@ -44,7 +44,7 @@ function getTagViolationsForSingleLevelTags(
newTransactionViolations.push({name: CONST.VIOLATIONS.MISSING_TAG, type: 'violation'});
}
return newTransactionViolations;
};
}

/**
* Calculates some tag levels required and missing tag violations for the given transaction
Expand Down Expand Up @@ -104,9 +104,8 @@ function getTagViolationsForMultiLevelTags(
});
}
}
return newTransactionViolations;
};

return newTransactionViolations;
}

const ViolationsUtils = {
/**
Expand All @@ -123,6 +122,7 @@ const ViolationsUtils = {
): OnyxUpdate {
let newTransactionViolations = [...transactionViolations];

// Calculate client-side category violations
if (policyRequiresCategories) {
const hasCategoryOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === 'categoryOutOfPolicy');
const hasMissingCategoryViolation = transactionViolations.some((violation) => violation.name === 'missingCategory');
Expand Down Expand Up @@ -150,13 +150,12 @@ const ViolationsUtils = {
}
}

// Calculate client-side tag violations
if (policyRequiresTags) {
const policyTagKeys = Object.keys(policyTagList);
if (policyTagKeys.length === 1) {
newTransactionViolations = getTagViolationsForSingleLevelTags(updatedTransaction, newTransactionViolations, policyRequiresTags, policyTagList);
} else {
newTransactionViolations = getTagViolationsForMultiLevelTags(updatedTransaction, newTransactionViolations, policyRequiresTags, policyTagList);
}
newTransactionViolations =
Object.keys(policyTagList).length === 1
? getTagViolationsForSingleLevelTags(updatedTransaction, newTransactionViolations, policyRequiresTags, policyTagList)
: getTagViolationsForMultiLevelTags(updatedTransaction, newTransactionViolations, policyRequiresTags, policyTagList);
}

return {
Expand Down

0 comments on commit e77b01a

Please sign in to comment.