Skip to content

[No QA] [Better Expense Report View] Add TransactionPreview component#57614

Merged
mountiny merged 31 commits into
Expensify:mainfrom
software-mansion-labs:transaction-preview
Mar 17, 2025
Merged

[No QA] [Better Expense Report View] Add TransactionPreview component#57614
mountiny merged 31 commits into
Expensify:mainfrom
software-mansion-labs:transaction-preview

Conversation

@JakubKorytko

@JakubKorytko JakubKorytko commented Feb 28, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

This is a visual implementation of the replacement for MoneyRequestPreview in Storybook - TransactionPreview.

For now, the MoneyRequestPreview still exists and is being used, so it can't be replaced, the component just lives in the story so it can be easily replaced later.

I'm aware that this component will be inside Carousel, but for the recordings I replaced MoneyRequestPreview locally with this one to get a better view of how these components render in the real environment.

Fixed Issues

$ #57506
PROPOSAL: N/A

Tests

  1. Run storybook.
  2. Select TransactionPreview component.
  3. Select any variant.
  4. Modify controls and verify that no visual errors occur.

OR

  1. Replace the MoneyRequestPreview rendering in the src/components/ReportActionItem/MoneyRequestAction.tsx component with TransactionPreview.
  2. For performance reasons, replace return in the above component with commented code on line 117.
  3. Open any expense report or chat with split/distance expenses.

Offline tests

N/A

QA Steps

N/A

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 used JaimeGPT to get English > Spanish translation. I then posted it 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.ts 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.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • 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-Native.mov
Android: mWeb Chrome
Android-Web.mov
iOS: Native
iOS-Native.mov
iOS: mWeb Safari
iOS-Web.mov
MacOS: Chrome / Safari
Web.mov
Storybook.mov
MacOS: Desktop
Desktop.mov

@JakubKorytko JakubKorytko force-pushed the transaction-preview branch from 6405358 to 9c8fcba Compare March 5, 2025 09:45
@mountiny mountiny changed the title [WIP] Add TransactionPreview component [WIP] [Better Expense Report View] Add TransactionPreview component Mar 5, 2025
@JakubKorytko JakubKorytko changed the title [WIP] [Better Expense Report View] Add TransactionPreview component [Better Expense Report View] Add TransactionPreview component Mar 10, 2025
@shawnborton

Copy link
Copy Markdown
Contributor

Let us know when this one is ready for a design review, and I'll run a test build for us.

@Kicu Kicu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dropped you a few more comments, please take a look.
Otherwise the UI itself and story looks really nice 👍

Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment thread tests/unit/TransactionPreviewUtils.test.ts Outdated
Comment thread src/libs/TransactionPreviewUtils.ts Outdated
Comment thread src/libs/TransactionPreviewUtils.ts Outdated
Comment thread src/libs/TransactionPreviewUtils.ts
Comment thread src/components/SelectionList/Search/UserInfoCellsWithArrow.tsx Outdated
Comment thread src/components/SelectionList/Search/UserInfoCell.tsx Outdated
@shawnborton

Copy link
Copy Markdown
Contributor

Let me know if you have any screenshots to review :) thanks!

Comment thread src/stories/TransactionPreviewContent.stories.tsx Outdated
Comment thread src/stories/TransactionPreviewContent.stories.tsx Outdated
Comment thread src/libs/TransactionPreviewUtils.ts Outdated
@shawnborton

Copy link
Copy Markdown
Contributor

Not sure if you are ready for feedback yet, but we have some truncation issues happening when the merchant name is long:
CleanShot 2025-03-12 at 13 15 41@2x

@shawnborton

Copy link
Copy Markdown
Contributor

I don't think we want any top padding on this bottom footer row:
CleanShot 2025-03-12 at 13 35 55@2x

@JakubKorytko

JakubKorytko commented Mar 13, 2025

Copy link
Copy Markdown
Contributor Author

I've fixed things you mentioned.

Last request - is it possible to add a prop into Storybook to see this with a receipt or not? As in, I would love to see this one with the default placeholder when no receipt is present, like so:

In previous commits in this PR it was possible, but it was because each transaction, action, etc. property was passed separately as a component prop, which resulted in too many props on that component.
At the moment it can't be changed that easily (or at least I don't know how to do it rn) as each object is passed as it is so I've created some "templates" with pre-defined data to choose from.

However, there is an addon called addon-deep-controls which allows a control for every object property in Storybook UI. It would make it possible to change each property separately, so that's one way - I can add this dependency and adapt my story to it - shouldn't take long.

But if we do not want additional dev dependency, you can modify src/stories/mockData/transactions.ts and then see the changes in Storybook. For example, for no receipt image (default placeholder) you need to remove hasEReceipt, receipt and filename from the transaction object in the mentioned file. Then its image will look like this for each variant:
Screenshot 2025-03-13 at 12 40 44

@shawnborton

Copy link
Copy Markdown
Contributor

Sounds good, thanks for confirming! I say let's get this into final review then so we can keep marching along.

@allgandalf allgandalf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code LGTM! , @JakubKorytko can you mark this one as [No QA] since Qa won't be able to test it

