preview-logs-pane-max-entries.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { useCallback } from 'react'
  2. import PropTypes from 'prop-types'
  3. import { Trans, useTranslation } from 'react-i18next'
  4. import { Button } from 'react-bootstrap'
  5. import PreviewLogEntryHeader from './preview-log-entry-header'
  6. import Icon from '../../../shared/components/icon'
  7. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  8. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  9. function PreviewLogsPaneMaxEntries({ totalEntries, entriesShown, hasErrors }) {
  10. const { t } = useTranslation()
  11. const { startCompile, stoppedOnFirstError, setAnimateCompileDropdownArrow } =
  12. useCompileContext()
  13. const { enableStopOnFirstError } = useStopOnFirstError({
  14. eventSource: 'too-many-logs',
  15. })
  16. const title = t('log_entry_maximum_entries_title', {
  17. total: totalEntries,
  18. displayed: entriesShown,
  19. })
  20. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  21. enableStopOnFirstError()
  22. startCompile({ stopOnFirstError: true })
  23. setAnimateCompileDropdownArrow(true)
  24. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  25. return (
  26. <div className="log-entry" aria-label={t('log_entry_maximum_entries')}>
  27. <PreviewLogEntryHeader level="raw" headerTitle={title} />
  28. <div className="log-entry-content">
  29. <div className="log-entry-formatted-content">
  30. {hasErrors && !stoppedOnFirstError ? (
  31. <>
  32. <p>
  33. <Icon type="lightbulb-o" />
  34. &nbsp;
  35. <strong>{t('tip')}: </strong>
  36. <Trans
  37. i18nKey="log_entry_maximum_entries_enable_stop_on_first_error"
  38. components={[
  39. <Button
  40. key="enable-stop-on-first-error"
  41. bsSize="xs"
  42. bsStyle="info"
  43. onClick={handleEnableStopOnFirstErrorClick}
  44. />,
  45. // eslint-disable-next-line jsx-a11y/anchor-has-content
  46. <a
  47. key="learn-more"
  48. href="https://www.overleaf.com/learn/latex/Questions/Tips_and_Tricks_for_Troubleshooting_LaTeX"
  49. />,
  50. ]}
  51. />{' '}
  52. </p>
  53. <p>{t('log_entry_maximum_entries_see_full_logs')}</p>
  54. </>
  55. ) : (
  56. <p>
  57. <Icon type="lightbulb-o" />
  58. &nbsp;
  59. <strong>{t('tip')}: </strong>
  60. {t('log_entry_maximum_entries_see_full_logs')}
  61. </p>
  62. )}
  63. </div>
  64. </div>
  65. </div>
  66. )
  67. }
  68. PreviewLogsPaneMaxEntries.propTypes = {
  69. totalEntries: PropTypes.number,
  70. entriesShown: PropTypes.number,
  71. hasErrors: PropTypes.bool,
  72. }
  73. export default PreviewLogsPaneMaxEntries