pdf-logs-viewer.tsx 3.5 KB

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