2020-09-28 06:51:15 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Dropdown, MenuItem } from 'react-bootstrap'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-09-29 07:08:49 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
|
|
|
function PreviewRecompileButton({
|
|
|
|
compilerState: {
|
|
|
|
isAutoCompileOn,
|
|
|
|
isCompiling,
|
|
|
|
isDraftModeOn,
|
|
|
|
isSyntaxCheckOn
|
|
|
|
},
|
|
|
|
onRecompile,
|
|
|
|
onRunSyntaxCheckNow,
|
|
|
|
onSetAutoCompile,
|
|
|
|
onSetDraftMode,
|
|
|
|
onSetSyntaxCheck
|
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
function handleSelectAutoCompileOn() {
|
|
|
|
onSetAutoCompile(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectAutoCompileOff() {
|
|
|
|
onSetAutoCompile(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectDraftModeOn() {
|
|
|
|
onSetDraftMode(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectDraftModeOff() {
|
|
|
|
onSetDraftMode(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectSyntaxCheckOn() {
|
|
|
|
onSetSyntaxCheck(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectSyntaxCheckOff() {
|
|
|
|
onSetSyntaxCheck(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown id="pdf-recompile-dropdown" className="btn-recompile-group">
|
|
|
|
<button className="btn btn-recompile" onClick={onRecompile}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type="refresh" spin={isCompiling} />
|
2020-09-28 06:51:15 -04:00
|
|
|
{isCompiling ? (
|
|
|
|
<span className="btn-recompile-label">
|
|
|
|
{t('compiling')}
|
|
|
|
…
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span className="btn-recompile-label">{t('recompile')}</span>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
<Dropdown.Toggle className="btn btn-recompile" />
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<MenuItem header>{t('auto_compile')}</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectAutoCompileOn}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={isAutoCompileOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('on')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectAutoCompileOff}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={!isAutoCompileOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('off')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem header>{t('compile_mode')}</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectDraftModeOff}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={!isDraftModeOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('normal')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectDraftModeOn}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={isDraftModeOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('fast')} <span className="subdued">[draft]</span>
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem header>Syntax Checks</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectSyntaxCheckOn}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={isSyntaxCheckOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('stop_on_validation_error')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onSelect={handleSelectSyntaxCheckOff}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type={!isSyntaxCheckOn ? 'check' : ''} modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('ignore_validation_errors')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onSelect={onRunSyntaxCheckNow}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type="" modifier="fw" />
|
2020-09-28 06:51:15 -04:00
|
|
|
{t('run_syntax_check_now')}
|
|
|
|
</MenuItem>
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewRecompileButton.propTypes = {
|
|
|
|
compilerState: PropTypes.shape({
|
|
|
|
isAutoCompileOn: PropTypes.bool.isRequired,
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
isDraftModeOn: PropTypes.bool.isRequired,
|
2020-09-29 07:08:49 -04:00
|
|
|
isSyntaxCheckOn: PropTypes.bool.isRequired,
|
|
|
|
logEntries: PropTypes.object.isRequired
|
2020-09-28 06:51:15 -04:00
|
|
|
}),
|
|
|
|
onRecompile: PropTypes.func.isRequired,
|
|
|
|
onRunSyntaxCheckNow: PropTypes.func.isRequired,
|
|
|
|
onSetAutoCompile: PropTypes.func.isRequired,
|
|
|
|
onSetDraftMode: PropTypes.func.isRequired,
|
|
|
|
onSetSyntaxCheck: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewRecompileButton
|