pdf-log-entry.js 2.5 KB

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