Skip to content
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

Adds new ReportUtils for Violations #31448

Conversation

cdanwards
Copy link
Contributor

@cdanwards cdanwards commented Nov 16, 2023

Details

Fixed Issues

$ #31095
PROPOSAL:

This PR is the next installment to implement the Violations project in New Expensify. This PR adds logic that will display a Red Brick Indicator in the LHN for the parent of a report in violation. It also will add a Red Brick Indicator to the Report Preview of the report in violation.

Tests

Setup

  1. Enable Violations Beta:
    • Turn on the Violations beta or set canUseViolations to true.
  2. Configure Control Policy in OldDot:
    • Open or create a Control policy.
    • Enable violations for the workspace in Settings > [Workspace] > Expenses with:
      • Expense Violations: true
      • Max expense amount: $100
  3. Enable Policy’s Expense Chat:
    • Go to the policy page.
    • Use JS Console with the policy open:
      p = Policy.getCurrent();
      p.policy.isPolicyExpenseChatEnabled = “true”;
      p.save();
    • Invite a new user to the policy.
    • Sign into the new user account in New Dot.
  4. Create Money Requests:
    • Make a request for less than $100 (no violations expected).
    • Make a request for more than $100 (violations expected).

Testing Steps for Workspace User and Admin

  1. Access Policy Workspace Chat:
    • Verify the RBR is not shown on workspace chat in LHN.
    • Verify the RBR is shown on the Report card.
  2. Navigate to Transaction Thread - Request with Violation:
    • Violations should be visible on the money request fields for the Admin, only after submission.
    • For the Workspace User, verify violations are shown on the fields.
    • Ensure the RBR is showing on the Transaction Thread in LHN for the Workspace User.
    • Confirm the RBR is not shown on the parent policy chat.
  3. Navigate to Transaction Thread - Request without Violation:
    • Confirm no violations are shown on the money request fields for both User and Admin.
    • Ensure the RBR is not showing on the Transaction Thread in LHN.
    • Confirm the RBR is not showing on the parent policy chat.

Offline tests

Same as Tests

QA Steps

Same as tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native Report_Error_Desktop Report_Error_Desktop
Android: mWeb Chrome Report_Error_Desktop Report_Error_Desktop
iOS: Native Report_Error_Desktop Report_Error_Desktop
iOS: mWeb Safari Report_Error_Desktop Report_Error_Desktop
MacOS: Chrome / Safari BRI_Error_Web Report_Error_Web
MacOS: Desktop Screenshot 2023-11-16 at 11 14 23 AM Report_Error_Desktop

@cdanwards
Copy link
Contributor Author

@cead22 I've had some issues testing out the functionality of this PR. Even with setting a policy up that has violations for amount, tags, and categories, and then creating requests that violate those policies, I've not had any violations be provided through the Onyx connection. Is there something I'm missing? Once I get that tested I can finish the testing instructions and this PR should be good to go!

@cead22
Copy link
Contributor

cead22 commented Nov 16, 2023

What's missing is that we haven't yet added the backend code to send the violations data down to onyx. Can you set it manually to test?

@cdanwards
Copy link
Contributor Author

@cead22 I'll look into it! I can set the function to return true (that's how I generated the screenshots) but I'll see if I can set the onyx state locally for testing

src/libs/ReportUtils.js Outdated Show resolved Hide resolved
src/libs/ReportUtils.js Outdated Show resolved Hide resolved
@cdanwards
Copy link
Contributor Author

Looks like this needs to be reworked with the ReportUtils conversion to TS. Will work on getting that up.

@cdanwards
Copy link
Contributor Author

@cead22 Got the TS conversion working and fixed that test bug! Retesting on all the platforms but this should be up today.

@cdanwards
Copy link
Contributor Author

@cead22 another thought when looking at the testing instructions. This is another PR that won't be able to be tested by QA until Violations are coming through from the back end. Should I specify how to manually set the violations functions as being true for review and then worry about QA later?

@lindboe
Copy link
Contributor

lindboe commented Jan 18, 2024

After fixing violation, error is removed only when online (offline is not supported)

@situchan Yup, optimistic changes for client-side violations (not all violations are calculated client-side) is being added in #34402

@quinthar
Copy link
Contributor

Hi! It's been determined that this PR is blocking #33029, which is a pretty important one. Can you give an ETA for when this will be finished? Thanks!

@situchan
Copy link
Contributor

Almost close. Hopefully merged tomorrow

@situchan
Copy link
Contributor

@trevor-coleman please fix last conflict

…s/transaction-thread-violations

# Conflicts:
#	src/libs/SidebarUtils.ts
@trevor-coleman
Copy link
Contributor

Conflicts resolved!

…s/transaction-thread-violations

# Conflicts:
#	src/pages/home/sidebar/SidebarLinksData.js
@trevor-coleman
Copy link
Contributor

Resolved new merge conflict

@situchan
Copy link
Contributor

Checklist complete

@melvin-bot melvin-bot bot requested a review from cead22 January 18, 2024 22:58
@cead22 cead22 merged commit e6b0761 into Expensify:main Jan 18, 2024
16 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/cead22 in version: 1.4.28-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@@ -231,5 +268,9 @@ export default compose(
selector: policySelector,
initialValue: {},
},
transactionViolations: {
key: ONYXKEYS.TRANSACTION_VIOLATIONS,
Copy link
Contributor

Choose a reason for hiding this comment

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

Too bad this file is still .js and not .tsx or this mistake would've been caught earlier. The correct key is ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, not ONYXKEYS.TRANSACTION_VIOLATIONS

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching it. That might break this logic in LHN:

App/src/libs/ReportUtils.ts

Lines 3656 to 3659 in 68e997d

// Always show IOU reports with violations
if (isExpenseRequest(report) && doesReportHaveViolations) {
return true;
}

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.4.28-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

const participantPersonalDetailList: PersonalDetails[] = Object.values(OptionsListUtils.getPersonalDetailsForAccountIDs(report.participantAccountIDs ?? [], personalDetails));
const personalDetail = participantPersonalDetailList[0] ?? {};
const hasErrors = Object.keys(result.allReportErrors ?? {}).length !== 0;
Copy link
Contributor

@NikkiWines NikkiWines Feb 22, 2024

Choose a reason for hiding this comment

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

Defining hasErrors before result.allReportErrors on line 320 resulted in the following regression, which should've ideally been caught before deploy by having more robust offline testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.