pdf-logs-entries.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. autoExpand={index === 0}
  43. index={index}
  44. id={logEntry.key}
  45. logEntry={logEntry}
  46. ruleId={logEntry.ruleId}
  47. headerTitle={logEntry.messageComponent ?? logEntry.message}
  48. rawContent={logEntry.content}
  49. logType={logEntry.type}
  50. level={logEntry.level}
  51. contentDetails={logEntry.contentDetails}
  52. entryAriaLabel={t('log_entry_description', {
  53. level: logEntry.level,
  54. })}
  55. sourceLocation={{
  56. file: logEntry.file,
  57. line: logEntry.line,
  58. column: logEntry.column,
  59. }}
  60. onSourceLocationClick={syncToEntry}
  61. />
  62. ))}
  63. </>
  64. )
  65. }
  66. export default memo(PdfLogsEntries)