import React from 'react' import PropTypes from 'prop-types' import { Dropdown, MenuItem, OverlayTrigger, Tooltip } from 'react-bootstrap' import { useTranslation } from 'react-i18next' import Icon from '../../../shared/components/icon' function PreviewRecompileButton({ compilerState: { isAutoCompileOn, isClearingCache, isCompiling, isDraftModeOn, isSyntaxCheckOn }, onClearCache, onRecompile, onRunSyntaxCheckNow, onSetAutoCompile, onSetDraftMode, onSetSyntaxCheck, showText }) { const { t } = useTranslation() function handleRecompileFromScratch() { onClearCache() .then(() => { onRecompile() }) .catch(error => { console.error(error) }) } function handleSelectAutoCompileOn() { onSetAutoCompile(true) } function handleSelectAutoCompileOff() { onSetAutoCompile(false) } function handleSelectDraftModeOn() { onSetDraftMode(true) } function handleSelectDraftModeOff() { onSetDraftMode(false) } function handleSelectSyntaxCheckOn() { onSetSyntaxCheck(true) } function handleSelectSyntaxCheckOff() { onSetSyntaxCheck(false) } 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 = ( {t('auto_compile')} {t('on')} {t('off')} {t('compile_mode')} {t('normal')} {t('fast')} [draft] Syntax Checks {t('stop_on_validation_error')} {t('ignore_validation_errors')} {t('run_syntax_check_now')} {t('recompile_from_scratch')} ) return showText ? ( buttonElement ) : ( {isCompiling || isClearingCache ? t('compiling') : t('recompile')} } > {buttonElement} ) } PreviewRecompileButton.propTypes = { compilerState: PropTypes.shape({ isAutoCompileOn: PropTypes.bool.isRequired, isClearingCache: PropTypes.bool.isRequired, isCompiling: PropTypes.bool.isRequired, isDraftModeOn: PropTypes.bool.isRequired, isSyntaxCheckOn: PropTypes.bool.isRequired, logEntries: PropTypes.object.isRequired }), onClearCache: PropTypes.func.isRequired, onRecompile: PropTypes.func.isRequired, onRunSyntaxCheckNow: PropTypes.func.isRequired, onSetAutoCompile: PropTypes.func.isRequired, onSetDraftMode: PropTypes.func.isRequired, onSetSyntaxCheck: PropTypes.func.isRequired, showText: PropTypes.bool.isRequired } export default PreviewRecompileButton