2020-09-28 06:51:15 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-11-09 09:52:22 -05:00
|
|
|
import { Dropdown, MenuItem, OverlayTrigger, Tooltip } from 'react-bootstrap'
|
2020-09-28 06:51:15 -04:00
|
|
|
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,
|
2020-10-20 08:44:19 -04:00
|
|
|
isClearingCache,
|
2020-09-28 06:51:15 -04:00
|
|
|
isCompiling,
|
|
|
|
isDraftModeOn,
|
|
|
|
isSyntaxCheckOn
|
|
|
|
},
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile,
|
|
|
|
onRunSyntaxCheckNow,
|
|
|
|
onSetAutoCompile,
|
|
|
|
onSetDraftMode,
|
2020-11-09 09:52:22 -05:00
|
|
|
onSetSyntaxCheck,
|
|
|
|
showText
|
2020-09-28 06:51:15 -04:00
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2020-10-20 08:44:19 -04:00
|
|
|
function handleRecompileFromScratch() {
|
|
|
|
onClearCache()
|
|
|
|
.then(() => {
|
|
|
|
onRecompile()
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
function handleSelectAutoCompileOn() {
|
|
|
|
onSetAutoCompile(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectAutoCompileOff() {
|
|
|
|
onSetAutoCompile(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectDraftModeOn() {
|
|
|
|
onSetDraftMode(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectDraftModeOff() {
|
|
|
|
onSetDraftMode(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectSyntaxCheckOn() {
|
|
|
|
onSetSyntaxCheck(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSelectSyntaxCheckOff() {
|
|
|
|
onSetSyntaxCheck(false)
|
|
|
|
}
|
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
let compilingProps = {}
|
|
|
|
let recompileProps = {}
|
|
|
|
function _hideText(keepAria) {
|
|
|
|
return {
|
|
|
|
'aria-hidden': !keepAria,
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
right: '-100vw'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!showText) {
|
|
|
|
compilingProps = _hideText(isCompiling || isClearingCache)
|
|
|
|
recompileProps = _hideText(!isCompiling || !isClearingCache)
|
|
|
|
} else if (isCompiling || isClearingCache) {
|
|
|
|
recompileProps = _hideText()
|
|
|
|
} else {
|
|
|
|
compilingProps = _hideText()
|
|
|
|
}
|
|
|
|
|
|
|
|
const buttonElement = (
|
|
|
|
<Dropdown
|
|
|
|
id="pdf-recompile-dropdown"
|
|
|
|
className="btn-recompile-group toolbar-item"
|
|
|
|
>
|
2020-09-28 06:51:15 -04:00
|
|
|
<button className="btn btn-recompile" onClick={onRecompile}>
|
2020-09-29 07:08:49 -04:00
|
|
|
<Icon type="refresh" spin={isCompiling} />
|
2020-11-09 09:52:22 -05:00
|
|
|
|
|
|
|
<span id="text-compiling" className="toolbar-text" {...compilingProps}>
|
|
|
|
{t('compiling')}
|
|
|
|
…
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span id="text-recompile" className="toolbar-text" {...recompileProps}>
|
|
|
|
{t('recompile')}
|
|
|
|
</span>
|
2020-09-28 06:51:15 -04:00
|
|
|
</button>
|
2020-10-20 08:44:19 -04:00
|
|
|
<Dropdown.Toggle
|
|
|
|
aria-label={t('toggle_compile_options_menu')}
|
|
|
|
className="btn btn-recompile"
|
|
|
|
/>
|
2020-09-28 06:51:15 -04:00
|
|
|
<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>
|
2020-10-20 08:44:19 -04:00
|
|
|
<MenuItem divider />
|
|
|
|
<MenuItem
|
|
|
|
onSelect={handleRecompileFromScratch}
|
|
|
|
disabled={isCompiling || isClearingCache}
|
|
|
|
aria-disabled={!!(isCompiling || isClearingCache)}
|
|
|
|
>
|
|
|
|
{t('recompile_from_scratch')}
|
|
|
|
</MenuItem>
|
2020-09-28 06:51:15 -04:00
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
2020-11-09 09:52:22 -05:00
|
|
|
|
|
|
|
return showText ? (
|
|
|
|
buttonElement
|
|
|
|
) : (
|
|
|
|
<OverlayTrigger
|
|
|
|
placement="bottom"
|
|
|
|
overlay={
|
|
|
|
<Tooltip id="tooltip-download-pdf">
|
|
|
|
{isCompiling || isClearingCache ? t('compiling') : t('recompile')}
|
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{buttonElement}
|
|
|
|
</OverlayTrigger>
|
|
|
|
)
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewRecompileButton.propTypes = {
|
|
|
|
compilerState: PropTypes.shape({
|
|
|
|
isAutoCompileOn: PropTypes.bool.isRequired,
|
2020-10-20 08:44:19 -04:00
|
|
|
isClearingCache: PropTypes.bool.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
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
|
|
|
}),
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache: PropTypes.func.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,
|
2020-11-09 09:52:22 -05:00
|
|
|
onSetSyntaxCheck: PropTypes.func.isRequired,
|
|
|
|
showText: PropTypes.bool.isRequired
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewRecompileButton
|