Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 51 additions & 21 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ import {
isUserCreatedPolicyRoom,
} from './ReportUtils';

type ComputeReportName = {
report?: Report;
reports?: OnyxCollection<Report>;
policies?: OnyxCollection<Policy>;
transactions?: OnyxCollection<Transaction>;
allReportNameValuePairs?: OnyxCollection<ReportNameValuePairs>;
allPolicyTags?: OnyxCollection<PolicyTagLists>;
personalDetailsList?: PersonalDetailsList;
reportActions?: OnyxCollection<ReportActions>;
currentUserAccountID?: number;
currentUserLogin: string;
};

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

// eslint-disable-next-line rulesdir/no-onyx-connect -- allPersonalDetails is used by the deprecated getReportName function; will be removed as part of the Onyx.connect migration
Expand Down Expand Up @@ -673,6 +686,7 @@ function computeChatThreadReportName(
isArchived: boolean,
report: Report,
reports: OnyxCollection<Report>,
currentUserLogin: string,
parentReportAction?: ReportAction,
policyTags?: OnyxEntry<PolicyTagLists>,
policy?: OnyxEntry<Policy>,
Expand Down Expand Up @@ -745,16 +759,14 @@ function computeChatThreadReportName(
movedToReport,
policyTags,
policy,
// currentUserLogin is not threaded through this call chain yet; the empty string
// causes policy-admin checks to fall back to the non-admin message path.
// This will be addressed as part of the broader Onyx.connect migration.
currentUserLogin: '',
currentUserLogin,
})
: getForReportAction({
reportAction: parentReportAction,
policyID,
movedFromReport,
movedToReport,
currentUserLogin,
});
return formatReportLastMessageText(modifiedMessage);
}
Expand All @@ -771,18 +783,18 @@ function computeChatThreadReportName(
* @internal Use this only for computation in derived report attributes
* In all other cases you should use `getReportName`
*/
function computeReportName(
report?: Report,
reports?: OnyxCollection<Report>,
policies?: OnyxCollection<Policy>,
transactions?: OnyxCollection<Transaction>,
allReportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
personalDetailsList?: PersonalDetailsList,
reportActions?: OnyxCollection<ReportActions>,
currentUserAccountID?: number,
privateIsArchived?: string,
allPolicyTags?: OnyxCollection<PolicyTagLists>,
): string {
function computeReportName({
report,
reports,
policies,
transactions,
allReportNameValuePairs,
personalDetailsList,
reportActions,
currentUserAccountID,
currentUserLogin,
allPolicyTags,
}: ComputeReportName): string {
if (!report || !report.reportID) {
return '';
}
Expand All @@ -805,7 +817,17 @@ function computeReportName(
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS)) {
const {originalID} = getOriginalMessage(parentReportAction) ?? {};
const originalReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${originalID}`];
const reportName = computeReportName(originalReport, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserAccountID);
const reportName = computeReportName({
report: originalReport,
reports,
policies,
transactions,
allReportNameValuePairs,
personalDetailsList,
reportActions,
currentUserAccountID,
currentUserLogin,
});
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, isOriginalReportDeleted(parentReportAction, originalReport), translateLocal);
}
Expand All @@ -816,12 +838,20 @@ function computeReportName(
return Parser.isHTML(taskName) ? Parser.htmlToText(taskName).trim() : taskName.trim();
}

const privateIsArchivedValue = privateIsArchived ?? allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived;
Comment thread
linhvovan29546 marked this conversation as resolved.
const privateIsArchivedValue = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived;

// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report.policyID}`];
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; computeReportName is non-React code that cannot use the translate hook
const chatThreadReportName = computeChatThreadReportName(translateLocal, !!privateIsArchivedValue, report, reports ?? {}, parentReportAction, policyTags, reportPolicy);
const chatThreadReportName = computeChatThreadReportName(
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; computeReportName is non-React code that cannot use the translate hook
translateLocal,
!!privateIsArchivedValue,
report,
reports ?? {},
currentUserLogin ?? '',
parentReportAction,
policyTags,
reportPolicy,
);
if (chatThreadReportName) {
return chatThreadReportName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1024 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1029,7 +1029,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1032 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1047,7 +1047,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1050 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1059,7 +1059,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1062 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1068,7 +1068,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1071 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1079,7 +1079,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1082 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1087,7 +1087,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1090 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1123,14 +1123,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1126 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1133 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1156,7 +1156,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1159 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -5267,7 +5267,7 @@
const reportActionMessage = getReportActionHtml(iouReportAction);
if (isCopyAction) {
if (report) {
return computeReportName(report) || (originalReportAction?.childReportName ?? '');
return computeReportName({report, currentUserLogin: ''}) || (originalReportAction?.childReportName ?? '');
Comment thread
linhvovan29546 marked this conversation as resolved.
}
return originalReportAction?.childReportName ?? '';
}
Expand Down
12 changes: 11 additions & 1 deletion src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ export default createOnyxDerivedValueConfig({

acc[report.reportID] = {
reportName: report
? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions, session?.accountID ?? CONST.DEFAULT_NUMBER_ID)
? computeReportName({
report,
reports,
policies,
transactions,
allReportNameValuePairs: reportNameValuePairs,
personalDetailsList: personalDetails,
reportActions,
currentUserAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserLogin: session?.email ?? '',
})
: '',
isEmpty: generateIsEmptyReport(report, isReportArchived),
brickRoadStatus,
Expand Down
34 changes: 22 additions & 12 deletions tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {fakePersonalDetails} from '../utils/LHNTestUtils';
import {formatPhoneNumber} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

const currentUserLogin = 'lagertha2@vikings.net';
describe('ReportNameUtils', () => {
const currentUserAccountID = 5;
const computeReportName = (
Expand All @@ -33,7 +34,18 @@ describe('ReportNameUtils', () => {
personalDetailsList?: PersonalDetailsList,
reportActions?: OnyxCollection<ReportActions>,
currentUserID = currentUserAccountID,
) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID);
) =>
computeReportNameOriginal({
report,
reports,
policies,
transactions,
allReportNameValuePairs,
personalDetailsList,
reportActions,
currentUserAccountID: currentUserID,
currentUserLogin,
});
const participantsPersonalDetails: PersonalDetailsList = [
{
accountID: 1,
Expand Down Expand Up @@ -534,18 +546,16 @@ describe('ReportNameUtils', () => {
},
} as OnyxCollection<PolicyTagLists>;

const name = computeReportNameOriginal(
thread,
emptyCollections.reports,
emptyCollections.policies,
undefined,
undefined,
participantsPersonalDetails,
reportActionsCollection,
const name = computeReportNameOriginal({
report: thread,
reports: emptyCollections.reports,
policies: emptyCollections.policies,
personalDetailsList: participantsPersonalDetails,
reportActions: reportActionsCollection,
currentUserAccountID,
undefined,
policyTagsCollection,
);
currentUserLogin: '',
allPolicyTags: policyTagsCollection,
});

expect(name).toContain('Cost Center');
});
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,18 @@ const computeReportName = (
personalDetailsList?: PersonalDetailsList,
reportActions?: OnyxCollection<ReportActions>,
currentUserID = currentUserAccountID,
) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID);
) =>
computeReportNameOriginal({
report,
reports,
policies,
transactions,
allReportNameValuePairs,
personalDetailsList,
reportActions,
currentUserAccountID: currentUserID,
currentUserLogin: currentUserEmail,
});
const participantsPersonalDetails: PersonalDetailsList = {
'1': {
accountID: 1,
Expand Down
Loading