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

[Held requests] Clean up the hold/unhold logic #45151

Merged

Conversation

cdOut
Copy link
Contributor

@cdOut cdOut commented Jul 10, 2024

Details

Fix for hold/unhold logic to make it display properly as an option both in the context menu on right-click/long-press as well as a promoted aciton in the reports details page.

Fixed Issues

$ #44573
$ #45518
PROPOSAL:

Tests

Expenses on iouReports

  1. Submit an expense to another account.
  2. Confirm that you can hold the expense from both accounts participating in the expense report.
  3. Hold it from one of the accounts and confirm that it only can be unheld by the account that held it.

Expenses on expenseReports

  1. Create a workspace and invite a second account into it
  2. Submit an expense for said workspace from the other account.
  3. Confirm that the member of said expense report can hold it, same for approved assigned to it and also admin of said workspace.
  4. As for unholding, members should be able to do so if they also put it on hold originally, approvers should be able to unhold expenses assigned to them and admins should be able to unhold any expenses from their workspaces.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

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

MacOS: Desktop and Chrome / Safari
DESKTOP.WEB.mov

Copy link
Contributor

@war-in war-in left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@robertjchen
Copy link
Contributor

@cdOut Is this ready for review? 🙏

@cdOut cdOut marked this pull request as ready for review July 19, 2024 09:34
@cdOut cdOut requested a review from a team as a code owner July 19, 2024 09:34
@melvin-bot melvin-bot bot requested review from parasharrajat and removed request for a team July 19, 2024 09:34
Copy link

melvin-bot bot commented Jul 19, 2024

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

@parasharrajat
Copy link
Member

parasharrajat commented Jul 20, 2024

I am getting unhold request error from backend when I try to unhold the request from Approver.

Screenshot 2024-07-20 at 2 59 35 PM

@parasharrajat
Copy link
Member

BUG: If some reason hold/unhold request is failed on the client. After clearing the RBR error from request, the unheld or held message from report is not removed.

Expected: The message should also remove on clearing RBR when the operation failed.

20.07.2024_15.05.01_REC.mp4

@parasharrajat
Copy link
Member

parasharrajat commented Jul 20, 2024

Now, I have couple of questions on how the button visibility should work for all the cases.

  1. If a user is not able to hold a request, should the hold button be hidden on the report. Vice-versa for unhold.
  2. If the buttons should be visible all the times, What should happen when a non-autorized user clicks that button. For example, a member tries to unhold a request which was held by approver.

@trjExpensify

@parasharrajat
Copy link
Member

parasharrajat commented Jul 20, 2024

  1. Approver of workspace is not able to unhold a expense request PUT on hold by someone else (member or admin).
  2. Admin of workspace is not able to unhold a expense request PUT on hold by someone else (member or approver).

Related: #45151 (comment)

@robertjchen
Copy link
Contributor

robertjchen commented Jul 22, 2024

@parasharrajat

  1. If a user is not able to hold a request, should the hold button be hidden on the report. Vice-versa for unhold.

Yes, the hold button should be hidden if the user is not able to hold a particular request and vice versa.

  1. If the buttons should be visible all the times, What should happen when a non-autorized user clicks that button. For example, a member tries to unhold a request which was held by approver.

Ideally, we would not allow the user to get to this state through the frontend.

  1. Approver of workspace is not able to unhold a expense request PUT on hold by someone else (member or admin).
  2. Admin of workspace is not able to unhold a expense request PUT on hold by someone else (member or approver).

Interesting- let me double-check the backend. In theory, admin/approvers for expense reports should be unable to unhold in all cases to move a report/request through the approval workflow.

The submitter is prevented from unholding in all cases EXCEPT the case where they had specifically held their submission in the first place. 🤔

In the case of an IOU, the approver cannot unhold if the submitter/requestor had put it on hold.

@robertjchen
Copy link
Contributor

Thanks again for the tests @parasharrajat ! Made a few tweaks to the backend to allow an approver/admin to unhold an expense put on hold by someone else, but it shouldn't block the progress here 👍

@parasharrajat
Copy link
Member

@cdOut Can you please look into the bugs above?

@cdOut
Copy link
Contributor Author

cdOut commented Jul 22, 2024

Yes, I'll look into them today.

@cdOut
Copy link
Contributor Author

cdOut commented Jul 24, 2024

Update to the issue, I'm working on fixing the bugs today and will focus on getting it to be ready for a re-review early tomorrow.

@cdOut
Copy link
Contributor Author

cdOut commented Jul 29, 2024

As an update to the issue thread, today I'm completing the fix for the context menu (Long-press / Right Mouse Button) to also work properly with our current logic and I'll let @parasharrajat know when it's ready for a re-review later.

@parasharrajat
Copy link
Member

@cdOut Please Resolve conflicts.

Comment on lines +143 to +175
const childReport = ReportUtils.getReport(reportAction?.childReportID ?? '-1');
const parentReportAction = ReportActionsUtils.getReportAction(childReport?.parentReportID ?? '', childReport?.parentReportActionID ?? '');
const {reportActions: paginatedReportActions} = usePaginatedReportActions(childReport?.reportID ?? '-1');

