pdf-log-entry.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import PropTypes from 'prop-types'
  2. import classNames from 'classnames'
  3. import { memo, useCallback } from 'react'
  4. import PreviewLogEntryHeader from '../../preview/components/preview-log-entry-header'
  5. import PdfLogEntryContent from './pdf-log-entry-content'
  6. function PdfLogEntry({
  7. headerTitle,
  8. headerIcon,
  9. rawContent,
  10. logType,
  11. formattedContent,
  12. extraInfoURL,
  13. level,
  14. sourceLocation,
  15. showSourceLocationLink = true,
  16. showCloseButton = false,
  17. entryAriaLabel = null,
  18. customClass,
  19. onSourceLocationClick,
  20. onClose,
  21. }) {
  22. const handleLogEntryLinkClick = useCallback(
  23. event => {
  24. event.preventDefault()
  25. onSourceLocationClick(sourceLocation)
  26. },
  27. [onSourceLocationClick, sourceLocation]
  28. )
  29. return (
  30. <div
  31. className={classNames('log-entry', customClass)}
  32. aria-label={entryAriaLabel}
  33. >
  34. <PreviewLogEntryHeader
  35. level={level}
  36. sourceLocation={sourceLocation}
  37. headerTitle={headerTitle}
  38. headerIcon={headerIcon}
  39. logType={logType}
  40. showSourceLocationLink={showSourceLocationLink}
  41. onSourceLocationClick={handleLogEntryLinkClick}
  42. showCloseButton={showCloseButton}
  43. onClose={onClose}
  44. />
  45. {(rawContent || formattedContent) && (
  46. <PdfLogEntryContent
  47. rawContent={rawContent}
  48. formattedContent={formattedContent}
  49. extraInfoURL={extraInfoURL}
  50. />
  51. )}
  52. </div>
  53. )
  54. }
  55. PdfLogEntry.propTypes = {
  56. sourceLocation: PreviewLogEntryHeader.propTypes.sourceLocation,
  57. headerTitle: PropTypes.string,
  58. headerIcon: PropTypes.element,
  59. rawContent: PropTypes.string,
  60. logType: PropTypes.string,
  61. formattedContent: PropTypes.node,
  62. extraInfoURL: PropTypes.string,
  63. level: PropTypes.oneOf(['error', 'warning', 'typesetting', 'raw', 'success'])
  64. .isRequired,
  65. customClass: PropTypes.string,
  66. showSourceLocationLink: PropTypes.bool,
  67. showCloseButton: PropTypes.bool,
  68. entryAriaLabel: PropTypes.string,
  69. onSourceLocationClick: PropTypes.func,
  70. onClose: PropTypes.func,
  71. }
  72. export default memo(PdfLogEntry)