Skip to content

Commit ce400f7

Browse files
authored
Merge pull request #51015 from Expensify/revert-50122-cmartins-addNoOperator
[CP Staging] Revert "Support empty value for categories and tags"
2 parents ee384b0 + 5abb86d commit ce400f7

File tree

7 files changed

+14
-73
lines changed

7 files changed

+14
-73
lines changed

src/CONST.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5683,7 +5683,6 @@ const CONST = {
56835683
KEYWORD: 'keyword',
56845684
IN: 'in',
56855685
},
5686-
EMPTY_VALUE: 'none',
56875686
},
56885687

56895688
REFERRER: {

src/components/Search/SearchMultipleSelectionPicker.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import useLocalize from '@hooks/useLocalize';
77
import localeCompare from '@libs/LocaleCompare';
88
import Navigation from '@libs/Navigation/Navigation';
99
import type {OptionData} from '@libs/ReportUtils';
10-
import CONST from '@src/CONST';
1110
import ROUTES from '@src/ROUTES';
1211

1312
type SearchMultipleSelectionPickerItem = {
@@ -29,25 +28,14 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit
2928
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
3029
const [selectedItems, setSelectedItems] = useState<SearchMultipleSelectionPickerItem[]>(initiallySelectedItems ?? []);
3130

32-
const sortOptionsWithEmptyValue = (a: SearchMultipleSelectionPickerItem, b: SearchMultipleSelectionPickerItem) => {
33-
// Always show `No category` and `No tag` as the first option
34-
if (a.value === CONST.SEARCH.EMPTY_VALUE) {
35-
return -1;
36-
}
37-
if (b.value === CONST.SEARCH.EMPTY_VALUE) {
38-
return 1;
39-
}
40-
return localeCompare(a.name, b.name);
41-
};
42-
4331
useEffect(() => {
4432
setSelectedItems(initiallySelectedItems ?? []);
4533
}, [initiallySelectedItems]);
4634

4735
const {sections, noResultsFound} = useMemo(() => {
4836
const selectedItemsSection = selectedItems
4937
.filter((item) => item?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase()))
50-
.sort((a, b) => sortOptionsWithEmptyValue(a, b))
38+
.sort((a, b) => localeCompare(a.name, b.name))
5139
.map((item) => ({
5240
text: item.name,
5341
keyForList: item.name,
@@ -56,7 +44,7 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit
5644
}));
5745
const remainingItemsSection = items
5846
.filter((item) => selectedItems.some((selectedItem) => selectedItem.value === item.value) === false && item?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase()))
59-
.sort((a, b) => sortOptionsWithEmptyValue(a, b))
47+
.sort((a, b) => localeCompare(a.name, b.name))
6048
.map((item) => ({
6149
text: item.name,
6250
keyForList: item.name,

src/languages/en.ts

-2
Original file line numberDiff line numberDiff line change
@@ -4292,8 +4292,6 @@ const translations = {
42924292
current: 'Current',
42934293
past: 'Past',
42944294
},
4295-
noCategory: 'No category',
4296-
noTag: 'No tag',
42974295
expenseType: 'Expense type',
42984296
recentSearches: 'Recent searches',
42994297
recentChats: 'Recent chats',

src/languages/es.ts

-2
Original file line numberDiff line numberDiff line change
@@ -4338,8 +4338,6 @@ const translations = {
43384338
current: 'Actual',
43394339
past: 'Anterior',
43404340
},
4341-
noCategory: 'Sin categoría',
4342-
noTag: 'Sin etiqueta',
43434341
expenseType: 'Tipo de gasto',
43444342
recentSearches: 'Búsquedas recientes',
43454343
recentChats: 'Chats recientes',

src/pages/Search/AdvancedSearchFilters.tsx

+4-28
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,6 @@ function getFilterParticipantDisplayTitle(accountIDs: string[], personalDetails:
139139
.join(', ');
140140
}
141141

142-
const sortOptionsWithEmptyValue = (a: string, b: string) => {
143-
// Always show `No category` and `No tag` as the first option
144-
if (a === CONST.SEARCH.EMPTY_VALUE) {
145-
return -1;
146-
}
147-
if (b === CONST.SEARCH.EMPTY_VALUE) {
148-
return 1;
149-
}
150-
return localeCompare(a, b);
151-
};
152-
153142
function getFilterDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, fieldName: AdvancedFiltersKeys, translate: LocaleContextProps['translate']) {
154143
if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE) {
155144
// the value of date filter is a combination of dateBefore + dateAfter values
@@ -186,27 +175,14 @@ function getFilterDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, fiel
186175
return;
187176
}
188177

189-
if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY && filters[fieldName]) {
178+
if (
179+
(fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY || fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY || fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG) &&
180+
filters[fieldName]
181+
) {
190182
const filterArray = filters[fieldName] ?? [];
191183
return filterArray.sort(localeCompare).join(', ');
192184
}
193185

194-
if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY && filters[fieldName]) {
195-
const filterArray = filters[fieldName] ?? [];
196-
return filterArray
197-
.sort(sortOptionsWithEmptyValue)
198-
.map((value) => (value === CONST.SEARCH.EMPTY_VALUE ? translate('search.noCategory') : value))
199-
.join(', ');
200-
}
201-
202-
if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG && filters[fieldName]) {
203-
const filterArray = filters[fieldName] ?? [];
204-
return filterArray
205-
.sort(sortOptionsWithEmptyValue)
206-
.map((value) => (value === CONST.SEARCH.EMPTY_VALUE ? translate('search.noTag') : value))
207-
.join(', ');
208-
}
209-
210186
if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION) {
211187
return filters[fieldName];
212188
}

src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import useSafePaddingBottomStyle from '@hooks/useSafePaddingBottomStyle';
99
import useThemeStyles from '@hooks/useThemeStyles';
1010
import Navigation from '@libs/Navigation/Navigation';
1111
import * as SearchActions from '@userActions/Search';
12-
import CONST from '@src/CONST';
1312
import ONYXKEYS from '@src/ONYXKEYS';
1413
import ROUTES from '@src/ROUTES';
1514

@@ -18,27 +17,19 @@ function SearchFiltersCategoryPage() {
1817
const {translate} = useLocalize();
1918

2019
const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);
21-
const selectedCategoriesItems = searchAdvancedFiltersForm?.category?.map((category) => {
22-
if (category === CONST.SEARCH.EMPTY_VALUE) {
23-
return {name: translate('search.noCategory'), value: category};
24-
}
25-
return {name: category, value: category};
26-
});
20+
const selectedCategoriesItems = searchAdvancedFiltersForm?.category?.map((category) => ({name: category, value: category}));
2721
const policyID = searchAdvancedFiltersForm?.policyID ?? '-1';
2822
const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
2923
const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`];
3024

3125
const categoryItems = useMemo(() => {
32-
const items = [{name: translate('search.noCategory'), value: CONST.SEARCH.EMPTY_VALUE as string}];
3326
if (!singlePolicyCategories) {
3427
const uniqueCategoryNames = new Set<string>();
3528
Object.values(allPolicyIDCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
36-
items.push(...Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName})));
37-
} else {
38-
items.push(...Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name})));
29+
return Array.from(uniqueCategoryNames).map((categoryName) => ({name: categoryName, value: categoryName}));
3930
}
40-
return items;
41-
}, [allPolicyIDCategories, singlePolicyCategories, translate]);
31+
return Object.values(singlePolicyCategories ?? {}).map((category) => ({name: category.name, value: category.name}));
32+
}, [allPolicyIDCategories, singlePolicyCategories]);
4233

4334
const onSaveSelection = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({category: values}), []);
4435
const safePaddingBottomStyle = useSafePaddingBottomStyle();

src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import useThemeStyles from '@hooks/useThemeStyles';
99
import Navigation from '@libs/Navigation/Navigation';
1010
import {getTagNamesFromTagsLists} from '@libs/PolicyUtils';
1111
import * as SearchActions from '@userActions/Search';
12-
import CONST from '@src/CONST';
1312
import ONYXKEYS from '@src/ONYXKEYS';
1413
import ROUTES from '@src/ROUTES';
1514
import type {PolicyTagLists} from '@src/types/onyx';
@@ -19,18 +18,12 @@ function SearchFiltersTagPage() {
1918
const {translate} = useLocalize();
2019

2120
const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);
22-
const selectedTagsItems = searchAdvancedFiltersForm?.tag?.map((tag) => {
23-
if (tag === CONST.SEARCH.EMPTY_VALUE) {
24-
return {name: translate('search.noTag'), value: tag};
25-
}
26-
return {name: tag, value: tag};
27-
});
21+
const selectedTagsItems = searchAdvancedFiltersForm?.tag?.map((tag) => ({name: tag, value: tag}));
2822
const policyID = searchAdvancedFiltersForm?.policyID ?? '-1';
2923
const [allPoliciesTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
3024
const singlePolicyTagsList: PolicyTagLists | undefined = allPoliciesTagsLists?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`];
3125

