pdf-logs-viewer.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. function PdfLogsViewer() {
  18. const {
  19. codeCheckFailed,
  20. error,
  21. hasShortCompileTimeout,
  22. logEntries,
  23. rawLog,
  24. validationIssues,
  25. showLogs,
  26. stoppedOnFirstError,
  27. } = useCompileContext()
  28. const { loadingError } = usePdfPreviewContext()
  29. const { t } = useTranslation()
  30. return (
  31. <div
  32. className={classnames('logs-pane', {
  33. hidden: !showLogs && !loadingError,
  34. })}
  35. >
  36. <div className="logs-pane-content">
  37. {codeCheckFailed && <PdfCodeCheckFailedNotice />}
  38. {stoppedOnFirstError && <StopOnFirstErrorPrompt />}
  39. {loadingError && <PdfPreviewError error="pdf-viewer-loading-error" />}
  40. {hasShortCompileTimeout && error === 'timedout' ? (
  41. <TimeoutUpgradePromptNew />
  42. ) : (
  43. <>{error && <PdfPreviewError error={error} />}</>
  44. )}
  45. {validationIssues &&
  46. Object.entries(validationIssues).map(([name, issue]) => (
  47. <PdfValidationIssue key={name} name={name} issue={issue} />
  48. ))}
  49. {logEntries?.all && (
  50. <PdfLogsEntries
  51. entries={logEntries.all}
  52. hasErrors={logEntries.errors.length > 0}
  53. />
  54. )}
  55. {rawLog && (
  56. <PdfLogEntry
  57. headerTitle={t('raw_logs')}
  58. rawContent={rawLog}
  59. entryAriaLabel={t('raw_logs_description')}
  60. level="raw"
  61. />
  62. )}
  63. <div className="logs-pane-actions">
  64. <PdfClearCacheButton />
  65. <PdfDownloadFilesButton />
  66. </div>
  67. </div>
  68. </div>
  69. )
  70. }
  71. export default withErrorBoundary(memo(PdfLogsViewer), () => (
  72. <PdfPreviewErrorBoundaryFallback type="logs" />
  73. ))