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'
|
2021-03-18 09:49:01 -04:00
|
|
|
import classNames from 'classnames'
|
2020-09-29 07:08:49 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2021-06-18 05:29:06 -04:00
|
|
|
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
|
|
|
function PreviewRecompileButton({
|
|
|
|
compilerState: {
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasChanges,
|
|
|
|
autoCompileHasLintingError,
|
2020-09-28 06:51:15 -04:00
|
|
|
isAutoCompileOn,
|
|
|
|
isCompiling,
|
|
|
|
isDraftModeOn,
|
2021-04-27 03:52:58 -04:00
|
|
|
isSyntaxCheckOn,
|
2020-09-28 06:51:15 -04:00
|
|
|
},
|
|
|
|
onRecompile,
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRunSyntaxCheckNow,
|
2020-12-02 05:03:03 -05:00
|
|
|
onStopCompilation,
|
2020-09-28 06:51:15 -04:00
|
|
|
onSetAutoCompile,
|
|
|
|
onSetDraftMode,
|
2020-11-09 09:52:22 -05:00
|
|
|
onSetSyntaxCheck,
|
2021-04-27 03:52:58 -04:00
|
|
|
showText,
|
2020-09-28 06:51:15 -04:00
|
|
|
}) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
let compilingProps = {}
|
|
|
|
let recompileProps = {}
|
|
|
|
function _hideText(keepAria) {
|
|
|
|
return {
|
|
|
|
'aria-hidden': !keepAria,
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
2021-04-27 03:52:58 -04:00
|
|
|
right: '-100vw',
|
|
|
|
},
|
2020-11-09 09:52:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!showText) {
|
2020-12-02 05:03:03 -05:00
|
|
|
compilingProps = _hideText(isCompiling)
|
|
|
|
recompileProps = _hideText(!isCompiling)
|
|
|
|
} else if (isCompiling) {
|
2020-11-09 09:52:22 -05:00
|
|
|
recompileProps = _hideText()
|
|
|
|
} else {
|
|
|
|
compilingProps = _hideText()
|
|
|
|
}
|
|
|
|
|
2021-03-18 09:49:01 -04:00
|
|
|
const recompileButtonGroupClasses = classNames(
|
|
|
|
'btn-recompile-group',
|
|
|
|
'toolbar-item',
|
|
|
|
{
|
|
|
|
'btn-recompile-group-has-changes':
|
2021-04-27 03:52:58 -04:00
|
|
|
autoCompileHasChanges && !autoCompileHasLintingError,
|
2021-03-18 09:49:01 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
const buttonElement = (
|
2021-06-18 05:29:06 -04:00
|
|
|
<ControlledDropdown
|
2020-11-09 09:52:22 -05:00
|
|
|
id="pdf-recompile-dropdown"
|
2021-03-18 09:49:01 -04:00
|
|
|
className={recompileButtonGroupClasses}
|
2020-11-09 09:52:22 -05:00
|
|
|
>
|
2021-05-31 04:25:41 -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-11-12 09:09:48 -05:00
|
|
|
bsStyle="success"
|
2020-10-20 08:44:19 -04:00
|
|
|
/>
|
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-12-02 05:03:03 -05:00
|
|
|
<MenuItem className={!isCompiling ? 'hidden' : ''} divider />
|
|
|
|
<MenuItem
|
|
|
|
onSelect={onStopCompilation}
|
|
|
|
className={!isCompiling ? 'hidden' : ''}
|
|
|
|
disabled={!isCompiling}
|
|
|
|
aria-disabled={!isCompiling}
|
|
|
|
>
|
|
|
|
{t('stop_compile')}
|
|
|
|
</MenuItem>
|
2020-10-20 08:44:19 -04:00
|
|
|
<MenuItem divider />
|
|
|
|
<MenuItem
|
2020-12-02 05:03:03 -05:00
|
|
|
onSelect={onRecompileFromScratch}
|
|
|
|
disabled={isCompiling}
|
|
|
|
aria-disabled={!!isCompiling}
|
2020-10-20 08:44:19 -04:00
|
|
|
>
|
|
|
|
{t('recompile_from_scratch')}
|
|
|
|
</MenuItem>
|
2020-09-28 06:51:15 -04:00
|
|
|
</Dropdown.Menu>
|
2021-06-18 05:29:06 -04:00
|
|
|
</ControlledDropdown>
|
2020-09-28 06:51:15 -04:00
|
|
|
)
|
2020-11-09 09:52:22 -05:00
|
|
|
|
|
|
|
return showText ? (
|
|
|
|
buttonElement
|
|
|
|
) : (
|
|
|
|
<OverlayTrigger
|
|
|
|
placement="bottom"
|
|
|
|
overlay={
|
|
|
|
<Tooltip id="tooltip-download-pdf">
|
2020-12-02 05:03:03 -05:00
|
|
|
{isCompiling ? t('compiling') : t('recompile')}
|
2020-11-09 09:52:22 -05:00
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{buttonElement}
|
|
|
|
</OverlayTrigger>
|
|
|
|
)
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewRecompileButton.propTypes = {
|
|
|
|
compilerState: PropTypes.shape({
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasChanges: PropTypes.bool.isRequired,
|
|
|
|
autoCompileHasLintingError: PropTypes.bool,
|
2020-09-28 06:51:15 -04:00
|
|
|
isAutoCompileOn: PropTypes.bool.isRequired,
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
isDraftModeOn: PropTypes.bool.isRequired,
|
2020-09-29 07:08:49 -04:00
|
|
|
isSyntaxCheckOn: PropTypes.bool.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
logEntries: PropTypes.object.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
}),
|
|
|
|
onRecompile: PropTypes.func.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch: PropTypes.func.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRunSyntaxCheckNow: PropTypes.func.isRequired,
|
|
|
|
onSetAutoCompile: PropTypes.func.isRequired,
|
|
|
|
onSetDraftMode: PropTypes.func.isRequired,
|
2020-11-09 09:52:22 -05:00
|
|
|
onSetSyntaxCheck: PropTypes.func.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
onStopCompilation: PropTypes.func.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
showText: PropTypes.bool.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewRecompileButton
|