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

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