analytics/assets/js/dashboard/index.js
RobertJoonas 3999f282a5
Last updated tooltip (#2576)
* extract blinkingDot function

* position pulsating-circle with tailwind instead

* remove unused function

* extract renderStatName function

* display seconds since last realtime update

Adds a 'Last updated X seconds ago' label to the Current Visitors tooltip.

* small refactor: avoid duplication of this.props and this.state

* show the 'last updated ...' tooltip in historical

* changelog update

* use className utility function
2023-01-16 10:30:22 +02:00

49 lines
1.5 KiB
JavaScript

import React from 'react';
import { withRouter } from 'react-router-dom'
import Historical from './historical'
import Realtime from './realtime'
import {parseQuery} from './query'
import * as api from './api'
import { withComparisonProvider } from './comparison-provider-hoc';
class Dashboard extends React.Component {
constructor(props) {
super(props)
this.updateLastLoadTimestamp = this.updateLastLoadTimestamp.bind(this)
this.state = {
query: parseQuery(props.location.search, this.props.site),
lastLoadTimestamp: new Date()
}
}
componentDidMount() {
document.addEventListener('tick', this.updateLastLoadTimestamp)
}
componentDidUpdate(prevProps) {
if (prevProps.location.search !== this.props.location.search) {
api.cancelAll()
this.setState({query: parseQuery(this.props.location.search, this.props.site)})
this.updateLastLoadTimestamp()
}
}
updateLastLoadTimestamp() {
this.setState({lastLoadTimestamp: new Date()})
}
render() {
const { site, loggedIn, currentUserRole } = this.props
const { query, lastLoadTimestamp } = this.state
if (this.state.query.period === 'realtime') {
return <Realtime site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
} else {
return <Historical site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
}
}
}
export default withRouter(withComparisonProvider(Dashboard))