AdminRebuildSearch.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class AdminRebuildSearch extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. isCompleted: false,
  8. total: 0,
  9. current: 0,
  10. skip: 0,
  11. };
  12. }
  13. componentDidMount() {
  14. const socket = this.props.crowi.getWebSocket();
  15. socket.on('admin:addPageProgress', data => {
  16. const newStates = Object.assign(data, { isCompleted: false });
  17. this.setState(newStates);
  18. });
  19. socket.on('admin:finishAddPage', data => {
  20. const newStates = Object.assign(data, { isCompleted: true });
  21. this.setState(newStates);
  22. });
  23. }
  24. render() {
  25. const { total, current, skip, isCompleted } = this.state;
  26. if (total === 0) {
  27. return null;
  28. }
  29. const progressBarLabel = isCompleted ? 'Completed' : `Processing.. ${current}/${total} (${skip} skips)`;
  30. const progressBarWidth = isCompleted ? '100%' : `${(current / total) * 100}%`;
  31. const progressBarClassNames = isCompleted
  32. ? 'progress-bar progress-bar-success'
  33. : 'progress-bar progress-bar-striped progress-bar-animated active';
  34. return (
  35. <div>
  36. <h5>
  37. {progressBarLabel}
  38. <span className="pull-right">{progressBarWidth}</span>
  39. </h5>
  40. <div className="progress progress-sm">
  41. <div
  42. className={progressBarClassNames}
  43. role="progressbar"
  44. aria-valuemin="0"
  45. aria-valuenow={current}
  46. aria-valuemax={total}
  47. style={{ width: progressBarWidth }}
  48. >
  49. </div>
  50. </div>
  51. </div>
  52. );
  53. }
  54. }
  55. AdminRebuildSearch.propTypes = {
  56. crowi: PropTypes.object.isRequired,
  57. };