2021-10-12 04:47:46 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Button, Label, OverlayTrigger, Tooltip } from 'react-bootstrap'
|
|
|
|
import Icon from '../../../shared/components/icon'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
function PdfHybridLogsButton() {
|
2022-03-31 07:22:36 -04:00
|
|
|
const { error, logEntries, toggleLogs, showLogs } = useCompileContext()
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
2022-03-31 07:22:36 -04:00
|
|
|
toggleLogs()
|
|
|
|
}, [toggleLogs])
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
const errorCount = Number(logEntries?.errors?.length)
|
|
|
|
const warningCount = Number(logEntries?.warnings?.length)
|
|
|
|
const totalCount = errorCount + warningCount
|
|
|
|
|
|
|
|
return (
|
|
|
|
<OverlayTrigger
|
|
|
|
placement="bottom"
|
|
|
|
overlay={
|
|
|
|
<Tooltip id="tooltip-logs-toggle">{t('logs_and_output_files')}</Tooltip>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
bsStyle="link"
|
|
|
|
disabled={Boolean(error)}
|
|
|
|
active={showLogs}
|
|
|
|
className="toolbar-item log-btn"
|
|
|
|
onClick={handleClick}
|
|
|
|
style={{ position: 'relative' }}
|
|
|
|
aria-label={showLogs ? t('view_pdf') : t('view_logs')}
|
|
|
|
>
|
2022-01-19 06:56:57 -05:00
|
|
|
<Icon type="file-text-o" fw />
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
{!showLogs && totalCount > 0 && (
|
|
|
|
<Label bsStyle={errorCount === 0 ? 'warning' : 'danger'}>
|
|
|
|
{totalCount}
|
|
|
|
</Label>
|
|
|
|
)}
|
|
|
|
</Button>
|
|
|
|
</OverlayTrigger>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfHybridLogsButton)
|