-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[NoQA] Memoize expensive calls in ReportActionsList renderItem #27957
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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,87 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {memo} from 'react'; | ||
import _ from 'underscore'; | ||
import CONST from '../../../CONST'; | ||
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; | ||
import * as ReportUtils from '../../../libs/ReportUtils'; | ||
import reportPropTypes from '../../reportPropTypes'; | ||
import ReportActionItem from './ReportActionItem'; | ||
import ReportActionItemParentAction from './ReportActionItemParentAction'; | ||
import reportActionPropTypes from './reportActionPropTypes'; | ||
|
||
const propTypes = { | ||
/** All the data of the action item */ | ||
reportAction: PropTypes.shape(reportActionPropTypes).isRequired, | ||
|
||
/** Position index of the report action in the overall report FlatList view */ | ||
index: PropTypes.number.isRequired, | ||
|
||
/** Report for this action */ | ||
report: reportPropTypes.isRequired, | ||
|
||
/** Whether the option has an outstanding IOU */ | ||
hasOutstandingIOU: PropTypes.bool, | ||
|
||
/** Sorted actions prepared for display */ | ||
sortedReportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)).isRequired, | ||
|
||
/** The ID of the most recent IOU report action connected with the shown report */ | ||
mostRecentIOUReportActionID: PropTypes.string, | ||
|
||
/** If the thread divider line should be hidden */ | ||
shouldHideThreadDividerLine: PropTypes.bool.isRequired, | ||
|
||
/** Should we display the new marker on top of the comment? */ | ||
shouldDisplayNewMarker: PropTypes.bool.isRequired, | ||
}; | ||
|
||
const defaultProps = { | ||
mostRecentIOUReportActionID: '', | ||
hasOutstandingIOU: false, | ||
}; | ||
|
||
function ReportActionsListItemRenderer({ | ||
reportAction, | ||
index, | ||
report, | ||
hasOutstandingIOU, | ||
sortedReportActions, | ||
mostRecentIOUReportActionID, | ||
shouldHideThreadDividerLine, | ||
shouldDisplayNewMarker, | ||
}) { | ||
const shouldDisplayParentAction = | ||
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && | ||
ReportUtils.isChatThread(report) && | ||
!ReportActionsUtils.isTransactionThread(ReportActionsUtils.getParentReportAction(report)); | ||
|
||
return shouldDisplayParentAction ? ( | ||
<ReportActionItemParentAction | ||
shouldHideThreadDividerLine={shouldDisplayParentAction && shouldHideThreadDividerLine} | ||
reportID={report.reportID} | ||
parentReportID={`${report.parentReportID}`} | ||
shouldDisplayNewMarker={shouldDisplayNewMarker} | ||
/> | ||
) : ( | ||
<ReportActionItem | ||
shouldHideThreadDividerLine={shouldHideThreadDividerLine} | ||
report={report} | ||
action={reportAction} | ||
displayAsGroup={ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(sortedReportActions, index)} | ||
shouldDisplayNewMarker={shouldDisplayNewMarker} | ||
shouldShowSubscriptAvatar={ | ||
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. We don't want to show subscript avatar if it is money request: #38974 |
||
(ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isExpenseReport(report)) && | ||
_.contains([CONST.REPORT.ACTIONS.TYPE.IOU, CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW], reportAction.actionName) | ||
} | ||
isMostRecentIOUReportAction={reportAction.reportActionID === mostRecentIOUReportActionID} | ||
hasOutstandingIOU={hasOutstandingIOU} | ||
index={index} | ||
/> | ||
); | ||
} | ||
|
||
ReportActionsListItemRenderer.propTypes = propTypes; | ||
ReportActionsListItemRenderer.defaultProps = defaultProps; | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReportActionsListItemRenderer.displayName = 'ReportActionsListItemRenderer'; | ||
|
||
export default memo(ReportActionsListItemRenderer); |
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.
This line created a bug in offline mode. More details in #32101