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

Add One Transaction Report View #36934

Merged
merged 51 commits into from
Mar 29, 2024
Merged

Conversation

NikkiWines
Copy link
Contributor

@NikkiWines NikkiWines commented Feb 20, 2024

Details

Held on the following PRs

Auth PR: https://github.com/Expensify/Auth/pull/9940
Web PR: https://github.com/Expensify/Web-Expensify/pull/40900

Fixed Issues

Part 3 of 3
$ https://github.com/Expensify/Expensify/issues/342922
$ #38655

Tests

(Before checking out this branch)

  1. Log into an account that is a member of a workspace and make a single money request on the workspace chat like so:
Workspace Chat Expense Report Transaction Thread
Screenshot 2024-02-20 at 11 02 30 Screenshot 2024-02-20 at 11 01 56 Screenshot 2024-02-20 at 11 01 48

(After checking out this branch)

  1. Navigate to the workspace chat and click on the expense report preview
  2. Confirm that opens the report and that you see a combined expense view showing the details of both the expense report and transaction thread with an updated simplified icon (non-diagonal version) without a total.
  1. Modify something on the transaction (category, merchant, currency etc.) and confirm the associated report action is displayed accordingly in the one-transaction view.
    • If you modify the currency, ensure the total appears on the one transaction view reflecting the amount in the report currency
  2. Add a comment and confirm it displays correctly
  3. Create a new request on the workspace chat and navigate back to the expense report
  4. Confirm you see the separated expense report and transaction thread views:
  1. Confirm the changes you made to the expense are reflected on the transaction level, but the comment is retained on the expense report level
  2. Delete the new request and confirm the view updates back to the one-transaction view
Screen.Recording.2024-03-08.at.17.02.18.mov
  1. Repeat the same steps but for a 1:1 money request and confirm you see the one-transaction view with a simplified single icon
Screen.Recording.2024-03-08.at.17.12.11.mov
  • Verify that no errors appear in the JS console

Offline tests

Offline view won't shows the one-transaction view and will be the same as it is currently
image

QA Steps

Same as test 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 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
Screen.Recording.2024-03-15.at.19.00.08.mov
Android: mWeb Chrome
Screen.Recording.2024-03-15.at.19.22.16.mov
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.-.2024-03-15.at.16.30.38.mp4
iOS: mWeb Safari
workspace.chat.test.mp4
iou.test.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-03-08.at.17.02.18.mov
MacOS: Desktop
Screen.Recording.2024-03-15.at.15.18.35.mov

@NikkiWines NikkiWines self-assigned this Feb 20, 2024
@NikkiWines NikkiWines changed the title Nikki one transaction report view Add One Transaction Report View Feb 20, 2024
@NikkiWines NikkiWines changed the title Add One Transaction Report View [HOLD] Add One Transaction Report View Feb 20, 2024
Comment on lines 1202 to 1233
/**
* Checks if a report has only one transaction associated with it
*/
function isOneTransactionReport(reportOrID: OnyxEntry<Report> | string): boolean {
const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null;

// Check the parent report (which would be the IOU or expense report if the passed report is an IOU or expense request)
// to see how many IOU report actions it contains
const iouReportActions = ReportActionsUtils.getIOUReportActions(report?.reportID ?? '');
return (iouReportActions?.length ?? 0) === 1;
}

/**
* Returns the reportID of the first transaction thread associated with a report
*/
function getOneTransactionThreadReportID(reportOrID: OnyxEntry<Report> | string): string | undefined {
const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null;

// Get all IOU report actions for the report.
const iouReportAction = ReportActionsUtils.getIOUReportActions(report?.reportID ?? '')?.find(reportAction => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.childReportID);
return iouReportAction ? String(iouReportAction.childReportID) : '0'
}

