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
3 changes: 2 additions & 1 deletion src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributesDerived),
);
const isReportArchived = !!privateIsArchived;
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, {}, undefined, undefined, reportAttributesDerived);
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, policy, {}, undefined, undefined, reportAttributesDerived);
return {...report, alternateText};
});

Expand Down
7 changes: 7 additions & 0 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@
*/

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 209 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 209 in src/libs/OptionsListUtils/index.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) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

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

Check warning on line 215 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 215 in src/libs/OptionsListUtils/index.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 All @@ -221,7 +221,7 @@
});

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 224 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 224 in src/libs/OptionsListUtils/index.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_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -232,7 +232,7 @@
const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 235 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 235 in src/libs/OptionsListUtils/index.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 @@ -274,7 +274,7 @@
});

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

Check warning on line 277 in src/libs/OptionsListUtils/index.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.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -431,6 +431,8 @@
{showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig,
isReportArchived: boolean | undefined,
currentUserLogin: string,
// We'll make it required in the next PR. Ref: https://github.com/Expensify/App/issues/66415
policy?: OnyxEntry<Policy>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment noting that the optional operator will be removed in the next PR as part of the refactor (note to leave the issue link)

lastActorDetails: Partial<PersonalDetails> | null = {},
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
translate?: LocalizedTranslate,
Expand All @@ -451,6 +453,7 @@
translate: translateFn,
report,
lastActorDetails,
policy,
isReportArchived,
chatReport,
visibleReportActionsDataParam: visibleReportActionsData,
Expand Down Expand Up @@ -1058,6 +1061,8 @@
{showChatPreviewLine, forcePolicyNamePreview},
!!result.private_isArchived,
currentUserLogin,
// TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415
undefined,
lastActorDetails,
visibleReportActionsData,
translateFn,
Expand Down Expand Up @@ -2257,6 +2262,8 @@
{showChatPreviewLine, forcePolicyNamePreview},
!!option.private_isArchived,
currentUserLogin,
// TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415
undefined,
null,
visibleReportActionsData,
undefined,
Expand Down
4 changes: 1 addition & 3 deletions 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,21 +1059,19 @@
});

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),
});

let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1070 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) => {
allPolicies = value;
hasPolicies = !isEmptyObject(value);
policiesArray = Object.values(value ?? {}).filter((policy): policy is Policy => !!policy);
},
});
Expand Down Expand Up @@ -1412,7 +1410,7 @@
const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation;
const parentReport = report ? getRootParentReport({report, reports}) : undefined;

