Skip to content

Commit 90d03e8

Browse files
committed
chore: refactor
1 parent 0773398 commit 90d03e8

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

src/CONST/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {sub as dateSubtract} from 'date-fns/sub';
44
import Config from 'react-native-config';
55
import * as KeyCommand from 'react-native-key-command';
66
import type {ValueOf} from 'type-fest';
7+
import {SearchFilterKey} from '@components/Search/types';
78
import type ResponsiveLayoutResult from '@hooks/useResponsiveLayout/types';
89
import type {MileageRate} from '@libs/DistanceRequestUtils';
910
import BankAccount from '@libs/models/BankAccount';
@@ -6254,6 +6255,7 @@ const CONST = {
62546255
TRIP: 'trip',
62556256
CHAT: 'chat',
62566257
},
6258+
CONTINUATION_DETECTION_SEARCH_FILTER_KEYS: 'continuationDetectionSearchFilterKeys',
62576259
ACTION_FILTERS: {
62586260
APPROVE: 'approve',
62596261
PAY: 'pay',
@@ -6974,6 +6976,14 @@ const CONST = {
69746976
},
69756977
} as const;
69766978

6979+
const CONTINUATION_DETECTION_SEARCH_FILTER_KEYS = [
6980+
CONST.SEARCH.SYNTAX_FILTER_KEYS.TO,
6981+
CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
6982+
CONST.SEARCH.SYNTAX_FILTER_KEYS.ASSIGNEE,
6983+
CONST.SEARCH.SYNTAX_FILTER_KEYS.PAYER,
6984+
CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTER,
6985+
] as SearchFilterKey[];
6986+
69776987
type Country = keyof typeof CONST.ALL_COUNTRIES;
69786988

69796989
type IOUType = ValueOf<typeof CONST.IOU.TYPE>;
@@ -6987,4 +6997,6 @@ type CancellationType = ValueOf<typeof CONST.CANCELLATION_TYPE>;
69876997

69886998
export type {Country, IOUAction, IOUType, IOURequestType, SubscriptionType, FeedbackSurveyOptionID, CancellationType, OnboardingInvite, OnboardingAccounting, IOUActionParams};
69896999

7000+
export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS};
7001+
69907002
export default CONST;

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {buildSearchQueryJSON, buildUserReadableQueryString, getQueryWithoutFilte
3535
import {getDatePresets} from '@libs/SearchUIUtils';
3636
import StringUtils from '@libs/StringUtils';
3737
import Timing from '@userActions/Timing';
38-
import CONST from '@src/CONST';
38+
import CONST, {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS} from '@src/CONST';
3939
import ONYXKEYS from '@src/ONYXKEYS';
4040
import type {CardFeeds, CardList, PersonalDetailsList, Policy, Report} from '@src/types/onyx';
4141
import {getEmptyObject} from '@src/types/utils/EmptyObject';
@@ -260,16 +260,7 @@ function SearchAutocompleteList(
260260

261261
if (!autocomplete && ranges.length > 0) {
262262
const lastRange = ranges.at(ranges.length - 1);
263-
264-
const continuationDetectionSearchFilterKey = [
265-
CONST.SEARCH.SYNTAX_FILTER_KEYS.TO,
266-
CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
267-
CONST.SEARCH.SYNTAX_FILTER_KEYS.ASSIGNEE,
268-
CONST.SEARCH.SYNTAX_FILTER_KEYS.PAYER,
269-
CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTER,
270-
] as SearchFilterKey[];
271-
272-
if (lastRange && continuationDetectionSearchFilterKey.includes(lastRange.key)) {
263+
if (lastRange && CONTINUATION_DETECTION_SEARCH_FILTER_KEYS.includes(lastRange.key)) {
273264
const afterLastRange = autocompleteQueryValue.substring(lastRange.start + lastRange.length);
274265
const continuationMatch = afterLastRange.match(/^\s+(\w+)/);
275266

@@ -677,14 +668,7 @@ function SearchAutocompleteList(
677668
}
678669

679670
const fieldKey = focusedItem.mapKey?.includes(':') ? focusedItem.mapKey.split(':').at(0) : focusedItem.mapKey;
680-
const continuationDetectionSearchFilterKey = [
681-
CONST.SEARCH.SYNTAX_FILTER_KEYS.TO,
682-
CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
683-
CONST.SEARCH.SYNTAX_FILTER_KEYS.ASSIGNEE,
684-
CONST.SEARCH.SYNTAX_FILTER_KEYS.PAYER,
685-
CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTER,
686-
] as SearchFilterKey[];
687-
const isNameField = fieldKey && continuationDetectionSearchFilterKey.includes(fieldKey as SearchFilterKey);
671+
const isNameField = fieldKey && CONTINUATION_DETECTION_SEARCH_FILTER_KEYS.includes(fieldKey as SearchFilterKey);
688672

689673
let trimmedUserSearchQuery;
690674
if (isNameField && fieldKey) {

src/components/Search/SearchRouter/SearchRouter.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Navigation from '@navigation/Navigation';
3434
import type {ReportsSplitNavigatorParamList} from '@navigation/types';
3535
import variables from '@styles/variables';
3636
import {navigateToAndOpenReport, searchInServer} from '@userActions/Report';
37-
import CONST from '@src/CONST';
37+
import CONST, { CONTINUATION_DETECTION_SEARCH_FILTER_KEYS } from '@src/CONST';
3838
import ONYXKEYS from '@src/ONYXKEYS';
3939
import ROUTES from '@src/ROUTES';
4040
import SCREENS from '@src/SCREENS';
@@ -350,14 +350,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
350350
});
351351
} else if (item.searchItemType === CONST.SEARCH.SEARCH_ROUTER_ITEM_TYPE.AUTOCOMPLETE_SUGGESTION && textInputValue) {
352352
const fieldKey = item.mapKey?.includes(':') ? item.mapKey.split(':').at(0) : item.mapKey;
353-
const nameFields = [
354-
CONST.SEARCH.SYNTAX_FILTER_KEYS.TO,
355-
CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
356-
CONST.SEARCH.SYNTAX_FILTER_KEYS.ASSIGNEE,
357-
CONST.SEARCH.SYNTAX_FILTER_KEYS.PAYER,
358-
CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTER,
359-
] as SearchFilterKey[];
360-
const isNameField = fieldKey && nameFields.includes(fieldKey as SearchFilterKey);
353+
const isNameField = fieldKey && CONTINUATION_DETECTION_SEARCH_FILTER_KEYS.includes(fieldKey as SearchFilterKey);
361354

362355
let trimmedUserSearchQuery;
363356
if (isNameField && fieldKey) {

0 commit comments

Comments
 (0)