2021-10-12 04:47:46 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-05-18 09:46:10 -04:00
|
|
|
import { Button, Label } from 'react-bootstrap'
|
|
|
|
import Tooltip from '../../../shared/components/tooltip'
|
2021-10-12 04:47:46 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2023-08-22 09:33:19 -04:00
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
function PdfHybridLogsButton() {
|
2022-06-07 07:55:48 -04:00
|
|
|
const { error, logEntries, toggleLogs, showLogs, stoppedOnFirstError } =
|
|
|
|
useCompileContext()
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
2023-08-22 09:33:19 -04:00
|
|
|
// only send analytics on open
|
|
|
|
if (!showLogs) {
|
|
|
|
eventTracking.sendMB('logs-click')
|
|
|
|
}
|
2022-03-31 07:22:36 -04:00
|
|
|
toggleLogs()
|
2023-08-22 09:33:19 -04:00
|
|
|
}, [toggleLogs, showLogs])
|
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 (
|
2022-05-18 09:46:10 -04:00
|
|
|
<Tooltip
|
|
|
|
id="logs-toggle"
|
|
|
|
description={t('logs_and_output_files')}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2021-10-12 04:47:46 -04:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
bsStyle="link"
|
2022-06-07 07:55:48 -04:00
|
|
|
disabled={Boolean(error || stoppedOnFirstError)}
|
2021-10-12 04:47:46 -04:00
|
|
|
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>
|
2022-05-18 09:46:10 -04:00
|
|
|
</Tooltip>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfHybridLogsButton)
|