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

Use error prop for violations for consistent styling #34303

Merged
merged 41 commits into from
Feb 13, 2024

Conversation

trevor-coleman
Copy link
Contributor

@trevor-coleman trevor-coleman commented Jan 10, 2024

Details

Initially error messages for violations were added as a component under the input. This resulted in odd spacing and behaviour inconsistent with other inputs in the application.

This PR moves the error messages into the error prop of the input where it is available.

Because the logic for seelcting which error message to display was getting complicated, I gathered it into a getErrorForField function.

I also included the fix for #34773 since it was small and related.

Important

Due to an issue outside the scope of this PR, violations will not appear immediately on some fields.

To get them to update you will need to browse away from the MoneyRequestView and back, as that will trigger the necessary update.

This issue should be solved soon -- it may even be solved before you read this! So if all the expected violations appear immediately in your tests, you can to safely ignore the instructions to browse away and back.

Fixed Issues

$ #33527
$ #34773

Tests

Create a workspace and enable violations for the policy.

Important

All accounts used in this test need to have the Violations beta enabled in the back end in order to receive the correct violations. Ask @cead22 if you need to get accounts added to the beta.

  1. Turn on the Violations beta (or set canUseViolations to true)

  2. Go to OldDot and open or create a Control policy

  3. Enable violations for the workspace in Settings > [Workspace] > Expenses

    1. Expense Violations: true
  4. Set up requirements that will a violation on every field:

    Section Settings
    Expenses
    • Max Expense Age: 30 days
    • Max Expense Amount: $100
    • Receipt Required Amount: $200
    Categories
    • People Must Categorize Expenses: ON
    • Set limit for "Advertising" category to $50
    • Set descriptions required for "Advertising"
    Tags
    • People Must Tag Expenses: ON
    • Add a tag "TestTag"
  5. Enable the policy’s expense chat:

    1. Go to the policy page

    2. In the JS console with the policy open do:

      p = Policy.getCurrent();
      p.policy.isPolicyExpenseChatEnabled = "true";
      p.save();
    3. Invite an employee to the policy

    4. Return to New Dot

    5. Sign into the employee account you just added to the policy

A. First Money Request

  1. As the employee go through the money request flow, create the following money request under that policy:

    Request 1

    • Receipt - don't include a receipt
    • Amount - $500
    • Category - None
    • Date - 2013-01-01
    • Tag - None
    • Description - leave blank
  2. Click another option in the LHN, then browse back to the MoneyRequestView and and check that the errors in the table below are shown.

Note

A refresh alone will not be enough to get the violations to appear. You will need to browse to another chat and then back to the money request to get the violations to show. (Local processing for violations is being added in a separate PR).

Field Error
Receipt "Receipt required"
Amount "Amount greater than $100/person limit"
Date "Date older than 0 days"
(note: "0 days" is a backend bug, but an issue has been opened to address it)
Tag "Missing Tag"
Category "Missing Category

B. Changes to show category violations

  1. Update the money to:

    • change the amount to $80
    • change the category to "Advertising"
  2. Click another option in the LHN, then browse back to MoneyRequestView and check that the errors in the table below are shown.

Note

Violations will not show until you browse away and come back.

Note

Errors from previous step will still be visible.

Field Error
Amount "Amount over C$50.00/person category limit"
Description "Description required for selected category"
Tag "Missing Tag"

C. Changes to clear violations

  1. Update the money to:

    • change the category to "Equipment"
    • Set the tag to "TestTag"
    • Set Date to a date within 30 days
  2. Click another option in the LHN, then browse back to the MoneyRequestView and check that violation messages are NOT shown on amount, category, description, and tag fields.

Note

Violations will not be cleared until you browse away and come back.

Note

The receipt field will still show a violation.

  • Verify that no errors appear in the JS console

Offline tests

This will not work offline yet, as we are waiting for local processing of violations to be added in a separate PR.

QA Steps

  • Same as tests above

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(theme.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

A. First Money Request
android-A

B. Changes to show category violations
android-B

C. Changes to clear violations
android-C

D. Check receipt violations
android-D

Android: mWeb Chrome

A. First Money Request
m-web-android-A

B. Changes to show category violations
m-web-android-B

C. Changes to clear violations
m-web-android-C

D. Check receipt violations
m-web-android-D

iOS: Native

A. First Money Request
ios-A

B. Changes to show category violations
ios-B

C. Changes to clear violations
ios-C

D. Check receipt violations
ios-D

iOS: mWeb Safari

A. First Money Request
m-web-ios-A

B. Changes to show category violations
m-web-ios-B

C. Changes to clear violations
m-web-ios-C

D. Check receipt violations
m-web-ios-D

MacOS: Chrome / Safari

A. First Money Request
web-A

B. Changes to show category violations
web-B

C. Changes to clear violations
web-C

D. Check receipt violations
web-D

MacOS: Desktop

A. First Money Request
dasktop-A

B. Changes to show category violations
desktop-B

C. Changes to clear violations
desktop-C

D. Check receipt violations
desktop-D

@trevor-coleman trevor-coleman changed the title feat(Violations): create useMoneyRequestViewErrors and move violation… Use error prop for violations for consistent styling Jan 10, 2024
@trevor-coleman trevor-coleman marked this pull request as ready for review January 22, 2024 20:50
@trevor-coleman trevor-coleman requested a review from a team as a code owner January 22, 2024 20:50
@melvin-bot melvin-bot bot requested review from cubuspl42 and dubielzyk-expensify and removed request for a team January 22, 2024 20:50
Copy link

melvin-bot bot commented Jan 22, 2024

@dubielzyk-expensify @cubuspl42 One of you needs to 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]