const transactionThreadReportID = useMemo(
() => ReportActionsUtils.getOneTransactionThreadReportID(childReport?.reportID ?? '-1', paginatedReportActions ?? [], isOffline),
[childReport?.reportID, paginatedReportActions, isOffline],
);

const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);

const isMoneyRequestReport = useMemo(() => ReportUtils.isMoneyRequestReport(childReport), [childReport]);
const isInvoiceReport = useMemo(() => ReportUtils.isInvoiceReport(childReport), [childReport]);

const requestParentReportAction = useMemo(() => {
if (isMoneyRequestReport || isInvoiceReport) {
if (!paginatedReportActions || !transactionThreadReport?.parentReportActionID) {
return undefined;
}
return paginatedReportActions.find((action) => action.reportActionID === transactionThreadReport.parentReportActionID);
}
return parentReportAction;
}, [parentReportAction, isMoneyRequestReport, isInvoiceReport, paginatedReportActions, transactionThreadReport?.parentReportActionID]);

const moneyRequestAction = transactionThreadReportID ? requestParentReportAction : parentReportAction;

const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${childReport?.parentReportID ?? '-1'}`);
const parentReport = ReportUtils.getReport(childReport?.parentReportID ?? '-1');

const isMoneyRequest = useMemo(() => ReportUtils.isMoneyRequest(childReport), [childReport]);
const isTrackExpenseReport = ReportUtils.isTrackExpenseReport(childReport);
const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport;
const isMoneyRequestOrReport = isMoneyRequestReport || isInvoiceReport || isSingleTransactionView;
Copy link
Member

Choose a reason for hiding this comment

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

Don't we have utils to get all these already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you know of said utils then please point them out to me, but I don't think we already have one that would handle this sort of logic. This was recently written for just ReportDetailsPage which unified multiple pages with hold functionalities into one component.

Copy link
Member

Choose a reason for hiding this comment

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

Let me see.

@trjExpensify
Copy link
Contributor

@parasharrajat did you look for those Utils, can we continue the review? Thanks!

@parasharrajat
Copy link
Member

@trjExpensify Yes, I am testing it. I will have more updates in sometime today.

@parasharrajat
Copy link
Member

parasharrajat commented Aug 4, 2024

Members can only unhold expenses they put on hold themselves.

This case is failing. User A requested money from user B. User B held the request.

BUG: User A is seeing unhold button.
BUG: User B does not see unhold button.

@parasharrajat
Copy link
Member

Members can unhold their own expenses, but only if they themselves put the expense on hold.

User A requested money to a Workspace. User A held the request.

BUG: User A does not see unhold button.

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Bugs above. Rest the code looks good to me.

@cdOut
Copy link
Contributor Author

cdOut commented Aug 5, 2024

I'll be looking at the bugs today, will let you know when it's done.

merge main into @cdOut/cleanup-hold-unhold
@parasharrajat
Copy link
Member

@cdOut Any updates?

@cdOut
Copy link
Contributor Author

cdOut commented Aug 7, 2024

I am finishing this one now, will send you an update later today when it's ready

@cdOut
Copy link
Contributor Author

cdOut commented Aug 8, 2024

Got a little blocked since the way we detect who held the expense changed with this logic, will notify when I resolve this one

@cdOut
Copy link
Contributor Author

cdOut commented Aug 9, 2024

@parasharrajat ready for your re-review, merged the latest main also

@parasharrajat
Copy link
Member

parasharrajat commented Aug 9, 2024

Screenshots

🔲 iOS / native

10.08.2024_16.34.08_REC.mp4

🔲 iOS / Safari

10.08.2024_16.26.26_REC.mp4

🔲 MacOS / Desktop

10.08.2024_16.24.15_REC.mp4

🔲 MacOS / Chrome

10.08.2024_16.18.47_REC.mp4

🔲 Android / Chrome

10.08.2024_16.42.10_REC.mp4

🔲 Android / native

10.08.2024_16.31.22_REC.mp4

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

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.

🎀 👀 🎀 C+ reviewed

@melvin-bot melvin-bot bot requested a review from Beamanator August 10, 2024 11:09
Copy link
Contributor

@robertjchen robertjchen left a comment

Choose a reason for hiding this comment

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

Thanks!

@robertjchen robertjchen merged commit 93dc1c9 into Expensify:main Aug 10, 2024
17 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.

@Beamanator
Copy link
Contributor

FYI I believe this was deployed to prod yesterday, from this checklist - #47219

const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport;
const isMoneyRequestOrReport = isMoneyRequestReport || isInvoiceReport || isSingleTransactionView;

const areHoldRequirementsMet = isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs);
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused an issue where the hold options are shown for invoice reports. More info here. #47570

Copy link
Member

Choose a reason for hiding this comment

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

Invoice reports were added after this change so technically it didn't cause the issue.

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.

8 participants