pdf-log-entry.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. import HumanReadableLogsHints from '../../../ide/human-readable-logs/HumanReadableLogsHints'
  7. function PdfLogEntry({
  8. ruleId,
  9. headerTitle,
  10. headerIcon,
  11. rawContent,
  12. logType,
  13. formattedContent,
  14. extraInfoURL,
  15. level,
  16. sourceLocation,
  17. showSourceLocationLink = true,
  18. showCloseButton = false,
  19. entryAriaLabel = null,
  20. customClass,
  21. onSourceLocationClick,
  22. onClose,
  23. }) {
  24. if (ruleId && HumanReadableLogsHints[ruleId]) {
  25. const hint = HumanReadableLogsHints[ruleId]
  26. formattedContent = hint.formattedContent
  27. extraInfoURL = hint.extraInfoURL
  28. }
  29. const handleLogEntryLinkClick = useCallback(
  30. event => {
  31. event.preventDefault()
  32. onSourceLocationClick(sourceLocation)
  33. },
  34. [onSourceLocationClick, sourceLocation]
  35. )
  36. return (
  37. <div
  38. className={classNames('log-entry', customClass)}
  39. aria-label={entryAriaLabel}
  40. >
  41. <PreviewLogEntryHeader
  42. level={level}
  43. sourceLocation={sourceLocation}
  44. headerTitle={headerTitle}
  45. headerIcon={headerIcon}
  46. logType={logType}
  47. showSourceLocationLink={showSourceLocationLink}
  48. onSourceLocationClick={handleLogEntryLinkClick}
  49. showCloseButton={showCloseButton}
  50. onClose={onClose}
  51. />
  52. {(rawContent || formattedContent) && (
  53. <PdfLogEntryContent
  54. rawContent={rawContent}
  55. formattedContent={formattedContent}
  56. extraInfoURL={extraInfoURL}
  57. />
  58. )}
  59. </div>
  60. )
  61. }
  62. PdfLogEntry.propTypes = {
  63. ruleId: PropTypes.string,
  64. sourceLocation: PreviewLogEntryHeader.propTypes.sourceLocation,
  65. headerTitle: PropTypes.string,
  66. headerIcon: PropTypes.element,
  67. rawContent: PropTypes.string,
  68. logType: PropTypes.string,
  69. formattedContent: PropTypes.node,
  70. extraInfoURL: PropTypes.string,
  71. level: PropTypes.oneOf([
  72. 'error',
  73. 'warning',
  74. 'info',
  75. 'typesetting',
  76. 'raw',
  77. 'success',
  78. ]).isRequired,
  79. customClass: PropTypes.string,
  80. showSourceLocationLink: PropTypes.bool,
  81. showCloseButton: PropTypes.bool,
  82. entryAriaLabel: PropTypes.string,
  83. onSourceLocationClick: PropTypes.func,
  84. onClose: PropTypes.func,
  85. }
  86. export default memo(PdfLogEntry)