2018-07-29 19:39:00 +03:00
|
|
|
import React from 'react';
|
2018-07-30 21:31:48 +03:00
|
|
|
import { Doughnut, HorizontalBar } from 'react-chartjs-2';
|
2018-07-29 19:39:00 +03:00
|
|
|
import { connect } from 'react-redux';
|
2018-07-29 20:25:22 +03:00
|
|
|
import { pick } from 'ramda';
|
2018-07-30 21:31:48 +03:00
|
|
|
import { Card, CardBody, CardHeader } from 'reactstrap';
|
2018-07-29 20:25:22 +03:00
|
|
|
import { getShortUrlVisits } from './reducers/shortUrlVisits';
|
2018-07-30 21:31:48 +03:00
|
|
|
import VisitsParser from '../visits/services/VisitsParser';
|
2018-07-29 19:39:00 +03:00
|
|
|
|
|
|
|
export class ShortUrlsVisits extends React.Component {
|
2018-07-30 21:31:48 +03:00
|
|
|
state = { startDate: '', endDate: '' };
|
|
|
|
|
2018-07-29 20:25:22 +03:00
|
|
|
componentDidMount() {
|
2018-07-29 19:39:00 +03:00
|
|
|
const { match: { params } } = this.props;
|
2018-07-30 21:31:48 +03:00
|
|
|
this.props.getShortUrlVisits(params.shortCode, this.state);
|
2018-07-29 20:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-07-30 21:31:48 +03:00
|
|
|
const { match: { params }, selectedServer, visitsParser, shortUrlVisits } = this.props;
|
2018-07-29 20:25:22 +03:00
|
|
|
const serverUrl = selectedServer ? selectedServer.url : '';
|
|
|
|
const shortUrl = `${serverUrl}/${params.shortCode}`;
|
2018-07-30 21:31:48 +03:00
|
|
|
const generateGraphData = stats => ({
|
|
|
|
labels: Object.keys(stats),
|
|
|
|
datasets: Object.values(stats)
|
|
|
|
});
|
2018-07-29 20:25:22 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="short-urls-container">
|
2018-07-30 21:31:48 +03:00
|
|
|
<Card className="bg-light">
|
|
|
|
<CardBody>
|
2018-07-29 20:25:22 +03:00
|
|
|
<h2>Visit stats for <a target="_blank" href={shortUrl}>{shortUrl}</a></h2>
|
2018-07-30 21:31:48 +03:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-6">
|
|
|
|
<Card className="mt-4">
|
|
|
|
<CardHeader>Operating systems</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<Doughnut data={generateGraphData(visitsParser.processOsStats(shortUrlVisits))} />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6">
|
|
|
|
<Card className="mt-4">
|
|
|
|
<CardHeader>Browsers</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<Doughnut data={generateGraphData(visitsParser.processBrowserStats(shortUrlVisits))} />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6">
|
|
|
|
<Card className="mt-4">
|
|
|
|
<CardHeader>Countries</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<HorizontalBar data={generateGraphData(visitsParser.processCountriesStats(shortUrlVisits))} />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6">
|
|
|
|
<Card className="mt-4">
|
|
|
|
<CardHeader>Referrers</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<HorizontalBar data={generateGraphData(visitsParser.processReferrersStats(shortUrlVisits))} />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
2018-07-29 20:25:22 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2018-07-29 19:39:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 21:31:48 +03:00
|
|
|
ShortUrlsVisits.defaultProps = {
|
|
|
|
visitsParser: VisitsParser
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(pick(['selectedServer', 'shortUrlVisits']), {
|
2018-07-29 20:25:22 +03:00
|
|
|
getShortUrlVisits
|
|
|
|
})(ShortUrlsVisits);
|