3226
const tagItems = useMemo(() => {
33-
const items = [{name: translate('search.noTag'), value: CONST.SEARCH.EMPTY_VALUE as string}];
3427
if (!singlePolicyTagsList) {
3528
const uniqueTagNames = new Set<string>();
3629
const tagListsUnpacked = Object.values(allPoliciesTagsLists ?? {}).filter((item) => !!item) as PolicyTagLists[];
@@ -40,12 +33,10 @@ function SearchFiltersTagPage() {
4033
})
4134
.flat()
4235
.forEach((tag) => uniqueTagNames.add(tag));
43-
items.push(...Array.from(uniqueTagNames).map((tagName) => ({name: tagName, value: tagName})));
44-
} else {
45-
items.push(...getTagNamesFromTagsLists(singlePolicyTagsList).map((name) => ({name, value: name})));
36+
return Array.from(uniqueTagNames).map((tagName) => ({name: tagName, value: tagName}));
4637
}
47-
return items;
48-
}, [allPoliciesTagsLists, singlePolicyTagsList, translate]);
38+
return getTagNamesFromTagsLists(singlePolicyTagsList).map((name) => ({name, value: name}));
39+
}, [allPoliciesTagsLists, singlePolicyTagsList]);
4940

5041
const updateTagFilter = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({tag: values}), []);
5142

0 commit comments

Comments
 (0)