pdf-logs-viewer.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { useTranslation } from 'react-i18next'
  2. import { memo } from 'react'
  3. import classnames from 'classnames'
  4. import PdfValidationIssue from './pdf-validation-issue'
  5. import StopOnFirstErrorPrompt from './stop-on-first-error-prompt'
  6. import TimeoutUpgradePromptNew from './timeout-upgrade-prompt-new'
  7. import PdfPreviewError from './pdf-preview-error'
  8. import PdfClearCacheButton from './pdf-clear-cache-button'
  9. import PdfDownloadFilesButton from './pdf-download-files-button'
  10. import PdfLogsEntries from './pdf-logs-entries'
  11. import withErrorBoundary from '../../../infrastructure/error-boundary'
  12. import PdfPreviewErrorBoundaryFallback from './pdf-preview-error-boundary-fallback'
  13. import PdfCodeCheckFailedNotice from './pdf-code-check-failed-notice'
  14. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  15. import PdfLogEntry from './pdf-log-entry'
  16. import { usePdfPreviewContext } from '@/features/pdf-preview/components/pdf-preview-provider'
  17. import PropTypes from 'prop-types'
  18. function PdfLogsViewer({ alwaysVisible = false }) {
  19. const {
  20. codeCheckFailed,
  21. error,
  22. hasShortCompileTimeout,
  23. logEntries,
  24. rawLog,
  25. validationIssues,
  26. showLogs,
  27. stoppedOnFirstError,
  28. } = useCompileContext()
  29. const { loadingError } = usePdfPreviewContext()
  30. const { t } = useTranslation()
  31. return (
  32. <div
  33. className={classnames('logs-pane', {
  34. hidden: !showLogs && !alwaysVisible && !loadingError,
  35. })}
  36. >
  37. <div className="logs-pane-content">
  38. {codeCheckFailed && <PdfCodeCheckFailedNotice />}
  39. {stoppedOnFirstError && <StopOnFirstErrorPrompt />}
  40. {loadingError && <PdfPreviewError error="pdf-viewer-loading-error" />}
  41. {hasShortCompileTimeout && error === 'timedout' ? (
  42. <TimeoutUpgradePromptNew />
  43. ) : (
  44. <>{error && <PdfPreviewError error={error} />}</>
  45. )}
  46. {validationIssues &&
  47. Object.entries(validationIssues).map(([name, issue]) => (
  48. <PdfValidationIssue key={name} name={name} issue={issue} />
  49. ))}
  50. {logEntries?.all && (
  51. <PdfLogsEntries
  52. entries={logEntries.all}
  53. hasErrors={logEntries.errors.length > 0}
  54. />
  55. )}
  56. {rawLog && (
  57. <PdfLogEntry
  58. headerTitle={t('raw_logs')}
  59. rawContent={rawLog}
  60. entryAriaLabel={t('raw_logs_description')}
  61. level="raw"
  62. />
  63. )}
  64. <div className="logs-pane-actions">
  65. <PdfClearCacheButton />
  66. <PdfDownloadFilesButton />
  67. </div>
  68. </div>
  69. </div>
  70. )
  71. }
  72. PdfLogsViewer.propTypes = {
  73. alwaysVisible: PropTypes.bool,
  74. }
  75. export default withErrorBoundary(memo(PdfLogsViewer), () => (
  76. <PdfPreviewErrorBoundaryFallback type="logs" />
  77. ))