diff --git a/src/CONST.ts b/src/CONST.ts index 171dc7ff2c8a..f4145f0631e7 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5683,7 +5683,6 @@ const CONST = { KEYWORD: 'keyword', IN: 'in', }, - EMPTY_VALUE: 'none', }, REFERRER: { diff --git a/src/components/Search/SearchMultipleSelectionPicker.tsx b/src/components/Search/SearchMultipleSelectionPicker.tsx index d76f2e76ab02..558b89715b61 100644 --- a/src/components/Search/SearchMultipleSelectionPicker.tsx +++ b/src/components/Search/SearchMultipleSelectionPicker.tsx @@ -7,7 +7,6 @@ import useLocalize from '@hooks/useLocalize'; import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import type {OptionData} from '@libs/ReportUtils'; -import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; type SearchMultipleSelectionPickerItem = { @@ -29,17 +28,6 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); const [selectedItems, setSelectedItems] = useState(initiallySelectedItems ?? []); - const sortOptionsWithEmptyValue = (a: SearchMultipleSelectionPickerItem, b: SearchMultipleSelectionPickerItem) => { - // Always show `No category` and `No tag` as the first option - if (a.value === CONST.SEARCH.EMPTY_VALUE) { - return -1; - } - if (b.value === CONST.SEARCH.EMPTY_VALUE) { - return 1; - } - return localeCompare(a.name, b.name); - }; - useEffect(() => { setSelectedItems(initiallySelectedItems ?? []); }, [initiallySelectedItems]); @@ -47,7 +35,7 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit const {sections, noResultsFound} = useMemo(() => { const selectedItemsSection = selectedItems .filter((item) => item?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase())) - .sort((a, b) => sortOptionsWithEmptyValue(a, b)) + .sort((a, b) => localeCompare(a.name, b.name)) .map((item) => ({ text: item.name, keyForList: item.name, @@ -56,7 +44,7 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit })); const remainingItemsSection = items .filter((item) => selectedItems.some((selectedItem) => selectedItem.value === item.value) === false && item?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase())) - .sort((a, b) => sortOptionsWithEmptyValue(a, b)) + .sort((a, b) => localeCompare(a.name, b.name)) .map((item) => ({ text: item.name, keyForList: item.name, diff --git a/src/languages/en.ts b/src/languages/en.ts index d73015693e7a..24f0d990cd7a 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -4292,8 +4292,6 @@ const translations = { current: 'Current', past: 'Past', }, - noCategory: 'No category', - noTag: 'No tag', expenseType: 'Expense type', recentSearches: 'Recent searches', recentChats: 'Recent chats', diff --git a/src/languages/es.ts b/src/languages/es.ts index a9d35a6f8228..ff1c9238e847 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -4338,8 +4338,6 @@ const translations = { current: 'Actual', past: 'Anterior', }, - noCategory: 'Sin categoría', - noTag: 'Sin etiqueta', expenseType: 'Tipo de gasto', recentSearches: 'Búsquedas recientes', recentChats: 'Chats recientes', diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 6e117a8baaab..54b62a61724d 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -139,17 +139,6 @@ function getFilterParticipantDisplayTitle(accountIDs: string[], personalDetails: .join(', '); } -const sortOptionsWithEmptyValue = (a: string, b: string) => { - // Always show `No category` and `No tag` as the first option - if (a === CONST.SEARCH.EMPTY_VALUE) { - return -1; - } - if (b === CONST.SEARCH.EMPTY_VALUE) { - return 1; - } - return localeCompare(a, b); -}; - function getFilterDisplayTitle(filters: Partial, fieldName: AdvancedFiltersKeys, translate: LocaleContextProps['translate']) { if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE) { // the value of date filter is a combination of dateBefore + dateAfter values @@ -186,27 +175,14 @@ function getFilterDisplayTitle(filters: Partial, fiel return; } - if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY && filters[fieldName]) { + if ( + (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY || fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY || fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG) && + filters[fieldName] + ) { const filterArray = filters[fieldName] ?? []; return filterArray.sort(localeCompare).join(', '); } - if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY && filters[fieldName]) { - const filterArray = filters[fieldName] ?? []; - return filterArray - .sort(sortOptionsWithEmptyValue) - .map((value) => (value === CONST.SEARCH.EMPTY_VALUE ? translate('search.noCategory') : value)) - .join(', '); - } - - if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG && filters[fieldName]) { - const filterArray = filters[fieldName] ?? []; - return filterArray - .sort(sortOptionsWithEmptyValue) - .map((value) => (value === CONST.SEARCH.EMPTY_VALUE ? translate('search.noTag') : value)) - .join(', '); - } - if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION) { return filters[fieldName]; } diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx index d92554d42453..0aa6cea05c0e 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx @@ -9,7 +9,6 @@ import useSafePaddingBottomStyle from '@hooks/useSafePaddingBottomStyle'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as SearchActions from '@userActions/Search'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -18,27 +17,19 @@ function SearchFiltersCategoryPage() { const {translate} = useLocalize(); const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const selectedCategoriesItems = searchAdvancedFiltersForm?.category?.map((category) => { - if (category === CONST.SEARCH.EMPTY_VALUE) { - return {name: translate('search.noCategory'), value: category}; - } - return {name: category, value: category}; - }); + const selectedCategoriesItems = searchAdvancedFiltersForm?.category?.map((category) => ({name: category, value: category})); const policyID = searchAdvancedFiltersForm?.policyID ?? '-1'; const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES); const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]; const categoryItems = useMemo(() => { - const items = [{name: translate('search.noCategory'), value: CONST.SEARCH.EMPTY_VALUE as string}]; if (!singlePolicyCategories) { const uniqueCategoryNames = new Set(); Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name))); - items.push(...Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName}))); - } else { - items.push(...Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name}))); + return Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName})); } - return items; - }, [allPolicyIDCategories, singlePolicyCategories, translate]); + return Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name})); + }, [allPolicyIDCategories, singlePolicyCategories]); const onSaveSelection = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({category: values}), []); const safePaddingBottomStyle = useSafePaddingBottomStyle(); diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx index 76e2ca45144f..107d100254cb 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx @@ -9,7 +9,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import {getTagNamesFromTagsLists} from '@libs/PolicyUtils'; import * as SearchActions from '@userActions/Search'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {PolicyTagLists} from '@src/types/onyx'; @@ -19,18 +18,12 @@ function SearchFiltersTagPage() { const {translate} = useLocalize(); const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const selectedTagsItems = searchAdvancedFiltersForm?.tag?.map((tag) => { - if (tag === CONST.SEARCH.EMPTY_VALUE) { - return {name: translate('search.noTag'), value: tag}; - } - return {name: tag, value: tag}; - }); + const selectedTagsItems = searchAdvancedFiltersForm?.tag?.map((tag) => ({name: tag, value: tag})); const policyID = searchAdvancedFiltersForm?.policyID ?? '-1'; const [allPoliciesTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS); const singlePolicyTagsList: PolicyTagLists | undefined = allPoliciesTagsLists?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`]; const tagItems = useMemo(() => { - const items = [{name: translate('search.noTag'), value: CONST.SEARCH.EMPTY_VALUE as string}]; if (!singlePolicyTagsList) { const uniqueTagNames = new Set(); const tagListsUnpacked = Object.values(allPoliciesTagsLists ?? {}).filter((item) => !!item) as PolicyTagLists[]; @@ -40,12 +33,10 @@ function SearchFiltersTagPage() { }) .flat() .forEach((tag) => uniqueTagNames.add(tag)); - items.push(...Array.from(uniqueTagNames).map((tagName) => ({name: tagName, value: tagName}))); - } else { - items.push(...getTagNamesFromTagsLists(singlePolicyTagsList).map((name) => ({name, value: name}))); + return Array.from(uniqueTagNames).map((tagName) => ({name: tagName, value: tagName})); } - return items; - }, [allPoliciesTagsLists, singlePolicyTagsList, translate]); + return getTagNamesFromTagsLists(singlePolicyTagsList).map((name) => ({name, value: name})); + }, [allPoliciesTagsLists, singlePolicyTagsList]); const updateTagFilter = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({tag: values}), []);