pdf-logs-viewer.js 2.3 KB

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