pdf-logs-entries.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { memo } from 'react'
  2. import PropTypes from 'prop-types'
  3. import { useTranslation } from 'react-i18next'
  4. import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries'
  5. import PdfLogEntry from './pdf-log-entry'
  6. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  7. const LOG_PREVIEW_LIMIT = 100
  8. function PdfLogsEntries({ entries, hasErrors }) {
  9. const { t } = useTranslation()
  10. const { syncToEntry } = useDetachCompileContext()
  11. const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT)
  12. return (
  13. <>
  14. {entries.length > LOG_PREVIEW_LIMIT && (
  15. <PreviewLogsPaneMaxEntries
  16. totalEntries={entries.length}
  17. entriesShown={LOG_PREVIEW_LIMIT}
  18. hasErrors={hasErrors}
  19. />
  20. )}
  21. {logEntries.map(logEntry => (
  22. <PdfLogEntry
  23. key={logEntry.key}
  24. ruleId={logEntry.ruleId}
  25. headerTitle={logEntry.messageComponent ?? logEntry.message}
  26. rawContent={logEntry.content}
  27. logType={logEntry.type}
  28. level={logEntry.level}
  29. contentDetails={logEntry.contentDetails}
  30. entryAriaLabel={t('log_entry_description', {
  31. level: logEntry.level,
  32. })}
  33. sourceLocation={{
  34. file: logEntry.file,
  35. line: logEntry.line,
  36. column: logEntry.column,
  37. }}
  38. onSourceLocationClick={syncToEntry}
  39. />
  40. ))}
  41. </>
  42. )
  43. }
  44. PdfLogsEntries.propTypes = {
  45. entries: PropTypes.arrayOf(PropTypes.object),
  46. hasErrors: PropTypes.bool,
  47. }
  48. export default memo(PdfLogsEntries)