@trevor-coleman
Copy link
Contributor Author

@cead22 -- This is ready to go!

@trevor-coleman
Copy link
Contributor Author

Merged in latest main and it seems to have fixed the failing performance test.

@trevor-coleman
Copy link
Contributor Author

trevor-coleman commented Feb 8, 2024

I'm not sure what is going on, tbh. I've not been able to reproduce anything like this here and I had a teammember run through the instructions and it worked fine as well so we're kind of stuck without some more data to go on, as I don't have access to the back-end.

Can you log some of the data and post it here so we can take a look to try and identify what is going wrong? The value of the transactionViolations prop of moneyRequestView is probably a good start, also the reportID, transactionID, etc

Also look at the report/transaction etc in the onyx DB and see if they appear to be well-formed. Maybe there is something weird there.

It might also be worth trying from the start with a fresh policy, now that your accounts have been authorized. And delete/clear out your local onyx db in case something has gotten corrupted in there.

@cead22
Copy link
Contributor

cead22 commented Feb 8, 2024

I think it's possible everything is working correctly, but if you can share the workspace IDs you're using, and maybe more specifically what you think it's not working, I can confirm.

For the things that look strange there

  • We have a feature that works in the back end called auto categorization or implicit categorization, and in short if you set Advertising as the category for a request with the merchant set to A, the next time you create a request with a merchant set to A and don't categorize it, we'll infer that the category should be Advertising
  • You don't see this for other requests, eg the one with merchant set to B, because it's not the same merchant as A
  • Submitting is separate from violations so I don't know if there's anything wrong there, but even unsubmitted requests should show violations, so that seems to be working fine

@cubuspl42
Copy link
Contributor

I don't want to block this PR. I'll go through all the tests and let you decide whether the videos' results are correct.

@cead22
Copy link
Contributor

cead22 commented Feb 8, 2024

Feel free to ask any questions and I'll be happy to add clarity where I can, I know there's a lot of moving parts and some non-obvious things like implicit categorization that makes things confusing

@cubuspl42
Copy link
Contributor

A.

a-first-money-request.mp4

B.

b-changes-to-show-category-violations.mp4

C.

c-changes-to-clear-violations.mp4

D.

d-check-receipt-violations.mp4

walmart_receipt


Would you take a look at the test D? I couldn't get the "Amount is greater than scanned receipt" text to show up.

@trevor-coleman
Copy link
Contributor Author

Awesome! Glad we got all that sorted. Let me look into the scanning one.

@cead22
Copy link
Contributor

cead22 commented Feb 9, 2024

I think that's happening because we're not showing that violation (by design) on money request while the receipt is scanning. We only show it after the receipt finishes scanning.

Can you check again to see if it's showing now? I checked the database and it looks like SmartScan completed, and looking at the api response for a command to load violations, I see the violation in there now

image

@cubuspl42
Copy link
Contributor

while the receipt is scanning

It can be seen on the video that the receipt has finished scanning from the user's perspective. The price 23.19 comes from the receipt (although the currency got messed up).

image

@cead22
Copy link
Contributor

cead22 commented Feb 9, 2024

It can be seen on the video that the receipt has finished scanning from the user's perspective

Yes, when users input the data being scanned manually, the request looks like it's not scanning, but I believe we continue the scan in the background.

Is the violation showing now?

The price 23.19 comes from the receipt (although the currency got messed up).

Can you share more details about this, are you pointing to a specific error or problem with the PR? Sorry if I'm missing something obvious, I'm just trying to figure out if things are working correctly, and so far it seems like they are

@trevor-coleman
Copy link
Contributor Author

I think I've figured it out -- the modifiedAmount violation is a notice type violation, so it won't be displayed.

That notice type filter was part of a separate issue that I brought into this PR after the test instructions were written, and I didn't realize modifiedAmount was that kind of violation.

I've removed section D from the test instructions, and I think we are now passing all tests.

Just need to merge in main to fix the lint error and we are good.

@cead22
Copy link
Contributor

cead22 commented Feb 9, 2024

Awesome sauce!

@trevor-coleman
Copy link
Contributor Author

Main is merged, and now comes the time of anxious waiting for the CI checks to complete.

@cead22
Copy link
Contributor

cead22 commented Feb 9, 2024

Am I crazy or is the check for the reviewer checklist missing?

Copy link
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

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

(just for testing checks)
Is reviewer checklist missing

@cubuspl42
Copy link
Contributor

cubuspl42 commented Feb 12, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(theme.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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
violations-android-compressed.mp4
Android: mWeb Chrome
violations-android-web-compressed.mp4
iOS: Native
violations-ios-compressed.mp4
iOS: mWeb Safari
violations-ios-web-compressed.mp4
MacOS: Chrome / Safari

A.

a-first-money-request.mp4

B.

b-changes-to-show-category-violations.mp4

C.

c-changes-to-clear-violations.mp4
MacOS: Desktop image image image

@melvin-bot melvin-bot bot requested a review from cead22 February 12, 2024 10:32
…for-violations

# Conflicts:
#	src/components/ReportActionItem/MoneyRequestView.tsx
@trevor-coleman
Copy link
Contributor Author

Merged main and resovled conflict.

@trevor-coleman
Copy link
Contributor Author

So close!

@cead22
Copy link
Contributor

cead22 commented Feb 13, 2024

Yeah I just wanted to test dekstop becasue I didn't see screenshots/videos in the reviewer checklist. I added them now

@cead22 cead22 merged commit 07d97ef into Expensify:main Feb 13, 2024
15 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 production by https://github.com/thienlnam in version: 1.4.41-12 🚀

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

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

Successfully merging this pull request may close these issues.

6 participants