ZoomPlugin: Remove the timeRange prop (#69148)

* fix: remove a breaking change

---------

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Levente Balogh 2023-05-26 18:52:09 +02:00 committed by GitHub
parent 2e6c71fd39
commit fa6afc7ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 17 deletions

View File

@ -1,6 +1,4 @@
import { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { useEffect, useLayoutEffect, useState } from 'react';
import { TimeRange } from '@grafana/data';
import { UPlotConfigBuilder } from '../config/UPlotConfigBuilder'; import { UPlotConfigBuilder } from '../config/UPlotConfigBuilder';
import { PlotSelection } from '../types'; import { PlotSelection } from '../types';
@ -9,7 +7,6 @@ import { pluginLog } from '../utils';
interface ZoomPluginProps { interface ZoomPluginProps {
onZoom: (range: { from: number; to: number }) => void; onZoom: (range: { from: number; to: number }) => void;
config: UPlotConfigBuilder; config: UPlotConfigBuilder;
timeRange: TimeRange;
} }
// min px width that triggers zoom // min px width that triggers zoom
@ -18,14 +15,9 @@ const MIN_ZOOM_DIST = 5;
/** /**
* @alpha * @alpha
*/ */
export const ZoomPlugin = ({ onZoom, config, timeRange }: ZoomPluginProps) => { export const ZoomPlugin = ({ onZoom, config }: ZoomPluginProps) => {
const [selection, setSelection] = useState<PlotSelection | null>(null); const [selection, setSelection] = useState<PlotSelection | null>(null);
const refTimeRange = useRef<TimeRange>(timeRange);
useEffect(() => {
refTimeRange.current = timeRange;
}, [timeRange]);
useEffect(() => { useEffect(() => {
if (selection) { if (selection) {
pluginLog('ZoomPlugin', false, 'selected', selection); pluginLog('ZoomPlugin', false, 'selected', selection);
@ -59,9 +51,11 @@ export const ZoomPlugin = ({ onZoom, config, timeRange }: ZoomPluginProps) => {
config.setCursor({ config.setCursor({
bind: { bind: {
dblclick: () => () => { dblclick: (u) => () => {
const frTs = refTimeRange.current.from.valueOf(); let xScale = u.scales.x;
const toTs = refTimeRange.current.to.valueOf();
const frTs = xScale.min!;
const toTs = xScale.max!;
const pad = (toTs - frTs) / 2; const pad = (toTs - frTs) / 2;
onZoom({ from: frTs - pad, to: toTs + pad }); onZoom({ from: frTs - pad, to: toTs + pad });

View File

@ -260,7 +260,7 @@ export const CandlestickPanel = ({
return ( return (
<> <>
<ZoomPlugin config={config} onZoom={onChangeTimeRange} timeRange={timeRange} /> <ZoomPlugin config={config} onZoom={onChangeTimeRange} />
<TooltipPlugin <TooltipPlugin
data={alignedDataFrame} data={alignedDataFrame}
config={config} config={config}

View File

@ -191,7 +191,7 @@ export const StateTimelinePanel = ({
return ( return (
<> <>
<ZoomPlugin config={config} onZoom={onChangeTimeRange} timeRange={timeRange} /> <ZoomPlugin config={config} onZoom={onChangeTimeRange} />
<OutsideRangePlugin config={config} onChangeTimeRange={onChangeTimeRange} /> <OutsideRangePlugin config={config} onChangeTimeRange={onChangeTimeRange} />

View File

@ -215,7 +215,7 @@ export const StatusHistoryPanel = ({
return ( return (
<> <>
<ZoomPlugin config={config} onZoom={onChangeTimeRange} timeRange={timeRange} /> <ZoomPlugin config={config} onZoom={onChangeTimeRange} />
{renderTooltip(alignedFrame)} {renderTooltip(alignedFrame)}
<OutsideRangePlugin config={config} onChangeTimeRange={onChangeTimeRange} /> <OutsideRangePlugin config={config} onChangeTimeRange={onChangeTimeRange} />
</> </>

View File

@ -88,7 +88,7 @@ export const TimeSeriesPanel = ({
return ( return (
<> <>
<KeyboardPlugin config={config} /> <KeyboardPlugin config={config} />
<ZoomPlugin config={config} onZoom={onChangeTimeRange} timeRange={timeRange} /> <ZoomPlugin config={config} onZoom={onChangeTimeRange} />
{options.tooltip.mode === TooltipDisplayMode.None || ( {options.tooltip.mode === TooltipDisplayMode.None || (
<TooltipPlugin <TooltipPlugin
frames={frames} frames={frames}