From 347d13969cbd707b2b21609680a7cb356559fa5b Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 6 Feb 2024 15:33:31 -0700 Subject: [PATCH 1/4] Move linked transaction to parent component --- .../LHNOptionsList/LHNOptionsList.tsx | 6 ++++++ .../LHNOptionsList/OptionRowLHNData.tsx | 21 ++++++++++++------- src/components/LHNOptionsList/types.ts | 3 +++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 15c12afb2609..ab5607ffb5dc 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -7,7 +7,9 @@ import withCurrentReportID from '@components/withCurrentReportID'; import usePermissions from '@hooks/usePermissions'; import useThemeStyles from '@hooks/useThemeStyles'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import * as TransactionUtils from '@libs/TransactionUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -64,6 +66,9 @@ function LHNOptionsList({ const itemComment = draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] ?? ''; const participants = [...ReportUtils.getParticipantsIDs(itemFullReport), itemFullReport?.ownerAccountID, itemParentReportAction?.actorAccountID].filter(Boolean) as number[]; const participantsPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, personalDetails); + const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions); + const lastReportAction = sortedReportActions[0]; + const lastReportActionTransaction = TransactionUtils.getLinkedTransaction(lastReportAction); return ( (); - const linkedTransaction = useMemo(() => { - const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions); - const lastReportAction = sortedReportActions[0]; - return TransactionUtils.getLinkedTransaction(lastReportAction); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [fullReport?.reportID, receiptTransactions, reportActions]); const hasViolations = canUseViolations && ReportUtils.doesTransactionThreadHaveViolations(fullReport, transactionViolations, parentReportAction ?? null); @@ -64,7 +59,19 @@ 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, transaction, transactionViolations, canUseViolations]); + }, [ + fullReport, + lastReportActionTransaction, + reportActions, + personalDetails, + preferredLocale, + policy, + parentReportAction, + transaction, + transactionViolations, + canUseViolations, + receiptTransactions, + ]); useEffect(() => { if (!optionItem || !!optionItem.hasDraftComment || !comment || comment.length <= 0 || isFocused) { diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index 1f2c98301f9a..b91a49328e75 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -83,6 +83,9 @@ type OptionRowLHNDataProps = { /** The transaction from the parent report action */ transaction: OnyxEntry; + /** The transaction linked to the report's last action */ + lastReportActionTransaction: OnyxEntry; + /** Comment added to report */ comment: string; From 6e02a92c67ab240787d4aa03e78da5e8c88e30e9 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 6 Feb 2024 15:36:41 -0700 Subject: [PATCH 2/4] Fix types --- src/components/LHNOptionsList/OptionRowLHNData.tsx | 4 +--- src/components/LHNOptionsList/types.ts | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index b23d84ac37a6..a18d5a8ec1ec 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -1,9 +1,7 @@ import {deepEqual} from 'fast-equals'; import React, {useEffect, useMemo, useRef} from 'react'; -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import SidebarUtils from '@libs/SidebarUtils'; -import * as TransactionUtils from '@libs/TransactionUtils'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; import type {OptionData} from '@src/libs/ReportUtils'; @@ -27,7 +25,7 @@ function OptionRowLHNData({ receiptTransactions, parentReportAction, transaction, - lastReportActionTransaction, + lastReportActionTransaction = {}, transactionViolations, canUseViolations, ...propsToForward diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index b91a49328e75..58bea97f04c9 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -7,6 +7,7 @@ import type {CurrentReportIDContextValue} from '@components/withCurrentReportID' import type CONST from '@src/CONST'; import type {OptionData} from '@src/libs/ReportUtils'; import type {Locale, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx'; +import type {EmptyObject} from '@src/types/utils/EmptyObject'; type OptionMode = ValueOf; @@ -84,7 +85,7 @@ type OptionRowLHNDataProps = { transaction: OnyxEntry; /** The transaction linked to the report's last action */ - lastReportActionTransaction: OnyxEntry; + lastReportActionTransaction?: OnyxEntry; /** Comment added to report */ comment: string; From 25e06351f77e0c557c8e1a702958d3493ee85ba9 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 6 Feb 2024 15:45:47 -0700 Subject: [PATCH 3/4] Remove deprecated method and use transactions collection --- src/components/LHNOptionsList/LHNOptionsList.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index ab5607ffb5dc..c21f758287e9 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -68,7 +68,14 @@ function LHNOptionsList({ const participantsPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, personalDetails); const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions); const lastReportAction = sortedReportActions[0]; - const lastReportActionTransaction = TransactionUtils.getLinkedTransaction(lastReportAction); + + // Get the transaction for the last report action + let lastReportActionTransactionID = ''; + + if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) { + lastReportActionTransactionID = lastReportAction.originalMessage?.IOUTransactionID ?? ''; + } + const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`] ?? {}; return ( Date: Tue, 6 Feb 2024 16:29:27 -0700 Subject: [PATCH 4/4] Remove unused lib --- src/components/LHNOptionsList/LHNOptionsList.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index c21f758287e9..81ab1ae33268 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -9,7 +9,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import * as TransactionUtils from '@libs/TransactionUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS';