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
|
|
|
|
2023-07-06 17:29:08 +03:00
|
|
|
export const statsBoxClass = "stats-item relative w-full mt-6 p-4 flex flex-col bg-white dark:bg-gray-825 shadow-xl rounded"
|
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
class Dashboard extends React.Component {
|
2019-11-19 07:30:42 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2023-01-16 11:30:22 +03:00
|
|
|
this.updateLastLoadTimestamp = this.updateLastLoadTimestamp.bind(this)
|
2020-07-14 16:52:26 +03:00
|
|
|
this.state = {
|
|
|
|
query: parseQuery(props.location.search, this.props.site),
|
2023-01-16 11:30:22 +03:00
|
|
|
lastLoadTimestamp: new Date()
|
2020-07-14 16:52:26 +03:00
|
|
|
}
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
|
2023-01-16 11:30:22 +03:00
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('tick', this.updateLastLoadTimestamp)
|
|
|
|
}
|
|
|
|
|
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)})
|
2023-01-16 11:30:22 +03:00
|
|
|
this.updateLastLoadTimestamp()
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-16 11:30:22 +03:00
|
|
|
updateLastLoadTimestamp() {
|
|
|
|
this.setState({lastLoadTimestamp: new Date()})
|
|
|
|
}
|
|
|
|
|
2019-11-19 07:30:42 +03:00
|
|
|
render() {
|
2023-01-16 11:30:22 +03:00
|
|
|
const { site, loggedIn, currentUserRole } = this.props
|
|
|
|
const { query, lastLoadTimestamp } = this.state
|
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
if (this.state.query.period === 'realtime') {
|
2023-01-16 11:30:22 +03:00
|
|
|
return <Realtime site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
|
2020-07-14 16:52:26 +03:00
|
|
|
} else {
|
2023-01-16 11:30:22 +03:00
|
|
|
return <Historical site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
|
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))
|