pdf-logs-viewer.tsx 2.8 KB

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