Skip to content

Commit 1748359

Browse files
authored
Adrian/dropped data drawer disable zoom (#128298)
This PR adds a disableZoom prop to the `TimeSeriesWidgetVisualization` component to prevent zooming in the drawer's chart. Close DAIN-1949
1 parent 665da47 commit 1748359

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

‎static/app/components/droppedData/drawer/droppedDataChart.spec.tsx‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
1+
import type {ECharts} from 'echarts';
12
import {DroppedEventFixture} from 'sentry-fixture/droppedEvent';
23

3-
import {droppedEventsToSeries} from './droppedDataChart';
4+
import {act, render} from 'sentry-test/reactTestingLibrary';
5+
6+
import {BaseChart} from 'sentry/components/charts/baseChart';
7+
import type {EChartDataZoomHandler} from 'sentry/types/echarts';
8+
9+
import {DroppedDataChart, droppedEventsToSeries} from './droppedDataChart';
10+
11+
jest.mock('sentry/components/charts/baseChart', () => ({
12+
BaseChart: jest.fn(() => null),
13+
}));
14+
15+
describe('DroppedDataChart', () => {
16+
it('does not zoom or change the time range', () => {
17+
const {router} = render(
18+
<DroppedDataChart
19+
droppedEvents={[DroppedEventFixture({outcome: 'filtered', count: 5})]}
20+
colors={{filtered: '#000'}}
21+
selection={{}}
22+
onSelectionChange={jest.fn()}
23+
/>,
24+
{
25+
initialRouterConfig: {
26+
location: {pathname: '/explore/traces/', query: {statsPeriod: '14d'}},
27+
},
28+
}
29+
);
30+
31+
const props = jest.mocked(BaseChart).mock.calls.at(-1)![0];
32+
expect(props.toolBox).toEqual({});
33+
34+
act(() => {
35+
props.onDataZoom?.(
36+
{
37+
type: 'datazoom',
38+
start: 0,
39+
end: 100,
40+
batch: [{startValue: 0, endValue: 600_000}],
41+
} as Parameters<EChartDataZoomHandler>[0],
42+
{} as ECharts
43+
);
44+
});
45+
46+
expect(router.location.query).toEqual({statsPeriod: '14d'});
47+
});
48+
});
449

550
describe('droppedEventsToSeries', () => {
651
it('returns an empty object for no events', () => {

‎static/app/components/droppedData/drawer/droppedDataChart.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export function DroppedDataChart({
119119
/>
120120
<Container height={CHART_HEIGHT}>
121121
{plottables.length > 0 ? (
122-
<TimeSeriesWidgetVisualization plottables={plottables} showLegend="never" />
122+
<TimeSeriesWidgetVisualization
123+
plottables={plottables}
124+
showLegend="never"
125+
disableZoom
126+
/>
123127
) : legendItems.length > 0 ? (
124128
<Flex height="100%" align="center">
125129
<EmptyState

‎static/app/views/dashboards/widgets/timeSeriesWidget/timeSeriesWidgetVisualization.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export interface TimeSeriesWidgetVisualizationProps extends Partial<LoadableChar
9797
*/
9898
chartXRangeSelection?: Partial<ChartXRangeSelectionProps>;
9999

100+
/**
101+
* Disables drag-to-zoom, so zooming never updates the URL or page filters.
102+
*/
103+
disableZoom?: boolean;
104+
100105
/**
101106
* Dropped-data annotations rendered as a severity band between the plot and
102107
* the x-axis line. The band is hidden when `visible` is false or no bucket has
@@ -226,6 +231,7 @@ export function TimeSeriesWidgetVisualization(props: TimeSeriesWidgetVisualizati
226231
onChartReady: onChartReadyZoom,
227232
...chartZoomProps
228233
} = useChartZoom({
234+
disabled: props.disableZoom,
229235
saveOnZoom: true,
230236
});
231237

0 commit comments

Comments
 (0)