/**
* Checks if a report is a transaction thread associated with a report that has only one transaction
*/
function isOneTransactionThread(reportOrID: OnyxEntry<Report> | string): boolean {
const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null;
const parentReport = getParentReport(report);
return isOneTransactionReport(parentReport?.reportID ?? '');
}

Copy link
Contributor

Choose a reason for hiding this comment

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

These methods are anti-patterns, like the ones being removed in #27262.

The problem with them is in how they are used. If a view component uses these methods, then the view is accessing data that is not connected via withOnyx(). Meaning that if the onyx data changes, the view won't re-render and it will have stale data.

What you'll have to do instead is make sure the component is connected to the REPORT collection, and then using they key function and maybe a selector, you'll have to look up all this stuff from the connected data.

I hope that makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was not awaer of that tracking/ clean up issue, thanks for raising this. It makes sense, annoyingly this is easy to miss, these methods are convenient so that you might not realize the consequence

@shawnborton
Copy link
Contributor

Apologies if you are still making progress on the screenshots but for this screen here:
image

I don't think we need the extra "Total" row above the total that is found in the expense details body. So we can remove the one on top.

@NikkiWines
Copy link
Contributor Author

I asked about that here a few weeks ago and Tom brought up that we might need to keep it because there may be distinctions between the report currency and transaction currency - definitely open to revisiting that decision though!

@shawnborton
Copy link
Contributor

Ah okay - is it possible to just not show it if it's the same value? cc @trjExpensify

@NikkiWines
Copy link
Contributor Author

NikkiWines commented Feb 26, 2024

Personally, I think ideally we'd avoid conditional logic where we only occasionally show certain elements. This was brought up in an earlier discussion for part of this view, as that sort of approach can lead to a less clean implementation.

The Total section is the expense report detail and everything below it is the transaction thread detail, so we could conditionally not show the report details if the currencies are the same. But, in general, I'm more opposed to the idea of a bunch of conditional logic for this view than I am to particularly changing this one aspect - so happy to go with a majority preference here.

@trjExpensify
Copy link
Contributor

Yeah, I agree it looks strange when the currencies are the same. It's the multi-currency case we need it for really.

@tgolen
Copy link
Contributor

tgolen commented Mar 5, 2024

What's the next step for this PR?

@ishpaul777 ishpaul777 mentioned this pull request Mar 30, 2024
50 tasks
@OSBotify
Copy link
Contributor

OSBotify commented Apr 2, 2024

🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.59-0 🚀

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

@shawnborton
Copy link
Contributor

cc @NikkiWines - looks like this one generated a few bugs. Can you take a look please? Thanks!

@NikkiWines
Copy link
Contributor Author

NikkiWines commented Apr 2, 2024

Lots of edge cases coming up! Luckily most of these are pretty easily addressed. The main one that I think will involve more discussion is how to handle the status of an expense in the one transaction view given the original design involved just showing the report header, not the request header. Going to raise that in slack once I've got the majority of these blockers under control

Edit: raised here

@OSBotify
Copy link
Contributor

OSBotify commented Apr 8, 2024

🚀 Deployed to production by https://github.com/Julesssss in version: 1.4.60-13 🚀

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

@parasharrajat
Copy link
Member

We missed an edge case to hide the IOUpreview for send money one-transaction reports. #39490

// Get a sorted array of reportActions for both the current report and the transaction thread report associated with this report (if there is one)
// so that we display transaction-level and report-level report actions in order in the one-transaction view
const combinedReportActions = useMemo(() => {
if (isEmptyObject(transactionThreadReportActions)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In case the thread report actions aren't fetched yet, it causes an issue #43034. So instead of actions we can validate only transactionThreadReportID.

Comment on lines +756 to +764
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
<>
{transactionCurrency !== report.currency && (
<MoneyReportView
report={report}
policy={policy}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
/>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

For BZ checklist in #44162:
MoneyReportView is briefly displayed even when there are no transactions (optimistic).
This caused flickering effect. More details in this PR description

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.