-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Feature/offline pattern in the report table view #62093
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
Merged
mountiny
merged 18 commits into
Expensify:main
from
software-mansion-labs:feature/offline-pattern-in-the-report-table-view
May 28, 2025
+214
−101
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
101cf9b
offline pattern in the report table view
jmusial 54f7d43
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial d05d12a
fix prettier
jmusial 2995e07
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 2a31f52
add errors display in the table view
jmusial f3a9583
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 68cc289
cleanup RBR component
jmusial 0076409
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 1319c28
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 9edd6c4
prettier fix
jmusial 9e27901
update readability v1
jmusial 7ef0abd
extractErrorMessages refactor
jmusial 7fe5f38
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 12e702c
remove redundant defaults
jmusial 9f3f07e
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial 14c9a15
Merge branch 'main' into feature/offline-pattern-in-the-report-table-…
jmusial f456117
fix PR comments
jmusial e55740a
block row interactions when transaction is pending delete
jmusial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 73 additions & 10 deletions
83
src/components/TransactionItemRow/TransactionItemRowRBR.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,97 @@ | ||
| import React from 'react'; | ||
| import React, {useCallback} from 'react'; | ||
| import type {ViewStyle} from 'react-native'; | ||
| import {View} from 'react-native'; | ||
| import Icon from '@components/Icon'; | ||
| import {DotIndicator} from '@components/Icon/Expensicons'; | ||
| import type {LocaleContextProps} from '@components/LocaleContextProvider'; | ||
| import RenderHTML from '@components/RenderHTML'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import usePaginatedReportActions from '@hooks/usePaginatedReportActions'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import useTransactionViolations from '@hooks/useTransactionViolations'; | ||
| import {isReceiptError} from '@libs/ErrorUtils'; | ||
| import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils'; | ||
| import ViolationsUtils from '@libs/Violations/ViolationsUtils'; | ||
| import variables from '@styles/variables'; | ||
| import type {Errors} from '@src/types/onyx/OnyxCommon'; | ||
| import type ReportAction from '@src/types/onyx/ReportAction'; | ||
| import type Transaction from '@src/types/onyx/Transaction'; | ||
| import type {ReceiptError, ReceiptErrors} from '@src/types/onyx/Transaction'; | ||
|
|
||
| function TransactionItemRowRBR({transaction, containerStyles}: {transaction: Transaction; containerStyles?: ViewStyle[]}) { | ||
| type TransactionItemRowRBRProps = { | ||
| /** Transaction item */ | ||
| transaction: Transaction; | ||
|
|
||
| /** Styles for the RBR messages container */ | ||
| containerStyles?: ViewStyle[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Extracts unique error messages from errors and actions | ||
| */ | ||
| const extractErrorMessages = (errors: Errors | ReceiptErrors, errorActions: ReportAction[], translate: LocaleContextProps['translate']): string[] => { | ||
| const uniqueMessages = new Set<string>(); | ||
|
|
||
| // Combine transaction and action errors | ||
| let allErrors: Record<string, string | Errors | ReceiptError | null | undefined> = {...errors}; | ||
| errorActions.forEach((action) => { | ||
| if (!action.errors) { | ||
| return; | ||
| } | ||
| allErrors = {...allErrors, ...action.errors}; | ||
| }); | ||
|
|
||
| // Extract error messages | ||
| Object.values(allErrors).forEach((errorValue) => { | ||
| if (!errorValue) { | ||
| return; | ||
| } | ||
| if (typeof errorValue === 'string') { | ||
| uniqueMessages.add(errorValue); | ||
| } else if (isReceiptError(errorValue)) { | ||
| uniqueMessages.add(translate('iou.error.receiptFailureMessageShort')); | ||
| } else { | ||
| Object.values(errorValue).forEach((nestedErrorValue) => { | ||
| if (!nestedErrorValue) { | ||
| return; | ||
| } | ||
| uniqueMessages.add(nestedErrorValue); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| return Array.from(uniqueMessages); | ||
| }; | ||
|
|
||
| function TransactionItemRowRBR({transaction, containerStyles}: TransactionItemRowRBRProps) { | ||
| const styles = useThemeStyles(); | ||
| const transactionViolations = useTransactionViolations(transaction?.transactionID); | ||
| const {translate} = useLocalize(); | ||
| const theme = useTheme(); | ||
|
|
||
| // 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. | ||
| const RBRMessages = transactionViolations | ||
| .map((violation) => { | ||
| const {sortedAllReportActions: transactionActions} = usePaginatedReportActions(transaction.reportID); | ||
| const transactionThreadId = transactionActions ? getIOUActionForTransactionID(transactionActions, transaction.transactionID)?.childReportID : undefined; | ||
| const {sortedAllReportActions: transactionThreadActions} = usePaginatedReportActions(transactionThreadId); | ||
| const getErrorMessages = useCallback( | ||
| (errors: Errors | ReceiptErrors | undefined = {}, errorActions: ReportAction[] | undefined = []) => extractErrorMessages(errors, errorActions, translate), | ||
| [translate], | ||
| ); | ||
|
|
||
| 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) => { | ||
|
Comment on lines
+81
to
+88
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This array was missing FE-based which we addressed by including these FE-based |
||
| const message = ViolationsUtils.getViolationTranslation(violation, translate); | ||
| return message.endsWith('.') || transactionViolations.length === 1 ? message : `${message}.`; | ||
| }) | ||
| .join(' '); | ||
|
|
||
| }), | ||
| ].join(' '); | ||
| return ( | ||
| transactionViolations.length > 0 && ( | ||
| RBRMessages.length > 0 && ( | ||
| <View style={[styles.flexRow, styles.alignItemsCenter, styles.gap1, containerStyles, styles.w100]}> | ||
| <Icon | ||
| src={DotIndicator} | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 😿