Skip to content

Commit cf4e836

Browse files
authored
Merge pull request Expensify#76204 from marufsharifi/fix/visibility-of-admin-tag-LHN-member
clear reportIDToNameMap every time report collection update
2 parents 393ba0f + e366244 commit cf4e836

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/libs/MentionUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const getReportMentionDetails = (htmlAttributeReportID: string, currentReport: O
1717
if (!isEmpty(htmlAttributeReportID)) {
1818
const report = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${htmlAttributeReportID}`];
1919
reportID = report?.reportID ?? htmlAttributeReportID;
20-
mentionDisplayText = removeLeadingLTRAndHash(report?.reportName ?? htmlAttributeReportID);
20+
// Match ExpensiMark htmlToText behavior: if we can't resolve a report name, show "Hidden".
21+
// This keeps chat mentions consistent with LHN previews.
22+
mentionDisplayText = removeLeadingLTRAndHash(report?.reportID && report?.reportName ? report?.reportName : 'Hidden');
2123
// Get mention details from name inside tnode
2224
} else if ('data' in tnode && !isEmptyObject(tnode.data)) {
2325
mentionDisplayText = removeLeadingLTRAndHash(tnode.data);

src/libs/Parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import Log from './Log';
66

77
const accountIDToNameMap: Record<string, string> = {};
88

9-
const reportIDToNameMap: Record<string, string> = {};
9+
let reportIDToNameMap: Record<string, string> = {};
1010
Onyx.connect({
1111
key: ONYXKEYS.COLLECTION.REPORT,
1212
waitForCollectionCallback: true,
1313
callback: (value) => {
14+
// Clear the map so removed reports don’t linger
15+
reportIDToNameMap = {};
16+
1417
if (!value) {
1518
return;
1619
}

src/libs/ReportNameUtils.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Onyx from 'react-native-onyx';
66
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
77
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
88
import CONST from '@src/CONST';
9+
import IntlStore from '@src/languages/IntlStore';
910
import ONYXKEYS from '@src/ONYXKEYS';
1011
import type {
1112
PersonalDetails,
@@ -24,7 +25,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
2425
import {convertToDisplayString} from './CurrencyUtils';
2526
import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNumber';
2627
// eslint-disable-next-line @typescript-eslint/no-deprecated
27-
import {translateLocal} from './Localize';
28+
import {translateLocal, translate as translateWithLocale} from './Localize';
2829
// eslint-disable-next-line import/no-cycle
2930
import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage';
3031
import Parser from './Parser';
@@ -38,6 +39,7 @@ import {
3839
getChangedApproverActionMessage,
3940
getCompanyAddressUpdateMessage,
4041
getCompanyCardConnectionBrokenMessage,
42+
getCreatedReportForUnapprovedTransactionsMessage,
4143
getCurrencyDefaultTaxUpdateMessage,
4244
getCustomTaxNameUpdateMessage,
4345
getDefaultApproverUpdateMessage,
@@ -871,12 +873,33 @@ function computeReportName(
871873
*
872874
* @param report
873875
* @param reportAttributesDerivedValue
876+
* @param reports
877+
* @param parentReportActionParam
874878
*/
875-
function getReportName(report?: Report, reportAttributesDerivedValue?: ReportAttributesDerivedValue['reports']): string {
879+
function getReportName(
880+
report?: Report,
881+
reportAttributesDerivedValue?: ReportAttributesDerivedValue['reports'],
882+
reports?: OnyxCollection<Report>,
883+
parentReportActionParam?: OnyxEntry<ReportAction> | null,
884+
): string {
876885
if (!report || !report.reportID) {
877886
return '';
878887
}
879888

889+
const parentReportAction = parentReportActionParam;
890+
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS)) {
891+
const {originalID} = getOriginalMessage(parentReportAction) ?? {};
892+
const originalReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${originalID}`];
893+
const originalReportName = originalReport ? getReportName(originalReport, reportAttributesDerivedValue) : '';
894+
const currentLocale = IntlStore.getCurrentLocale();
895+
const translateInCurrentLocale: LocalizedTranslate = (path, ...parameters) => translateWithLocale(currentLocale, path, ...parameters);
896+
return getCreatedReportForUnapprovedTransactionsMessage(originalID, originalReportName, translateInCurrentLocale);
897+
}
898+
899+
if (isInvoiceRoom(report)) {
900+
return getInvoicesChatName({report, receiverPolicy: undefined, personalDetails: allPersonalDetails});
901+
}
902+
880903
return reportAttributesDerivedValue?.[report.reportID]?.reportName ?? report.reportName ?? '';
881904
}
882905

src/pages/inbox/HeaderView.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
3535
import Navigation from '@libs/Navigation/Navigation';
3636
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
3737
import Parser from '@libs/Parser';
38+
import {getReportName} from '@libs/ReportNameUtils';
3839
import {
3940
canJoinChat,
4041
canUserPerformWriteAction,
@@ -45,7 +46,6 @@ import {
4546
getPolicyDescriptionText,
4647
getPolicyName,
4748
getReportDescription,
48-
getReportName,
4949
getReportStatusColorStyle,
5050
getReportStatusTranslation,
5151
hasReportNameError,
@@ -78,6 +78,7 @@ import {callFunctionIfActionIsAllowed} from '@userActions/Session';
7878
import CONST from '@src/CONST';
7979
import ONYXKEYS from '@src/ONYXKEYS';
8080
import SCREENS from '@src/SCREENS';
81+
import reportsSelector from '@src/selectors/Attributes';
8182
import type {Report, ReportAction} from '@src/types/onyx';
8283
import {isEmptyObject} from '@src/types/utils/EmptyObject';
8384

@@ -106,8 +107,6 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
106107
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
107108
const {isSmallScreenWidth} = useResponsiveLayout();
108109
const route = useRoute();
109-
const invoiceReceiverPolicyID = report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : undefined;
110-
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`);
111110
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`);
112111
const [grandParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`);
113112
const [grandParentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`);
@@ -121,6 +120,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
121120
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
122121
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`);
123122
const isReportArchived = isArchivedReport(reportNameValuePairs);
123+
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: reportsSelector});
124124

125125
const {translate, localeCompare, formatPhoneNumber} = useLocalize();
126126
const theme = useTheme();
@@ -129,6 +129,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
129129
const isGroupChat = isGroupChatReportUtils(report) || isDeprecatedGroupDM(report, isReportArchived);
130130
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
131131
const [onboarding] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
132+
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
132133
const allParticipants = getParticipantsAccountIDsForDisplay(report, false, true, undefined, reportMetadata);
133134
const shouldAddEllipsis = allParticipants?.length > CONST.DISPLAY_PARTICIPANTS_LIMIT;
134135
const participants = allParticipants.slice(0, CONST.DISPLAY_PARTICIPANTS_LIMIT);
@@ -149,8 +150,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
149150
const isReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.reportID);
150151
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
151152
// Use sorted display names for the title for group chats on native small screen widths
152-
// eslint-disable-next-line @typescript-eslint/no-deprecated
153-
const title = getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy, undefined, undefined, isReportHeaderDataArchived);
153+
const title = getReportName(reportHeaderData, reportAttributes, reports, parentReportAction);
154154
const subtitle = getChatRoomSubtitle(reportHeaderData, false, isReportHeaderDataArchived);
155155
// This is used to get the status badge for invoice report subtitle.
156156
const statusTextForInvoiceReport = isParentInvoiceAndIsChatThread

0 commit comments

Comments
 (0)