Skip to content

Commit 8208c7c

Browse files
committed
refactor: onBrushEnd breaking changes
1 parent 5fd2026 commit 8208c7c

File tree

20 files changed

+148
-111
lines changed

20 files changed

+148
-111
lines changed

src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/histogram.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
TooltipType,
4040
ElementClickListener,
4141
XYChartElementEvent,
42+
BrushEndListener,
4243
} from '@elastic/charts';
4344

4445
import { i18n } from '@kbn/i18n';
@@ -143,13 +144,12 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
143144
}
144145
}
145146

146-
public onBrushEnd = (min: number, max: number) => {
147-
const range = {
148-
from: min,
149-
to: max,
150-
};
151-
152-
this.props.timefilterUpdateHandler(range);
147+
public onBrushEnd: BrushEndListener = ({ x }) => {
148+
if (!x) {
149+
return;
150+
}
151+
const [from, to] = x;
152+
this.props.timefilterUpdateHandler({ from, to });
153153
};
154154

155155
public onElementClick = (xInterval: number): ElementClickListener => ([elementData]) => {

src/plugins/vis_type_timeseries/public/application/visualizations/views/timeseries/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,21 @@ export const TimeSeries = ({
100100
const { colors } = getChartsSetup();
101101
colors.mappedColors.mapKeys(series.filter(({ color }) => !color).map(({ label }) => label));
102102

103+
const onBrushEndListener = ({ x }) => {
104+
if (!x) {
105+
return;
106+
}
107+
const [min, max] = x;
108+
onBrush(min, max);
109+
};
110+
103111
return (
104112
<Chart ref={chartRef} renderer="canvas" className={classes}>
105113
<Settings
106114
showLegend={legend}
107115
showLegendExtra={true}
108116
legendPosition={legendPosition}
109-
onBrushEnd={onBrush}
117+
onBrushEnd={onBrushEndListener}
110118
animateData={false}
111119
onPointerUpdate={handleCursorUpdate}
112120
theme={

x-pack/legacy/plugins/uptime/public/components/common/charts/duration_chart.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import React, { useState } from 'react';
88
import { i18n } from '@kbn/i18n';
99
import moment from 'moment';
1010
import { FormattedMessage } from '@kbn/i18n/react';
11-
import { Axis, Chart, Position, timeFormatter, Settings, SeriesIdentifier } from '@elastic/charts';
11+
import {
12+
Axis,
13+
Chart,
14+
Position,
15+
timeFormatter,
16+
Settings,
17+
SeriesIdentifier,
18+
BrushEndListener,
19+
} from '@elastic/charts';
1220
import { getChartDateLabel } from '../../../lib/helper';
1321
import { LocationDurationLine } from '../../../../common/types';
1422
import { DurationLineSeriesList } from './duration_line_series_list';
@@ -51,7 +59,11 @@ export const DurationChartComponent = ({
5159

5260
const [hiddenLegends, setHiddenLegends] = useState<string[]>([]);
5361

54-
const onBrushEnd = (minX: number, maxX: number) => {
62+
const onBrushEnd: BrushEndListener = ({ x }) => {
63+
if (!x) {
64+
return;
65+
}
66+
const [minX, maxX] = x;
5567
updateUrlParams({
5668
dateRangeStart: moment(minX).toISOString(),
5769
dateRangeEnd: moment(maxX).toISOString(),

x-pack/legacy/plugins/uptime/public/components/common/charts/monitor_bar_series.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Settings,
1313
Position,
1414
timeFormatter,
15+
BrushEndListener,
1516
} from '@elastic/charts';
1617
import { i18n } from '@kbn/i18n';
1718
import React, { useContext } from 'react';
@@ -42,7 +43,11 @@ export const MonitorBarSeries = ({ histogramSeries }: MonitorBarSeriesProps) =>
4243
const [getUrlParams, updateUrlParams] = useUrlParams();
4344
const { absoluteDateRangeStart, absoluteDateRangeEnd } = getUrlParams();
4445

45-
const onBrushEnd = (min: number, max: number) => {
46+
const onBrushEnd: BrushEndListener = ({ x }) => {
47+
if (!x) {
48+
return;
49+
}
50+
const [min, max] = x;
4651
updateUrlParams({
4752
dateRangeStart: moment(min).toISOString(),
4853
dateRangeEnd: moment(max).toISOString(),

x-pack/legacy/plugins/uptime/public/components/common/charts/ping_histogram.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { Axis, BarSeries, Chart, Position, Settings, timeFormatter } from '@elastic/charts';
7+
import {
8+
Axis,
9+
BarSeries,
10+
Chart,
11+
Position,
12+
Settings,
13+
timeFormatter,
14+
BrushEndListener,
15+
} from '@elastic/charts';
816
import { EuiTitle } from '@elastic/eui';
917
import { i18n } from '@kbn/i18n';
1018
import React, { useContext } from 'react';
@@ -79,7 +87,11 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
7987
defaultMessage: 'Up',
8088
});
8189

82-
const onBrushEnd = (min: number, max: number) => {
90+
const onBrushEnd: BrushEndListener = ({ x }) => {
91+
if (!x) {
92+
return;
93+
}
94+
const [min, max] = x;
8395
updateUrlParams({
8496
dateRangeStart: moment(min).toISOString(),
8597
dateRangeEnd: moment(max).toISOString(),

x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/chart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
LIGHT_THEME,
1616
DARK_THEME,
1717
RectAnnotation,
18+
BrushEndListener,
1819
} from '@elastic/charts';
1920
import numeral from '@elastic/numeral';
2021
import { i18n } from '@kbn/i18n';
@@ -53,8 +54,12 @@ export const AnomaliesChart: React.FunctionComponent<{
5354
[dateFormat]
5455
);
5556

56-
const handleBrushEnd = useCallback(
57-
(startTime: number, endTime: number) => {
57+
const handleBrushEnd = useCallback<BrushEndListener>(
58+
({ x }) => {
59+
if (!x) {
60+
return;
61+
}
62+
const [startTime, endTime] = x;
5863
setTimeRange({
5964
endTime,
6065
startTime,

x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/bar_chart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
niceTimeFormatter,
1212
Settings,
1313
TooltipValue,
14+
BrushEndListener,
1415
LIGHT_THEME,
1516
DARK_THEME,
1617
} from '@elastic/charts';
@@ -43,8 +44,12 @@ export const LogEntryRateBarChart: React.FunctionComponent<{
4344
[dateFormat]
4445
);
4546

46-
const handleBrushEnd = useCallback(
47-
(startTime: number, endTime: number) => {
47+
const handleBrushEnd = useCallback<BrushEndListener>(
48+
({ x }) => {
49+
if (!x) {
50+
return;
51+
}
52+
const [startTime, endTime] = x;
4853
setTimeRange({
4954
endTime,
5055
startTime,

x-pack/plugins/infra/public/pages/metrics/metric_detail/components/chart_section_vis.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
import React, { useCallback, useMemo } from 'react';
77
import moment from 'moment';
88
import { i18n } from '@kbn/i18n';
9-
import { Axis, Chart, niceTimeFormatter, Position, Settings, TooltipValue } from '@elastic/charts';
9+
import {
10+
Axis,
11+
Chart,
12+
niceTimeFormatter,
13+
Position,
14+
Settings,
15+
TooltipValue,
16+
BrushEndListener,
17+
} from '@elastic/charts';
1018
import { EuiPageContentBody } from '@elastic/eui';
1119
import { getChartTheme } from '../../metrics_explorer/components/helpers/get_chart_theme';
1220
import { SeriesChart } from './series_chart';
@@ -45,8 +53,12 @@ export const ChartSectionVis = ({
4553
() => (metric != null ? niceTimeFormatter(getMaxMinTimestamp(metric)) : undefined),
4654
[metric]
4755
);
48-
const handleTimeChange = useCallback(
49-
(from: number, to: number) => {
56+
const handleTimeChange = useCallback<BrushEndListener>(
57+
({ x }) => {
58+
if (!x) {
59+
return;
60+
}
61+
const [from, to] = x;
5062
if (onChangeRangeTime) {
5163
if (isLiveStreaming && stopLiveStreaming) {
5264
stopLiveStreaming();

x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
import React, { useCallback, useMemo } from 'react';
88

99
import { EuiTitle, EuiToolTip, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
10-
import { Axis, Chart, niceTimeFormatter, Position, Settings, TooltipValue } from '@elastic/charts';
10+
import {
11+
Axis,
12+
Chart,
13+
niceTimeFormatter,
14+
Position,
15+
Settings,
16+
TooltipValue,
17+
BrushEndListener,
18+
} from '@elastic/charts';
1119
import { first, last } from 'lodash';
1220
import moment from 'moment';
1321
import { MetricsExplorerSeries } from '../../../../../common/http_api/metrics_explorer';
@@ -58,7 +66,11 @@ export const MetricsExplorerChart = ({
5866
const isDarkMode = useUiSetting<boolean>('theme:darkMode');
5967
const { metrics } = options;
6068
const [dateFormat] = useKibanaUiSetting('dateFormat');
61-
const handleTimeChange = (from: number, to: number) => {
69+
const handleTimeChange: BrushEndListener = ({ x }) => {
70+
if (!x) {
71+
return;
72+
}
73+
const [from, to] = x;
6274
onTimeChange(moment(from).toISOString(), moment(to).toISOString());
6375
};
6476
const dateFormatter = useMemo(

x-pack/plugins/infra/types/eui_experimental.d.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)