Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/components/LHNOptionsList/LHNOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {FlatList, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import participantPropTypes from '@components/participantPropTypes';
import transactionPropTypes from '@components/transactionPropTypes';
import withCurrentReportID, {withCurrentReportIDDefaultProps, withCurrentReportIDPropTypes} from '@components/withCurrentReportID';
import compose from '@libs/compose';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -60,12 +61,7 @@ const propTypes = {
personalDetails: PropTypes.objectOf(participantPropTypes),

/** The transaction from the parent report action */
transactions: PropTypes.objectOf(
PropTypes.shape({
/** The ID of the transaction */
transactionID: PropTypes.string,
}),
),
transactions: PropTypes.objectOf(transactionPropTypes),
/** List of draft comments */
draftComments: PropTypes.objectOf(PropTypes.string),
...withCurrentReportIDPropTypes,
Expand Down Expand Up @@ -136,21 +132,20 @@ function LHNOptionsList({
({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 itemParentReportActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport.parentReportID}`] || {};
const itemParentReportAction = itemParentReportActions[itemFullReport.parentReportActionID] || {};
const itemPolicy = policy[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport.policyID}`] || {};
const transactionID = lodashGet(itemParentReportAction, ['originalMessage', 'IOUTransactionID'], '');
const itemTransaction = transactionID ? transactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] : {};
const itemComment = draftComments[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] || '';
const participantsPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(itemFullReport.participantAccountIDs, personalDetails);

return (
<OptionRowLHNData
reportID={reportID}
fullReport={itemFullReport}
reportActions={itemReportActions}
parentReportActions={itemParentReportActions}
parentReportAction={itemParentReportAction}
policy={itemPolicy}
personalDetails={participantsPersonalDetails}
transaction={itemTransaction}
Expand Down
19 changes: 9 additions & 10 deletions src/components/LHNOptionsList/OptionRowLHNData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import React, {useEffect, useMemo, useRef} from 'react';
import _ from 'underscore';
import participantPropTypes from '@components/participantPropTypes';
import transactionPropTypes from '@components/transactionPropTypes';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import SidebarUtils from '@libs/SidebarUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand Down Expand Up @@ -35,11 +36,11 @@ const propTypes = {
avatar: PropTypes.string,
}),

/** The actions from the parent report */
parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
/** The action from the parent report */
parentReportAction: PropTypes.shape(reportActionPropTypes),

/** The transaction from the parent report action */
transactionID: PropTypes.string,
transaction: transactionPropTypes,

...basePropTypes,
};
Expand All @@ -49,8 +50,8 @@ const defaultProps = {
personalDetails: {},
fullReport: {},
policy: {},
parentReportActions: {},
transactionID: undefined,
parentReportAction: {},
transaction: {},
preferredLocale: CONST.LOCALES.DEFAULT,
...baseDefaultProps,
};
Expand All @@ -70,15 +71,13 @@ function OptionRowLHNData({
comment,
policy,
receiptTransactions,
parentReportActions,
transactionID,
parentReportAction,
transaction,
...propsToForward
}) {
const reportID = propsToForward.reportID;
const parentReportAction = parentReportActions[fullReport.parentReportActionID];

const optionItemRef = useRef();

const linkedTransaction = useMemo(() => {
const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions);
const lastReportAction = _.first(sortedReportActions);
Expand All @@ -97,7 +96,7 @@ function OptionRowLHNData({
// Listen parentReportAction to update title of thread report when parentReportAction changed
// Listen to transaction to update title of transaction report when transaction changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fullReport, linkedTransaction, reportActions, personalDetails, preferredLocale, policy, parentReportAction, transactionID]);
}, [fullReport, linkedTransaction, reportActions, personalDetails, preferredLocale, policy, parentReportAction, transaction]);

useEffect(() => {
if (!optionItem || optionItem.hasDraftComment || !comment || comment.length <= 0 || isFocused) {
Expand Down