pdf-logs-viewer.jsx 3.1 KB

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