Skip to content

Commit dc7e199

Browse files
authored
Merge pull request Expensify#86643 from truph01/fix/66381-part-3
Remove Onyx.connect() key ONYXKEYS.COLLECTION.REPORT_ACTIONS in src/libs/OptionsListUtils.ts - part 3
2 parents 76e46b9 + 0ed673c commit dc7e199

3 files changed

Lines changed: 89 additions & 19 deletions

File tree

src/libs/OptionsListUtils/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ type GetAlternateTextConfig = {
436436
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
437437
policyTags?: OnyxEntry<PolicyTagLists>;
438438
conciergeReportID: string | undefined;
439+
sortedActions?: Record<string, ReportAction[]>;
439440
};
440441

441442
/**
@@ -444,7 +445,17 @@ type GetAlternateTextConfig = {
444445
function getAlternateText(
445446
option: OptionData,
446447
{showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig,
447-
{isReportArchived, policy, lastActorDetails = {}, visibleReportActionsData = {}, translate, reportAttributesDerived, policyTags, conciergeReportID}: GetAlternateTextConfig,
448+
{
449+
isReportArchived,
450+
policy,
451+
lastActorDetails = {},
452+
visibleReportActionsData = {},
453+
translate,
454+
reportAttributesDerived,
455+
policyTags,
456+
conciergeReportID,
457+
sortedActions,
458+
}: GetAlternateTextConfig,
448459
) {
449460
const report = getReportOrDraftReport(option.reportID);
450461
const isAdminRoom = reportUtilsIsAdminRoom(report);
@@ -464,6 +475,7 @@ function getAlternateText(
464475
reportAttributesDerived,
465476
policyTags,
466477
conciergeReportID,
478+
sortedActions,
467479
});
468480
const reportPrefix = getReportSubtitlePrefix(report);
469481
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;
@@ -610,6 +622,8 @@ function getLastMessageTextForReport({
610622
policyTags,
611623
currentUserLogin,
612624
conciergeReportID,
625+
// eslint-disable-next-line @typescript-eslint/no-deprecated
626+
sortedActions = deprecatedAllSortedReportActions,
613627
}: {
614628
translate: LocalizedTranslate;
615629
report: OnyxEntry<Report>;
@@ -627,6 +641,7 @@ function getLastMessageTextForReport({
627641
currentUserLogin?: string;
628642
// TODO: conciergeReportID will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66411
629643
conciergeReportID?: string;
644+
sortedActions?: Record<string, ReportAction[]>;
630645
}): string {
631646
const reportID = report?.reportID;
632647
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
@@ -695,7 +710,7 @@ function getLastMessageTextForReport({
695710
const iouReportID = iouReport?.reportID;
696711
const reportCache = iouReportID ? visibleReportActionsDataParam?.[iouReportID] : undefined;
697712
const visibleReportActionsForIOUReport = reportCache && Object.keys(reportCache).length > 0 ? visibleReportActionsDataParam : undefined;
698-
const iouReportActions = iouReportID ? deprecatedAllSortedReportActions[iouReportID] : undefined;
713+
const iouReportActions = iouReportID ? sortedActions?.[iouReportID] : undefined;
699714
const canPerformWrite = canUserPerformWriteAction(report, isReportArchived);
700715
const lastIOUMoneyReportAction =
701716
iouReportID && iouReportActions
@@ -2205,6 +2220,7 @@ function prepareReportOptionsForDisplay(
22052220
reportAttributesDerived,
22062221
policyTags: reportPolicyTags,
22072222
conciergeReportID,
2223+
sortedActions,
22082224
},
22092225
);
22102226
const isSelected = isReportSelected(option, selectedOptions);

tests/unit/OptionsListUtilsTest.tsx

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7796,15 +7796,16 @@ describe('OptionsListUtils', () => {
77967796
});
77977797
});
77987798

7799-
describe('getSearchOptions with sortedActions', () => {
7800-
it('should forward sortedActions through getSearchOptions without errors', async () => {
7801-
const reportID = 'search-sorted-1';
7802-
const iouReportID = 'search-iou-1';
7799+
describe('getValidOptions with sortedActions', () => {
7800+
it('returns lastIOUCreationDate from the latest IOU action linked via REPORT_PREVIEW', async () => {
7801+
const reportID = 'gvo-sorted-1';
7802+
const iouReportID = 'gvo-iou-1';
7803+
const expectedDate = '2025-06-15 10:30:00.000';
78037804

78047805
const report: Report = {
78057806
...createRegularChat(Number(reportID), [1]),
78067807
reportID,
7807-
reportName: 'Search Sorted Test',
7808+
reportName: 'Expense Chat',
78087809
lastVisibleActionCreated: '2025-06-15 10:00:00.000',
78097810
lastActorAccountID: 1,
78107811
lastMessageText: 'Test',
@@ -7822,13 +7823,13 @@ describe('OptionsListUtils', () => {
78227823
const iouAction: ReportAction = {
78237824
...createRandomReportAction(2),
78247825
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
7825-
lastModified: '2025-06-15 10:30:00.000',
7826+
lastModified: expectedDate,
78267827
} as ReportAction;
78277828

78287829
const inputOption: SearchOption<Report> = {
78297830
item: report,
78307831
reportID,
7831-
text: 'Search Sorted Test',
7832+
text: 'Expense Chat',
78327833
isUnread: false,
78337834
participantsList: [],
78347835
keyForList: reportID,
@@ -7855,22 +7856,74 @@ describe('OptionsListUtils', () => {
78557856
[iouReportID]: [iouAction],
78567857
};
78577858

7858-
const results = getSearchOptions({
7859-
options: {reports: [inputOption], personalDetails: []},
7860-
draftComments: {},
7861-
betas: [CONST.BETAS.ALL],
7862-
loginList,
7863-
policyCollection: allPolicies,
7864-
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
7865-
currentUserEmail: CURRENT_USER_EMAIL,
7859+
const results = getValidOptions({reports: [inputOption], personalDetails: []}, allPolicies, {}, loginList, CURRENT_USER_ACCOUNT_ID, CURRENT_USER_EMAIL, undefined, {
7860+
includeRecentReports: true,
7861+
includeMultipleParticipantReports: true,
7862+
action: CONST.IOU.ACTION.CREATE,
78667863
sortedActions,
7867-
conciergeReportID: undefined,
78687864
});
78697865

78707866
expect(results.recentReports.length).toBe(1);
7867+
expect(results.recentReports.at(0)?.lastIOUCreationDate).toBe(expectedDate);
7868+
});
7869+
7870+
it('returns undefined lastIOUCreationDate when sortedActions has no matching IOU actions', async () => {
7871+
const reportID = 'gvo-sorted-2';
7872+
7873+
const report: Report = {
7874+
...createRegularChat(Number(reportID), [1]),
7875+
reportID,
7876+
reportName: 'Chat with no IOU',
7877+
lastVisibleActionCreated: '2025-06-15 10:00:00.000',
7878+
lastActorAccountID: 1,
7879+
lastMessageText: 'Test',
7880+
};
7881+
7882+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report);
7883+
await waitForBatchedUpdates();
7884+
7885+
const commentAction: ReportAction = {
7886+
...createRandomReportAction(1),
7887+
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
7888+
} as ReportAction;
7889+
7890+
const inputOption: SearchOption<Report> = {
7891+
item: report,
7892+
reportID,
7893+
text: 'Chat with no IOU',
7894+
isUnread: false,
7895+
participantsList: [],
7896+
keyForList: reportID,
7897+
isChatRoom: true,
7898+
policyID: '123',
7899+
lastMessageText: 'Test',
7900+
lastVisibleActionCreated: report.lastVisibleActionCreated,
7901+
notificationPreference: 'always',
7902+
accountID: 0,
7903+
login: '',
7904+
alternateText: '',
7905+
subtitle: '',
7906+
firstName: '',
7907+
lastName: '',
7908+
icons: [],
7909+
isSelected: false,
7910+
isDisabled: false,
7911+
brickRoadIndicator: null,
7912+
isBold: false,
7913+
};
7914+
7915+
const results = getValidOptions({reports: [inputOption], personalDetails: []}, allPolicies, {}, loginList, CURRENT_USER_ACCOUNT_ID, CURRENT_USER_EMAIL, undefined, {
7916+
includeRecentReports: true,
7917+
action: CONST.IOU.ACTION.CREATE,
7918+
sortedActions: {[reportID]: [commentAction]},
7919+
});
7920+
7921+
expect(results.recentReports.at(0)?.lastIOUCreationDate).toBeUndefined();
78717922
});
7923+
});
78727924

7873-
it('should handle undefined sortedActions via getSearchOptions', async () => {
7925+
describe('getSearchOptions with sortedActions', () => {
7926+
it('should not have lastIOUCreationDate when sortedActions is undefined', async () => {
78747927
const reportID = 'search-sorted-2';
78757928

78767929
const report: Report = {

tests/unit/hooks/useAutocompleteSuggestions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const defaultParams = {
101101
loginList: {},
102102
policies: {},
103103
visibleReportActionsData: undefined,
104+
sortedActions: undefined,
104105
currentUserAccountID: 100,
105106
currentUserEmail: 'me@example.com',
106107
personalDetails: {},

0 commit comments

Comments
 (0)