2021-10-12 04:47:46 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-10-08 10:22:13 -04:00
|
|
|
import Icon from '@/shared/components/icon'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
import { useDetachCompileContext as useCompileContext } from '@/shared/context/detach-compile-context'
|
|
|
|
import * as eventTracking from '@/infrastructure/event-tracking'
|
|
|
|
import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
|
|
import OLBadge from '@/features/ui/components/ol/ol-badge'
|
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
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 (
|
2024-10-08 10:22:13 -04:00
|
|
|
<OLTooltip
|
2022-05-18 09:46:10 -04:00
|
|
|
id="logs-toggle"
|
|
|
|
description={t('logs_and_output_files')}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2021-10-12 04:47:46 -04:00
|
|
|
>
|
2024-10-08 10:22:13 -04:00
|
|
|
<OLButton
|
|
|
|
variant="link"
|
2022-06-07 07:55:48 -04:00
|
|
|
disabled={Boolean(error || stoppedOnFirstError)}
|
2021-10-12 04:47:46 -04:00
|
|
|
active={showLogs}
|
2024-05-31 04:51:27 -04:00
|
|
|
className="pdf-toolbar-btn toolbar-item log-btn"
|
2021-10-12 04:47:46 -04:00
|
|
|
onClick={handleClick}
|
|
|
|
style={{ position: 'relative' }}
|
|
|
|
aria-label={showLogs ? t('view_pdf') : t('view_logs')}
|
|
|
|
>
|
2024-10-08 10:22:13 -04:00
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="file-text-o" fw />}
|
|
|
|
bs5={<MaterialIcon type="description" />}
|
|
|
|
/>
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
{!showLogs && totalCount > 0 && (
|
2024-10-08 10:22:13 -04:00
|
|
|
<OLBadge bg={errorCount === 0 ? 'warning' : 'danger'}>
|
2021-10-12 04:47:46 -04:00
|
|
|
{totalCount}
|
2024-10-08 10:22:13 -04:00
|
|
|
</OLBadge>
|
2021-10-12 04:47:46 -04:00
|
|
|
)}
|
2024-10-08 10:22:13 -04:00
|
|
|
</OLButton>
|
|
|
|
</OLTooltip>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfHybridLogsButton)
|