From d34683f91d09cd5d5a6444d0cca1ae54437803a2 Mon Sep 17 00:00:00 2001 From: Harshal sanghvi Date: Tue, 14 Nov 2023 21:08:05 +0530 Subject: [PATCH] [MM-52941] Adds from: suggestion when typing @ in search (#24168) * migrated session_length_settings, settings_group to typescript * migrated cluster_table_container to typescript * resolved linter and non null assertions * fixed settings_group import * fixed cluster_table_container import * fixed CI CD errors * fixed names and added in built type for license * fixed consitency and mouse event * fixed type annotations and imports * added search by @ * handle case by replacing * fixed implementation and added tests * new implementation to search with @ * fix space * fixed comments --------- Co-authored-by: Mattermost Build --- webapp/channels/src/components/search/search.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/webapp/channels/src/components/search/search.tsx b/webapp/channels/src/components/search/search.tsx index b7e11b1e72..46ccffbf70 100644 --- a/webapp/channels/src/components/search/search.tsx +++ b/webapp/channels/src/components/search/search.tsx @@ -55,11 +55,21 @@ const determineVisibleSearchHintOptions = (searchTerms: string, searchType: Sear const pretext = pretextArray[pretextArray.length - 1]; const penultimatePretext = pretextArray[pretextArray.length - 2]; - const shouldShowHintOptions = penultimatePretext ? !options.some(({searchTerm}) => penultimatePretext.toLowerCase().endsWith(searchTerm.toLowerCase())) : !options.some(({searchTerm}) => searchTerms.toLowerCase().endsWith(searchTerm.toLowerCase())); + let shouldShowHintOptions: boolean; + + if (penultimatePretext) { + shouldShowHintOptions = !(options.some(({searchTerm}) => penultimatePretext.toLowerCase().endsWith(searchTerm.toLowerCase())) && penultimatePretext !== '@'); + } else { + shouldShowHintOptions = !options.some(({searchTerm}) => searchTerms.toLowerCase().endsWith(searchTerm.toLowerCase())) || searchTerms === '@'; + } if (shouldShowHintOptions) { try { newVisibleSearchHintOptions = options.filter((option) => { + if (pretext === '@' && option.searchTerm === 'From:') { + return true; + } + return new RegExp(pretext, 'ig'). test(option.searchTerm) && option.searchTerm.toLowerCase() !== pretext.toLowerCase(); });