pdf-logs-viewer.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { useTranslation } from 'react-i18next'
  2. import { memo } from 'react'
  3. import classnames from 'classnames'
  4. import RollingBuildSelectedReminder from './rolling-build-selected-reminder'
  5. import PdfValidationIssue from './pdf-validation-issue'
  6. import StopOnFirstErrorPrompt from './stop-on-first-error-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. 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. } = useCompileContext()
  29. const { loadingError } = usePdfPreviewContext()
  30. const { compileTimeout } = getMeta('ol-compileSettings')
  31. const { t } = useTranslation()
  32. return (
  33. <div
  34. className={classnames('logs-pane', {
  35. hidden: !showLogs && !alwaysVisible && !loadingError,
  36. })}
  37. data-testid="logs-pane"
  38. >
  39. <div className="logs-pane-content">
  40. <RollingBuildSelectedReminder />
  41. {codeCheckFailed && <PdfCodeCheckFailedNotice />}
  42. {stoppedOnFirstError && <StopOnFirstErrorPrompt />}
  43. {loadingError && <PdfPreviewError error="pdf-viewer-loading-error" />}
  44. {compileTimeout < 60 && error === 'timedout' ? (
  45. <TimeoutUpgradePromptNew />
  46. ) : (
  47. <>{error && <PdfPreviewError error={error} />}</>
  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. ))