-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add violation logic for multi level tags #37461
Conversation
@DylanDylann Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
cc @yuwenmemon @allroundexperts since you reviewed #34983 |
Sorry for the back and forth @parasharrajat , I thought I had linked to this PR in this issue #36441, which you had asked to be a reviewer on, but I had linked a different PR |
@cead22 I was assigned to this PR by Melvin. Should I review this PR? |
I think it would be better if I review this since I have good context on this. |
Updated |
newTransactionViolations = reject(newTransactionViolations, { | ||
name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, | ||
}); |
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.
filter
can be used here as well.
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.
There's no difference here since we're only calling reject once, so it should go over the array only once, right?
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.
Yes, but aren't we preferring native JS methods for filtering after TS migration?
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.
Looks good other than a NAB change that is upon the engineers discretion to fix.
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.
NAB comments, otherwise looks good 👍
errorIndexes.push(i); | ||
} | ||
} | ||
if (errorIndexes.length !== 0) { |
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.
NAB: since 0 is falsy in JS this can be simplified.
if (errorIndexes.length !== 0) { | |
if (errorIndexes.length) { |
required: true, | ||
}, | ||
}; | ||
}); |
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.
NAB: can we add a line break in between tests?
result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policyRequiresTags, policyTags, policyRequiresCategories, policyCategories); | ||
expect(result.value).toEqual([]); | ||
}); | ||
it('should return tagOutOfPolicy when a tag is not enabled in the policy but is set in the transaction', () => { |
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.
NAB: can we add a line break in between tests?
@@ -201,4 +196,77 @@ describe('getViolationsOnyxData', () => { | |||
expect(result.value).not.toContainEqual([missingTagViolation]); | |||
}); | |||
}); | |||
describe('policy has multi level tags', () => { |
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.
NAB: can we add a line break in between describe statements?
hasInvalidTag = true; | ||
break; | ||
} | ||
} |
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.
NAB Can we add some line breaks to the new code for readability?
@@ -78,6 +79,53 @@ const ViolationsUtils = { | |||
if (!hasMissingTagViolation && !updatedTransaction.tag && policyRequiresTags) { | |||
newTransactionViolations.push({name: CONST.VIOLATIONS.MISSING_TAG, type: 'violation'}); | |||
} | |||
} else { |
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.
NAB: can we consider extracting some part of this new code into a helper function? I find the logic hard to follow with all the if/else/for statements nested together. Abstracting out some of the logic would make this a lot more readable IMO.
Updated! Please re-review. @blimpich I'm taking the NAB that I didn't reply to as non-blockers
|
Sounds good! @cead22 can you help me find that style guide? I can't find one that mentions that we prefer to not use newlines to separate code. |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
I meant to address this but forgot 😬 |
@blimpich I thought it was in our general style guides, but it looks like it's on our php style guide https://github.com/Expensify/Style-Guides/blob/4a2750183223b1f84398e0c1c633fa95a7512841/php.md#blank-lines
|
🚀 Deployed to production by https://github.com/luacmartins in version: 1.4.50-5 🚀
|
/** | ||
* Calculates some tag levels required and missing tag violations for the given transaction | ||
*/ | ||
function getTagViolationsForMultiLevelTags( |
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.
Hi team, come from #38095, this function was missing to handle multilevel dependent tags cases.
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.
Thanks! This wasn't really missing, as much as it just hadn't been implemented yet. When we added support for multi level tags, we broke the violations for tags, and this PR was meant to fix that.
We then added support for dependent tags, and then implemented getTagViolationsForDependentTags
and getTagViolationForIndependentTags
in https://github.com/Expensify/App/pull/40741/files
policyTagList: PolicyTagList, | ||
): TransactionViolation[] { | ||
const policyTagKeys = Object.keys(policyTagList); | ||
const selectedTags = updatedTransaction.tag?.split(CONST.COLON) ?? []; |
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.
We should have split the tags using getTagArrayFromName
method instead. The split
function fails if a tag contains more than one :
. This caused #50105
Details
Fixed Issues
$ #37117
PROPOSAL:
Tests
Offline tests
Covered in tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Note
I posted about console warnings here https://expensify.slack.com/archives/C01GTK53T8Q/p1709336500920559
Screenshots/Videos
Android: Native
nativeandroid.mp4
Android: mWeb Chrome
I'm having issues running the app on android web, so will rely on reviewer testing this platform
iOS: Native
nativeios.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
Online
desktopweboffline.mp4
Offline
https://github.com/Expensify/App/assets/165133/363e8b52-b5c9-4b36-b8b0-1ad9f3cb02b3 x
MacOS: Desktop
desktop.mp4