mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 00:51:36 +03:00
232298d327
* Auto-updating dashboard with realtime info * Remove extra route * Draw list of countries next to the map * Nice animations * Do not show bounce rates in realtime modals * Update countries and devices in realtime * Remove unused component * Show total pageviews in the last 30 minutes * Show proper labels * Remove unnecessary z-index * Fix label for main graph * Fix compiler warnings * Add tests * Fix copy pluralizations * Fix copy in countries modal * Real-time -> Realtime * Looser test assertion * Show last 30 minutes conversions on realtime report * Remove EventTarget API because it doesn't work on Safari * Get referrer drilldown from sessions table * Fix failing tests
55 lines
1.3 KiB
JavaScript
55 lines
1.3 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'
|
|
|
|
|
|
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 {
|
|
constructor(props) {
|
|
super(props)
|
|
this.state = {
|
|
query: parseQuery(props.location.search, this.props.site),
|
|
timer: new Timer()
|
|
}
|
|
}
|
|
|
|
componentDidUpdate(prevProps) {
|
|
if (prevProps.location.search !== this.props.location.search) {
|
|
api.cancelAll()
|
|
this.setState({query: parseQuery(this.props.location.search, this.props.site)})
|
|
}
|
|
}
|
|
|
|
render() {
|
|
if (this.state.query.period === 'realtime') {
|
|
return <Realtime timer={this.state.timer} site={this.props.site} query={this.state.query} />
|
|
} else {
|
|
return <Historical timer={this.state.timer} site={this.props.site} query={this.state.query} />
|
|
}
|
|
}
|
|
}
|
|
|
|
export default withRouter(Dashboard)
|