Skip to content

Commit

Permalink
fix(ui): Sort total statistics data points
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jan 9, 2022
1 parent ecd1aeb commit a568c03
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions frontend/src/robot/TotalStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,43 @@ const TotalStatisticsInternal: React.FunctionComponent = (): JSX.Element => {
return <Typography color="error">Error loading statistics</Typography>;
}

const statistics =
totalStatisticsState.map((dataPoint) => {
const achievement = statisticsAchievements[dataPoint.type].find(achievement => {
return dataPoint.value >= achievement.value;
});

return (
<Grid item xs={12} sm={4} key={dataPoint.type}>
<Card style={{height: "100%"}}>
<CardMedia component={StatisticsAward} achievement={achievement}/>
<CardContent>
{<Typography variant="body1" mb={2}>
{achievement?.description || "No achievement yet"}
</Typography>}

<Typography sx={{fontSize: 14}} color="text.secondary" gutterBottom>
{getFriendlyStatName(dataPoint)}
</Typography>
<Typography variant="h5" component="div">
{getHumanReadableStatValue(dataPoint)}
</Typography>
</CardContent>
</Card>
</Grid>
);
const statistics = totalStatisticsState.sort((a, b) => {
const aMapped = SORT_ORDER[a.type] ?? 10;
const bMapped = SORT_ORDER[b.type] ?? 10;

if (aMapped < bMapped) {
return -1;
} else if (bMapped < aMapped) {
return 1;
} else {
return 0;
}
}).map((dataPoint) => {
const achievement = statisticsAchievements[dataPoint.type].find(achievement => {
return dataPoint.value >= achievement.value;
});

return (
<Grid item xs={12} sm={4} key={dataPoint.type}>
<Card style={{height: "100%"}}>
<CardMedia component={StatisticsAward} achievement={achievement}/>
<CardContent>
{<Typography variant="body1" mb={2}>
{achievement?.description || "No achievement yet"}
</Typography>}

<Typography sx={{fontSize: 14}} color="text.secondary" gutterBottom>
{getFriendlyStatName(dataPoint)}
</Typography>
<Typography variant="h5" component="div">
{getHumanReadableStatValue(dataPoint)}
</Typography>
</CardContent>
</Card>
</Grid>
);
});

return (
<>
<Grid container spacing={2}>
Expand All @@ -190,4 +200,10 @@ const TotalStatistics = (): JSX.Element => {
);
};

const SORT_ORDER = {
"time": 1,
"area": 2,
"count": 3
};

export default TotalStatistics;

0 comments on commit a568c03

Please sign in to comment.