diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 4910254d5cfc0..929ea5f7229a1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -215,7 +215,7 @@ type GetOptionsConfig = { includeRecentReports?: boolean; includeSelectedOptions?: boolean; recentAttendees?: Attendee[]; - excludeHiddenReports?: boolean; + excludeHiddenThreads?: boolean; canShowManagerMcTest?: boolean; } & GetValidReportsConfig; @@ -1484,7 +1484,7 @@ function getValidOptions( selectedOptions = [], shouldSeparateSelfDMChat = false, shouldSeparateWorkspaceChat = false, - excludeHiddenReports = false, + excludeHiddenThreads = false, canShowManagerMcTest = false, ...config }: GetOptionsConfig = {}, @@ -1579,8 +1579,8 @@ function getValidOptions( } } - if (excludeHiddenReports) { - recentReportOptions = recentReportOptions.filter((option) => option.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + if (excludeHiddenThreads) { + recentReportOptions = recentReportOptions.filter((option) => !option.isThread || option.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); } return { @@ -1613,7 +1613,7 @@ function getSearchOptions(options: OptionList, betas: Beta[] = [], isUsedInChatF includeTasks: true, includeSelfDM: true, shouldBoldTitleByDefault: !isUsedInChatFinder, - excludeHiddenReports: true, + excludeHiddenThreads: true, }); const orderedOptions = orderOptions(optionList); Timing.end(CONST.TIMING.LOAD_SEARCH_OPTIONS); diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 5a964cd7d6f04..5f99086aec562 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -179,9 +179,24 @@ describe('OptionsListUtils', () => { isOwnPolicyExpenseChat: true, type: CONST.REPORT.TYPE.CHAT, }, + '11': { + lastReadTime: '2021-01-14 11:25:39.200', + lastVisibleActionCreated: '2022-11-22 03:26:02.001', + reportID: '11', + isPinned: false, + participants: { + 10: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}, + }, + reportName: '', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, + type: CONST.REPORT.TYPE.CHAT, + policyID, + policyName: POLICY.name, + }, // Thread report with notification preference = hidden - '11': { + '12': { lastReadTime: '2021-01-14 11:25:39.200', lastVisibleActionCreated: '2022-11-22 03:26:02.001', reportID: '11', @@ -195,6 +210,8 @@ describe('OptionsListUtils', () => { type: CONST.REPORT.TYPE.CHAT, policyID, policyName: POLICY.name, + parentReportActionID: '123', + parentReportID: '123', }, }; @@ -547,7 +564,7 @@ describe('OptionsListUtils', () => { // Filtering of personalDetails that have reports is done in filterOptions expect(results.personalDetails.length).toBe(9); - // Then all of the reports should be shown including the archived rooms, except for the report with notificationPreferences hidden. + // Then all of the reports should be shown including the archived rooms, except for the thread report with notificationPreferences hidden. expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 1); }); @@ -766,8 +783,8 @@ describe('OptionsListUtils', () => { // When we pass an empty search value let results = getShareDestinationOptions(filteredReports, OPTIONS.personalDetails, []); - // Then we should expect all the recent reports to show but exclude the archived rooms - expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 1); + // Then we should expect all the recent reports to show but exclude the archived rooms and the hidden thread + expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 2); // Filter current REPORTS_WITH_WORKSPACE_ROOMS as we do in the component, before getting share destination options const filteredReportsWithWorkspaceRooms = Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).reduce((filtered, option) => { @@ -782,8 +799,8 @@ describe('OptionsListUtils', () => { // When we also have a policy to return rooms in the results results = getShareDestinationOptions(filteredReportsWithWorkspaceRooms, OPTIONS.personalDetails, []); // Then we should expect the DMS, the group chats and the workspace room to show - // We should expect all the recent reports to show, excluding the archived rooms - expect(results.recentReports.length).toBe(Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).length - 1); + // We should expect all the recent reports to show, excluding the archived rooms and the hidden thread + expect(results.recentReports.length).toBe(Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).length - 2); }); describe('getShareLogOptions', () => { @@ -834,7 +851,7 @@ describe('OptionsListUtils', () => { const options = getSearchOptions(OPTIONS, [CONST.BETAS.ALL]); const filteredOptions = filterAndOrderOptions(options, ''); - expect(filteredOptions.recentReports.length + filteredOptions.personalDetails.length).toBe(12); + expect(filteredOptions.recentReports.length + filteredOptions.personalDetails.length).toBe(13); }); it('should return filtered options in correct order', () => { @@ -923,7 +940,7 @@ describe('OptionsListUtils', () => { const options = getSearchOptions(OPTIONS); const filteredOptions = filterAndOrderOptions(options, searchText); - expect(filteredOptions.recentReports.length).toBe(2); + expect(filteredOptions.recentReports.length).toBe(3); expect(filteredOptions.recentReports.at(0)?.text).toBe('Mister Fantastic'); expect(filteredOptions.recentReports.at(1)?.text).toBe('Mister Fantastic, Invisible Woman'); }); @@ -1151,7 +1168,7 @@ describe('OptionsListUtils', () => { const options = getSearchOptions(OPTIONS); const filteredOptions = filterAndOrderOptions(options, 'fantastic'); - expect(filteredOptions.recentReports.length).toBe(2); + expect(filteredOptions.recentReports.length).toBe(3); expect(filteredOptions.recentReports.at(0)?.text).toBe('Mister Fantastic'); expect(filteredOptions.recentReports.at(1)?.text).toBe('Mister Fantastic, Invisible Woman');