pdf-log-entry.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { memo } from 'react'
  2. import PreviewLogEntryHeader from '../../preview/components/preview-log-entry-header'
  3. import PdfLogEntryContent from './pdf-log-entry-content'
  4. import HumanReadableLogsHints from '../../../ide/human-readable-logs/HumanReadableLogsHints'
  5. import getMeta from '@/utils/meta'
  6. import { ErrorLevel, LogEntry, SourceLocation } from '../util/types'
  7. import NewLogEntry from '@/features/pdf-preview/components/log-entry'
  8. import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
  9. import useHandleLogEntryClick from '../hooks/use-handle-log-entry-click'
  10. function PdfLogEntry({
  11. autoExpand,
  12. ruleId,
  13. headerTitle,
  14. headerIcon,
  15. rawContent,
  16. logType,
  17. formattedContent,
  18. extraInfoURL,
  19. level,
  20. sourceLocation,
  21. showSourceLocationLink = true,
  22. entryAriaLabel = undefined,
  23. contentDetails,
  24. onSourceLocationClick,
  25. index,
  26. logEntry,
  27. id,
  28. }: {
  29. headerTitle: string | React.ReactNode
  30. level: ErrorLevel
  31. autoExpand?: boolean
  32. ruleId?: string
  33. headerIcon?: React.ReactElement
  34. rawContent?: string
  35. logType?: string
  36. formattedContent?: React.ReactNode
  37. extraInfoURL?: string | null
  38. sourceLocation?: SourceLocation
  39. showSourceLocationLink?: boolean
  40. entryAriaLabel?: string
  41. contentDetails?: string[]
  42. onSourceLocationClick?: (sourceLocation: SourceLocation) => void
  43. index?: number
  44. logEntry?: LogEntry
  45. id?: string
  46. }) {
  47. const showAiErrorAssistant = getMeta('ol-showAiFeatures')
  48. if (ruleId && HumanReadableLogsHints[ruleId]) {
  49. const hint = HumanReadableLogsHints[ruleId]
  50. formattedContent = hint.formattedContent(contentDetails)
  51. extraInfoURL = hint.extraInfoURL
  52. }
  53. const handleLogEntryLinkClick = useHandleLogEntryClick({
  54. level,
  55. ruleId,
  56. sourceLocation,
  57. onSourceLocationClick,
  58. })
  59. const newEditor = useIsNewEditorEnabled()
  60. if (newEditor) {
  61. return (
  62. <NewLogEntry
  63. autoExpand={autoExpand}
  64. index={index}
  65. id={id}
  66. logEntry={logEntry}
  67. ruleId={ruleId}
  68. headerTitle={headerTitle}
  69. formattedContent={formattedContent}
  70. rawContent={rawContent}
  71. logType={logType}
  72. level={level}
  73. contentDetails={contentDetails}
  74. entryAriaLabel={entryAriaLabel}
  75. sourceLocation={sourceLocation}
  76. onSourceLocationClick={handleLogEntryLinkClick}
  77. showSourceLocationLink={showSourceLocationLink}
  78. extraInfoURL={extraInfoURL}
  79. />
  80. )
  81. }
  82. return (
  83. <div
  84. className="log-entry"
  85. aria-label={entryAriaLabel}
  86. data-ruleid={ruleId}
  87. data-log-entry-id={id}
  88. >
  89. <PreviewLogEntryHeader
  90. level={level}
  91. sourceLocation={sourceLocation}
  92. headerTitle={headerTitle}
  93. headerIcon={headerIcon}
  94. logType={logType}
  95. showSourceLocationLink={showSourceLocationLink}
  96. onSourceLocationClick={handleLogEntryLinkClick}
  97. />
  98. {(rawContent || formattedContent || showAiErrorAssistant) && (
  99. <PdfLogEntryContent
  100. rawContent={rawContent}
  101. formattedContent={formattedContent}
  102. extraInfoURL={extraInfoURL}
  103. index={index}
  104. logEntry={logEntry}
  105. />
  106. )}
  107. </div>
  108. )
  109. }
  110. export default memo(PdfLogEntry)