Skip to content

Feature/offline pattern in the report table view#62093

Merged
mountiny merged 18 commits into
Expensify:mainfrom
software-mansion-labs:feature/offline-pattern-in-the-report-table-view
May 28, 2025
Merged

Feature/offline pattern in the report table view#62093
mountiny merged 18 commits into
Expensify:mainfrom
software-mansion-labs:feature/offline-pattern-in-the-report-table-view

Conversation

@jmusial

@jmusial jmusial commented May 15, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

We want to add offline pattern for new expenses in the report table view

Fixed Issues

$ #61848

PROPOSAL:
N/A

Tests

Offline

1. Adding expense
  1. Log in to the app
  2. Force offline mode
  3. Go to Expense Report view
  4. Add expense
  5. Expense row has opacity
  6. Exit offline mode
  7. Expense syncs and looks like others
2. Editing expense
  1. Log in to the app
  2. Force offline mode
  3. Go to Expense Report view
  4. Edit an existing expense
  5. Expense row has opacity
  6. Exit offline mode
  7. Expense syncs and looks like others
3. Deleting expense
  1. Log in to the app
  2. Force offline mode
  3. Go to Expense Report view
  4. Delete expense
  5. Expense row has opacity and striketrhough
  6. Exit offline mode
  7. Expense syncs and dissapears

Errors

4. Editing errors 1. Log in to the app 3. Force failing requests mode 4. Go to Expense Report view 5. Open expense edit (you need to have data locally before) 6. Try to: add receipt, add comment, edit 7. RBR shows on edit view and on the list 8. When dismissed it disappears

Offline tests

Same as tests

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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 #### Offline
android_native_offline.mov

Errors

android_native_errors.mov
Android: mWeb Chrome
android_web_offline.mov
iOS: Native

Offline

ios_native_offline.mp4

Errors

ios_native_errors.mp4
iOS: mWeb Safari

Offline

ios_web_offline.mp4

Errors

ios_web_errors.mp4
MacOS: Chrome / Safari

Offline

web_offline.mov

Errors

web_errors.mov
MacOS: Desktop

@jmusial

jmusial commented May 15, 2025

Copy link
Copy Markdown
Contributor Author

@shawnborton can you please take a look @ videos for web and ios native and let me know if it is ok?

@shawnborton

Copy link
Copy Markdown
Contributor

Something is wrong with the table spacing in this video at the very end - notice how the last table row has extra margin/gap above it? This is for the offline case.

CleanShot 2025-05-15 at 14 23 17@2x

@shawnborton

Copy link
Copy Markdown
Contributor

For the failing requests video, I think we decided that we also want to show the RBR errors in the table view.

cc @trjExpensify @Expensify/design for extra eyes here too.

@jmusial

jmusial commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

does this look ok ?

Screen.Recording.2025-05-19.at.16.17.54.mov

@shawnborton

Copy link
Copy Markdown
Contributor

Nice, that feels great to me!

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

Looks good, but I left some comments that I think can improve the code readability.
Good job writing tests 👍

