From 50c582d7f850dfafba442e2e826ca9eaa6a3441b Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Wed, 30 Jul 2025 18:01:13 +0800 Subject: [PATCH] fix: deleted reports in recent chats --- src/components/OptionListContextProvider.tsx | 3 ++- src/libs/OptionsListUtils.ts | 13 ++++++++++--- src/libs/ReportUtils.ts | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 172b3274c20a..6f1bbbdfee60 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -54,6 +54,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const personalDetails = usePersonalDetails(); const prevPersonalDetails = usePrevious(personalDetails); const hasInitialData = useMemo(() => Object.keys(personalDetails ?? {}).length > 0, [personalDetails]); + const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); const loadOptions = useCallback(() => { const optionLists = createOptionList(personalDetails, reports, reportAttributes?.reports); @@ -162,7 +163,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { reports: Array.from(updatedReportsMap.values()), }; }); - }, [changedReportActions, personalDetails, reportAttributes?.reports]); + }, [changedReportActions, personalDetails, reportAttributes?.reports, transactions]); /** * This effect is used to update the options list when personal details change. diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5401cf0514be..6a59ead7c98e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -33,6 +33,7 @@ import type { import type {Attendee, Participant} from '@src/types/onyx/IOU'; import type {Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {OriginalMessageMovedTransaction} from '@src/types/onyx/OriginalMessage'; +import type {SearchTransaction} from '@src/types/onyx/SearchResults'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import Timing from './actions/Timing'; import {getEnabledCategoriesCount} from './CategoryUtils'; @@ -904,6 +905,7 @@ function createOption( report: OnyxInputOrEntry, config?: PreviewConfig, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], + transactions?: SearchTransaction[], ): OptionData { const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {}; const result: OptionData = { @@ -1014,7 +1016,9 @@ function createOption( // If displaying chat preview line is needed, let's overwrite the default alternate text result.alternateText = showPersonalDetails && personalDetail?.login ? personalDetail.login : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}); - reportName = showPersonalDetails ? getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '') : getReportName(report); + reportName = showPersonalDetails + ? getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '') + : getReportName(report, undefined, undefined, undefined, undefined, undefined, transactions); } else { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing reportName = getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? ''); @@ -1248,6 +1252,7 @@ function processReport( report: OnyxEntry, personalDetails: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], + transactions?: SearchTransaction[], ): { reportMapEntry?: [number, Report]; // The entry to add to reportMapForAccountIDs if applicable reportOption: SearchOption | null; // The report option to add to allReportOptions if applicable @@ -1271,7 +1276,7 @@ function processReport( reportMapEntry, reportOption: { item: report, - ...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived), + ...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived, transactions), }, }; } @@ -2713,7 +2718,9 @@ function shallowOptionsListCompare(a: OptionList, b: OptionList): boolean { return false; } for (let i = 0; i < a.reports.length; i++) { - if (a.reports.at(i)?.reportID !== b.reports.at(i)?.reportID) { + const aReport = a.reports.at(i); + const bReport = b.reports.at(i); + if (aReport?.reportID !== bReport?.reportID || aReport?.text !== bReport?.text) { return false; } } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 07bc99fa8314..0d5702605280 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5025,6 +5025,7 @@ function getReportName( personalDetails?: Partial, invoiceReceiverPolicy?: OnyxEntry, reportAttributes?: ReportAttributesDerivedValue['reports'], + transactions?: SearchTransaction[], ): string { // Check if we can use report name in derived values - only when we have report but no other params const canUseDerivedValue = report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined; @@ -5033,7 +5034,7 @@ function getReportName( if (canUseDerivedValue && derivedNameExists) { return attributes[report.reportID].reportName; } - return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy}); + return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy, transactions}); } function getSearchReportName(props: GetReportNameParams): string {