Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: "Recent" and "All" appear in report field selection list when there is no result #36304

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading