-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathindex.tsx
71 lines (60 loc) · 1.83 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { fromQuery, toQuery } from '../../Links/url_helpers';
import { history } from '../../../../utils/history';
export interface RangeSelection {
start: number;
end: number;
}
type HoverX = number;
type OnHoverHandler = (hoverX: HoverX) => void;
type OnMouseLeaveHandler = () => void;
type OnSelectionEndHandler = (range: RangeSelection) => void;
export interface HoverXHandlers {
onHover: OnHoverHandler;
onMouseLeave: OnMouseLeaveHandler;
onSelectionEnd: OnSelectionEndHandler;
hoverX: HoverX | null;
}
interface SyncChartGroupProps {
render: (props: HoverXHandlers) => React.ReactNode;
}
interface SyncChartState {
hoverX: HoverX | null;
}
export class SyncChartGroup extends React.Component<
SyncChartGroupProps,
SyncChartState
> {
public state = { hoverX: null };
public onHover: OnHoverHandler = hoverX => this.setState({ hoverX });
public onMouseLeave: OnMouseLeaveHandler = () =>
this.setState({ hoverX: null });
public onSelectionEnd: OnSelectionEndHandler = range => {
this.setState({ hoverX: null });
const currentSearch = toQuery(history.location.search);
const nextSearch = {
rangeFrom: new Date(range.start).toISOString(),
rangeTo: new Date(range.end).toISOString()
};
history.push({
...history.location,
search: fromQuery({
...currentSearch,
...nextSearch
})
});
};
public render() {
return this.props.render({
onHover: this.onHover,
onMouseLeave: this.onMouseLeave,
onSelectionEnd: this.onSelectionEnd,
hoverX: this.state.hoverX
});
}
}