2021-10-15 05:45:06 -04:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classNames from 'classnames'
|
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import PreviewLogEntryHeader from '../../preview/components/preview-log-entry-header'
|
|
|
|
import PdfLogEntryContent from './pdf-log-entry-content'
|
2022-03-31 07:22:36 -04:00
|
|
|
import HumanReadableLogsHints from '../../../ide/human-readable-logs/HumanReadableLogsHints'
|
2021-10-15 05:45:06 -04:00
|
|
|
|
|
|
|
function PdfLogEntry({
|
2022-03-31 07:22:36 -04:00
|
|
|
ruleId,
|
2021-10-15 05:45:06 -04:00
|
|
|
headerTitle,
|
|
|
|
headerIcon,
|
|
|
|
rawContent,
|
|
|
|
logType,
|
|
|
|
formattedContent,
|
|
|
|
extraInfoURL,
|
|
|
|
level,
|
|
|
|
sourceLocation,
|
|
|
|
showSourceLocationLink = true,
|
|
|
|
showCloseButton = false,
|
|
|
|
entryAriaLabel = null,
|
|
|
|
customClass,
|
|
|
|
onSourceLocationClick,
|
|
|
|
onClose,
|
|
|
|
}) {
|
2022-03-31 07:22:36 -04:00
|
|
|
if (ruleId && HumanReadableLogsHints[ruleId]) {
|
|
|
|
const hint = HumanReadableLogsHints[ruleId]
|
|
|
|
formattedContent = hint.formattedContent
|
|
|
|
extraInfoURL = hint.extraInfoURL
|
|
|
|
}
|
|
|
|
|
2021-10-15 05:45:06 -04:00
|
|
|
const handleLogEntryLinkClick = useCallback(
|
|
|
|
event => {
|
|
|
|
event.preventDefault()
|
|
|
|
onSourceLocationClick(sourceLocation)
|
|
|
|
},
|
|
|
|
[onSourceLocationClick, sourceLocation]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames('log-entry', customClass)}
|
|
|
|
aria-label={entryAriaLabel}
|
|
|
|
>
|
|
|
|
<PreviewLogEntryHeader
|
|
|
|
level={level}
|
|
|
|
sourceLocation={sourceLocation}
|
|
|
|
headerTitle={headerTitle}
|
|
|
|
headerIcon={headerIcon}
|
|
|
|
logType={logType}
|
|
|
|
showSourceLocationLink={showSourceLocationLink}
|
|
|
|
onSourceLocationClick={handleLogEntryLinkClick}
|
|
|
|
showCloseButton={showCloseButton}
|
|
|
|
onClose={onClose}
|
|
|
|
/>
|
|
|
|
{(rawContent || formattedContent) && (
|
|
|
|
<PdfLogEntryContent
|
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
|
|
|
extraInfoURL={extraInfoURL}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PdfLogEntry.propTypes = {
|
2022-03-31 07:22:36 -04:00
|
|
|
ruleId: PropTypes.string,
|
2021-10-15 05:45:06 -04:00
|
|
|
sourceLocation: PreviewLogEntryHeader.propTypes.sourceLocation,
|
|
|
|
headerTitle: PropTypes.string,
|
|
|
|
headerIcon: PropTypes.element,
|
|
|
|
rawContent: PropTypes.string,
|
|
|
|
logType: PropTypes.string,
|
|
|
|
formattedContent: PropTypes.node,
|
|
|
|
extraInfoURL: PropTypes.string,
|
2022-06-07 07:55:48 -04:00
|
|
|
level: PropTypes.oneOf([
|
|
|
|
'error',
|
|
|
|
'warning',
|
|
|
|
'info',
|
|
|
|
'typesetting',
|
|
|
|
'raw',
|
|
|
|
'success',
|
|
|
|
]).isRequired,
|
2021-10-15 05:45:06 -04:00
|
|
|
customClass: PropTypes.string,
|
|
|
|
showSourceLocationLink: PropTypes.bool,
|
|
|
|
showCloseButton: PropTypes.bool,
|
|
|
|
entryAriaLabel: PropTypes.string,
|
|
|
|
onSourceLocationClick: PropTypes.func,
|
|
|
|
onClose: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfLogEntry)
|