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

Move RBR to workspace chats instead of transaction threads #51893

Merged
merged 13 commits into from
Nov 12, 2024

Conversation

iwiznia
Copy link
Contributor

@iwiznia iwiznia commented Nov 1, 2024

Held on https://github.com/Expensify/Web-Expensify/pull/44293

Explanation of Change

Fixed Issues

https://github.com/Expensify/Expensify/issues/433103

Tests

  • Have a report with violations
  • Check the RBR is only shown:
    • In the workspace chat
    • In the report preview in the workspace chat
    • In the expense preview in the workspace chat for reports with only one expense
    • In the expense preview of the report for reports with more than one expense
    • In the expense itself
  • Check that a receipt with only modified date/amount violation is not shown with a RBR in the LHN, but it does show in the expense page when the report is in open state
  • Check that a receipt with only modified date/amount violation is shown with a RBR in in the report/expense page when the report is in submitted state

Offline tests

No

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 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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 UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

@iwiznia iwiznia self-assigned this Nov 1, 2024
// - Belong to the same workspace
// And if any have a violation, then it should have a RBR
const allReports = Object.values(ReportConnection.getAllReports() ?? {});
const potentialReports = allReports.filter((r: Report) => r?.ownerAccountID === currentUserAccountID && r?.stateNum <= 1 && r?.policyID === report.policyID);
Copy link
Contributor

Choose a reason for hiding this comment

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

error must be for these lines

@@ -693,46 +693,6 @@ describe('DebugUtils', () => {
});
expect(reason).toBe('debug.reasonVisibleInLHN.pinnedByUser');
});
it('returns correct reason when report has IOU violations', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted this since it seems to me it's testing the same thing as this other test

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the harm in leaving it? That sounds better if it's possible for there to be a case that this catches that the other test doesn't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why have 2 tests that do the same? It's confusing, useless and a waste of time to have to update it now (and in the future whenever this changes)

Copy link
Contributor

Choose a reason for hiding this comment

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

Cause I got the impression that we think they're identical, but not 100% sure. If that's the case, I think it's better to leave it, but NAB

@iwiznia iwiznia changed the title Move RBR to workspace chats instead of transaction threads [HOLD] Move RBR to workspace chats instead of transaction threads Nov 5, 2024
@iwiznia iwiznia requested review from cead22 and pecanoro November 5, 2024 18:47
@iwiznia iwiznia marked this pull request as ready for review November 5, 2024 18:47
@iwiznia iwiznia requested a review from a team as a code owner November 5, 2024 18:47
@melvin-bot melvin-bot bot removed the request for review from a team November 5, 2024 18:47
Copy link

melvin-bot bot commented Nov 5, 2024

@ 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]

@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 5, 2024

Oh I also need to update a regression test: https://expensify.slack.com/archives/C9YU7BX5M/p1730833945360329

@iwiznia iwiznia changed the title [HOLD] Move RBR to workspace chats instead of transaction threads Move RBR to workspace chats instead of transaction threads Nov 6, 2024
@pecanoro
Copy link
Contributor

pecanoro commented Nov 6, 2024

@iwiznia Should we review or wait? I am a little confused

@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 6, 2024

Review! What was confusing?

@pecanoro
Copy link
Contributor

pecanoro commented Nov 7, 2024

@iwiznia You mentioned something about regression tests so I wasn't sure if you wanted to add more tests to the PR

@iwiznia iwiznia requested a review from allgandalf November 7, 2024 14:36
@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 7, 2024

@iwiznia You mentioned something about regression tests so I wasn't sure if you wanted to add more tests to the PR

Yes, if you follow the link, we have a plan to update the regression tests when this is merged, but that update is outside of this PR code.

Copy link
Contributor

@cead22 cead22 left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! I think one of the most important parts of this PR should be to update the regression tests we have for violations to make sure the steps that used to check for RBRs on the transaction threads are updated to check the workspace chat.

That way we can have Applause run the full suite of violation tests as part of this PR and be confident we're not going to push bugs

@@ -693,46 +693,6 @@ describe('DebugUtils', () => {
});
expect(reason).toBe('debug.reasonVisibleInLHN.pinnedByUser');
});
it('returns correct reason when report has IOU violations', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the harm in leaving it? That sounds better if it's possible for there to be a case that this catches that the other test doesn't

tests/unit/DebugUtilsTest.ts Outdated Show resolved Hide resolved
@@ -92,6 +92,9 @@ type TransactionViolation = {

/** Additional violation information to provide the user */
data?: TransactionViolationData;

/** Indicates if this violation should be shown in review */
showInReview?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because I am not sending it from PHP when it is not true

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
showInReview?: boolean;
showInReview: boolean | undefined;

This should be required to be set (and still allow for undefined). This is needed so we create the correct optimistic data. Not doing so led to a regression #54510

However, now we need to know which violations has showInReview=true. Can you please provide a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would this need to be set for optimistic actions to work? 😕

However, now we need to know which violations has showInReview=true. Can you please provide a list?

I don't think there's a list, there's a bunch of logic controlling this property's value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this need to be set for optimistic actions to work?

If we don't then expenses created offline that violate policy rules won't have the red dot set on their previews. This is due to this logic

const hasViolations = TransactionUtils.hasViolation(transaction?.transactionID ?? '-1', transactionViolations, true);
that only take into account violations with showInReview=true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, so let's add that property to the optimistic actions (assuming the property will be removed when the data from the server is returned), but no need to mark this prop as required

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with not making this required is that the bug could resurface (one could simply forget to add the field). Do you think we shouldn't optimize for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it actually prevents bugs? Allowing undefined gives the same signal to code authors as allowing it to not be passed, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point. Forcing the field to be set can reduce the occurrence of such bugs as you will get a chance to put in the correct value but it won't 100% prevent the bug.

We will keep the types untouched.

(violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING,
);
function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, showInReview?: boolean | null): boolean {
const warningTypeViolations =
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB but break this down to make it more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like how? I had it formatted more readable but then the styler changed it to this

Copy link
Contributor

Choose a reason for hiding this comment

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

Putting transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID] in a variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did that, not sure if it makes it any better though 🤷

const warningTypeViolations = transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.filter(
(violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING,
);
function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, showInReview?: boolean | null): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the last param mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

}

