ServerStats.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from 'react';
  2. import { hot } from 'react-hot-loader';
  3. import { connect } from 'react-redux';
  4. import { initNav } from 'app/core/actions';
  5. import { ContainerProps } from 'app/types';
  6. import { getServerStats, ServerStat } from './api';
  7. import PageHeader from 'app/core/components/PageHeader/PageHeader';
  8. interface Props extends ContainerProps {
  9. getServerStats: () => Promise<ServerStat[]>;
  10. }
  11. interface State {
  12. stats: ServerStat[];
  13. }
  14. export class ServerStats extends React.Component<Props, State> {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. stats: [],
  19. };
  20. this.props.initNav('cfg', 'admin', 'server-stats');
  21. }
  22. async componentDidMount() {
  23. try {
  24. const stats = await this.props.getServerStats();
  25. this.setState({ stats });
  26. } catch (error) {
  27. console.error(error);
  28. }
  29. }
  30. render() {
  31. const { navModel } = this.props;
  32. const { stats } = this.state;
  33. return (
  34. <div>
  35. <PageHeader model={navModel} />
  36. <div className="page-container page-body">
  37. <table className="filter-table form-inline">
  38. <thead>
  39. <tr>
  40. <th>Name</th>
  41. <th>Value</th>
  42. </tr>
  43. </thead>
  44. <tbody>{stats.map(StatItem)}</tbody>
  45. </table>
  46. </div>
  47. </div>
  48. );
  49. }
  50. }
  51. function StatItem(stat: ServerStat) {
  52. return (
  53. <tr key={stat.name}>
  54. <td>{stat.name}</td>
  55. <td>{stat.value}</td>
  56. </tr>
  57. );
  58. }
  59. const mapStateToProps = state => ({
  60. navModel: state.navModel,
  61. getServerStats: getServerStats,
  62. });
  63. const mapDispatchToProps = {
  64. initNav,
  65. };
  66. export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(ServerStats));