-
Notifications
You must be signed in to change notification settings - Fork 3.7k
refactor: PureReportActionItem, IouReportActionMessage #88691
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
cristipaval
merged 10 commits into
Expensify:main
from
callstack-internal:perf-send-message-phase-11
May 4, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3de24ae
refactor: Extract IouReportActionMessage from ReportActionItemMessage
LukasMod 8bd84e6
clean up
LukasMod 41ddb33
Merge branch 'main' of github.com:Expensify/App into perf-send-messag…
LukasMod dfacd84
refactor: DRY ReportActionItemMessage
LukasMod 00383c6
Merge branch 'main' of github.com:Expensify/App into perf-send-messag…
LukasMod 2894a40
refactor: remove unreached shouldShowAddBankAccountButton, add unit t…
LukasMod f36341b
add additional comment
LukasMod 971852d
Merge branch 'main' of github.com:Expensify/App into perf-send-messag…
LukasMod fa112a5
Merge branch 'main' of github.com:Expensify/App into perf-send-messag…
LukasMod 9ab1f95
Merge branch 'main' of github.com:Expensify/App into perf-send-messag…
LukasMod 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
55 changes: 55 additions & 0 deletions
55
src/pages/inbox/report/actionContents/IouReportActionMessage.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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import React from 'react'; | ||
| import type {StyleProp, TextStyle, ViewStyle} from 'react-native'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import {getLinkedTransactionID, getOriginalMessage, isActionOfType} from '@libs/ReportActionsUtils'; | ||
| import {getIOUReportActionDisplayMessage} from '@libs/ReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {ReportAction} from '@src/types/onyx'; | ||
| import ReportActionMessageContent from './ReportActionMessageContent'; | ||
|
|
||
| type IouReportActionMessageProps = { | ||
| /** The report action */ | ||
| action: ReportAction; | ||
|
|
||
| /** Should the comment have the appearance of being grouped with the previous comment? */ | ||
| displayAsGroup: boolean; | ||
|
|
||
| /** Additional styles to add after local styles. */ | ||
| style?: StyleProp<ViewStyle & TextStyle>; | ||
|
|
||
| /** Whether or not the message is hidden by moderation */ | ||
| isHidden?: boolean; | ||
|
|
||
| /** The ID of the report */ | ||
| reportID: string | undefined; | ||
| }; | ||
|
|
||
| function IouReportActionMessage({action, displayAsGroup, reportID, style, isHidden = false}: IouReportActionMessageProps) { | ||
| const {translate} = useLocalize(); | ||
| const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`); | ||
| const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(getLinkedTransactionID(action))}`); | ||
| const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); | ||
|
|
||
| let iouMessage: string | undefined; | ||
| const originalMessage = isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU) ? getOriginalMessage(action) : null; | ||
| const iouReportID = originalMessage?.IOUReportID; | ||
| if (iouReportID) { | ||
| iouMessage = getIOUReportActionDisplayMessage(translate, action, transaction, report, bankAccountList); | ||
| } | ||
|
|
||
| return ( | ||
| <ReportActionMessageContent | ||
| action={action} | ||
| displayAsGroup={displayAsGroup} | ||
| reportID={reportID} | ||
| style={style} | ||
| isHidden={isHidden} | ||
| iouMessage={iouMessage} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default IouReportActionMessage; |
90 changes: 90 additions & 0 deletions
90
src/pages/inbox/report/actionContents/ReportActionMessageContent.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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type {ReactElement} from 'react'; | ||
| import React from 'react'; | ||
| import type {StyleProp, TextStyle, ViewStyle} from 'react-native'; | ||
| import {View} from 'react-native'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import { | ||
| getOriginalMessage, | ||
| getReportActionMessage, | ||
| getReportActionMessageFragments, | ||
| isAddCommentAction, | ||
| isApprovedOrSubmittedReportAction as isApprovedOrSubmittedReportActionUtils, | ||
| isThreadParentMessage, | ||
| } from '@libs/ReportActionsUtils'; | ||
| import ReportActionItemFragment from '@pages/inbox/report/ReportActionItemFragment'; | ||
| import CONST from '@src/CONST'; | ||
| import type {ReportAction} from '@src/types/onyx'; | ||
|
|
||
| type ReportActionMessageContentProps = { | ||
| /** The report action */ | ||
| action: ReportAction; | ||
|
|
||
| /** Should the comment have the appearance of being grouped with the previous comment? */ | ||
| displayAsGroup: boolean; | ||
|
|
||
| /** Additional styles to add after local styles. */ | ||
| style?: StyleProp<ViewStyle & TextStyle>; | ||
|
|
||
| /** Whether or not the message is hidden by moderation */ | ||
| isHidden?: boolean; | ||
|
|
||
| /** The ID of the report */ | ||
| reportID: string | undefined; | ||
|
|
||
| /** Optional IOU display message passed into each fragment */ | ||
| iouMessage?: string; | ||
| }; | ||
|
|
||
| function ReportActionMessageContent({action, displayAsGroup, reportID, style, isHidden = false, iouMessage}: ReportActionMessageContentProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const isApprovedOrSubmittedReportAction = isApprovedOrSubmittedReportActionUtils(action); | ||
| const isHoldReportAction = [CONST.REPORT.ACTIONS.TYPE.HOLD, CONST.REPORT.ACTIONS.TYPE.UNHOLD].some((type) => type === action.actionName); | ||
| const fragments = getReportActionMessageFragments(translate, action); | ||
|
|
||
| const renderReportActionItemFragments = (shouldWrapInText: boolean): ReactElement | ReactElement[] => { | ||
| const reportActionItemFragments = fragments.map((fragment, index) => ( | ||
| <ReportActionItemFragment | ||
| // Message fragments don't have stable unique IDs, so index is the best available key | ||
| /* eslint-disable-next-line react/no-array-index-key */ | ||
|
LukasMod marked this conversation as resolved.
|
||
| key={`actionFragment-${action.reportActionID}-${index}`} | ||
| reportActionID={action.reportActionID} | ||
| fragment={fragment} | ||
| iouMessage={iouMessage} | ||
| isThreadParentMessage={isThreadParentMessage(action, reportID)} | ||
| pendingAction={action.pendingAction} | ||
| actionName={action.actionName} | ||
| source={isAddCommentAction(action) ? getOriginalMessage(action)?.source : ''} | ||
| accountID={action.actorAccountID ?? CONST.DEFAULT_NUMBER_ID} | ||
| style={style} | ||
| displayAsGroup={displayAsGroup} | ||
| isApprovedOrSubmittedReportAction={isApprovedOrSubmittedReportAction} | ||
| isHoldReportAction={isHoldReportAction} | ||
| // Since system messages from Old Dot begin with the person who performed the action, | ||
| // the first fragment will contain the person's display name and their email. We'll use this | ||
| // to decide if the fragment should be from left to right for RTL display names e.g. Arabic for proper | ||
| // formatting. | ||
| isFragmentContainingDisplayName={index === 0} | ||
| moderationDecision={getReportActionMessage(action)?.moderationDecision?.decision} | ||
| /> | ||
| )); | ||
|
|
||
| // Approving or submitting reports in oldDot results in system messages made up of multiple fragments of `TEXT` type | ||
| // which we need to wrap in `<Text>` to prevent them rendering on separate lines. | ||
| return shouldWrapInText ? <Text style={styles.ltr}>{reportActionItemFragments}</Text> : reportActionItemFragments; | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={[styles.chatItemMessage, style]}> | ||
| {!isHidden ? ( | ||
| renderReportActionItemFragments(isApprovedOrSubmittedReportAction) | ||
| ) : ( | ||
| <Text style={[styles.textLabelSupporting, styles.lh20]}>{translate('moderation.flaggedContent')}</Text> | ||
| )} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default ReportActionMessageContent; | ||
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
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.
❌ CLEAN-REACT-PATTERNS-4 (docs)
renderReportActionItemFragmentsis an internal render helper defined inside the component body and called in the return statement (renderReportActionItemFragments(isApprovedOrSubmittedReportAction)). This closure captures the entire component scope, preventing React Compiler from independently memoizing it.Extract this into a separate component with explicit props:
Then use it in the return:
Reviewed at: 2894a40 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Uh oh!
There was an error while loading. Please reload this page.
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.
React Compiler compliance passes on the original, the closure here is not opaque to RC. This component renders once per visible report action, the extraction would add a component frame and an extra useThemeStyles() call per row for no realized benefit. I will keep it as it was originally (it was moved to new file)