2021-09-30 07:29:25 -04:00
|
|
|
import { memo, useCallback, useMemo } from 'react'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import { PdfLogsButtonContent } from './pdf-logs-button-content'
|
|
|
|
import { sendMBOnce } from '../../../infrastructure/event-tracking'
|
2021-10-15 05:39:56 -04:00
|
|
|
import { useCompileContext } from '../../../shared/context/compile-context'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
function PdfLogsButton() {
|
|
|
|
const {
|
2021-10-08 05:23:33 -04:00
|
|
|
codeCheckFailed,
|
2021-09-30 07:29:25 -04:00
|
|
|
error,
|
|
|
|
logEntries,
|
|
|
|
showLogs,
|
|
|
|
setShowLogs,
|
2021-10-15 05:39:56 -04:00
|
|
|
} = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const buttonStyle = useMemo(() => {
|
|
|
|
if (showLogs) {
|
|
|
|
return 'default'
|
|
|
|
}
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
if (codeCheckFailed) {
|
2021-09-30 07:29:25 -04:00
|
|
|
return 'danger'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logEntries) {
|
|
|
|
if (logEntries.errors?.length) {
|
|
|
|
return 'danger'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logEntries.warnings?.length) {
|
|
|
|
return 'warning'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'default'
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [codeCheckFailed, logEntries, showLogs])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
|
|
|
setShowLogs(value => {
|
|
|
|
if (!value) {
|
|
|
|
sendMBOnce('ide-open-logs-once')
|
|
|
|
}
|
|
|
|
|
|
|
|
return !value
|
|
|
|
})
|
|
|
|
}, [setShowLogs])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
bsSize="xsmall"
|
|
|
|
bsStyle={buttonStyle}
|
|
|
|
disabled={Boolean(error)}
|
|
|
|
className="btn-toggle-logs toolbar-item"
|
|
|
|
onClick={handleClick}
|
|
|
|
>
|
|
|
|
<PdfLogsButtonContent
|
|
|
|
showLogs={showLogs}
|
|
|
|
logEntries={logEntries}
|
2021-10-08 05:23:33 -04:00
|
|
|
codeCheckFailed={codeCheckFailed}
|
2021-09-30 07:29:25 -04:00
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfLogsButton)
|