Skip to content
7 changes: 6 additions & 1 deletion src/components/Search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type SearchListProps = Pick<FlatListPropsWithLayout<SearchListItem>, 'onScroll'
/** Whether to prevent long press of options */
shouldPreventLongPressRow?: boolean;

/** The hash of the queryJSON */
queryJSONHash: number;

/** Called when the viewability of rows changes, as defined by the viewabilityConfig prop. */
onViewableItemsChanged?: (info: {changed: ViewToken[]; viewableItems: ViewToken[]}) => void;
};
Expand All @@ -87,6 +90,7 @@ function SearchList(
ListFooterComponent,
shouldPreventDefaultFocusOnSelectRow,
shouldPreventLongPressRow,
queryJSONHash,
onViewableItemsChanged,
}: SearchListProps,
ref: ForwardedRef<SearchListHandle>,
Expand Down Expand Up @@ -294,10 +298,11 @@ function SearchList(
...item,
}}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
queryJSONHash={queryJSONHash}
/>
);
},
[ListItem, canSelectMultiple, focusedIndex, handleLongPressRow, itemsToHighlight, onCheckboxPress, onSelectRow, setFocusedIndex, shouldPreventDefaultFocusOnSelectRow],
[ListItem, canSelectMultiple, focusedIndex, handleLongPressRow, itemsToHighlight, onCheckboxPress, onSelectRow, queryJSONHash, setFocusedIndex, shouldPreventDefaultFocusOnSelectRow],
);

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
/>
) : undefined
}
queryJSONHash={hash}
onViewableItemsChanged={onViewableItemsChanged}
/>
);
Expand Down
10 changes: 9 additions & 1 deletion src/components/SelectionList/ChatListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import {AttachmentContext} from '@components/AttachmentContext';
import MentionReportContext from '@components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/MentionReportContext';
import MultipleAvatars from '@components/MultipleAvatars';
Expand All @@ -12,10 +13,12 @@ import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {getChatListItemReportName} from '@libs/ReportUtils';
import ReportActionItemDate from '@pages/home/report/ReportActionItemDate';
import ReportActionItemFragment from '@pages/home/report/ReportActionItemFragment';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import BaseListItem from './BaseListItem';
import type {ChatListItemProps, ListItem, ReportActionListItemType} from './types';

Expand All @@ -30,7 +33,9 @@ function ChatListItem<TItem extends ListItem>({
onFocus,
onLongPressRow,
shouldSyncFocus,
queryJSONHash,
}: ChatListItemProps<TItem>) {
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSONHash ?? CONST.DEFAULT_NUMBER_ID}`);
const reportActionItem = item as unknown as ReportActionListItemType;
const from = reportActionItem.from;
const icons = [
Expand Down Expand Up @@ -110,7 +115,10 @@ function ChatListItem<TItem extends ListItem>({
onPress={() => onSelectRow(item)}
numberOfLines={1}
>
{reportActionItem.reportName}
{getChatListItemReportName(
reportActionItem,
currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID ?? CONST.DEFAULT_NUMBER_ID}`],
)}
</TextLink>
</View>
<View style={styles.flexRow}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {

type ReportListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem>;
type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
queryJSONHash?: number;
};

type ValidListItem =
| typeof RadioListItem
Expand Down
23 changes: 20 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4504,6 +4504,12 @@ function getSearchReportName(props: GetReportNameParams): string {
return getReportNameInternal(props);
}

function getInvoiceReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy | SearchPolicy>, invoiceReceiverPolicy?: OnyxEntry<Policy | SearchPolicy>): string {
const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy});
const oldDotInvoiceName = report?.reportName ?? moneyRequestReportName;
return isNewDotInvoice(report?.chatReportID) ? moneyRequestReportName : oldDotInvoiceName;
}

function getReportNameInternal({
report,
policy,
Expand Down Expand Up @@ -4652,9 +4658,7 @@ function getReportNameInternal({
}

if (isInvoiceReport(report)) {
const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy});
const oldDotInvoiceName = report?.reportName ?? moneyRequestReportName;
formattedName = isNewDotInvoice(report?.chatReportID) ? moneyRequestReportName : oldDotInvoiceName;
formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy);
}

if (isInvoiceRoom(report)) {
Expand Down Expand Up @@ -9484,6 +9488,17 @@ function getGroupChatDraft() {
return newGroupChatDraft;
}

function getChatListItemReportName(action: ReportAction & {reportName?: string}, report: SearchReport | undefined): string {
if (report && isInvoiceReport(report)) {
const properInvoiceReport = report;
properInvoiceReport.chatReportID = report.parentReportID;

return getInvoiceReportName(properInvoiceReport);
}

return action?.reportName ?? '';
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -9838,6 +9853,8 @@ export {
getTitleReportField,
getReportFieldsByPolicyID,
getGroupChatDraft,
getInvoiceReportName,
getChatListItemReportName,
};

export type {
Expand Down