@@ -43,6 +43,7 @@ import type {
43
43
PolicyReportField ,
44
44
Report ,
45
45
ReportAction ,
46
+ ReportAttributes ,
46
47
ReportMetadata ,
47
48
ReportNameValuePairs ,
48
49
ReportViolationName ,
@@ -1035,6 +1036,17 @@ Onyx.connect({
1035
1036
callback : ( value ) => ( activePolicyID = value ) ,
1036
1037
} ) ;
1037
1038
1039
+ let reportAttributes : OnyxEntry < Record < string , ReportAttributes > > ;
1040
+ Onyx . connect ( {
1041
+ key : ONYXKEYS . DERIVED . REPORT_ATTRIBUTES ,
1042
+ callback : ( value ) => {
1043
+ if ( ! value ) {
1044
+ return ;
1045
+ }
1046
+ reportAttributes = value ;
1047
+ } ,
1048
+ } ) ;
1049
+
1038
1050
let newGroupChatDraft : OnyxEntry < NewGroupChatDraft > ;
1039
1051
Onyx . connect ( {
1040
1052
key : ONYXKEYS . NEW_GROUP_CHAT_DRAFT ,
@@ -4510,13 +4522,6 @@ function getInvoicesChatName({
4510
4522
return getPolicyName ( { report, policy : invoiceReceiverPolicy , policies} ) ;
4511
4523
}
4512
4524
4513
- const reportNameCache = new Map < string , { lastVisibleActionCreated : string ; reportName : string } > ( ) ;
4514
-
4515
- /**
4516
- * Get a cache key for the report name.
4517
- */
4518
- const getCacheKey = ( report : OnyxEntry < Report > ) : string => `${ report ?. reportID } -${ report ?. lastVisibleActionCreated } -${ report ?. reportName } ` ;
4519
-
4520
4525
/**
4521
4526
* Get the title for a report using only participant names. This may be used for 1:1 DMs and other non-categorized chats.
4522
4527
*/
@@ -4534,6 +4539,13 @@ function buildReportNameFromParticipantNames({report, personalDetails}: {report:
4534
4539
. join ( ', ' ) ;
4535
4540
}
4536
4541
4542
+ function generateReportName ( report : OnyxEntry < Report > ) : string {
4543
+ if ( ! report ) {
4544
+ return '' ;
4545
+ }
4546
+ return getReportNameInternal ( { report} ) ;
4547
+ }
4548
+
4537
4549
/**
4538
4550
* Get the title for a report.
4539
4551
*/
@@ -4544,6 +4556,12 @@ function getReportName(
4544
4556
personalDetails ?: Partial < PersonalDetailsList > ,
4545
4557
invoiceReceiverPolicy ?: OnyxEntry < Policy > ,
4546
4558
) : string {
4559
+ // Check if we can use report name in derived values - only when we have report but no other params
4560
+ const canUseDerivedValue = report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined ;
4561
+
4562
+ if ( canUseDerivedValue && reportAttributes ?. [ report . reportID ] ) {
4563
+ return reportAttributes [ report . reportID ] . reportName ;
4564
+ }
4547
4565
return getReportNameInternal ( { report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy} ) ;
4548
4566
}
4549
4567
@@ -4573,15 +4591,6 @@ function getReportNameInternal({
4573
4591
policies,
4574
4592
} : GetReportNameParams ) : string {
4575
4593
const reportID = report ?. reportID ;
4576
- const cacheKey = getCacheKey ( report ) ;
4577
-
4578
- if ( reportID ) {
4579
- const reportNameFromCache = reportNameCache . get ( cacheKey ) ;
4580
-
4581
- if ( reportNameFromCache ?. reportName && reportNameFromCache . reportName === report ?. reportName && reportNameFromCache . reportName !== CONST . REPORT . DEFAULT_REPORT_NAME ) {
4582
- return reportNameFromCache . reportName ;
4583
- }
4584
- }
4585
4594
4586
4595
let formattedName : string | undefined ;
4587
4596
let parentReportAction : OnyxEntry < ReportAction > ;
@@ -4765,20 +4774,12 @@ function getReportNameInternal({
4765
4774
}
4766
4775
4767
4776
if ( formattedName ) {
4768
- if ( reportID ) {
4769
- reportNameCache . set ( cacheKey , { lastVisibleActionCreated : report ?. lastVisibleActionCreated ?? '' , reportName : formattedName } ) ;
4770
- }
4771
-
4772
4777
return formatReportLastMessageText ( formattedName ) ;
4773
4778
}
4774
4779
4775
4780
// Not a room or PolicyExpenseChat, generate title from first 5 other participants
4776
4781
formattedName = buildReportNameFromParticipantNames ( { report, personalDetails} ) ;
4777
4782
4778
- if ( reportID ) {
4779
- reportNameCache . set ( cacheKey , { lastVisibleActionCreated : report ?. lastVisibleActionCreated ?? '' , reportName : formattedName } ) ;
4780
- }
4781
-
4782
4783
return formattedName ;
4783
4784
}
4784
4785
@@ -10714,6 +10715,8 @@ export {
10714
10715
getMovedTransactionMessage ,
10715
10716
getUnreportedTransactionMessage ,
10716
10717
getExpenseReportStateAndStatus ,
10718
+ generateReportName ,
10719
+ navigateToLinkedReportAction ,
10717
10720
buildOptimisticUnreportedTransactionAction ,
10718
10721
buildOptimisticResolvedDuplicatesReportAction ,
10719
10722
getTitleReportField ,
@@ -10722,7 +10725,6 @@ export {
10722
10725
getInvoiceReportName ,
10723
10726
getChatListItemReportName ,
10724
10727
buildOptimisticMovedTransactionAction ,
10725
- navigateToLinkedReportAction ,
10726
10728
populateOptimisticReportFormula ,
10727
10729
getOutstandingReports ,
10728
10730
isReportOutsanding ,
0 commit comments