From 6b814a43f095f83e058e2d4e79f8f2db9eda99e2 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Tue, 12 Aug 2025 15:55:01 -0700 Subject: [PATCH 1/3] WIP: create messages in single transaction thread --- .../MoneyRequestReportView.tsx | 1 + src/pages/home/ReportScreen.tsx | 1 + .../home/report/PureReportActionItem.tsx | 23 +++++++++++-------- src/pages/home/report/ReportFooter.tsx | 12 ++++++++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index ec5710093bb3..1457909121a3 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -246,6 +246,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe isComposerFullSize={!!isComposerFullSize} lastReportAction={lastReportAction} reportTransactions={transactions} + transactionThreadReportID={transactionThreadReportID} /> diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index e6df82f391a6..13902c4c1b55 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -860,6 +860,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { isComposerFullSize={!!isComposerFullSize} lastReportAction={lastReportAction} reportTransactions={reportTransactions} + transactionThreadReportID={transactionThreadReportID} /> ) : null} diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 55a96bf4e594..aa521fa65ec9 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -689,6 +689,9 @@ function PureReportActionItem({ const mentionReportContextValue = useMemo(() => ({currentReportID: report?.reportID, exactlyMatch: true}), [report?.reportID]); const actionableItemButtons: ActionableItem[] = useMemo(() => { + const actionOriginalMessage = getOriginalMessage(action); + const reportActionReportID = action.reportID ?? (actionOriginalMessage && 'reportID' in actionOriginalMessage && actionOriginalMessage.reportID) ?? reportID; + console.log('originalReportID',originalReportID); if (isActionableAddPaymentCard(action) && userBillingFundID === undefined && shouldRenderAddPaymentCard()) { return [ { @@ -712,7 +715,7 @@ function PureReportActionItem({ return []; } - if (!reportID) { + if (!reportActionReportID) { return []; } @@ -736,7 +739,7 @@ function PureReportActionItem({ text: 'actionableMentionTrackExpense.submit', key: `${action.reportActionID}-actionableMentionTrackExpense-submit`, onPress: () => { - createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportID, CONST.IOU.ACTION.SUBMIT, action.reportActionID); + createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.SUBMIT, action.reportActionID); }, }, ]; @@ -747,7 +750,7 @@ function PureReportActionItem({ text: 'actionableMentionTrackExpense.categorize', key: `${action.reportActionID}-actionableMentionTrackExpense-categorize`, onPress: () => { - createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportID, CONST.IOU.ACTION.CATEGORIZE, action.reportActionID); + createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.CATEGORIZE, action.reportActionID); }, }, { @@ -763,7 +766,7 @@ function PureReportActionItem({ text: 'actionableMentionTrackExpense.nothing', key: `${action.reportActionID}-actionableMentionTrackExpense-nothing`, onPress: () => { - dismissTrackExpenseActionableWhisper(reportID, action); + dismissTrackExpenseActionableWhisper(reportActionReportID, action); }, }); return options; @@ -774,13 +777,13 @@ function PureReportActionItem({ { text: 'actionableMentionJoinWorkspaceOptions.accept', key: `${action.reportActionID}-actionableMentionJoinWorkspace-${CONST.REPORT.ACTIONABLE_MENTION_JOIN_WORKSPACE_RESOLUTION.ACCEPT}`, - onPress: () => acceptJoinRequest(reportID, action), + onPress: () => acceptJoinRequest(reportActionReportID, action), isPrimary: true, }, { text: 'actionableMentionJoinWorkspaceOptions.decline', key: `${action.reportActionID}-actionableMentionJoinWorkspace-${CONST.REPORT.ACTIONABLE_MENTION_JOIN_WORKSPACE_RESOLUTION.DECLINE}`, - onPress: () => declineJoinRequest(reportID, action), + onPress: () => declineJoinRequest(reportActionReportID, action), }, ]; } @@ -790,13 +793,13 @@ function PureReportActionItem({ { text: 'common.yes', key: `${action.reportActionID}-actionableReportMentionWhisper-${CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.CREATE}`, - onPress: () => resolveActionableReportMentionWhisper(reportID, action, CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.CREATE), + onPress: () => resolveActionableReportMentionWhisper(reportActionReportID, action, CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.CREATE), isPrimary: true, }, { text: 'common.no', key: `${action.reportActionID}-actionableReportMentionWhisper-${CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.NOTHING}`, - onPress: () => resolveActionableReportMentionWhisper(reportID, action, CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.NOTHING), + onPress: () => resolveActionableReportMentionWhisper(reportActionReportID, action, CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.NOTHING), }, ]; } @@ -805,13 +808,13 @@ function PureReportActionItem({ { text: 'actionableMentionWhisperOptions.invite', key: `${action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE}`, - onPress: () => resolveActionableMentionWhisper(reportID, action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), + onPress: () => resolveActionableMentionWhisper(reportActionReportID, action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), isPrimary: true, }, { text: 'actionableMentionWhisperOptions.nothing', key: `${action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, - onPress: () => resolveActionableMentionWhisper(reportID, action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), + onPress: () => resolveActionableMentionWhisper(reportActionReportID, action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), }, ]; }, [ diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index 1e7257e7f260..b5ed3c3225db 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -53,6 +53,9 @@ type ReportFooterProps = { /** Report transactions */ reportTransactions?: OnyxEntry; + /** The ID of the transaction thread report if there is a single transaction */ + transactionThreadReportID?: string; + /** The policy of the report */ policy: OnyxEntry; @@ -86,6 +89,7 @@ function ReportFooter({ onComposerBlur, onComposerFocus, reportTransactions, + transactionThreadReportID, }: ReportFooterProps) { const styles = useThemeStyles(); const {isOffline} = useNetwork(); @@ -175,10 +179,14 @@ function ReportFooter({ if (isTaskCreated) { return; } - addComment(report.reportID, text, true); + + // If we are adding an action on an expense report that only has a single transaction thread child report, we need to add the action to the transaction thread instead. + // This is because we need it to be associated with the transaction thread and not the expense report in order for conversational corrections to work as expected. + const targetReportID = transactionThreadReportID ?? report.reportID; + addComment(targetReportID, text, true); }, // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - [report.reportID, handleCreateTask], + [report.reportID, handleCreateTask, transactionThreadReportID], ); const [didHideComposerInput, setDidHideComposerInput] = useState(!shouldShowComposeInput); From 29408ec7d7c8520d45ecedda8f57941a5f5ef7d9 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Tue, 12 Aug 2025 17:03:21 -0700 Subject: [PATCH 2/3] WIP: pass the right reportID --- src/libs/actions/Report.ts | 10 +++++----- src/pages/home/report/PureReportActionItem.tsx | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a018ae7b3626..54e887990f34 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4337,6 +4337,7 @@ function resolveActionableMentionWhisper( reportAction: OnyxEntry, resolution: ValueOf, ) { + console.log('resolveActionableMentionWhisper reportAction', reportAction, 'reportID', reportID, 'resolution', resolution); const message = ReportActionsUtils.getReportActionMessage(reportAction); if (!message || !reportAction || !reportID) { return; @@ -5807,19 +5808,18 @@ function changeReportPolicyAndInviteSubmitter(report: Report, policyID: string, /** * Resolves Concierge category options by adding a comment and updating the report action - * @param reportID - The report ID where the comment should be added - * @param actionReportID - The report ID where the report action should be updated (may be different for threads) + * @param reportID - The report ID where the comment should be added and the report action should be updated * @param reportActionID - The specific report action ID to update * @param selectedCategory - The category selected by the user */ -function resolveConciergeCategoryOptions(reportID: string | undefined, actionReportID: string | undefined, reportActionID: string | undefined, selectedCategory: string) { - if (!reportID || !actionReportID || !reportActionID) { +function resolveConciergeCategoryOptions(reportID: string | undefined, reportActionID: string | undefined, selectedCategory: string) { + if (!reportID || !reportActionID) { return; } addComment(reportID, selectedCategory); - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${actionReportID}`, { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { [reportActionID]: { originalMessage: { selectedCategory, diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index aa521fa65ec9..b23271eb702a 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -689,9 +689,6 @@ function PureReportActionItem({ const mentionReportContextValue = useMemo(() => ({currentReportID: report?.reportID, exactlyMatch: true}), [report?.reportID]); const actionableItemButtons: ActionableItem[] = useMemo(() => { - const actionOriginalMessage = getOriginalMessage(action); - const reportActionReportID = action.reportID ?? (actionOriginalMessage && 'reportID' in actionOriginalMessage && actionOriginalMessage.reportID) ?? reportID; - console.log('originalReportID',originalReportID); if (isActionableAddPaymentCard(action) && userBillingFundID === undefined && shouldRenderAddPaymentCard()) { return [ { @@ -705,6 +702,8 @@ function PureReportActionItem({ ]; } + const reportActionReportID = originalReportID ?? reportID; + console.log('PureReportActionItem originalReportID', originalReportID, 'reportID', reportID, 'action.actionName', action.actionName); if (isConciergeCategoryOptions(action)) { const options = getOriginalMessage(action)?.options; if (!options) { @@ -723,7 +722,7 @@ function PureReportActionItem({ text: `${i + 1} - ${option}`, key: `${action.reportActionID}-conciergeCategoryOptions-${option}`, onPress: () => { - resolveConciergeCategoryOptions(reportID, originalReportID, action.reportActionID, option); + resolveConciergeCategoryOptions(reportActionReportID, action.reportActionID, option); }, })); } From 2dabdd0ac45ea3796dfe33a90e48d35b59774b78 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Tue, 12 Aug 2025 18:29:32 -0700 Subject: [PATCH 3/3] Remove console log --- src/libs/actions/Report.ts | 1 - src/pages/home/report/PureReportActionItem.tsx | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 54e887990f34..026d5c87ce0d 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4337,7 +4337,6 @@ function resolveActionableMentionWhisper( reportAction: OnyxEntry, resolution: ValueOf, ) { - console.log('resolveActionableMentionWhisper reportAction', reportAction, 'reportID', reportID, 'resolution', resolution); const message = ReportActionsUtils.getReportActionMessage(reportAction); if (!message || !reportAction || !reportID) { return; diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index b23271eb702a..4511a088638f 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -703,7 +703,6 @@ function PureReportActionItem({ } const reportActionReportID = originalReportID ?? reportID; - console.log('PureReportActionItem originalReportID', originalReportID, 'reportID', reportID, 'action.actionName', action.actionName); if (isConciergeCategoryOptions(action)) { const options = getOriginalMessage(action)?.options; if (!options) { @@ -756,7 +755,7 @@ function PureReportActionItem({ text: 'actionableMentionTrackExpense.share', key: `${action.reportActionID}-actionableMentionTrackExpense-share`, onPress: () => { - createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportID, CONST.IOU.ACTION.SHARE, action.reportActionID); + createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.SHARE, action.reportActionID); }, }, );