pdf-compile-button.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { Dropdown, MenuItem } from 'react-bootstrap'
  2. import Icon from '../../../shared/components/icon'
  3. import ControlledDropdown from '../../../shared/components/controlled-dropdown'
  4. import { useTranslation } from 'react-i18next'
  5. import { memo } from 'react'
  6. import classnames from 'classnames'
  7. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  8. import PdfCompileButtonInner from './pdf-compile-button-inner'
  9. import getMeta from '../../../utils/meta'
  10. function PdfCompileButton() {
  11. const {
  12. autoCompile,
  13. compiling,
  14. draft,
  15. hasChanges,
  16. setAutoCompile,
  17. setDraft,
  18. setStopOnFirstError,
  19. setStopOnValidationError,
  20. stopOnFirstError,
  21. stopOnValidationError,
  22. startCompile,
  23. stopCompile,
  24. recompileFromScratch,
  25. } = useCompileContext()
  26. const { t } = useTranslation()
  27. const showStopOnFirstError = getMeta('ol-showStopOnFirstError')
  28. return (
  29. <ControlledDropdown
  30. className={classnames({
  31. 'toolbar-item': true,
  32. 'btn-recompile-group': true,
  33. 'btn-recompile-group-has-changes': hasChanges,
  34. })}
  35. id="pdf-recompile-dropdown"
  36. >
  37. <PdfCompileButtonInner
  38. startCompile={startCompile}
  39. compiling={compiling}
  40. />
  41. <Dropdown.Toggle
  42. aria-label={t('toggle_compile_options_menu')}
  43. className="btn-recompile"
  44. bsStyle="success"
  45. />
  46. <Dropdown.Menu>
  47. <MenuItem header>{t('auto_compile')}</MenuItem>
  48. <MenuItem onSelect={() => setAutoCompile(true)}>
  49. <Icon type={autoCompile ? 'check' : ''} fw />
  50. {t('on')}
  51. </MenuItem>
  52. <MenuItem onSelect={() => setAutoCompile(false)}>
  53. <Icon type={!autoCompile ? 'check' : ''} fw />
  54. {t('off')}
  55. </MenuItem>
  56. <MenuItem header>{t('compile_mode')}</MenuItem>
  57. <MenuItem onSelect={() => setDraft(false)}>
  58. <Icon type={!draft ? 'check' : ''} fw />
  59. {t('normal')}
  60. </MenuItem>
  61. <MenuItem onSelect={() => setDraft(true)}>
  62. <Icon type={draft ? 'check' : ''} fw />
  63. {t('fast')} <span className="subdued">[draft]</span>
  64. </MenuItem>
  65. <MenuItem header>Syntax Checks</MenuItem>
  66. <MenuItem onSelect={() => setStopOnValidationError(true)}>
  67. <Icon type={stopOnValidationError ? 'check' : ''} fw />
  68. {t('stop_on_validation_error')}
  69. </MenuItem>
  70. <MenuItem onSelect={() => setStopOnValidationError(false)}>
  71. <Icon type={!stopOnValidationError ? 'check' : ''} fw />
  72. {t('ignore_validation_errors')}
  73. </MenuItem>
  74. {showStopOnFirstError && (
  75. <MenuItem header>{t('compile_error_handling')}</MenuItem>
  76. )}
  77. {showStopOnFirstError && (
  78. <MenuItem onSelect={() => setStopOnFirstError(true)}>
  79. <Icon type={stopOnFirstError ? 'check' : ''} fw />
  80. {t('stop_on_first_error')}
  81. </MenuItem>
  82. )}
  83. {showStopOnFirstError && (
  84. <MenuItem onSelect={() => setStopOnFirstError(false)}>
  85. <Icon type={!stopOnFirstError ? 'check' : ''} fw />
  86. {t('try_to_compile_despite_errors')}
  87. </MenuItem>
  88. )}
  89. <MenuItem divider />
  90. <MenuItem
  91. onSelect={() => stopCompile()}
  92. disabled={!compiling}
  93. aria-disabled={!compiling}
  94. >
  95. {t('stop_compile')}
  96. </MenuItem>
  97. <MenuItem
  98. onSelect={() => recompileFromScratch()}
  99. disabled={compiling}
  100. aria-disabled={compiling}
  101. >
  102. {t('recompile_from_scratch')}
  103. </MenuItem>
  104. </Dropdown.Menu>
  105. </ControlledDropdown>
  106. )
  107. }
  108. export default memo(PdfCompileButton)