diff --git a/src/components/EmptyStateComponent/index.tsx b/src/components/EmptyStateComponent/index.tsx index 1c974808ab4f..976baac44fb0 100644 --- a/src/components/EmptyStateComponent/index.tsx +++ b/src/components/EmptyStateComponent/index.tsx @@ -19,6 +19,7 @@ const VIDEO_ASPECT_RATIO = 400 / 225; function EmptyStateComponent({ SkeletonComponent, + skeletonReasonAttributes, headerMediaType, headerMedia, buttons, @@ -93,6 +94,7 @@ function EmptyStateComponent({ )} diff --git a/src/components/EmptyStateComponent/types.ts b/src/components/EmptyStateComponent/types.ts index 23601b8087a3..68db2effa051 100644 --- a/src/components/EmptyStateComponent/types.ts +++ b/src/components/EmptyStateComponent/types.ts @@ -5,6 +5,7 @@ import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; import type DotLottieAnimation from '@components/LottieAnimations/types'; import type SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import type TableRowSkeleton from '@components/Skeletons/TableRowSkeleton'; +import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan'; import type CONST from '@src/CONST'; import type IconAsset from '@src/types/utils/IconAsset'; @@ -27,6 +28,7 @@ type EmptyStateButton = { type SharedProps = { SkeletonComponent?: ValidSkeletons; + skeletonReasonAttributes?: SkeletonSpanReasonAttributes; title: string; titleStyles?: StyleProp; subtitle?: string; diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index ccbed243a3ba..2c43ee05a5c2 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -66,6 +66,7 @@ import { } from '@libs/SearchUIUtils'; import {cancelSpan, endSpanWithAttributes, getSpan, startSpan} from '@libs/telemetry/activeSpans'; import markNavigateAfterExpenseCreateEnd from '@libs/telemetry/markNavigateAfterExpenseCreateEnd'; +import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan'; import {getOriginalTransactionWithSplitInfo, hasValidModifiedAmount, isOnHold, isTransactionPendingDelete} from '@libs/TransactionUtils'; import Navigation, {navigationRef} from '@navigation/Navigation'; import type {SearchFullscreenNavigatorParamList} from '@navigation/types'; @@ -282,7 +283,9 @@ function Search({ const spanExistedOnMount = useRef(!!getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_AFTER_EXPENSE_CREATE)); const savedSearchSelector = useCallback((searches: OnyxEntry) => searches?.[hash], [hash]); - const [savedSearch] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {selector: savedSearchSelector}); + const [savedSearch] = useOnyx(ONYXKEYS.SAVED_SEARCHES, { + selector: savedSearchSelector, + }); const handleDEWModalOpen = useCallback(() => { if (onDEWModalOpen) { @@ -404,6 +407,31 @@ function Search({ (hasErrors && searchRequestResponseStatusCode === null) || isCardFeedsLoading); const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; + + const loadingSkeletonReasonAttributes = useMemo( + () => ({ + context: 'Search', + isOffline, + isDataLoaded, + isCardFeedsLoading, + isSearchLoading: !!searchResults?.search?.isLoading, + hasEmptyData: Array.isArray(searchResults?.data) && searchResults?.data.length === 0, + hasErrors, + hasPendingResponse: searchRequestResponseStatusCode === null, + shouldUseLiveData, + }), + [isOffline, isDataLoaded, isCardFeedsLoading, searchResults?.search?.isLoading, searchResults?.data, hasErrors, searchRequestResponseStatusCode, shouldUseLiveData], + ); + + const loadMoreSkeletonReasonAttributes = useMemo( + () => ({ + context: 'Search.ListFooter', + isSearchLoading: !!searchResults?.search?.isLoading, + searchOffset: searchResults?.search?.offset ?? 0, + }), + [searchResults?.search?.isLoading, searchResults?.search?.offset], + ); + const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); const [baseFilteredData, filteredDataLength, allDataLength] = useMemo(() => { @@ -502,7 +530,10 @@ function Search({ allReportMetadata, cardList, }); - return {...item, transactions: transactions1 as TransactionListItemType[]}; + return { + ...item, + transactions: transactions1 as TransactionListItemType[], + }; }); return enriched; @@ -558,7 +589,14 @@ function Search({ return; } - handleSearch({queryJSON, searchKey, offset, shouldCalculateTotals, prevReportsLength: filteredDataLength, isLoading: !!searchResults?.search?.isLoading}); + handleSearch({ + queryJSON, + searchKey, + offset, + shouldCalculateTotals, + prevReportsLength: filteredDataLength, + isLoading: !!searchResults?.search?.isLoading, + }); // We don't need to run the effect on change of isFocused. // eslint-disable-next-line react-hooks/exhaustive-deps @@ -577,7 +615,14 @@ function Search({ } shouldRetrySearchWithTotalsOrGroupedRef.current = false; - handleSearch({queryJSON, searchKey, offset, shouldCalculateTotals: true, prevReportsLength: filteredDataLength, isLoading: false}); + handleSearch({ + queryJSON, + searchKey, + offset, + shouldCalculateTotals: true, + prevReportsLength: filteredDataLength, + isLoading: false, + }); }, [filteredDataLength, handleSearch, offset, queryJSON, searchKey, searchResults?.search?.count, searchResults?.search?.isLoading, shouldCalculateTotals, validGroupBy]); // When new data load, selectedTransactions is updated in next effect. We use this flag to whether selection is updated @@ -860,7 +905,9 @@ function Search({ if (selectedTransactions[reportKey]?.isSelected) { // Deselect the empty report - const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions}; + const reducedSelectedTransactions: SelectedTransactions = { + ...selectedTransactions, + }; delete reducedSelectedTransactions[reportKey]; setSelectedTransactions(reducedSelectedTransactions, filteredData); updateSelectAllMatchingItemsState(reducedSelectedTransactions); @@ -878,7 +925,9 @@ function Search({ } if (currentTransactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)) { - const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions}; + const reducedSelectedTransactions: SelectedTransactions = { + ...selectedTransactions, + }; for (const transaction of currentTransactions) { delete reducedSelectedTransactions[transaction.keyForList]; @@ -934,7 +983,13 @@ function Search({ } if (isTransactionGroupListItemType(item) && !isTransactionReportGroupListItemType(item) && item.transactionsQueryJSON) { - handleSearch({queryJSON: item.transactionsQueryJSON, searchKey, offset: 0, shouldCalculateTotals: false, isLoading: false}); + handleSearch({ + queryJSON: item.transactionsQueryJSON, + searchKey, + offset: 0, + shouldCalculateTotals: false, + isLoading: false, + }); return; } @@ -1084,7 +1139,10 @@ function Search({ // Use requestAnimationFrame to safely update navigation params without overriding the current route requestAnimationFrame(() => { // We want to explicitly clear stale rawQuery since it’s only used for manually typed-in queries. - Navigation.setParams({q: buildCannedSearchQuery(), rawQuery: undefined}); + Navigation.setParams({ + q: buildCannedSearchQuery(), + rawQuery: undefined, + }); }); if (shouldResetSearchQuery) { setShouldResetSearchQuery(false); @@ -1201,7 +1259,9 @@ function Search({ if (!hasHadFirstLayout.current) { return; } - endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: !shouldShowLoadingState}); + endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, { + [CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: !shouldShowLoadingState, + }); markNavigateAfterExpenseCreateEnd(); spanExistedOnMount.current = false; }, [shouldShowLoadingState]), @@ -1218,6 +1278,7 @@ function Search({ ); @@ -1238,7 +1299,9 @@ function Search({ shouldShow containerStyle={styles.searchBlockingErrorViewContainer} subtitleStyle={styles.textSupporting} - title={translate('errorPage.title', {isBreakLine: shouldUseNarrowLayout})} + title={translate('errorPage.title', { + isBreakLine: shouldUseNarrowLayout, + })} subtitle={translate(isInvalidQuery ? 'errorPage.wrongTypeSubtitle' : 'errorPage.subtitle')} /> @@ -1262,7 +1325,11 @@ function Search({ const onSortPress = (column: SearchColumnType, order: SortOrder) => { clearSelectedTransactions(); - const newQuery = buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order}); + const newQuery = buildSearchQueryString({ + ...queryJSON, + sortBy: column, + sortOrder: order, + }); onSortPressedCallback?.(); // We want to explicitly clear stale rawQuery since it's only used for manually typed-in queries. navigation.setParams({q: newQuery, rawQuery: undefined}); @@ -1354,6 +1421,7 @@ function Search({ ) : undefined } diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 09bb50b4e90a..27570ead43c8 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -1,6 +1,6 @@ import {hasSeenTourSelector, tryNewDotOnyxSelector} from '@selectors/Onboarding'; import {accountIDSelector} from '@selectors/Session'; -import React, {useState} from 'react'; +import React, {useMemo, useState} from 'react'; import type {ReactNode} from 'react'; // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, ImageStyle, Text as RNText, TextStyle, ViewStyle} from 'react-native'; @@ -44,6 +44,7 @@ import {generateReportID, hasViolations as hasViolationsReportUtils} from '@libs import {isDefaultExpenseReportsQuery, isDefaultExpensesQuery} from '@libs/SearchQueryUtils'; import type {SearchTypeMenuSection} from '@libs/SearchUIUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; +import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan'; import {showContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import CONST from '@src/CONST'; @@ -153,6 +154,15 @@ function EmptySearchViewContent({ const illustrations = useMemoizedLazyIllustrations(['PiggyBank', 'TravelAlerts']); + const skeletonReasonAttributes = useMemo( + () => ({ + context: 'EmptySearchView', + hasResults, + searchType: type, + }), + [hasResults, type], + ); + const tripsFeatures: FeatureListItem[] = [ { icon: illustrations.PiggyBank, @@ -169,7 +179,9 @@ function EmptySearchViewContent({ const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [betas] = useOnyx(ONYXKEYS.BETAS); - const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector}); + const [accountID] = useOnyx(ONYXKEYS.SESSION, { + selector: accountIDSelector, + }); const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, accountID ?? CONST.DEFAULT_NUMBER_ID, ''); const [hasTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { @@ -179,7 +191,9 @@ function EmptySearchViewContent({ selector: hasExpenseReportsSelector, }); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {selector: tryNewDotOnyxSelector}); + const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, { + selector: tryNewDotOnyxSelector, + }); const shouldRedirectToExpensifyClassic = areAllGroupPoliciesExpenseChatDisabled(allPolicies ?? {}); @@ -214,7 +228,12 @@ function EmptySearchViewContent({ shouldDismissEmptyReportsConfirmation, ); Navigation.setNavigationActionToMicrotaskQueue(() => { - Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: createdReportID, backTo: Navigation.getActiveRoute()})); + Navigation.navigate( + ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({ + reportID: createdReportID, + backTo: Navigation.getActiveRoute(), + }), + ); }); }; @@ -361,7 +380,11 @@ function EmptySearchViewContent({ title: translate('travel.title'), titleStyles: {...styles.textAlignLeft}, children: tripViewChildren, - lottieWebViewStyles: {backgroundColor: theme.travelBG, ...styles.emptyStateFolderWebStyles, ...styles.tripEmptyStateLottieWebView}, + lottieWebViewStyles: { + backgroundColor: theme.travelBG, + ...styles.emptyStateFolderWebStyles, + ...styles.tripEmptyStateLottieWebView, + }, }; break; case CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT: @@ -519,6 +542,7 @@ function EmptySearchViewContent({ >