pdf-logs-entries.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { ElementType, memo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries'
  4. import PdfLogEntry from './pdf-log-entry'
  5. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  6. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  7. import { LogEntry } from '../util/types'
  8. const LOG_PREVIEW_LIMIT = 100
  9. const pdfLogEntriesComponents = importOverleafModules(
  10. 'pdfLogEntriesComponents'
  11. ) as {
  12. import: { default: ElementType }
  13. path: string
  14. }[]
  15. function PdfLogsEntries({
  16. entries,
  17. hasErrors,
  18. }: {
  19. entries: LogEntry[]
  20. hasErrors?: boolean
  21. }) {
  22. const { t } = useTranslation()
  23. const { syncToEntry } = useDetachCompileContext()
  24. const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT)
  25. return (
  26. <>
  27. {entries.length > LOG_PREVIEW_LIMIT && (
  28. <PreviewLogsPaneMaxEntries
  29. totalEntries={entries.length}
  30. entriesShown={LOG_PREVIEW_LIMIT}
  31. hasErrors={hasErrors}
  32. />
  33. )}
  34. {pdfLogEntriesComponents.map(
  35. ({ import: { default: Component }, path }) => (
  36. <Component key={path} />
  37. )
  38. )}
  39. {logEntries.map((logEntry, index) => (
  40. <PdfLogEntry
  41. key={logEntry.key}
  42. index={index}
  43. id={logEntry.key}
  44. logEntry={logEntry}
  45. ruleId={logEntry.ruleId}
  46. headerTitle={logEntry.messageComponent ?? logEntry.message}
  47. rawContent={logEntry.content}
  48. logType={logEntry.type}
  49. level={logEntry.level}
  50. contentDetails={logEntry.contentDetails}
  51. entryAriaLabel={t('log_entry_description', {
  52. level: logEntry.level,
  53. })}
  54. sourceLocation={{
  55. file: logEntry.file,
  56. line: logEntry.line,
  57. column: logEntry.column,
  58. }}
  59. onSourceLocationClick={syncToEntry}
  60. />
  61. ))}
  62. </>
  63. )
  64. }
  65. export default memo(PdfLogsEntries)