pdf-log-entry.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. import { sendMB } from '@/infrastructure/event-tracking'
  8. import getMeta from '@/utils/meta'
  9. function PdfLogEntry({
  10. ruleId,
  11. headerTitle,
  12. headerIcon,
  13. rawContent,
  14. logType,
  15. formattedContent,
  16. extraInfoURL,
  17. level,
  18. sourceLocation,
  19. showSourceLocationLink = true,
  20. showCloseButton = false,
  21. entryAriaLabel = null,
  22. customClass,
  23. contentDetails,
  24. onSourceLocationClick,
  25. onClose,
  26. index,
  27. logEntry,
  28. id,
  29. }) {
  30. const showAiErrorAssistant = getMeta('ol-showAiErrorAssistant')
  31. if (ruleId && HumanReadableLogsHints[ruleId]) {
  32. const hint = HumanReadableLogsHints[ruleId]
  33. formattedContent = hint.formattedContent(contentDetails)
  34. extraInfoURL = hint.extraInfoURL
  35. }
  36. const handleLogEntryLinkClick = useCallback(
  37. event => {
  38. event.preventDefault()
  39. onSourceLocationClick(sourceLocation)
  40. const parts = sourceLocation?.file?.split('.')
  41. const extension = parts?.length > 1 ? parts.pop() : ''
  42. sendMB('log-entry-link-click', { level, ruleId, extension })
  43. },
  44. [level, onSourceLocationClick, ruleId, sourceLocation]
  45. )
  46. return (
  47. <div
  48. className={classNames('log-entry', customClass)}
  49. aria-label={entryAriaLabel}
  50. data-ruleid={ruleId}
  51. data-log-entry-id={id}
  52. >
  53. <PreviewLogEntryHeader
  54. level={level}
  55. sourceLocation={sourceLocation}
  56. headerTitle={headerTitle}
  57. headerIcon={headerIcon}
  58. logType={logType}
  59. showSourceLocationLink={showSourceLocationLink}
  60. onSourceLocationClick={handleLogEntryLinkClick}
  61. showCloseButton={showCloseButton}
  62. onClose={onClose}
  63. />
  64. {(rawContent || formattedContent || showAiErrorAssistant) && (
  65. <PdfLogEntryContent
  66. rawContent={rawContent}
  67. formattedContent={formattedContent}
  68. extraInfoURL={extraInfoURL}
  69. index={index}
  70. logEntry={logEntry}
  71. />
  72. )}
  73. </div>
  74. )
  75. }
  76. PdfLogEntry.propTypes = {
  77. ruleId: PropTypes.string,
  78. sourceLocation: PreviewLogEntryHeader.propTypes.sourceLocation,
  79. headerTitle: PreviewLogEntryHeader.propTypes.headerTitle,
  80. headerIcon: PropTypes.element,
  81. rawContent: PropTypes.string,
  82. logType: PropTypes.string,
  83. formattedContent: PropTypes.node,
  84. extraInfoURL: PropTypes.string,
  85. level: PropTypes.oneOf([
  86. 'error',
  87. 'warning',
  88. 'info',
  89. 'typesetting',
  90. 'raw',
  91. 'success',
  92. ]).isRequired,
  93. customClass: PropTypes.string,
  94. showSourceLocationLink: PropTypes.bool,
  95. showCloseButton: PropTypes.bool,
  96. entryAriaLabel: PropTypes.string,
  97. contentDetails: PropTypes.arrayOf(PropTypes.string),
  98. onSourceLocationClick: PropTypes.func,
  99. onClose: PropTypes.func,
  100. index: PropTypes.number,
  101. logEntry: PropTypes.any,
  102. id: PropTypes.string,
  103. }
  104. export default memo(PdfLogEntry)