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
14 changes: 13 additions & 1 deletion static/app/views/explore/metrics/metricGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
useMetricVisualize,
useSetMetricVisualize,
} from 'sentry/views/explore/metrics/metricsQueryParams';
import {METRICS_CHART_GROUP} from 'sentry/views/explore/metrics/metricsTab';
import {useMultiMetricsQueryParams} from 'sentry/views/explore/metrics/multiMetricsQueryParams';
import {
useQueryParamsQuery,
useQueryParamsTopEventsLimit,
Expand All @@ -29,7 +31,10 @@ import {
combineConfidenceForSeries,
prettifyAggregation,
} from 'sentry/views/explore/utils';
import {ChartType} from 'sentry/views/insights/common/components/chart';
import {
ChartType,
useSynchronizeCharts,
} from 'sentry/views/insights/common/components/chart';
import type {useSortedTimeSeries} from 'sentry/views/insights/common/queries/useSortedTimeSeries';
import {GenericWidgetEmptyStateWarning} from 'sentry/views/performance/landing/widgets/components/selectableList';

Expand All @@ -55,9 +60,16 @@ export function MetricsGraph({
infoContentHidden,
isMetricOptionsEmpty,
}: MetricsGraphProps) {
const metricQueries = useMultiMetricsQueryParams();
const visualize = useMetricVisualize();
const setVisualize = useSetMetricVisualize();

useSynchronizeCharts(
metricQueries.length,
!timeseriesResult.isPending,
METRICS_CHART_GROUP
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Hook Misuse Causes Chart Sync Issues

The useSynchronizeCharts hook is called per MetricsGraph component, rather than once for the chart group. This means multiple calls for the same group, each with its own loading state, which can cause inconsistent synchronization or race conditions.

Fix in Cursor Fix in Web


function handleChartTypeChange(newChartType: ChartType) {
setVisualize(visualize.replace({chartType: newChartType}));
}
Expand Down
32 changes: 18 additions & 14 deletions static/app/views/explore/metrics/metricsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
import {t} from 'sentry/locale';
import {WidgetSyncContextProvider} from 'sentry/views/dashboards/contexts/widgetSyncContext';
import {
ExploreBodyContent,
ExploreBodySearch,
Expand All @@ -31,6 +32,7 @@ import {
import type {PickableDays} from 'sentry/views/explore/utils';

const MAX_METRICS_ALLOWED = 4;
export const METRICS_CHART_GROUP = 'metrics-charts-group';

type MetricsTabProps = PickableDays;

Expand Down Expand Up @@ -118,20 +120,22 @@ function MetricsTabBodySection() {
<ExploreControlSection expanded={false} />
<ExploreContentSection expanded={false}>
<Flex direction="column" gap="lg">
{metricQueries.map((metricQuery, index) => {
return (
<MetricsQueryParamsProvider
key={`queryPanel-${index}`}
queryParams={metricQuery.queryParams}
setQueryParams={metricQuery.setQueryParams}
traceMetric={metricQuery.metric}
setTraceMetric={metricQuery.setTraceMetric}
removeMetric={metricQuery.removeMetric}
>
<MetricPanel traceMetric={metricQuery.metric} queryIndex={index} />
</MetricsQueryParamsProvider>
);
})}
<WidgetSyncContextProvider groupName={METRICS_CHART_GROUP}>
{metricQueries.map((metricQuery, index) => {
return (
<MetricsQueryParamsProvider
key={`queryPanel-${index}`}
queryParams={metricQuery.queryParams}
setQueryParams={metricQuery.setQueryParams}
traceMetric={metricQuery.metric}
setTraceMetric={metricQuery.setTraceMetric}
removeMetric={metricQuery.removeMetric}
>
<MetricPanel traceMetric={metricQuery.metric} queryIndex={index} />
</MetricsQueryParamsProvider>
);
})}
</WidgetSyncContextProvider>
</Flex>
</ExploreContentSection>
</ExploreBodyContent>
Expand Down
Loading