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
6 changes: 5 additions & 1 deletion src/components/Search/SearchChartView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ type SearchChartViewProps = {
/** Scroll handler for hiding the top bar on mobile */
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;

/** Layout handler for the root scroll view */
onLayout?: () => void;

/** Title to be displayed on the chart */
title: string;
};
Expand All @@ -146,7 +149,7 @@ const CHART_VIEW_TO_COMPONENT: Record<ChartView, React.ComponentType<SearchChart
* Layer 3 component - dispatches to the appropriate chart type based on view parameter
* and handles navigation/drill-down logic
*/
function SearchChartView({queryJSON, view, groupBy, data, isLoading, onScroll, title}: SearchChartViewProps) {
function SearchChartView({queryJSON, view, groupBy, data, isLoading, onScroll, onLayout, title}: SearchChartViewProps) {
const styles = useThemeStyles();
const {preferredLocale} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down Expand Up @@ -184,6 +187,7 @@ function SearchChartView({queryJSON, view, groupBy, data, isLoading, onScroll, t
style={styles.flex1}
contentContainerStyle={styles.flexGrow1}
onScroll={onScroll}
onLayout={onLayout}
scrollEventThrottle={16}
>
<View style={[shouldUseNarrowLayout ? styles.searchListContentContainerStyles : styles.mt3, styles.mh4, styles.mb4, styles.flex1]}>
Expand Down
20 changes: 10 additions & 10 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
shouldShowEmptyState,
shouldShowYear as shouldShowYearUtil,
} from '@libs/SearchUIUtils';
import {cancelSpan, endSpan, getSpan, startSpan} from '@libs/telemetry/activeSpans';
import {cancelSpan, endSpanWithAttributes, getSpan, startSpan} from '@libs/telemetry/activeSpans';
import markNavigateAfterExpenseCreateEnd from '@libs/telemetry/markNavigateAfterExpenseCreateEnd';
import {getOriginalTransactionWithSplitInfo, hasValidModifiedAmount, isOnHold, isTransactionPendingDelete} from '@libs/TransactionUtils';
import Navigation, {navigationRef} from '@navigation/Navigation';
Expand Down Expand Up @@ -1160,9 +1160,7 @@ function Search({

const onLayout = useCallback(() => {
hasHadFirstLayout.current = true;
const span = getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
span?.setAttributes({[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: true});
endSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: true});
markNavigateAfterExpenseCreateEnd();
// Reset the ref after the span is ended so future render-time cancelSpan calls are no longer guarded.
spanExistedOnMount.current = false;
Expand All @@ -1188,9 +1186,12 @@ function Search({

const onLayoutSkeleton = useCallback(() => {
hasHadFirstLayout.current = true;
const span = getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
span?.setAttributes({[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: false});
endSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: false});
}, []);

const onLayoutChart = useCallback(() => {
hasHadFirstLayout.current = true;
endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: true});
}, []);

// On re-visits, react-freeze serves the cached layout — onLayout/onLayoutSkeleton never fire.
Expand All @@ -1200,9 +1201,7 @@ function Search({
if (!hasHadFirstLayout.current) {
return;
}
const span = getSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
span?.setAttributes({[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: !shouldShowLoadingState});
endSpan(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS);
endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: !shouldShowLoadingState});
markNavigateAfterExpenseCreateEnd();
spanExistedOnMount.current = false;
}, [shouldShowLoadingState]),
Expand Down Expand Up @@ -1299,6 +1298,7 @@ function Search({
data={sortedData}
isLoading={shouldShowLoadingState}
onScroll={onSearchListScroll}
onLayout={onLayoutChart}
title={chartTitle}
/>
</SearchScopeProvider>
Expand Down
10 changes: 8 additions & 2 deletions src/libs/telemetry/activeSpans.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {StartSpanOptions} from '@sentry/core';
import type {SpanAttributeValue, StartSpanOptions} from '@sentry/core';
import * as Sentry from '@sentry/react-native';
import {spanToJSON} from '@sentry/react-native';
import Log from '@libs/Log';
Expand Down Expand Up @@ -81,4 +81,10 @@ function getSpan(spanId: string) {
return activeSpans.get(spanId);
}

export {startSpan, endSpan, getSpan, cancelSpan, cancelAllSpans, cancelSpansByPrefix};
function endSpanWithAttributes(spanId: string, attributes: Record<string, SpanAttributeValue>) {
const span = getSpan(spanId);
span?.setAttributes(attributes);
endSpan(spanId);
}

export {startSpan, endSpan, endSpanWithAttributes, getSpan, cancelSpan, cancelAllSpans, cancelSpansByPrefix};
Loading