2017-01-03 11:36:06 -05:00
|
|
|
var React = require('react');
|
|
|
|
|
2017-01-08 09:47:30 -05:00
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
|
|
|
var ButtonGroup = ReactBootstrap.ButtonGroup;
|
|
|
|
var DropdownButton = ReactBootstrap.DropdownButton;
|
|
|
|
var MenuItem = ReactBootstrap.MenuItem;
|
|
|
|
|
|
|
|
var BarChart = require('../components/BarChart');
|
2017-01-08 10:22:21 -05:00
|
|
|
var RatioBarChart = require('../components/RatioBarChart');
|
2017-01-03 11:36:06 -05:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "LunchStats",
|
2017-01-08 09:47:30 -05:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
selectedReportId: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
selectReport: function(reportId) {
|
2017-01-08 10:22:21 -05:00
|
|
|
if (reportId == "suggestion-veto-ratio") {
|
|
|
|
this.props.fetchReport("suggestions");
|
|
|
|
this.props.fetchReport("vetoed-suggestions");
|
2017-01-10 20:31:13 -05:00
|
|
|
} else if (reportId == "suggestor-veto-ratio") {
|
|
|
|
this.props.fetchReport("suggestors");
|
|
|
|
this.props.fetchReport("vetoed-suggestors");
|
2017-01-08 10:22:21 -05:00
|
|
|
} else {
|
|
|
|
this.props.fetchReport(reportId);
|
|
|
|
}
|
2017-01-08 09:47:30 -05:00
|
|
|
this.setState({
|
|
|
|
selectedReportId: reportId
|
|
|
|
});
|
|
|
|
},
|
2017-01-03 11:36:06 -05:00
|
|
|
render: function() {
|
2017-01-08 09:47:30 -05:00
|
|
|
var chart = (<div>Please select a report from above</div>);
|
|
|
|
if (this.state.selectedReportId &&
|
|
|
|
this.props.reports.hasOwnProperty(this.state.selectedReportId)) {
|
|
|
|
var report = this.props.reports[this.state.selectedReportId];
|
|
|
|
var data = report.Data;
|
|
|
|
data.sort(function(a, b){return b.Value - a.Value;});
|
2017-01-08 10:22:21 -05:00
|
|
|
chart=(<BarChart title={report.Title} data={data}/>);
|
|
|
|
} else if (this.state.selectedReportId == "suggestion-veto-ratio" &&
|
|
|
|
this.props.reports.hasOwnProperty("suggestions") &&
|
|
|
|
this.props.reports.hasOwnProperty("vetoed-suggestions")) {
|
|
|
|
chart=(<RatioBarChart
|
|
|
|
title="Suggestion Veto Ratio"
|
|
|
|
numerator={this.props.reports['vetoed-suggestions'].Data}
|
|
|
|
denominator={this.props.reports['suggestions'].Data}/>);
|
2017-01-10 20:31:13 -05:00
|
|
|
} else if (this.state.selectedReportId == "suggestor-veto-ratio" &&
|
|
|
|
this.props.reports.hasOwnProperty("suggestors") &&
|
|
|
|
this.props.reports.hasOwnProperty("vetoed-suggestors")) {
|
|
|
|
chart=(<RatioBarChart
|
|
|
|
title="Suggestor Veto Ratio"
|
|
|
|
numerator={this.props.reports['vetoed-suggestors'].Data}
|
|
|
|
denominator={this.props.reports['suggestors'].Data}/>);
|
2017-01-08 09:47:30 -05:00
|
|
|
}
|
|
|
|
|
2017-01-03 11:36:06 -05:00
|
|
|
return (
|
|
|
|
<div>
|
2017-01-08 09:47:30 -05:00
|
|
|
<ButtonGroup bsClass="lunch-report-dropdown">
|
|
|
|
<DropdownButton
|
|
|
|
title="Select Report"
|
|
|
|
id="lunch-report-selection-dropdown"
|
|
|
|
onSelect={this.selectReport}>
|
|
|
|
<MenuItem eventKey="suggestions">Suggestion Frequency</MenuItem>
|
2017-01-10 20:31:13 -05:00
|
|
|
<MenuItem eventKey="winning-suggestions">Winning Suggestions</MenuItem>
|
2017-01-08 09:47:30 -05:00
|
|
|
<MenuItem eventKey="vetoed-suggestions">Vetoed Suggestions</MenuItem>
|
2017-01-10 20:31:13 -05:00
|
|
|
<MenuItem eventKey="suggestion-veto-ratio">Suggestion Veto Ratio</MenuItem>
|
2017-01-08 09:47:30 -05:00
|
|
|
<MenuItem eventKey="attendees">Attendee Frequency</MenuItem>
|
2017-01-10 20:31:13 -05:00
|
|
|
<MenuItem eventKey="suggestors">Suggestor Frequency</MenuItem>
|
|
|
|
<MenuItem eventKey="winning-suggestors">Winning Suggestors</MenuItem>
|
|
|
|
<MenuItem eventKey="vetoed-suggestors">Vetoed Suggestors</MenuItem>
|
|
|
|
<MenuItem eventKey="suggestor-veto-ratio">Suggestor Veto Ratio</MenuItem>
|
2017-01-08 09:47:30 -05:00
|
|
|
</DropdownButton>
|
|
|
|
</ButtonGroup>
|
|
|
|
|
|
|
|
{chart}
|
2017-01-03 11:36:06 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|