From 0400007fd7b4b770746ab1d0e2058d6bf66402b4 Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:29:51 +0200 Subject: [PATCH 1/3] fix: empty list does not turn to empty state screen --- src/components/Search/index.tsx | 3 +-- src/libs/SearchUtils.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 6414501fb06d..11ce7fa4e2ea 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -24,7 +24,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SearchResults from '@src/types/onyx/SearchResults'; import type {SearchDataTypes, SearchQuery} from '@src/types/onyx/SearchResults'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import SearchListWithHeader from './SearchListWithHeader'; import SearchPageHeader from './SearchPageHeader'; @@ -90,7 +89,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { const isLoadingItems = (!isOffline && isLoadingOnyxValue(searchResultsMeta)) || searchResults?.data === undefined; const isLoadingMoreItems = !isLoadingItems && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; - const shouldShowEmptyState = !isLoadingItems && isEmptyObject(searchResults?.data); + const shouldShowEmptyState = !isLoadingItems && SearchUtils.isSearchResultEmpty(searchResults); if (isLoadingItems) { return ( diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index cd641cdc8c90..28cf2fca9a65 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -6,6 +6,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; import type {SearchAccountDetails, SearchDataTypes, SearchPersonalDetails, SearchTransaction, SearchTypeToItemMap, SectionsType} from '@src/types/onyx/SearchResults'; +import type SearchResults from '@src/types/onyx/SearchResults'; import DateUtils from './DateUtils'; import getTopmostCentralPaneRoute from './Navigation/getTopmostCentralPaneRoute'; import navigationRef from './Navigation/navigationRef'; @@ -298,5 +299,21 @@ function getSearchParams() { return topmostCentralPaneRoute?.params as AuthScreensParamList['Search_Central_Pane']; } -export {getListItem, getQueryHash, getSections, getSortedSections, getShouldShowMerchant, getSearchType, getSearchParams, shouldShowYear, isReportListItemType, isTransactionListItemType}; +function isSearchResultEmpty(searchResults: SearchResults) { + return !Object.keys(searchResults?.data).find((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); +} + +export { + getListItem, + getQueryHash, + getSections, + getSortedSections, + getShouldShowMerchant, + getSearchType, + getSearchParams, + shouldShowYear, + isReportListItemType, + isTransactionListItemType, + isSearchResultEmpty, +}; export type {SearchColumnType, SortOrder}; From 7397215d32778266edb30edc2490bd3664ead3c8 Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:47:00 +0200 Subject: [PATCH 2/3] rename: isSearchResultsEmpty --- src/components/Search/index.tsx | 2 +- src/libs/SearchUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 11ce7fa4e2ea..5454ffc61757 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -89,7 +89,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { const isLoadingItems = (!isOffline && isLoadingOnyxValue(searchResultsMeta)) || searchResults?.data === undefined; const isLoadingMoreItems = !isLoadingItems && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; - const shouldShowEmptyState = !isLoadingItems && SearchUtils.isSearchResultEmpty(searchResults); + const shouldShowEmptyState = !isLoadingItems && SearchUtils.isSearchResultsEmpty(searchResults); if (isLoadingItems) { return ( diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 28cf2fca9a65..fbe1539783bf 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -299,7 +299,7 @@ function getSearchParams() { return topmostCentralPaneRoute?.params as AuthScreensParamList['Search_Central_Pane']; } -function isSearchResultEmpty(searchResults: SearchResults) { +function isSearchResultsEmpty(searchResults: SearchResults) { return !Object.keys(searchResults?.data).find((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); } @@ -314,6 +314,6 @@ export { shouldShowYear, isReportListItemType, isTransactionListItemType, - isSearchResultEmpty, + isSearchResultsEmpty, }; export type {SearchColumnType, SortOrder}; From 9c5ed72cfaf914268b33eac8d037c0240566ac45 Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:32:46 +0200 Subject: [PATCH 3/3] address review --- src/libs/SearchUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index fbe1539783bf..7dd8c89a398d 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -300,7 +300,7 @@ function getSearchParams() { } function isSearchResultsEmpty(searchResults: SearchResults) { - return !Object.keys(searchResults?.data).find((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); + return !Object.keys(searchResults?.data).some((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); } export {