Comment thread src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Outdated
Comment thread src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Outdated
const extractErrorMessages = (errors: Errors | ReceiptErrors | undefined, errorActions: ReportAction[] | undefined, translate: LocaleContextProps['translate']): string[] => {
const uniqueMessages = new Set<string>();

const addErrorMessages = (rawErrors: unknown) => {

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.

do we have to create a function inside a function? is it really that helpful

if you need to run a for of loop over some collection of errorActions, then we could probably "smash" the errors together like so:

const errorsToProcess = [...errors, errorActions]

^ that is probably incorrect, but something similar.
Then run the logic of addErrorMessages just once. Is something like that possible?

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.

refactored it a bit to avoid nested functions, but TBH not sure which one is more readable.

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.

Yeah I can see it still quite hard to understand what types of errors happen there.
I don't have strong opinions so if you prefer the previous approach, then return it.

Comment thread src/libs/TransactionUtils/index.ts Outdated
@jmusial jmusial marked this pull request as ready for review May 23, 2025 12:49
@jmusial jmusial requested a review from a team as a code owner May 23, 2025 12:49
@melvin-bot melvin-bot Bot requested review from allgandalf and shawnborton May 23, 2025 12:49
@melvin-bot

melvin-bot Bot commented May 23, 2025

Copy link
Copy Markdown

@shawnborton @allgandalf One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot removed the request for review from a team May 23, 2025 12:49
@allgandalf

Copy link
Copy Markdown
Contributor

@jmusial can you fix the failing test please

@jmusial

jmusial commented May 23, 2025

Copy link
Copy Markdown
Contributor Author

hey @allgandalf it's the eslint on changed files, but the fail is not connected to any of my changes.
The getTransaction is TransactionUtils.ts has been deprecated by @luacmartins and it triggers it the fail.

The function is used in 10 places and TBH I don't think this should be addressed in this PR

@luacmartins

Copy link
Copy Markdown
Contributor

@jmusial correct, we can ignore that as we're handling removing that function in this PR

@jmusial

jmusial commented May 27, 2025

Copy link
Copy Markdown
Contributor Author

@allgandalf no worries 😄 Great timing though, I was just doing that!

const formattedCompanySpendAmount = convertToDisplayString(nonReimbursableSpend, report?.currency);
const shouldShowBreakdown = !!nonReimbursableSpend && !!reimbursableSpend;

const pendingChangesOpacity = useMemo(() => {

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.

Suggested change
const pendingChangesOpacity = useMemo(() => {
const pendingActionsOpacity = useMemo(() => {

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.

Actions is what we call them in our App, so lets follow the same here

<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.pr3]}>
<Text style={[styles.mr3, styles.textLabelSupporting]}>{translate('common.total')}</Text>
<Text style={[shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight, styles.textBold]}>
<Text style={[shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight, styles.textBold, pendingChangesOpacity]}>

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.

Suggested change
<Text style={[shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight, styles.textBold, pendingChangesOpacity]}>
<Text style={[shouldUseNarrowLayout ? styles.mnw64p : styles.mnw100p, styles.textAlignRight, styles.textBold, pendingActionsOpacity]}>

Comment on lines +22 to +25
type TransactionItemRowRBRProps = {
transaction: Transaction;
containerStyles?: ViewStyle[];
};

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.

return transaction.pendingAction;
}
const hasPendingFields = Object.keys(transaction?.pendingFields ?? {}).length > 0;
return hasPendingFields ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : 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.

@jmusial can't the pending action be add and delete? why do we always assume the action is update ?

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.

@allgandalf AFAIK from the RHP you can only edit fields, cannot add or delete them. You can add them from workspace settings, but I don't think this we need to adjust for this scenario here.

Also, even if you could delete a field from a transaction, from the transaction perspective that's an update.

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.

makes sense thanks!

@allgandalf

allgandalf commented May 27, 2025

Copy link
Copy Markdown
Contributor

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: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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: HybridApp
Screen.Recording.2025-05-29.at.12.36.54.AM.mov
Android: mWeb Chrome
Screen.Recording.2025-05-29.at.12.39.54.AM.mov
iOS: HybridApp build error
iOS: mWeb Safari
Screen.Recording.2025-05-29.at.12.35.33.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2025-05-29.at.12.32.10.AM.mov
MacOS: Desktop
Screen.Recording.2025-05-29.at.12.37.43.AM.mov

@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, finishing the checklist now

@allgandalf

Copy link
Copy Markdown
Contributor

Bug: When we delete expense, we are able to open the deleted reports RHP.

Screen.Recording.2025-05-27.at.10.57.37.PM.mov

I think we should block clicking on the transaction row when we delete it offline, @shawnborton @luacmartins is that right?

@allgandalf

Copy link
Copy Markdown
Contributor

For example take a look at the behaviour when we delete an expense:

Screen.Recording.2025-05-27.at.11.00.33.PM.mov

@jmusial

jmusial commented May 28, 2025

Copy link
Copy Markdown
Contributor Author

Hey @allgandalf thanks for the find! Blocking deleted transactions' interactions makes sense, added it to the pr.

Screen.Recording.2025-05-28.at.10.28.40.mov

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

LGTM!!! Lets ignore the failing test! @luacmartins all. yours

@melvin-bot melvin-bot Bot requested a review from mountiny May 28, 2025 19:11

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

Changes look good to me, thank you!

Comment thread src/languages/es.ts
genericCreateInvoiceFailureMessage: 'Error inesperado al enviar la factura. Por favor, inténtalo de nuevo más tarde.',
receiptDeleteFailureError: 'Error inesperado al borrar este recibo. Por favor, vuelve a intentarlo más tarde.',
receiptFailureMessage: 'Hubo un error al cargar tu recibo. Por favor, ',
receiptFailureMessageShort: 'Hubo un error al cargar tu recibo.',

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.

Did you get this verified?

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.

It's the first sentence from the message above. TBH I assumed it's correct.

@mountiny mountiny merged commit 23e8959 into Expensify:main May 28, 2025
17 of 18 checks passed
@melvin-bot

melvin-bot Bot commented May 28, 2025

Copy link
Copy Markdown

@mountiny looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@melvin-bot melvin-bot Bot added the Emergency label May 28, 2025
@mountiny

Copy link
Copy Markdown
Contributor

Optional eslint is failing so due to the size of the pr not going to ask for it to get resolved here

@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.54-0 🚀

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

@github-actions

github-actions Bot commented Jun 2, 2025

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.1.54-7 🚀

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

@@ -29,6 +29,7 @@ import {navigationRef} from '@libs/Navigation/Navigation';
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';

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 missed a bunch of edge cases with this PR like selection of deleted expenses in offline mode, this caused #63083, be little more careful reviewing @allgandalf 😿

Comment on lines +81 to +88
const RBRMessages = [
...getErrorMessages(
transaction?.errors,
transactionThreadActions?.filter((e) => !!e.errors),
),
// Some violations end with a period already so lets make sure the connected messages have only single period between them
// and end with a single dot.
...transactionViolations.map((violation) => {

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.

This array was missing FE-based required errors for fields like Merchant, leading to this issue:

which we addressed by including these FE-based required errors.

@jmusial jmusial deleted the feature/offline-pattern-in-the-report-table-view branch August 26, 2025 08:11
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