pdf-preview-error.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import PropTypes from 'prop-types'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import { memo, useCallback } from 'react'
  4. import { Button } from 'react-bootstrap'
  5. import PdfLogEntry from './pdf-log-entry'
  6. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  7. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  8. function PdfPreviewError({ error }) {
  9. const { t } = useTranslation()
  10. const { startCompile } = useCompileContext()
  11. switch (error) {
  12. case 'rendering-error-expected':
  13. return (
  14. <PdfLogEntry
  15. headerTitle={t('pdf_rendering_error')}
  16. formattedContent={
  17. <>
  18. <Trans i18nKey="something_went_wrong_rendering_pdf_expected">
  19. <Button
  20. bsSize="xs"
  21. bsStyle="info"
  22. onClick={() => startCompile()}
  23. />
  24. </Trans>
  25. <br />
  26. <br />
  27. <Trans i18nKey="last_resort_trouble_shooting_guide">
  28. {
  29. // eslint-disable-next-line jsx-a11y/anchor-has-content
  30. <a
  31. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  32. target="_blank"
  33. />
  34. }
  35. </Trans>
  36. </>
  37. }
  38. level="warning"
  39. />
  40. )
  41. case 'rendering-error':
  42. return (
  43. <ErrorLogEntry title={t('pdf_rendering_error')}>
  44. {t('something_went_wrong_rendering_pdf')}
  45. &nbsp;
  46. <Trans
  47. i18nKey="try_recompile_project_or_troubleshoot"
  48. components={[
  49. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  50. <a href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems" />,
  51. ]}
  52. />
  53. </ErrorLogEntry>
  54. )
  55. case 'clsi-maintenance':
  56. return (
  57. <ErrorLogEntry title={t('server_error')}>
  58. {t('clsi_maintenance')}
  59. </ErrorLogEntry>
  60. )
  61. case 'clsi-unavailable':
  62. return (
  63. <ErrorLogEntry title={t('server_error')}>
  64. {t('clsi_unavailable')}
  65. </ErrorLogEntry>
  66. )
  67. case 'too-recently-compiled':
  68. return (
  69. <ErrorLogEntry title={t('server_error')}>
  70. {t('too_recently_compiled')}
  71. </ErrorLogEntry>
  72. )
  73. case 'terminated':
  74. return (
  75. <ErrorLogEntry title={t('terminated')}>
  76. {t('compile_terminated_by_user')}
  77. </ErrorLogEntry>
  78. )
  79. case 'rate-limited':
  80. return (
  81. <ErrorLogEntry title={t('pdf_compile_rate_limit_hit')}>
  82. {t('project_flagged_too_many_compiles')}
  83. </ErrorLogEntry>
  84. )
  85. case 'compile-in-progress':
  86. return (
  87. <ErrorLogEntry title={t('pdf_compile_in_progress_error')}>
  88. {t('pdf_compile_try_again')}
  89. </ErrorLogEntry>
  90. )
  91. case 'auto-compile-disabled':
  92. return (
  93. <ErrorLogEntry title={t('autocompile_disabled')}>
  94. {t('autocompile_disabled_reason')}
  95. </ErrorLogEntry>
  96. )
  97. case 'project-too-large':
  98. return (
  99. <ErrorLogEntry title={t('project_too_large')}>
  100. {t('project_too_much_editable_text')}
  101. </ErrorLogEntry>
  102. )
  103. case 'timedout':
  104. return <TimedOutLogEntry />
  105. case 'failure':
  106. return (
  107. <ErrorLogEntry title={t('no_pdf_error_title')}>
  108. {t('no_pdf_error_explanation')}
  109. <ul className="log-entry-formatted-content-list">
  110. <li>{t('no_pdf_error_reason_unrecoverable_error')}</li>
  111. <li>
  112. <Trans
  113. i18nKey="no_pdf_error_reason_no_content"
  114. components={{ code: <code /> }}
  115. />
  116. </li>
  117. <li>
  118. <Trans
  119. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  120. components={{ code: <code /> }}
  121. />
  122. </li>
  123. </ul>
  124. </ErrorLogEntry>
  125. )
  126. case 'clear-cache':
  127. return (
  128. <ErrorLogEntry title={t('server_error')}>
  129. {t('somthing_went_wrong_compiling')}
  130. </ErrorLogEntry>
  131. )
  132. case 'pdf-viewer-loading-error':
  133. return (
  134. <ErrorLogEntry title={t('pdf_rendering_error')}>
  135. <Trans
  136. i18nKey="something_went_wrong_loading_pdf_viewer"
  137. components={[
  138. <strong key="strong-" />,
  139. // eslint-disable-next-line jsx-a11y/anchor-has-content
  140. <a
  141. key="learn-link"
  142. target="_blank"
  143. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  144. />,
  145. // eslint-disable-next-line jsx-a11y/anchor-has-content
  146. <a key="contact-link" target="_blank" href="/contact" />,
  147. ]}
  148. />
  149. </ErrorLogEntry>
  150. )
  151. case 'validation-problems':
  152. return null // handled elsewhere
  153. case 'error':
  154. default:
  155. return (
  156. <ErrorLogEntry title={t('server_error')}>
  157. {t('somthing_went_wrong_compiling')}
  158. </ErrorLogEntry>
  159. )
  160. }
  161. }
  162. PdfPreviewError.propTypes = {
  163. error: PropTypes.string.isRequired,
  164. }
  165. export default memo(PdfPreviewError)
  166. function ErrorLogEntry({ title, headerIcon, children }) {
  167. const { t } = useTranslation()
  168. return (
  169. <PdfLogEntry
  170. headerTitle={title}
  171. headerIcon={headerIcon}
  172. formattedContent={children}
  173. entryAriaLabel={t('compile_error_entry_description')}
  174. level="error"
  175. />
  176. )
  177. }
  178. ErrorLogEntry.propTypes = {
  179. title: PropTypes.string.isRequired,
  180. headerIcon: PropTypes.element,
  181. children: PropTypes.any.isRequired,
  182. }
  183. function TimedOutLogEntry() {
  184. const { t } = useTranslation()
  185. const { enableStopOnFirstError } = useStopOnFirstError({
  186. eventSource: 'timeout',
  187. })
  188. const { startCompile, lastCompileOptions, setAnimateCompileDropdownArrow } =
  189. useCompileContext()
  190. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  191. enableStopOnFirstError()
  192. startCompile({ stopOnFirstError: true })
  193. setAnimateCompileDropdownArrow(true)
  194. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  195. return (
  196. <ErrorLogEntry title={t('timedout')}>
  197. <p>{t('project_timed_out_intro')}</p>
  198. <ul>
  199. <li>
  200. <Trans
  201. i18nKey="project_timed_out_optimize_images"
  202. components={[
  203. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  204. <a href="https://www.overleaf.com/learn/how-to/Optimising_very_large_image_files" />,
  205. ]}
  206. />
  207. </li>
  208. <li>
  209. <Trans
  210. i18nKey="project_timed_out_fatal_error"
  211. components={[
  212. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  213. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F#Fatal_compile_errors_blocking_the_compilation" />,
  214. ]}
  215. />
  216. {!lastCompileOptions.stopOnFirstError && (
  217. <>
  218. {' '}
  219. <Trans
  220. i18nKey="project_timed_out_enable_stop_on_first_error"
  221. components={[
  222. // eslint-disable-next-line react/jsx-key
  223. <Button
  224. bsSize="xs"
  225. bsStyle="info"
  226. onClick={handleEnableStopOnFirstErrorClick}
  227. />,
  228. ]}
  229. />{' '}
  230. </>
  231. )}
  232. </li>
  233. </ul>
  234. <p>
  235. <Trans
  236. i18nKey="project_timed_out_learn_more"
  237. components={[
  238. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  239. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F" />,
  240. ]}
  241. />
  242. </p>
  243. </ErrorLogEntry>
  244. )
  245. }
  246. TimedOutLogEntry.propTypes = {}