2019-11-19 07:30:42 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
import Historical from './historical'
|
|
|
|
import Realtime from './realtime'
|
2019-11-19 07:30:42 +03:00
|
|
|
import {parseQuery} from './query'
|
2020-07-02 11:21:59 +03:00
|
|
|
import * as api from './api'
|
2022-04-13 10:38:47 +03:00
|
|
|
import { withComparisonProvider } from './comparison-provider-hoc';
|
2020-07-14 16:52:26 +03:00
|
|
|
|
|
|
|
const THIRTY_SECONDS = 30000
|
|
|
|
|
|
|
|
class Timer {
|
|
|
|
constructor() {
|
|
|
|
this.listeners = []
|
|
|
|
this.intervalId = setInterval(this.dispatchTick.bind(this), THIRTY_SECONDS)
|
|
|
|
}
|
|
|
|
|
|
|
|
onTick(listener) {
|
|
|
|
this.listeners.push(listener)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatchTick() {
|
|
|
|
for (const listener of this.listeners) {
|
|
|
|
listener()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Dashboard extends React.Component {
|
2019-11-19 07:30:42 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2020-07-14 16:52:26 +03:00
|
|
|
this.state = {
|
|
|
|
query: parseQuery(props.location.search, this.props.site),
|
|
|
|
timer: new Timer()
|
|
|
|
}
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (prevProps.location.search !== this.props.location.search) {
|
2020-07-02 11:21:59 +03:00
|
|
|
api.cancelAll()
|
2019-11-19 07:30:42 +03:00
|
|
|
this.setState({query: parseQuery(this.props.location.search, this.props.site)})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-07-14 16:52:26 +03:00
|
|
|
if (this.state.query.period === 'realtime') {
|
2021-06-16 15:00:07 +03:00
|
|
|
return <Realtime timer={this.state.timer} site={this.props.site} loggedIn={this.props.loggedIn} currentUserRole={this.props.currentUserRole} query={this.state.query} />
|
2020-07-14 16:52:26 +03:00
|
|
|
} else {
|
2021-06-16 15:00:07 +03:00
|
|
|
return <Historical timer={this.state.timer} site={this.props.site} loggedIn={this.props.loggedIn} currentUserRole={this.props.currentUserRole} query={this.state.query} />
|
2020-07-14 16:52:26 +03:00
|
|
|
}
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 10:38:47 +03:00
|
|
|
export default withRouter(withComparisonProvider(Dashboard))
|