Skip to content

Commit

Permalink
Merge pull request #44814 from software-mansion-labs/@kosmydel/fix-em…
Browse files Browse the repository at this point in the history
…pty-state

fix: empty list does not turn to empty state screen
  • Loading branch information
luacmartins authored Jul 4, 2024
2 parents 8ec71d6 + 9c5ed72 commit b559e57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.isSearchResultsEmpty(searchResults);

if (isLoadingItems) {
return (
Expand Down
19 changes: 18 additions & 1 deletion src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 isSearchResultsEmpty(searchResults: SearchResults) {
return !Object.keys(searchResults?.data).some((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION));
}

export {
getListItem,
getQueryHash,
getSections,
getSortedSections,
getShouldShowMerchant,
getSearchType,
getSearchParams,
shouldShowYear,
isReportListItemType,
isTransactionListItemType,
isSearchResultsEmpty,
};
export type {SearchColumnType, SortOrder};

0 comments on commit b559e57

Please sign in to comment.