Skip to content

Commit

Permalink
Merge pull request #36304 from Amarparab2024/patch-2
Browse files Browse the repository at this point in the history
Fix: "Recent" and "All" appear in report field selection list when there is no result
  • Loading branch information
NikkiWines authored Feb 13, 2024
2 parents 7218911 + 977b59c commit d109297
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pages/EditReportFieldDropdownPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ function EditReportFieldDropdownPage({fieldName, onSubmit, fieldID, fieldValue,
const {getSafeAreaMargins} = useStyleUtils();
const {translate} = useLocalize();
const recentlyUsedOptions = useMemo(() => recentlyUsedReportFields?.[fieldID] ?? [], [recentlyUsedReportFields, fieldID]);
const [headerMessage, setHeaderMessage] = useState('');

const sections = useMemo(() => {
const filteredRecentOptions = recentlyUsedOptions.filter((option) => option.toLowerCase().includes(searchValue.toLowerCase()));
const filteredRestOfOptions = fieldOptions.filter((option) => !filteredRecentOptions.includes(option) && option.toLowerCase().includes(searchValue.toLowerCase()));
setHeaderMessage(!filteredRecentOptions.length && !filteredRestOfOptions.length ? translate('common.noResultsFound') : '');

return [
{
title: translate('common.recents'),
shouldShow: true,
shouldShow: filteredRecentOptions.length > 0,
data: filteredRecentOptions.map((option) => ({
text: option,
keyForList: option,
Expand All @@ -61,7 +63,7 @@ function EditReportFieldDropdownPage({fieldName, onSubmit, fieldID, fieldValue,
},
{
title: translate('common.all'),
shouldShow: true,
shouldShow: filteredRestOfOptions.length > 0,
data: filteredRestOfOptions.map((option) => ({
text: option,
keyForList: option,
Expand Down Expand Up @@ -95,6 +97,7 @@ function EditReportFieldDropdownPage({fieldName, onSubmit, fieldID, fieldValue,
onChangeText={setSearchValue}
highlightSelectedOptions
isRowMultilineSupported
headerMessage={headerMessage}
/>
</>
)}
Expand Down

0 comments on commit d109297

Please sign in to comment.