-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
refactor: LHN dataflow rework #30242
Changes from all commits
5c55125
db18623
d1ef70e
ed2c4fc
d419ac3
4186a22
27e4e19
0702d7f
4d8617e
caf6556
92cbee8
a105947
5210444
c491848
82cde21
9f7b886
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import lodashGet from 'lodash/get'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import React, {useCallback} from 'react'; | ||
import {FlatList, View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import participantPropTypes from '@components/participantPropTypes'; | ||
import withCurrentReportID, {withCurrentReportIDDefaultProps, withCurrentReportIDPropTypes} from '@components/withCurrentReportID'; | ||
import compose from '@libs/compose'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
import reportActionPropTypes from '@pages/home/report/reportActionPropTypes'; | ||
import reportPropTypes from '@pages/reportPropTypes'; | ||
import styles from '@styles/styles'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import OptionRowLHNDataWithFocus from './OptionRowLHNDataWithFocus'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import OptionRowLHNData from './OptionRowLHNData'; | ||
|
||
const propTypes = { | ||
/** Wrapper style for the section list */ | ||
|
@@ -27,14 +36,72 @@ const propTypes = { | |
|
||
/** Whether to allow option focus or not */ | ||
shouldDisableFocusOptions: PropTypes.bool, | ||
|
||
/** The policy which the user has access to and which the report could be tied to */ | ||
policy: PropTypes.shape({ | ||
/** The ID of the policy */ | ||
id: PropTypes.string, | ||
/** Name of the policy */ | ||
name: PropTypes.string, | ||
/** Avatar of the policy */ | ||
avatar: PropTypes.string, | ||
}), | ||
|
||
/** All reports shared with the user */ | ||
reports: PropTypes.objectOf(reportPropTypes), | ||
|
||
/** Array of report actions for this report */ | ||
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), | ||
|
||
/** Indicates which locale the user currently has selected */ | ||
preferredLocale: PropTypes.string, | ||
|
||
/** List of users' personal details */ | ||
personalDetails: PropTypes.objectOf(participantPropTypes), | ||
|
||
/** The transaction from the parent report action */ | ||
transactions: PropTypes.objectOf( | ||
PropTypes.shape({ | ||
/** The ID of the transaction */ | ||
transactionID: PropTypes.string, | ||
}), | ||
), | ||
/** List of draft comments */ | ||
draftComments: PropTypes.objectOf(PropTypes.string), | ||
...withCurrentReportIDPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
style: styles.flex1, | ||
shouldDisableFocusOptions: false, | ||
reportActions: {}, | ||
reports: {}, | ||
policy: {}, | ||
preferredLocale: CONST.LOCALES.DEFAULT, | ||
personalDetails: {}, | ||
transactions: {}, | ||
draftComments: {}, | ||
...withCurrentReportIDDefaultProps, | ||
}; | ||
|
||
function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optionMode, shouldDisableFocusOptions}) { | ||
const keyExtractor = (item) => item; | ||
|
||
function LHNOptionsList({ | ||
style, | ||
contentContainerStyles, | ||
data, | ||
onSelectRow, | ||
optionMode, | ||
shouldDisableFocusOptions, | ||
reports, | ||
reportActions, | ||
policy, | ||
preferredLocale, | ||
personalDetails, | ||
transactions, | ||
draftComments, | ||
currentReportID, | ||
}) { | ||
/** | ||
* This function is used to compute the layout of any given item in our list. Since we know that each item will have the exact same height, this is a performance optimization | ||
* so that the heights can be determined before the options are rendered. Otherwise, the heights are determined when each option is rendering and it causes a lot of overhead on large | ||
|
@@ -45,14 +112,17 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio | |
* | ||
* @returns {Object} | ||
*/ | ||
const getItemLayout = (itemData, index) => { | ||
const optionHeight = optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight; | ||
return { | ||
length: optionHeight, | ||
offset: index * optionHeight, | ||
index, | ||
}; | ||
}; | ||
const getItemLayout = useCallback( | ||
(itemData, index) => { | ||
const optionHeight = optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight; | ||
return { | ||
length: optionHeight, | ||
offset: index * optionHeight, | ||
index, | ||
}; | ||
}, | ||
[optionMode], | ||
); | ||
|
||
/** | ||
* Function which renders a row in the list | ||
|
@@ -62,13 +132,38 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio | |
* | ||
* @return {Component} | ||
*/ | ||
const renderItem = ({item}) => ( | ||
<OptionRowLHNDataWithFocus | ||
reportID={item} | ||
viewMode={optionMode} | ||
shouldDisableFocusOptions={shouldDisableFocusOptions} | ||
onSelectRow={onSelectRow} | ||
/> | ||
const renderItem = useCallback( | ||
({item: reportID}) => { | ||
const itemFullReport = reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] || {}; | ||
const itemReportActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; | ||
const itemParentReportActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport.parentReportID}`]; | ||
const itemPolicy = policy[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport.policyID}`]; | ||
const itemTransaction = `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet( | ||
itemParentReportActions, | ||
[itemFullReport.parentReportActionID, 'originalMessage', 'IOUTransactionID'], | ||
'', | ||
)}`; | ||
const itemComment = draftComments[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] || ''; | ||
const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForAccountIDs(itemFullReport.participantAccountIDs, personalDetails)); | ||
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 misses an edge case where a user sent a last message in a room and then they leave the room. Then the report participant accountIDs do not include this user accountID and the user's email instead of their username is displayed in LHN. Issue #35477 |
||
return ( | ||
adhorodyski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<OptionRowLHNData | ||
reportID={reportID} | ||
fullReport={itemFullReport} | ||
reportActions={itemReportActions} | ||
parentReportActions={itemParentReportActions} | ||
policy={itemPolicy} | ||
personalDetails={participantPersonalDetailList} | ||
transaction={itemTransaction} | ||
receiptTransactions={transactions} | ||
viewMode={optionMode} | ||
isFocused={!shouldDisableFocusOptions && reportID === currentReportID} | ||
onSelectRow={onSelectRow} | ||
preferredLocale={preferredLocale} | ||
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. After adding 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. Probably a false positive, the above is true for |
||
comment={itemComment} | ||
/> | ||
); | ||
}, | ||
[currentReportID, draftComments, onSelectRow, optionMode, personalDetails, policy, preferredLocale, reportActions, reports, shouldDisableFocusOptions, transactions], | ||
); | ||
|
||
return ( | ||
|
@@ -80,7 +175,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio | |
showsVerticalScrollIndicator={false} | ||
data={data} | ||
testID="lhn-options-list" | ||
keyExtractor={(item) => item} | ||
keyExtractor={keyExtractor} | ||
stickySectionHeadersEnabled={false} | ||
renderItem={renderItem} | ||
getItemLayout={getItemLayout} | ||
|
@@ -96,4 +191,29 @@ LHNOptionsList.propTypes = propTypes; | |
LHNOptionsList.defaultProps = defaultProps; | ||
LHNOptionsList.displayName = 'LHNOptionsList'; | ||
|
||
export default LHNOptionsList; | ||
export default compose( | ||
withCurrentReportID, | ||
withOnyx({ | ||
reports: { | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
}, | ||
reportActions: { | ||
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||
}, | ||
policy: { | ||
key: ONYXKEYS.COLLECTION.POLICY, | ||
}, | ||
preferredLocale: { | ||
key: ONYXKEYS.NVP_PREFERRED_LOCALE, | ||
}, | ||
personalDetails: { | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
}, | ||
transactions: { | ||
key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
}, | ||
draftComments: { | ||
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, | ||
}, | ||
}), | ||
)(LHNOptionsList); |
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.
As we know already, there was crash after this refactor.
itemParentReportActions
was expected to be object but there's case of null.