Add detection of empty statistics and show according message

This commit is contained in:
Jonny 2019-05-29 08:13:20 +02:00
parent a0bcd328e6
commit 3286120f26
2 changed files with 44 additions and 15 deletions

View File

@ -13,9 +13,11 @@ export const defaultStateTournamentStatistics = {
description: '', description: '',
id: -1, id: -1,
name: '', name: '',
ownerUsername: '', owner_username: '',
isPublic: '', isPublic: '',
statistics_available: false,
most_dominant_team: {}, most_dominant_team: {},
least_dominant_team: {}, least_dominant_team: {},
group_phase_performances: [] group_phase_performances: []
@ -28,13 +30,23 @@ export function transformTournamentInfoToStatistics(data) {
description: data.description, description: data.description,
id: data.id, id: data.id,
name: data.name, name: data.name,
ownerUsername: data.owner_username, owner_username: data.owner_username,
isPublic: data.public isPublic: data.public
}; };
} }
export function transformTournamentStatsToStatistics(data) { export function transformTournamentStatsToStatistics(data) {
if(statisticsUnavailable(data)) {
return {
statistics_available: false,
most_dominant_team: {},
least_dominant_team: {},
group_phase_performances: []
};
}
const statistics = { const statistics = {
statistics_available: true,
most_dominant_team: { most_dominant_team: {
points_made: data.most_dominant_score.scored_points, points_made: data.most_dominant_score.scored_points,
points_received: data.most_dominant_score.received_points, points_received: data.most_dominant_score.received_points,
@ -62,3 +74,8 @@ export function transformTournamentStatsToStatistics(data) {
return statistics; return statistics;
} }
function statisticsUnavailable(data) {
return data === {} || data.most_dominant_score === null ||
data.least_dominant_score === null || data.group_scores === [];
}

View File

@ -37,19 +37,7 @@ class StatisticsTournamentPage extends React.Component {
<BigImage text={tournamentStatistics.name}/> <BigImage text={tournamentStatistics.name}/>
<div className='pb-5'> <div className='pb-5'>
<TournamentInformationView tournament={tournamentStatistics} currentpage='statistics'/> <TournamentInformationView tournament={tournamentStatistics} currentpage='statistics'/>
<Container className="py-5"> <StatisticsView tournamentStatistics={tournamentStatistics} />
<Row>
<Col xs="6">
<DominanceShower stats={tournamentStatistics.most_dominant_team} title="Stärkstes Team"/>
</Col>
<Col xs="6">
<DominanceShower stats={tournamentStatistics.least_dominant_team} title="Schwächstes Team"/>
</Col>
</Row>
</Container>
<Container className="pb-5">
<StandingsTable data={tournamentStatistics}/>
</Container>
</div> </div>
<Footer/> <Footer/>
</div> </div>
@ -57,6 +45,30 @@ class StatisticsTournamentPage extends React.Component {
} }
} }
function StatisticsView(props) {
if (props.tournamentStatistics.statistics_available) {
return (<div>
<Container className="py-5">
<Row>
<Col xs="6">
<DominanceShower stats={props.tournamentStatistics.most_dominant_team} title="Stärkstes Team"/>
</Col>
<Col xs="6">
<DominanceShower stats={props.tournamentStatistics.least_dominant_team} title="Schwächstes Team"/>
</Col>
</Row>
</Container>
<Container className="pb-5">
<StandingsTable data={props.tournamentStatistics}/>
</Container>
</div>);
} else {
return (<Container className="py-5">
<h2 className="text-center">Statistiken sind für dieses Turnier leider nicht verfügbar.</h2>
</Container>);
}
}
function mapTournamentStatisticsToProps(state) { function mapTournamentStatisticsToProps(state) {
const {tournamentStatistics} = state; const {tournamentStatistics} = state;
return {tournamentStatistics}; return {tournamentStatistics};