SearchResultList.jsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Page from '../PageList/Page';
  4. import loggerFactory from '~/utils/logger';
  5. const logger = loggerFactory('growi:searchResultList');
  6. class SearchResultList extends React.Component {
  7. render() {
  8. return this.props.pages.map((page) => {
  9. // Add prefix 'id_' in pageId, because scrollspy of bootstrap doesn't work when the first letter of id attr of target component is numeral.
  10. const pageId = `#${page._id}`;
  11. return (
  12. <li key={page._id} className="nav-item page-list-li w-100 m-0 border-bottom">
  13. <a
  14. className="nav-link page-list-link d-flex align-items-baseline"
  15. href={pageId}
  16. onClick={() => {
  17. try {
  18. if (this.props.onClickInvoked == null) { throw new Error('onClickInvoked is null') }
  19. this.props.onClickInvoked(page._id);
  20. }
  21. catch (error) {
  22. logger.error(error);
  23. }
  24. }}
  25. >
  26. <div className="form-check my-auto">
  27. <input className="form-check-input my-auto" type="checkbox" value="" id="flexCheckDefault" />
  28. </div>
  29. {/* TODO: remove dummy snippet and adjust style */}
  30. <div className="d-block">
  31. <Page page={page} noLink />
  32. <div className="border-gray mt-5">{page.snippet}</div>
  33. </div>
  34. <div className="ml-auto d-flex">
  35. {this.props.deletionMode && (
  36. <div className="custom-control custom-checkbox custom-checkbox-danger">
  37. <input
  38. type="checkbox"
  39. id={`page-delete-check-${page._id}`}
  40. className="custom-control-input search-result-list-delete-checkbox"
  41. value={pageId}
  42. checked={this.props.selectedPages.has(page)}
  43. onChange={() => {
  44. try {
  45. if (this.props.onChangeInvoked == null) { throw new Error('onChnageInvoked is null') }
  46. return this.props.onChangeInvoked(page);
  47. }
  48. catch (error) {
  49. logger.error(error);
  50. }
  51. }}
  52. />
  53. <label className="custom-control-label" htmlFor={`page-delete-check-${page._id}`}></label>
  54. </div>
  55. )}
  56. <div className="page-list-option">
  57. <button
  58. type="button"
  59. className="btn btn-link p-0"
  60. value={page.path}
  61. onClick={(e) => {
  62. window.location.href = e.currentTarget.value;
  63. }}
  64. >
  65. <i className="icon-login" />
  66. </button>
  67. </div>
  68. </div>
  69. </a>
  70. </li>
  71. );
  72. });
  73. }
  74. }
  75. SearchResultList.propTypes = {
  76. pages: PropTypes.array.isRequired,
  77. deletionMode: PropTypes.bool.isRequired,
  78. selectedPages: PropTypes.array.isRequired,
  79. onClickInvoked: PropTypes.func,
  80. onChangeInvoked: PropTypes.func,
  81. };
  82. export default SearchResultList;