Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Search in suggestion in Search Router #52100

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 18 additions & 3 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {forwardRef, useCallback} from 'react';
import type {ForwardedRef} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import * as Expensicons from '@components/Icon/Expensicons';
import {usePersonalDetails} from '@components/OnyxProvider';
import type {SearchFilterKey, SearchQueryString} from '@components/Search/types';
Expand Down Expand Up @@ -73,8 +74,14 @@ const setPerformanceTimersEnd = () => {
Performance.markEnd(CONST.TIMING.SEARCH_ROUTER_RENDER);
};

function getContextualSearchQuery(reportName: string) {
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${CONST.SEARCH.DATA_TYPES.CHAT} ${CONST.SEARCH.SYNTAX_FILTER_KEYS.IN}:${SearchQueryUtils.sanitizeSearchValue(reportName)}`;
function getContextualSearchQuery(item: SearchQueryItem) {
if (item.roomType === CONST.SEARCH.DATA_TYPES.EXPENSE) {
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${CONST.SEARCH.DATA_TYPES.EXPENSE} ${CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID}:${item.autocompleteID}`;
}
if (item.roomType === CONST.SEARCH.DATA_TYPES.INVOICE) {
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${CONST.SEARCH.DATA_TYPES.INVOICE} ${CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID}:${item.autocompleteID}`;
}
289Adam289 marked this conversation as resolved.
Show resolved Hide resolved
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${CONST.SEARCH.DATA_TYPES.CHAT} ${CONST.SEARCH.SYNTAX_FILTER_KEYS.IN}:${SearchQueryUtils.sanitizeSearchValue(item.searchQuery ?? '')}`;
}

function isSearchQueryItem(item: OptionData | SearchQueryItem): item is SearchQueryItem {
Expand Down Expand Up @@ -154,6 +161,13 @@ function SearchRouterList(

if (reportForContextualSearch && !textInputValue) {
const reportQueryValue = reportForContextualSearch.text ?? reportForContextualSearch.alternateText ?? reportForContextualSearch.reportID;
let type: ValueOf<typeof CONST.SEARCH.DATA_TYPES> = CONST.SEARCH.DATA_TYPES.CHAT;
289Adam289 marked this conversation as resolved.
Show resolved Hide resolved
if (reportForContextualSearch.isInvoiceRoom) {
type = CONST.SEARCH.DATA_TYPES.INVOICE;
}
if (reportForContextualSearch.isPolicyExpenseChat) {
type = CONST.SEARCH.DATA_TYPES.EXPENSE;
}
sections.push({
data: [
{
Expand All @@ -164,6 +178,7 @@ function SearchRouterList(
itemStyle: styles.activeComponentBG,
keyForList: 'contextualSearch',
searchItemType: CONST.SEARCH.SEARCH_ROUTER_ITEM_TYPE.CONTEXTUAL_SUGGESTION,
roomType: type,
},
],
});
Expand Down Expand Up @@ -209,7 +224,7 @@ function SearchRouterList(
return;
}
if (item.searchItemType === CONST.SEARCH.SEARCH_ROUTER_ITEM_TYPE.CONTEXTUAL_SUGGESTION) {
const searchQuery = getContextualSearchQuery(item.searchQuery);
const searchQuery = getContextualSearchQuery(item);
updateSearchValue(`${searchQuery} `);

if (item.autocompleteID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type SearchQueryItem = ListItem & {
singleIcon?: IconAsset;
searchQuery?: string;
autocompleteID?: string;
roomType?: ValueOf<typeof CONST.SEARCH.DATA_TYPES>;
searchItemType?: ValueOf<typeof CONST.SEARCH.SEARCH_ROUTER_ITEM_TYPE>;
};

Expand Down
Loading