From a9d01a848fc93c0063c9aa7b03b9cf12e91cbf57 Mon Sep 17 00:00:00 2001 From: dominictb Date: Wed, 3 Jul 2024 14:42:10 +0700 Subject: [PATCH 1/5] fix: restore report lastMessageText after resolve whisper msg Signed-off-by: dominictb --- src/libs/actions/Report.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d05f77f9c7a..acfdb68baa9 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3630,6 +3630,32 @@ function resolveActionableReportMentionWhisper( return; } + let optimisticReport: Partial = { + lastMessageTranslationKey: '', + lastMessageText: '', + lastVisibleActionCreated: '', + }; + const optimisticReportActions: NullishDeep = { + [reportAction.reportActionID]: { + originalMessage: { + resolution, + }, + }, + }; + const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(reportId, optimisticReportActions as ReportActions); + + if (lastMessageText || lastMessageTranslationKey) { + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportId, optimisticReportActions as ReportActions); + const lastVisibleActionCreated = lastVisibleAction?.created; + const lastActorAccountID = lastVisibleAction?.actorAccountID; + optimisticReport = { + lastMessageTranslationKey, + lastMessageText, + lastVisibleActionCreated, + lastActorAccountID, + }; + } + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3642,6 +3668,11 @@ function resolveActionableReportMentionWhisper( }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`, + value: optimisticReport, + }, ]; const failureData: OnyxUpdate[] = [ From 4e9f5d2ad3d32e5b580f2e5f87ed38a199026a2b Mon Sep 17 00:00:00 2001 From: dominictb Date: Wed, 10 Jul 2024 00:03:23 +0700 Subject: [PATCH 2/5] fix: add msg preview restoration for other whisper resolution Signed-off-by: dominictb --- src/libs/ReportUtils.ts | 31 ++++++++++++++++++++++++++++++ src/libs/actions/Report.ts | 39 +++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf1d86dad32..2484eb63d29 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7069,6 +7069,36 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry { return Object.values(ReportConnection.getAllReports() ?? {}).find((report) => isPolicyExpenseChat(report) && report?.policyID === policyID); } +/** + * A function to get the report last message. This is usually used to restore the report message preview in LHN after report actions change. + * @param reportID + * @param actionsToMerge + * @returns containing the calculated message preview data of the report + */ +function calcReportLastMessage(reportID: string, actionsToMerge?: ReportActions) { + let result: Partial = { + lastMessageTranslationKey: '', + lastMessageText: '', + lastVisibleActionCreated: '', + }; + + const {lastMessageText = '', lastMessageTranslationKey = ''} = getLastVisibleMessage(reportID, actionsToMerge); + + if (lastMessageText || lastMessageTranslationKey) { + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, actionsToMerge); + const lastVisibleActionCreated = lastVisibleAction?.created; + const lastActorAccountID = lastVisibleAction?.actorAccountID; + result = { + lastMessageTranslationKey, + lastMessageText, + lastVisibleActionCreated, + lastActorAccountID, + }; + } + + return result; +} + export { addDomainToShortMention, areAllRequestsBeingSmartScanned, @@ -7349,6 +7379,7 @@ export { getChatUsedForOnboarding, findPolicyExpenseChatByPolicyID, hasOnlyNonReimbursableTransactions, + calcReportLastMessage, }; export type { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1f236606a53..b1bc2df91c5 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3622,6 +3622,16 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt resolution, }; + const optimisticReportActions = { + [reportAction.reportActionID]: { + originalMessage: { + resolution, + }, + }, + }; + + const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions); + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3635,6 +3645,11 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`, + value: reportUpdateDataWithPreviousLastMessage, + }, ]; const failureData: OnyxUpdate[] = [ @@ -3669,31 +3684,15 @@ function resolveActionableReportMentionWhisper( return; } - let optimisticReport: Partial = { - lastMessageTranslationKey: '', - lastMessageText: '', - lastVisibleActionCreated: '', - }; - const optimisticReportActions: NullishDeep = { + const optimisticReportActions = { [reportAction.reportActionID]: { originalMessage: { resolution, }, }, }; - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(reportId, optimisticReportActions as ReportActions); - if (lastMessageText || lastMessageTranslationKey) { - const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportId, optimisticReportActions as ReportActions); - const lastVisibleActionCreated = lastVisibleAction?.created; - const lastActorAccountID = lastVisibleAction?.actorAccountID; - optimisticReport = { - lastMessageTranslationKey, - lastMessageText, - lastVisibleActionCreated, - lastActorAccountID, - }; - } + const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions); const optimisticData: OnyxUpdate[] = [ { @@ -3705,12 +3704,12 @@ function resolveActionableReportMentionWhisper( resolution, }, }, - }, + } as ReportActions, }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`, - value: optimisticReport, + value: reportUpdateDataWithPreviousLastMessage, }, ]; From 13583eaf2edf0cf023199783a7e59b5cab36d108 Mon Sep 17 00:00:00 2001 From: dominictb Date: Fri, 12 Jul 2024 18:52:21 +0700 Subject: [PATCH 3/5] fix: restore report last msg in case of failure Signed-off-by: dominictb --- src/libs/ReportUtils.ts | 4 +-- src/libs/actions/Report.ts | 60 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7bf50f1e1dd..7312844ff08 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7095,7 +7095,7 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry { * @param actionsToMerge * @returns containing the calculated message preview data of the report */ -function calcReportLastMessage(reportID: string, actionsToMerge?: ReportActions) { +function getReportLastMessage(reportID: string, actionsToMerge?: ReportActions) { let result: Partial = { lastMessageTranslationKey: '', lastMessageText: '', @@ -7399,7 +7399,7 @@ export { getChatUsedForOnboarding, findPolicyExpenseChatByPolicyID, hasOnlyNonReimbursableTransactions, - calcReportLastMessage, + getReportLastMessage, getMostRecentlyVisitedReport, }; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1e2a20189f1..66a0843be73 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3634,7 +3634,15 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt }, }; - const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions); + const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportId, optimisticReportActions as ReportActions); + + const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportId}`]; + const reportUpdateDataWithCurrentLastMessage = { + lastMessageTranslationKey: report?.lastMessageTranslationKey, + lastMessageText: report?.lastMessageText, + lastVisibleActionCreated: report?.lastVisibleActionCreated, + lastActorAccountID: report?.lastActorAccountID, + } const optimisticData: OnyxUpdate[] = [ { @@ -3669,6 +3677,11 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`, + value: reportUpdateDataWithCurrentLastMessage, // revert back to the current report last message data in case of failure + }, ]; const parameters: ResolveActionableMentionWhisperParams = { @@ -3696,7 +3709,15 @@ function resolveActionableReportMentionWhisper( }, }; - const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions); + const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportId, optimisticReportActions as ReportActions); + + const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportId}`]; + const reportUpdateDataWithCurrentLastMessage = { + lastMessageTranslationKey: report?.lastMessageTranslationKey, + lastMessageText: report?.lastMessageText, + lastVisibleActionCreated: report?.lastVisibleActionCreated, + lastActorAccountID: report?.lastActorAccountID, + } const optimisticData: OnyxUpdate[] = [ { @@ -3729,6 +3750,11 @@ function resolveActionableReportMentionWhisper( }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`, + value: reportUpdateDataWithCurrentLastMessage, // revert back to the current report last message data in case of failure + }, ]; const parameters: ResolveActionableReportMentionWhisperParams = { @@ -3740,6 +3766,7 @@ function resolveActionableReportMentionWhisper( } function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: OnyxEntry): void { + console.log('dismissTrackExpenseActionableWhisper', reportID, reportAction); const isArrayMessage = Array.isArray(reportAction?.message); const message = ReportActionsUtils.getReportActionMessage(reportAction); if (!message || !reportAction) { @@ -3751,6 +3778,25 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On resolution: CONST.REPORT.ACTIONABLE_TRACK_EXPENSE_WHISPER_RESOLUTION.NOTHING, }; + + const optimisticReportActions = { + [reportAction.reportActionID]: { + originalMessage: { + resolution: CONST.REPORT.ACTIONABLE_TRACK_EXPENSE_WHISPER_RESOLUTION.NOTHING, + }, + }, + }; + + const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportID, optimisticReportActions as ReportActions); + + const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const reportUpdateDataWithCurrentLastMessage = { + lastMessageTranslationKey: report?.lastMessageTranslationKey, + lastMessageText: report?.lastMessageText, + lastVisibleActionCreated: report?.lastVisibleActionCreated, + lastActorAccountID: report?.lastActorAccountID, + } + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3764,6 +3810,11 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: reportUpdateDataWithPreviousLastMessage, + }, ]; const failureData: OnyxUpdate[] = [ @@ -3779,6 +3830,11 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: reportUpdateDataWithCurrentLastMessage, // revert back to the current report last message data in case of failure + }, ]; const params = { From b2bfca74141ec6517fd2e67a563026d090a72d1a Mon Sep 17 00:00:00 2001 From: dominictb Date: Fri, 12 Jul 2024 18:54:04 +0700 Subject: [PATCH 4/5] fix: remove console.log Signed-off-by: dominictb --- src/libs/actions/Report.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 66a0843be73..d71b67c7bc6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3766,7 +3766,6 @@ function resolveActionableReportMentionWhisper( } function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: OnyxEntry): void { - console.log('dismissTrackExpenseActionableWhisper', reportID, reportAction); const isArrayMessage = Array.isArray(reportAction?.message); const message = ReportActionsUtils.getReportActionMessage(reportAction); if (!message || !reportAction) { From 77386c05f7dfa84f6d275bffb1b7e5edf256463b Mon Sep 17 00:00:00 2001 From: dominictb Date: Sat, 13 Jul 2024 15:12:19 +0700 Subject: [PATCH 5/5] fix: revert the change for dismiss track expense API Signed-off-by: dominictb --- src/libs/actions/Report.ts | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d71b67c7bc6..93fd8dcb2ab 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3642,7 +3642,7 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt lastMessageText: report?.lastMessageText, lastVisibleActionCreated: report?.lastVisibleActionCreated, lastActorAccountID: report?.lastActorAccountID, - } + }; const optimisticData: OnyxUpdate[] = [ { @@ -3717,7 +3717,7 @@ function resolveActionableReportMentionWhisper( lastMessageText: report?.lastMessageText, lastVisibleActionCreated: report?.lastVisibleActionCreated, lastActorAccountID: report?.lastActorAccountID, - } + }; const optimisticData: OnyxUpdate[] = [ { @@ -3777,25 +3777,6 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On resolution: CONST.REPORT.ACTIONABLE_TRACK_EXPENSE_WHISPER_RESOLUTION.NOTHING, }; - - const optimisticReportActions = { - [reportAction.reportActionID]: { - originalMessage: { - resolution: CONST.REPORT.ACTIONABLE_TRACK_EXPENSE_WHISPER_RESOLUTION.NOTHING, - }, - }, - }; - - const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportID, optimisticReportActions as ReportActions); - - const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; - const reportUpdateDataWithCurrentLastMessage = { - lastMessageTranslationKey: report?.lastMessageTranslationKey, - lastMessageText: report?.lastMessageText, - lastVisibleActionCreated: report?.lastVisibleActionCreated, - lastActorAccountID: report?.lastActorAccountID, - } - const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3809,11 +3790,6 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: reportUpdateDataWithPreviousLastMessage, - }, ]; const failureData: OnyxUpdate[] = [ @@ -3829,11 +3805,6 @@ function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: On }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: reportUpdateDataWithCurrentLastMessage, // revert back to the current report last message data in case of failure - }, ]; const params = {