From 10d48b33b531e17d9855298ef65dccc80a14cb5d Mon Sep 17 00:00:00 2001 From: Zuzanna Furtak Date: Fri, 30 Jan 2026 13:36:38 +0100 Subject: [PATCH 1/2] Make SearchSingleSelectionPicker use new SelectionListWithSections --- .../Search/SearchSingleSelectionPicker.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/Search/SearchSingleSelectionPicker.tsx b/src/components/Search/SearchSingleSelectionPicker.tsx index 88c95c804e5c..6ae137fe2ba0 100644 --- a/src/components/Search/SearchSingleSelectionPicker.tsx +++ b/src/components/Search/SearchSingleSelectionPicker.tsx @@ -1,7 +1,4 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react'; -// eslint-disable-next-line no-restricted-imports -import SelectionList from '@components/SelectionListWithSections'; -import SingleSelectListItem from '@components/SelectionListWithSections/SingleSelectListItem'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; @@ -10,6 +7,8 @@ import {sortOptionsWithEmptyValue} from '@libs/SearchQueryUtils'; import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; import SearchFilterPageFooterButtons from './SearchFilterPageFooterButtons'; +import SelectionList from '@components/SelectionList/SelectionListWithSections'; +import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; type SearchSingleSelectionPickerItem = { name: string; @@ -72,14 +71,12 @@ function SearchSingleSelectionPicker({ { title: undefined, data: initiallySelectedItemSection, - shouldShow: initiallySelectedItemSection.length > 0, - indexOffset: 0, + sectionIndex: 0, }, { title: pickerTitle, data: remainingItemsSection, - shouldShow: remainingItemsSection.length > 0, - indexOffset: initiallySelectedItemSection.length, + sectionIndex: 1, }, ], noResultsFound: isEmpty, @@ -121,21 +118,27 @@ function SearchSingleSelectionPicker({ ), [resetChanges, applyChanges], ); + + const textInputOptions = { + value: searchTerm, + label: translate('common.search'), + onChangeText: setSearchTerm, + headerMessage: noResultsFound ? translate('common.noResultsFound') : undefined, + }; + + return ( ); } From c0b479ed4a8580f73b595f5918895fdbb6b7b7db Mon Sep 17 00:00:00 2001 From: Zuzanna Furtak Date: Fri, 30 Jan 2026 13:44:31 +0100 Subject: [PATCH 2/2] Remove manual memoization --- .../Search/SearchSingleSelectionPicker.tsx | 137 ++++++++---------- 1 file changed, 64 insertions(+), 73 deletions(-) diff --git a/src/components/Search/SearchSingleSelectionPicker.tsx b/src/components/Search/SearchSingleSelectionPicker.tsx index 6ae137fe2ba0..e821980935fd 100644 --- a/src/components/Search/SearchSingleSelectionPicker.tsx +++ b/src/components/Search/SearchSingleSelectionPicker.tsx @@ -1,4 +1,6 @@ -import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import React, {useEffect, useState} from 'react'; +import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; +import SelectionList from '@components/SelectionList/SelectionListWithSections'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; @@ -7,8 +9,6 @@ import {sortOptionsWithEmptyValue} from '@libs/SearchQueryUtils'; import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; import SearchFilterPageFooterButtons from './SearchFilterPageFooterButtons'; -import SelectionList from '@components/SelectionList/SelectionListWithSections'; -import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; type SearchSingleSelectionPickerItem = { name: string; @@ -43,80 +43,72 @@ function SearchSingleSelectionPicker({ setSelectedItem(initiallySelectedItem); }, [initiallySelectedItem]); - const {sections, noResultsFound} = useMemo(() => { - const initiallySelectedItemSection = initiallySelectedItem?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase()) - ? [ - { - text: initiallySelectedItem.name, - keyForList: initiallySelectedItem.value, - isSelected: selectedItem?.value === initiallySelectedItem.value, - value: initiallySelectedItem.value, - }, - ] - : []; - const remainingItemsSection = items - .filter((item) => item?.value !== initiallySelectedItem?.value && item?.name?.toLowerCase().includes(debouncedSearchTerm?.toLowerCase())) - .sort((a, b) => sortOptionsWithEmptyValue(a.name.toString(), b.name.toString(), localeCompare)) - .map((item) => ({ - text: item.name, - keyForList: item.value, - isSelected: selectedItem?.value === item.value, - value: item.value, - })); - const isEmpty = !initiallySelectedItemSection.length && !remainingItemsSection.length; - return { - sections: isEmpty - ? [] - : [ - { - title: undefined, - data: initiallySelectedItemSection, - sectionIndex: 0, - }, - { - title: pickerTitle, - data: remainingItemsSection, - sectionIndex: 1, - }, - ], - noResultsFound: isEmpty, - }; - }, [initiallySelectedItem, selectedItem?.value, items, pickerTitle, debouncedSearchTerm, localeCompare]); - - const onSelectItem = useCallback( - (item: Partial) => { - if (!item.text || !item.keyForList || !item.value) { - return; - } - if (shouldAutoSave) { - onSaveSelection(item.isSelected ? '' : item.value); - Navigation.goBack(backToRoute ?? ROUTES.SEARCH_ADVANCED_FILTERS.getRoute()); - return; - } - if (!item.isSelected) { - setSelectedItem({name: item.text, value: item.value}); - } - }, - [shouldAutoSave, backToRoute, onSaveSelection], - ); + const initiallySelectedItemSection = initiallySelectedItem?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase()) + ? [ + { + text: initiallySelectedItem.name, + keyForList: initiallySelectedItem.value, + isSelected: selectedItem?.value === initiallySelectedItem.value, + value: initiallySelectedItem.value, + }, + ] + : []; + + const remainingItemsSection = items + .filter((item) => item.value !== initiallySelectedItem?.value && item.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase())) + .sort((a, b) => sortOptionsWithEmptyValue(a.name.toString(), b.name.toString(), localeCompare)) + .map((item) => ({ + text: item.name, + keyForList: item.value, + isSelected: selectedItem?.value === item.value, + value: item.value, + })); + + const noResultsFound = !initiallySelectedItemSection.length && !remainingItemsSection.length; + + const sections = noResultsFound + ? [] + : [ + { + title: undefined, + data: initiallySelectedItemSection, + sectionIndex: 0, + }, + { + title: pickerTitle, + data: remainingItemsSection, + sectionIndex: 1, + }, + ]; - const resetChanges = useCallback(() => { + const onSelectItem = (item: Partial) => { + if (!item.text || !item.keyForList || !item.value) { + return; + } + if (shouldAutoSave) { + onSaveSelection(item.isSelected ? '' : item.value); + Navigation.goBack(backToRoute ?? ROUTES.SEARCH_ADVANCED_FILTERS.getRoute()); + return; + } + if (!item.isSelected) { + setSelectedItem({name: item.text, value: item.value}); + } + }; + + const resetChanges = () => { setSelectedItem(undefined); - }, []); + }; - const applyChanges = useCallback(() => { + const applyChanges = () => { onSaveSelection(selectedItem?.value); Navigation.goBack(backToRoute ?? ROUTES.SEARCH_ADVANCED_FILTERS.getRoute()); - }, [onSaveSelection, selectedItem?.value, backToRoute]); - - const footerContent = useMemo( - () => ( - - ), - [resetChanges, applyChanges], + }; + + const footerContent = ( + ); const textInputOptions = { @@ -126,7 +118,6 @@ function SearchSingleSelectionPicker({ headerMessage: noResultsFound ? translate('common.noResultsFound') : undefined, }; - return (