From 75872d3c8e4e6e36a373315ea6f12a6dde9e0fe0 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Tue, 16 Apr 2024 15:10:03 +0200 Subject: [PATCH 1/3] implement filtering in task share somewhere --- .../TaskShareDestinationSelectorModal.tsx | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx index b4b8f9084a57..11f579b58d5f 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx @@ -59,22 +59,49 @@ function TaskShareDestinationSelectorModal({isSearchingForReports}: TaskShareDes const textInputHint = useMemo(() => (isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''), [isOffline, translate]); - const options = useMemo(() => { + const defaultOptions = useMemo(() => { if (!areOptionsInitialized) { return { - sections: [], - headerMessage: '', + recentReports: [], + personalDetails: [], + userToInvite: null, + currentUserOption: null, + categoryOptions: [], + tagOptions: [], + taxRatesOptions: [], + header: '', }; } const filteredReports = reportFilter(optionList.reports); - const {recentReports} = OptionsListUtils.getShareDestinationOptions(filteredReports, optionList.personalDetails, [], debouncedSearchValue.trim(), [], CONST.EXPENSIFY_EMAILS, true); - const headerMessage = OptionsListUtils.getHeaderMessage(recentReports && recentReports.length !== 0, false, debouncedSearchValue); + const {recentReports} = OptionsListUtils.getShareDestinationOptions(filteredReports, optionList.personalDetails, [], '', [], [], true); + const header = OptionsListUtils.getHeaderMessage(recentReports && recentReports.length !== 0, false, ''); + return { + recentReports, + personalDetails: [], + userToInvite: null, + currentUserOption: null, + categoryOptions: [], + tagOptions: [], + taxRatesOptions: [], + header, + }; + }, [areOptionsInitialized, optionList.personalDetails, optionList.reports]); + + const options = useMemo(() => { + if (debouncedSearchValue.trim() === '') { + return defaultOptions; + } + const filteredReports = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchValue.trim(), {excludeLogins: CONST.EXPENSIFY_EMAILS, canInviteUser: false}); + const header = OptionsListUtils.getHeaderMessage(filteredReports.recentReports && filteredReports.recentReports.length !== 0, false, debouncedSearchValue); + return {...filteredReports, header}; + }, [debouncedSearchValue, defaultOptions]); - const sections = - recentReports && recentReports.length > 0 + const sections = useMemo( + () => + options.recentReports && options.recentReports.length > 0 ? [ { - data: recentReports.map((option) => ({ + data: options.recentReports.map((option) => ({ ...option, text: option.text ?? '', alternateText: option.alternateText ?? undefined, @@ -86,10 +113,9 @@ function TaskShareDestinationSelectorModal({isSearchingForReports}: TaskShareDes shouldShow: true, }, ] - : []; - - return {sections, headerMessage}; - }, [areOptionsInitialized, optionList.reports, optionList.personalDetails, debouncedSearchValue]); + : [], + [options.recentReports], + ); useEffect(() => { ReportActions.searchInServer(debouncedSearchValue); @@ -109,13 +135,13 @@ function TaskShareDestinationSelectorModal({isSearchingForReports}: TaskShareDes From b4f910630b00f63e5d819edfdaea18e1a69d251c Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 26 Jun 2024 10:10:13 +0200 Subject: [PATCH 2/3] use double negation --- src/pages/tasks/TaskShareDestinationSelectorModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx index 10b2b2075c2e..645f9d3554cc 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx @@ -140,7 +140,7 @@ function TaskShareDestinationSelectorModal() { headerMessage={options.header} textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')} showLoadingPlaceholder={areOptionsInitialized && debouncedSearchValue.trim() === '' ? sections.length === 0 : !didScreenTransitionEnd} - isLoadingNewOptions={isSearchingForReports ?? undefined} + isLoadingNewOptions={!!isSearchingForReports} textInputHint={textInputHint} /> From bb3ea830d300fc006d9728ff49d37f0306944122 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 26 Jun 2024 11:56:58 +0200 Subject: [PATCH 3/3] display chatrooms by participants --- src/libs/OptionsListUtils.ts | 16 ++++++++++++++-- .../tasks/TaskShareDestinationSelectorModal.tsx | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 077fb5b72102..0cf356aa2203 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -220,7 +220,7 @@ type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: bo type FilterOptionsConfig = Pick< GetOptionsConfig, 'sortByReportTypeInSearch' | 'canInviteUser' | 'betas' | 'selectedOptions' | 'excludeUnknownUsers' | 'excludeLogins' | 'maxRecentReportsToShow' -> & {preferChatroomsOverThreads?: boolean}; +> & {preferChatroomsOverThreads?: boolean; includeChatRoomsByParticipants?: boolean}; /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can @@ -2422,7 +2422,15 @@ function getFirstKeyForList(data?: Option[] | null) { * Filters options based on the search input value */ function filterOptions(options: Options, searchInputValue: string, config?: FilterOptionsConfig): Options { - const {sortByReportTypeInSearch = false, canInviteUser = true, betas = [], maxRecentReportsToShow = 0, excludeLogins = [], preferChatroomsOverThreads = false} = config ?? {}; + const { + sortByReportTypeInSearch = false, + canInviteUser = true, + betas = [], + maxRecentReportsToShow = 0, + excludeLogins = [], + preferChatroomsOverThreads = false, + includeChatRoomsByParticipants = false, + } = config ?? {}; if (searchInputValue.trim() === '' && maxRecentReportsToShow > 0) { return {...options, recentReports: options.recentReports.slice(0, maxRecentReportsToShow)}; } @@ -2487,6 +2495,10 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt if (item.subtitle) { values.push(item.subtitle); } + + if (includeChatRoomsByParticipants) { + values = values.concat(getParticipantsLoginsArray(item)); + } } else { values = values.concat(getParticipantsLoginsArray(item)); } diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx index 645f9d3554cc..4367f2ccebcb 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx @@ -88,7 +88,11 @@ function TaskShareDestinationSelectorModal() { if (debouncedSearchValue.trim() === '') { return defaultOptions; } - const filteredReports = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchValue.trim(), {excludeLogins: CONST.EXPENSIFY_EMAILS, canInviteUser: false}); + const filteredReports = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchValue.trim(), { + excludeLogins: CONST.EXPENSIFY_EMAILS, + canInviteUser: false, + includeChatRoomsByParticipants: true, + }); const header = OptionsListUtils.getHeaderMessage(filteredReports.recentReports && filteredReports.recentReports.length !== 0, false, debouncedSearchValue); return {...filteredReports, header}; }, [debouncedSearchValue, defaultOptions]);