pdf-log-entry.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { memo } from 'react'
  2. import HumanReadableLogsHints from '../../../ide/human-readable-logs/HumanReadableLogsHints'
  3. import { ErrorLevel, LogEntry, SourceLocation } from '../util/types'
  4. import NewLogEntry from '@/features/pdf-preview/components/log-entry'
  5. import useHandleLogEntryClick from '../hooks/use-handle-log-entry-click'
  6. function PdfLogEntry({
  7. autoExpand,
  8. ruleId,
  9. headerTitle,
  10. rawContent,
  11. logType,
  12. formattedContent,
  13. extraInfoURL,
  14. level,
  15. sourceLocation,
  16. showSourceLocationLink = true,
  17. entryAriaLabel = undefined,
  18. contentDetails,
  19. onSourceLocationClick,
  20. index,
  21. logEntry,
  22. id,
  23. }: {
  24. headerTitle: string | React.ReactNode
  25. level: ErrorLevel
  26. autoExpand?: boolean
  27. ruleId?: string
  28. rawContent?: string
  29. logType?: string
  30. formattedContent?: React.ReactNode
  31. extraInfoURL?: string | null
  32. sourceLocation?: SourceLocation
  33. showSourceLocationLink?: boolean
  34. entryAriaLabel?: string
  35. contentDetails?: string[]
  36. onSourceLocationClick?: (sourceLocation: SourceLocation) => void
  37. index?: number
  38. logEntry?: LogEntry
  39. id?: string
  40. }) {
  41. if (ruleId && HumanReadableLogsHints[ruleId]) {
  42. const hint = HumanReadableLogsHints[ruleId]
  43. formattedContent = hint.formattedContent(contentDetails)
  44. extraInfoURL = hint.extraInfoURL
  45. }
  46. const handleLogEntryLinkClick = useHandleLogEntryClick({
  47. level,
  48. ruleId,
  49. sourceLocation,
  50. onSourceLocationClick,
  51. })
  52. return (
  53. <NewLogEntry
  54. autoExpand={autoExpand}
  55. index={index}
  56. id={id}
  57. logEntry={logEntry}
  58. ruleId={ruleId}
  59. headerTitle={headerTitle}
  60. formattedContent={formattedContent}
  61. rawContent={rawContent}
  62. logType={logType}
  63. level={level}
  64. contentDetails={contentDetails}
  65. entryAriaLabel={entryAriaLabel}
  66. sourceLocation={sourceLocation}
  67. onSourceLocationClick={handleLogEntryLinkClick}
  68. showSourceLocationLink={showSourceLocationLink}
  69. extraInfoURL={extraInfoURL}
  70. />
  71. )
  72. }
  73. export default memo(PdfLogEntry)