Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/components/EmptyStateComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const VIDEO_ASPECT_RATIO = 400 / 225;

function EmptyStateComponent({
SkeletonComponent,
skeletonReasonAttributes,
headerMediaType,
headerMedia,
buttons,
Expand Down Expand Up @@ -93,6 +94,7 @@ function EmptyStateComponent({
<SkeletonComponent
gradientOpacityEnabled
shouldAnimate={false}
reasonAttributes={skeletonReasonAttributes}
/>
</View>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/EmptyStateComponent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -27,6 +28,7 @@ type EmptyStateButton = {

type SharedProps<TMediaType> = {
SkeletonComponent?: ValidSkeletons;
skeletonReasonAttributes?: SkeletonSpanReasonAttributes;
title: string;
titleStyles?: StyleProp<TextStyle>;
subtitle?: string;
Expand Down
90 changes: 79 additions & 11 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -282,7 +283,9 @@ function Search({
const spanExistedOnMount = useRef(!!getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_AFTER_EXPENSE_CREATE));

const savedSearchSelector = useCallback((searches: OnyxEntry<SaveSearch>) => searches?.[hash], [hash]);
const [savedSearch] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {selector: savedSearchSelector});
const [savedSearch] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {
selector: savedSearchSelector,
});

const handleDEWModalOpen = useCallback(() => {
if (onDEWModalOpen) {
Expand Down Expand Up @@ -404,6 +407,31 @@ function Search({
(hasErrors && searchRequestResponseStatusCode === null) ||
isCardFeedsLoading);
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;

const loadingSkeletonReasonAttributes = useMemo<SkeletonSpanReasonAttributes>(
() => ({
context: 'Search',
isOffline,
isDataLoaded,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pass root conditions instead of derived ones. shouldShowLoadingState and shouldShowLoadingMoreItems are compound booleans — they tell "it's loading" but not why. We can break them into individual flags like isOffline, isDataLoaded, isCardFeedsLoading, isSearchLoading, etc. This was agreed in the Slack discussion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — replaced the compound booleans with all the root-level flags that compose them:

{
  context: 'Search',
  isOffline,
  isDataLoaded,
  isCardFeedsLoading,
  isSearchLoading: !!searchResults?.search?.isLoading,
  hasEmptyData: Array.isArray(searchResults?.data) && searchResults?.data.length === 0,
  hasErrors,
  hasPendingResponse: searchRequestResponseStatusCode === null,
  shouldUseLiveData,
}

Same for the footer skeleton — replaced shouldShowLoadingMoreItems with isSearchLoading + searchOffset.

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<SkeletonSpanReasonAttributes>(
() => ({
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(() => {
Expand Down Expand Up @@ -502,7 +530,10 @@ function Search({
allReportMetadata,
cardList,
});
return {...item, transactions: transactions1 as TransactionListItemType[]};
return {
...item,
transactions: transactions1 as TransactionListItemType[],
};
});

return enriched;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]),
Expand All @@ -1218,6 +1278,7 @@ function Search({
<SearchRowSkeleton
shouldAnimate
containerStyle={shouldUseNarrowLayout ? styles.searchListContentContainerStyles : styles.mt3}
reasonAttributes={loadingSkeletonReasonAttributes}
/>
</Animated.View>
);
Expand All @@ -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')}
/>
</View>
Expand All @@ -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});
Expand Down Expand Up @@ -1354,6 +1421,7 @@ function Search({
<SearchRowSkeleton
shouldAnimate
fixedNumItems={5}
reasonAttributes={loadMoreSkeletonReasonAttributes}
/>
) : undefined
}
Expand Down
34 changes: 29 additions & 5 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -153,6 +154,15 @@ function EmptySearchViewContent({

const illustrations = useMemoizedLazyIllustrations(['PiggyBank', 'TravelAlerts']);

const skeletonReasonAttributes = useMemo<SkeletonSpanReasonAttributes>(
() => ({
context: 'EmptySearchView',
hasResults,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sosek108 we should also pass the type so we know which search tab the empty state appeared on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — added searchType: type to skeletonReasonAttributes in EmptySearchView. Now each Sentry trace will show which tab (expense, invoice, trip, chat, etc.) was active.

searchType: type,
}),
[hasResults, type],
);

const tripsFeatures: FeatureListItem[] = [
{
icon: illustrations.PiggyBank,
Expand All @@ -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, {
Expand All @@ -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 ?? {});

Expand Down Expand Up @@ -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(),
}),
);
});
};

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -519,6 +542,7 @@ function EmptySearchViewContent({
>
<GenericEmptyStateComponent
SkeletonComponent={SearchRowSkeleton}
skeletonReasonAttributes={skeletonReasonAttributes}
headerMediaType={content.headerMediaType}
headerMedia={content.headerMedia}
headerStyles={[styles.emptyStateCardIllustrationContainer, styles.overflowHidden, content.headerStyles]}
Expand Down
Loading