@JakubKorytko JakubKorytko changed the title [Better Expense Report View] Add TransactionPreview component [No QA] [Better Expense Report View] Add TransactionPreview component Mar 14, 2025
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

Marked as [No QA], thank you.

@allgandalf allgandalf left a comment

Copy link
Copy Markdown
Contributor

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 that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • 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 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 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 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.ts 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • 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
Screen.Recording.2025-03-14.at.5.02.27.PM.mov
Android: mWeb Chrome
Screen.Recording.2025-03-14.at.5.11.51.PM.mov
iOS: Native
Screen.Recording.2025-03-14.at.4.57.30.PM.mov
iOS: mWeb Safari
Screen.Recording.2025-03-14.at.4.58.14.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2025-03-14.at.4.55.34.PM.mov
MacOS: Desktop
Screen.Recording.2025-03-14.at.5.08.06.PM.mov

@melvin-bot melvin-bot Bot requested a review from mountiny March 14, 2025 11:43

@mountiny mountiny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small changes

Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment on lines +116 to +118
// NOTE: this part of code is needed here if we want to replace MoneyRequestPreview with TransactionPreview
// const renderCondition = lodashIsEmpty(iouReport) && !(isSplitBillAction || isTrackExpenseAction);
// return renderCondition ? null : (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we have the tableReportView beta, could we just use that now and render the new component if user is on that beta?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe to keep the PR cleaner, let's not modify the app code in this PR so that it only adds to storybook. We can use them in the code later, when other PR's (like the carousel) are ready

Comment thread src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx Outdated
Comment on lines +8 to +11
/** The active IOUReport, used for Onyx subscription */
// The iouReportID is used inside withOnyx HOC
// eslint-disable-next-line react/no-unused-prop-types
iouReportID: string | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We dont use withOnyx in the component AND I think this should be always same as the reportID, right? Or did you see case when the reportID and iouReportID in this prop is not same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ve corrected the comment.

I think there is no case when reportID is a different number than iouReportID. However if the report is not IOU then reportID is a number and iouReportID is undefined.

It is a logic that was implemented in MoneyRequestPreview and moved to the new component and I think it is okay to have ID of IOU only if the report is IOU, but I can change this if you want, let me know what you think.

Comment thread src/components/SelectionList/Search/UserInfoCellsWithArrow.tsx
Comment thread src/libs/TransactionPreviewUtils.ts Outdated
Comment thread src/libs/TransactionPreviewUtils.ts Outdated
Comment thread src/libs/TransactionPreviewUtils.ts
Comment thread src/libs/TransactionPreviewUtils.ts
Comment thread tests/unit/TransactionPreviewUtils.test.ts
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@mountiny I've covered every returned value in tests, fixed code according to your comments and also added my own comments, please check if its okay now.

@mountiny mountiny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@mountiny mountiny merged commit 96edca9 into Expensify:main Mar 17, 2025
@OSBotify

Copy link
Copy Markdown
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.

@github-actions

Copy link
Copy Markdown
Contributor

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

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

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.1.15-9 🚀

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

const fromID = chooseIDBasedOnAmount(amount, managerID, ownerAccountID);
const toID = chooseIDBasedOnAmount(amount, ownerAccountID, managerID);

return reportOrID && isIOUReport(reportOrID)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We haven't considered the case where the IOU report is not available yet upon logging in and we haven't opened that report. Thus caused this bug #59688

isPreviewHeaderTextComplete = true;
}

if (shouldShowRBR && transaction) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the new table report view, the RBR is shown below the header text, so now we don't need to hide the preview header text when we have a RBR. If we do hide it, as this implemented, the expense status is also hidden (Bug: #60793).

<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.FROM)]}>
<UserInfoCell
participant={item.to}
accountID={item.to.accountID}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

item.to can be undefined when sending an invoice to new user. It's better if we keep the previous optional chaining here
More details: #61310 (comment)


// When there are no settled transactions in duplicates, show the "Keep this one" button
const shouldShowKeepButton = areThereDuplicates;
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming from #65027, we need to check also if the user is not a part of the split bill or not as we always fallback the splitShare amount with calculateAmount even though the current user is not a part of the split bill here

fill={theme.icon}
/>
)}
<View style={[styles.flex1, styles.mw50]}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 View with max width 50% and also an arrow will cause an overflow issue when user names are too long and occupy 50% of the width. Ref issue - #67891

Comment on lines +76 to +80
// Clear the draft before selecting a different expense to prevent merging fields from the previous expense
// (e.g., category, tag, tax) that may be not enabled/available in the new expense's policy.
abandonReviewDuplicateTransactions();
const comparisonResult = compareDuplicateTransactionFields(reviewingTransactionID, transaction?.reportID, transaction?.transactionID ?? reviewingTransactionID);
setReviewDuplicatesKey({...comparisonResult.keep, duplicates, transactionID: transaction?.transactionID, reportID: transaction?.reportID});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These lines created a race condition where wrong values were set due to quick updates to same onyx values. More details - #79179

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.