if ((!report?.policyName && !parentReport?.policyName && !hasPolicies && isEmptyObject(policies)) || isEmptyObject(report)) {
if ((!report?.policyName && !parentReport?.policyName && isEmptyObject(policies) && isEmptyObject(allPolicies)) || isEmptyObject(report)) {
Comment on lines -1415 to +1413
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next PR, I think we can remove policies params

return noPolicyFound;
}
const finalPolicy = (() => {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3147,8 +3147,8 @@ function getSortedTransactionData(
const aIsUnreported = a.report?.type !== CONST.REPORT.TYPE.EXPENSE && a.report?.type !== CONST.REPORT.TYPE.INVOICE;
const bIsUnreported = b.report?.type !== CONST.REPORT.TYPE.EXPENSE && b.report?.type !== CONST.REPORT.TYPE.INVOICE;

const aValue = !aIsUnreported ? getPolicyName({report: a.report}) : '';
const bValue = !bIsUnreported ? getPolicyName({report: b.report}) : '';
const aValue = !aIsUnreported ? getPolicyName({report: a.report, policy: a.policy}) : '';
const bValue = !bIsUnreported ? getPolicyName({report: b.report, policy: b.policy}) : '';
return compareValues(aValue, bValue, sortOrder, sortBy, localeCompare);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ function getWelcomeMessage(
} else {
welcomeMessage.messageHtml = translate(
'reportActionsView.beginningOfChatHistoryPolicyExpenseChat',
getPolicyName({report}),
getPolicyName({report, policy}),
getDisplayNameForParticipant({accountID: report?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}),
);
welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml);
Expand Down
105 changes: 105 additions & 0 deletions tests/unit/OptionsListUtilsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4349,6 +4350,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4375,6 +4377,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4401,6 +4404,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4424,6 +4428,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4446,6 +4451,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4467,6 +4473,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4488,6 +4495,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4509,6 +4517,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4530,6 +4539,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4551,6 +4561,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4576,6 +4587,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down Expand Up @@ -4603,6 +4615,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -4621,6 +4634,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down Expand Up @@ -4651,6 +4665,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down Expand Up @@ -4690,6 +4705,7 @@ describe('OptionsListUtils', () => {
report,
translate: translateLocal,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down Expand Up @@ -4775,6 +4791,7 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down Expand Up @@ -4805,13 +4822,99 @@ describe('OptionsListUtils', () => {
translate: translateLocal,
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
});
expect(lastMessage).toBe(translate(CONST.LOCALES.EN, 'iou.error.genericCreateFailureMessage'));
});
});

describe('archived report with policy', () => {
it('should use the passed policy name for POLICY_DELETED archive reason', async () => {
const testPolicyID = 'archivePolicyTest';
const policy: Policy = {
id: testPolicyID,
name: 'Test Workspace',
type: CONST.POLICY.TYPE.TEAM,
} as Policy;
const report: Report = {
...createRandomReport(0, undefined),
policyID: testPolicyID,
type: CONST.REPORT.TYPE.CHAT,
};
const closedAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.CLOSED,
originalMessage: {
policyName: policy.name,
reason: CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED,
},
} as ReportAction;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
[closedAction.reportActionID]: closedAction,
});

const lastMessage = getLastMessageTextForReport({
translate: translateLocal,
report,
lastActorDetails: null,
policy,
isReportArchived: true,
chatReport: undefined,
currentUserLogin: '',
});

expect(lastMessage).toBe(
translateLocal('reportArchiveReasons.policyDeleted', {
policyName: policy.name,
}),
);
});

it('should use the passed policy name for REMOVED_FROM_POLICY archive reason', async () => {
const testPolicyID = 'archivePolicyTest2';
const policy: Policy = {
id: testPolicyID,
name: 'My Workspace',
type: CONST.POLICY.TYPE.TEAM,
} as Policy;
const report: Report = {
...createRandomReport(0, undefined),
policyID: testPolicyID,
type: CONST.REPORT.TYPE.CHAT,
};
const closedAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.CLOSED,
originalMessage: {
policyName: policy.name,
reason: CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY,
},
} as ReportAction;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
[closedAction.reportActionID]: closedAction,
});

const lastMessage = getLastMessageTextForReport({
translate: translateLocal,
report,
lastActorDetails: null,
policy,
isReportArchived: true,
chatReport: undefined,
currentUserLogin: '',
});

expect(lastMessage).toBe(
translateLocal('reportArchiveReasons.removedFromPolicy', {
displayName: 'Hidden',
policyName: policy.name,
}),
);
});
});
});

describe('getPersonalDetailSearchTerms', () => {
Expand Down Expand Up @@ -6536,6 +6639,7 @@ describe('OptionsListUtils', () => {
translate: jest.fn().mockReturnValue(''),
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport,
currentUserLogin: CURRENT_USER_EMAIL,
Expand All @@ -6555,6 +6659,7 @@ describe('OptionsListUtils', () => {
translate: jest.fn().mockReturnValue(''),
report,
lastActorDetails: null,
policy: undefined,
isReportArchived: false,
chatReport: undefined,
currentUserLogin: CURRENT_USER_EMAIL,
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13428,6 +13428,45 @@ describe('ReportUtils', () => {
});
expect(result).toBe('Report Fallback Name');
});

it('should return noPolicyFound when policy, policies, and allPolicies are all empty and report has no policyName', async () => {
// Clear all policies from Onyx so allPolicies is empty
await Onyx.clear();
await waitForBatchedUpdates();

const report: Report = {
...createRandomReport(1, undefined),
policyID: 'nonexistent',
policyName: undefined,
oldPolicyName: undefined,
};

const result = getPolicyName({report, returnEmptyIfNotFound: true});
expect(result).toBe('');
});

it('should not trigger early return when allPolicies has data even if policy and policies params are empty', async () => {
const onyxPolicy: Policy = {
...createRandomPolicy(1),
id: 'guardTestPolicy',
name: 'Guard Test Policy',
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${onyxPolicy.id}`, onyxPolicy);
await waitForBatchedUpdates();

const report: Report = {
...createRandomReport(1, undefined),
policyID: 'guardTestPolicy',
policyName: undefined,
};

// No policy or policies passed, but allPolicies has the policy via Onyx
const result = getPolicyName({report});
expect(result).toBe('Guard Test Policy');

// Cleanup
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${onyxPolicy.id}`, null);
});
});

describe('getBillableAndTaxTotal', () => {
Expand Down
Loading