-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathlog_time_controls.tsx
100 lines (90 loc) · 3 KB
/
log_time_controls.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* 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 { EuiDatePicker, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import moment, { Moment } from 'moment';
import React from 'react';
const noop = () => undefined;
interface LogTimeControlsProps {
currentTime: number | null;
startLiveStreaming: (interval: number) => any;
stopLiveStreaming: () => any;
isLiveStreaming: boolean;
jumpToTime: (time: number) => any;
intl: InjectedIntl;
}
class LogTimeControlsUI extends React.PureComponent<LogTimeControlsProps> {
public render() {
const { currentTime, isLiveStreaming, intl } = this.props;
const currentMoment = currentTime ? moment(currentTime) : null;
if (isLiveStreaming) {
return (
<EuiFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiDatePicker
disabled
onChange={noop}
value={intl.formatMessage({
id: 'xpack.infra.logs.streamingDescription',
defaultMessage: 'Streaming new entries…',
})}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="primary"
iconType="pause"
iconSide="left"
onClick={this.stopLiveStreaming}
>
<FormattedMessage
id="xpack.infra.logs.stopStreamingButtonLabel"
defaultMessage="Stop streaming"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
);
} else {
return (
<EuiFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiDatePicker
dateFormat="L LTS"
onChange={this.handleChangeDate}
popperPlacement="top-end"
selected={currentMoment}
shouldCloseOnSelect
showTimeSelect
timeFormat="LTS"
injectTimes={currentMoment ? [currentMoment] : []}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty iconType="play" iconSide="left" onClick={this.startLiveStreaming}>
<FormattedMessage
id="xpack.infra.logs.startStreamingButtonLabel"
defaultMessage="Stream live"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
);
}
}
private handleChangeDate = (date: Moment | null) => {
if (date !== null) {
this.props.jumpToTime(date.valueOf());
}
};
private startLiveStreaming = () => {
this.props.startLiveStreaming(5000);
};
private stopLiveStreaming = () => {
this.props.stopLiveStreaming();
};
}
export const LogTimeControls = injectI18n(LogTimeControlsUI);