Stats Page Foundation with Chart.js

This commit is contained in:
Qstick
2021-01-09 00:04:55 -05:00
parent 76c271fab0
commit 88d1a3db6f
15 changed files with 394 additions and 3 deletions

View File

@@ -0,0 +1,22 @@
.fullWidthChart {
display: inline-block;
padding: 15px 25px;
width: 100%;
height: 300px;
}
.halfWidthChart {
display: inline-block;
padding: 15px 25px;
width: 50%;
height: 300px;
}
@media only screen and (max-width: $breakpointSmall) {
.halfWidthChart {
display: inline-block;
padding: 15px 25px;
width: 100%;
height: 300px;
}
}

View File

@@ -0,0 +1,87 @@
import PropTypes from 'prop-types';
import React from 'react';
import BarChart from 'Components/Chart/BarChart';
import DoughnutChart from 'Components/Chart/DoughnutChart';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import PageContent from 'Components/Page/PageContent';
import PageToolbar from 'Components/Page/Toolbar/PageToolbar';
import getErrorMessage from 'Utilities/Object/getErrorMessage';
import styles from './Stats.css';
function getAverageResponseTimeData(indexerStats) {
const data = indexerStats.map((indexer) => {
return {
label: indexer.indexerName,
value: indexer.averageResponseTime
};
});
return data;
}
function getTotalRequestsData(indexerStats) {
const data = indexerStats.map((indexer) => {
return {
label: indexer.indexerName,
value: indexer.numberOfQueries
};
});
return data;
}
function Stats(props) {
const {
items,
isFetching,
isPopulated,
error
} = props;
const isLoaded = !!(!error && isPopulated && items.length);
return (
<PageContent>
<PageToolbar />
{
isFetching && !isPopulated &&
<LoadingIndicator />
}
{
!isFetching && !!error &&
<div className={styles.errorMessage}>
{getErrorMessage(error, 'Failed to load indexer stats from API')}
</div>
}
{
isLoaded &&
<div>
<div className={styles.fullWidthChart}>
<BarChart
data={getAverageResponseTimeData(items)}
title='Average Response Times (ms)'
/>
</div>
<div className={styles.halfWidthChart}>
<DoughnutChart
data={getTotalRequestsData(items)}
title='Total Indexer Queries'
/>
</div>
</div>
}
</PageContent>
);
}
Stats.propTypes = {
items: PropTypes.arrayOf(PropTypes.object).isRequired,
isFetching: PropTypes.bool.isRequired,
isPopulated: PropTypes.bool.isRequired,
error: PropTypes.object,
data: PropTypes.object
};
export default Stats;

View File

@@ -0,0 +1,44 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { fetchIndexerStats } from 'Store/Actions/indexerStatsActions';
import Stats from './Stats';
function createMapStateToProps() {
return createSelector(
(state) => state.indexerStats,
(indexerStats) => indexerStats
);
}
const mapDispatchToProps = {
dispatchFetchIndexers: fetchIndexerStats
};
class StatsConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.dispatchFetchIndexers();
}
//
// Render
render() {
return (
<Stats
{...this.props}
/>
);
}
}
StatsConnector.propTypes = {
dispatchFetchIndexers: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(StatsConnector);