pdf-logs-entries.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { memo, useCallback } 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. const LOG_PREVIEW_LIMIT = 100
  7. function PdfLogsEntries({ entries }) {
  8. const { t } = useTranslation()
  9. const syncToEntry = useCallback(entry => {
  10. window.dispatchEvent(
  11. new CustomEvent('synctex:sync-to-entry', {
  12. detail: entry,
  13. })
  14. )
  15. }, [])
  16. const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT)
  17. return (
  18. <>
  19. {entries.length > LOG_PREVIEW_LIMIT && (
  20. <PreviewLogsPaneMaxEntries
  21. totalEntries={entries.length}
  22. entriesShown={LOG_PREVIEW_LIMIT}
  23. />
  24. )}
  25. {logEntries.map(logEntry => (
  26. <PdfLogEntry
  27. key={logEntry.key}
  28. headerTitle={logEntry.message}
  29. rawContent={logEntry.content}
  30. logType={logEntry.type}
  31. formattedContent={logEntry.humanReadableHintComponent}
  32. extraInfoURL={logEntry.extraInfoURL}
  33. level={logEntry.level}
  34. entryAriaLabel={t('log_entry_description', {
  35. level: logEntry.level,
  36. })}
  37. sourceLocation={{
  38. file: logEntry.file,
  39. line: logEntry.line,
  40. column: logEntry.column,
  41. }}
  42. onSourceLocationClick={syncToEntry}
  43. />
  44. ))}
  45. </>
  46. )
  47. }
  48. PdfLogsEntries.propTypes = {
  49. entries: PropTypes.arrayOf(PropTypes.object),
  50. }
  51. export default memo(PdfLogsEntries)