Skip to content

Commit

Permalink
Get the parent report action using withOnyx for the money request view
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Dec 4, 2023
1 parent 6dbaa4a commit 22ec91c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import AnimatedEmptyStateBackground from '@pages/home/report/AnimatedEmptyStateBackground';
import reportActionPropTypes from '@pages/home/report/reportActionPropTypes';
import iouReportPropTypes from '@pages/iouReportPropTypes';
import reportPropTypes from '@pages/reportPropTypes';
import * as StyleUtils from '@styles/StyleUtils';
Expand All @@ -51,6 +52,9 @@ const propTypes = {
/** The expense report or iou report (only will have a value if this is a transaction thread) */
parentReport: iouReportPropTypes,

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

/** Collection of categories attached to a policy */
policyCategories: PropTypes.objectOf(categoryPropTypes),

Expand All @@ -65,6 +69,7 @@ const propTypes = {

const defaultProps = {
parentReport: {},
parentReportActions: {},
policyCategories: {},
transaction: {
amount: 0,
Expand All @@ -74,13 +79,13 @@ const defaultProps = {
policyTags: {},
};

function MoneyRequestView({report, parentReport, policyCategories, shouldShowHorizontalRule, transaction, policyTags, policy}) {
function MoneyRequestView({report, parentReport, parentReportActions, policyCategories, shouldShowHorizontalRule, transaction, policyTags, policy}) {
const theme = useTheme();
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
const {canUseViolations} = usePermissions();
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const parentReportAction = parentReportActions[report.parentReportActionID] || {};
const moneyRequestReport = parentReport;
const {
created: transactionDate,
Expand Down Expand Up @@ -313,27 +318,33 @@ MoneyRequestView.displayName = 'MoneyRequestView';
export default compose(
withCurrentUserPersonalDetails,
withOnyx({
parentReport: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`,
session: {
key: ONYXKEYS.SESSION,
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
policyCategories: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report.policyID}`,
},
session: {
key: ONYXKEYS.SESSION,
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report.policyID}`,
},
parentReport: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`,
},
parentReportActions: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
canEvict: false,
},
}),
withOnyx({
transaction: {
key: ({report}) => {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
key: ({report, parentReportActions}) => {
const parentReportAction = parentReportActions[report.parentReportActionID];
const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], 0);
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report.policyID}`,
},
}),
)(MoneyRequestView);

0 comments on commit 22ec91c

Please sign in to comment.