import React from 'react'; import { Link } from 'react-router-dom' import FadeIn from '../../fade-in' import MoreLink from '../more-link' import numberFormatter from '../../number-formatter' import Bar from '../bar' import LazyLoader from '../../lazy-loader' export default class ListReport extends React.Component { constructor(props) { super(props) this.state = {loading: true} this.onVisible = this.onVisible.bind(this) } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.fetchData() } } onVisible() { this.fetchData() if (this.props.timer) this.props.timer.onTick(this.fetchData.bind(this)) } fetchData() { this.setState({loading: true, list: null}) this.props.fetchData() .then((res) => this.setState({loading: false, list: res})) } label() { if (this.props.query.period === 'realtime') { return 'Current visitors' } if (this.showConversionRate()) { return 'Conversions' } return 'Visitors' } showConversionRate() { return !!this.props.query.filters.goal } renderListItem(listItem) { const query = new URLSearchParams(window.location.search) Object.entries(this.props.filter).forEach((([key, valueKey]) => { query.set(key, listItem[valueKey]) })) const maxWidthDeduction = this.showConversionRate() ? "10rem" : "5rem" const lightBackground = this.props.color || 'bg-green-50' return (