/**
* Checks to see if a report contains a violation of type `warning`
*/
function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>): boolean {
function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, shouldShowInReview?: boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the last param mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@@ -809,41 +809,36 @@ function isOnHoldByTransactionID(transactionID: string): boolean {
/**
* Checks if any violations for the provided transaction are of type 'violation'
*/
function hasViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolations>): boolean {
function hasViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolations>, showInReview?: boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the last param mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

);
}

/**
* Checks if any violations for the provided transaction are of type 'notice'
*/
function hasNoticeTypeViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolation[]>): boolean {
return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some((violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.NOTICE);
function hasNoticeTypeViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, showInReview?: boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the last param mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

}

/**
* Checks to see if a report contains a violation
*/
function hasViolations(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>): boolean {
function hasViolations(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, shouldShowInReview?: boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the last param mandatory?

Copy link
Contributor Author

@iwiznia iwiznia Nov 8, 2024

Choose a reason for hiding this comment

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

In the places we are calling this that I did not update, we do not care about the state of this variable, so no.

// - Owned by the same user
// - Are either open or submitted
// - Belong to the same workspace
// And if any have a violation, then it should have a RBR
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this condition was deleted if (isSettled(IOUReportID) || isReportApproved(IOUReportID?.toString())) {, but should we be checking for settled/approved reports, and only show RBR on workspace chats if there's an expense report on the same policy of the workspace chat that isn't approved or settled?

Copy link
Contributor Author

@iwiznia iwiznia Nov 8, 2024

Choose a reason for hiding this comment

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

That's done with (r.stateNum ?? 0) <= 1 below

@allgandalf
Copy link
Contributor

I will wait for the ^ comments to be addressed before continuing the review

@iwiznia iwiznia requested a review from cead22 November 8, 2024 18:09
Copy link
Contributor

@allgandalf allgandalf left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Verified the following cases as mentioned in the tests:

  • In the workspace chat
Verified Screenshot 2024-11-12 at 12 01 18 AM
  • In the report preview in the workspace chat
Verified Screenshot 2024-11-12 at 12 01 38 AM
  • In the expense preview in the workspace chat for reports with only one expense
Verified Screenshot 2024-11-12 at 12 04 47 AM
  • In the expense preview of the report for reports with more than one expense
Verified Screenshot 2024-11-12 at 12 03 49 AM
  • In the expense itself
Verified Screenshot 2024-11-12 at 12 02 08 AM
  • Check that a receipt with only modified date/amount violation is not shown with a RBR in the LHN, but it does show in the expense page when the report is in open state
Verified Screenshot 2024-11-12 at 12 30 37 AM
  • Check that a receipt with only modified date/amount violation is shown with a RBR in in the report/expense page when the report is in submitted state
Verified Screenshot 2024-11-12 at 1 22 28 AM

@melvin-bot melvin-bot bot requested a review from tgolen November 11, 2024 20:26
Copy link

melvin-bot bot commented Nov 11, 2024

@tgolen 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]

Copy link

melvin-bot bot commented Nov 11, 2024

🎯 @allgandalf, thanks for reviewing and testing this PR! 🎉

An E/App issue has been created to issue payment here: #52341.

@iwiznia iwiznia removed the request for review from tgolen November 11, 2024 20:31
@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 11, 2024

Oh then please update the last test in the OP, it says to check for RBR in the LHN:

That phrase is not there anymore, I think you were looking at the outdated description?

@allgandalf
Copy link
Contributor

That phrase is not there anymore, I think you were looking at the outdated description?

i guess my GH's live update didn't work this time 🤣

@iwiznia iwiznia requested review from cead22 and pecanoro November 11, 2024 20:50
@cead22 cead22 merged commit 861d7e5 into main Nov 12, 2024
19 of 21 checks passed
@cead22 cead22 deleted the ionatan_moverbrworkspacechat branch November 12, 2024 20:54
@jayeshmangwani
Copy link
Contributor

@iwiznia @cead22 We removed the shouldDisplayTransactionThreadViolations function, but it’s still being used on this page.

const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(report, allTransactionViolations, parentReportAction);

@mvtglobally
Copy link

@pecanoro @iwiznia
This PR is revered here #52431.
Are we ok to check it off?

Copy link
Contributor

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

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

@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 13, 2024

Damn, so someone must've added a usage in the meantime

@iwiznia
Copy link
Contributor Author

iwiznia commented Nov 13, 2024

Are we ok to check it off?

Yes

Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 9.0.61-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 skipped 🚫
🍎🔄 iOS HybridApp 🍎🔄 skipped 🚫

return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some(
(violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION,
(violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION && (showInReview === undefined || showInReview === (violation.showInReview ?? false)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is confusing. If showInReview is false and violation.showInReview is unset (not sent by BE). Then we will end up showing this in review? (false === false)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see it now, that's a filter.

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.

7 participants