pdf-logs-viewer.jsx 2.8 KB

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