import React from 'react'; import { Doughnut, HorizontalBar } from 'react-chartjs-2'; import Moment from 'react-moment'; import { connect } from 'react-redux'; import { pick } from 'ramda'; import { Card, CardBody, CardHeader, UncontrolledTooltip } from 'reactstrap'; import { getShortUrlVisits } from './reducers/shortUrlVisits'; import VisitsParser from '../visits/services/VisitsParser'; import preloader from '@fortawesome/fontawesome-free-solid/faCircleNotch'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; export class ShortUrlsVisits extends React.Component { state = { startDate: '', endDate: '' }; componentDidMount() { const { match: { params } } = this.props; this.props.getShortUrlVisits(params.shortCode, this.state); } render() { const { match: { params }, selectedServer, visitsParser, shortUrlVisits: { visits, loading, error, shortUrl } } = this.props; const colors = [ '#97BBCD', '#DCDCDC', '#F7464A', '#46BFBD', '#FDB45C', '#949FB1', '#4D5360' ]; const serverUrl = selectedServer ? selectedServer.url : ''; const shortLink = `${serverUrl}/${params.shortCode}`; const generateGraphData = (stats, label, isBarChart) => ({ labels: Object.keys(stats), datasets: [ { label, data: Object.values(stats), backgroundColor: isBarChart ? 'rgba(70, 150, 229, 0.4)' : colors, borderColor: isBarChart ? 'rgba(70, 150, 229, 1)' : 'white', borderWidth: 2 } ] }); const renderGraphCard = (title, stats, isBarChart, label) =>