ImpactReport.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import PropTypes from 'prop-types';
  2. import { PureComponent } from 'react';
  3. import { FormattedNumber, FormattedMessage } from 'react-intl';
  4. import classNames from 'classnames';
  5. import api from 'mastodon/api';
  6. import { Skeleton } from 'mastodon/components/skeleton';
  7. export default class ImpactReport extends PureComponent {
  8. static propTypes = {
  9. domain: PropTypes.string.isRequired,
  10. };
  11. state = {
  12. loading: true,
  13. data: null,
  14. };
  15. componentDidMount () {
  16. const { domain } = this.props;
  17. const params = {
  18. domain: domain,
  19. include_subdomains: true,
  20. };
  21. api().post('/api/v1/admin/measures', {
  22. keys: ['instance_accounts', 'instance_follows', 'instance_followers'],
  23. start_at: null,
  24. end_at: null,
  25. instance_accounts: params,
  26. instance_follows: params,
  27. instance_followers: params,
  28. }).then(res => {
  29. this.setState({
  30. loading: false,
  31. data: res.data,
  32. });
  33. }).catch(err => {
  34. console.error(err);
  35. });
  36. }
  37. render () {
  38. const { loading, data } = this.state;
  39. return (
  40. <div className='dimension'>
  41. <h4><FormattedMessage id='admin.impact_report.title' defaultMessage='Impact summary' /></h4>
  42. <table>
  43. <tbody>
  44. <tr className='dimension__item'>
  45. <td className='dimension__item__key'>
  46. <FormattedMessage id='admin.impact_report.instance_accounts' defaultMessage='Accounts profiles this would delete' />
  47. </td>
  48. <td className='dimension__item__value'>
  49. {loading ? <Skeleton width={60} /> : <FormattedNumber value={data[0].total} />}
  50. </td>
  51. </tr>
  52. <tr className={classNames('dimension__item', { negative: !loading && data[1].total > 0 })}>
  53. <td className='dimension__item__key'>
  54. <FormattedMessage id='admin.impact_report.instance_follows' defaultMessage='Followers their users would lose' />
  55. </td>
  56. <td className='dimension__item__value'>
  57. {loading ? <Skeleton width={60} /> : <FormattedNumber value={data[1].total} />}
  58. </td>
  59. </tr>
  60. <tr className={classNames('dimension__item', { negative: !loading && data[2].total > 0 })}>
  61. <td className='dimension__item__key'>
  62. <FormattedMessage id='admin.impact_report.instance_followers' defaultMessage='Followers our users would lose' />
  63. </td>
  64. <td className='dimension__item__value'>
  65. {loading ? <Skeleton width={60} /> : <FormattedNumber value={data[2].total} />}
  66. </td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. </div>
  71. );
  72. }
  73. }