mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* time selector for explore section * mostly ported the angular time selector, but left out the timepicker (3rd-party angular component) * can be initialised via url parameters (jump from panels to explore) * refreshing not implemented for now * moved the forward/backward nav buttons around the time selector
47 lines
941 B
TypeScript
47 lines
941 B
TypeScript
import React, { PureComponent } from 'react';
|
|
|
|
const INTERVAL = 150;
|
|
|
|
export default class ElapsedTime extends PureComponent<any, any> {
|
|
offset: number;
|
|
timer: number;
|
|
|
|
state = {
|
|
elapsed: 0,
|
|
};
|
|
|
|
start() {
|
|
this.offset = Date.now();
|
|
this.timer = window.setInterval(this.tick, INTERVAL);
|
|
}
|
|
|
|
tick = () => {
|
|
const jetzt = Date.now();
|
|
const elapsed = jetzt - this.offset;
|
|
this.setState({ elapsed });
|
|
};
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
if (nextProps.time) {
|
|
clearInterval(this.timer);
|
|
} else if (this.props.time) {
|
|
this.start();
|
|
}
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.start();
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearInterval(this.timer);
|
|
}
|
|
|
|
render() {
|
|
const { elapsed } = this.state;
|
|
const { className, time } = this.props;
|
|
const value = (time || elapsed) / 1000;
|
|
return <span className={`elapsed-time ${className}`}>{value.toFixed(1)}s</span>;
|
|
}
|
|
}
|