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'
|
2024-01-23 04:25:00 -05:00
|
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
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,
|
2023-02-20 08:45:22 -05:00
|
|
|
contentDetails,
|
2021-10-15 05:45:06 -04:00
|
|
|
onSourceLocationClick,
|
|
|
|
onClose,
|
2024-05-08 06:36:45 -04:00
|
|
|
index,
|
|
|
|
logEntry,
|
2021-10-15 05:45:06 -04:00
|
|
|
}) {
|
2022-03-31 07:22:36 -04:00
|
|
|
if (ruleId && HumanReadableLogsHints[ruleId]) {
|
|
|
|
const hint = HumanReadableLogsHints[ruleId]
|
2023-02-20 08:45:22 -05:00
|
|
|
formattedContent = hint.formattedContent(contentDetails)
|
2022-03-31 07:22:36 -04:00
|
|
|
extraInfoURL = hint.extraInfoURL
|
|
|
|
}
|
|
|
|
|
2021-10-15 05:45:06 -04:00
|
|
|
const handleLogEntryLinkClick = useCallback(
|
|
|
|
event => {
|
|
|
|
event.preventDefault()
|
|
|
|
onSourceLocationClick(sourceLocation)
|
2024-01-23 04:25:00 -05:00
|
|
|
|
|
|
|
const parts = sourceLocation?.file?.split('.')
|
|
|
|
const extension = parts?.length > 1 ? parts.pop() : ''
|
|
|
|
sendMB('log-entry-link-click', { level, ruleId, extension })
|
2021-10-15 05:45:06 -04:00
|
|
|
},
|
2024-01-23 04:25:00 -05:00
|
|
|
[level, onSourceLocationClick, ruleId, sourceLocation]
|
2021-10-15 05:45:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames('log-entry', customClass)}
|
|
|
|
aria-label={entryAriaLabel}
|
2024-04-30 05:33:45 -04:00
|
|
|
data-ruleid={ruleId}
|
2021-10-15 05:45:06 -04:00
|
|
|
>
|
|
|
|
<PreviewLogEntryHeader
|
|
|
|
level={level}
|
|
|
|
sourceLocation={sourceLocation}
|
|
|
|
headerTitle={headerTitle}
|
|
|
|
headerIcon={headerIcon}
|
|
|
|
logType={logType}
|
|
|
|
showSourceLocationLink={showSourceLocationLink}
|
|
|
|
onSourceLocationClick={handleLogEntryLinkClick}
|
|
|
|
showCloseButton={showCloseButton}
|
|
|
|
onClose={onClose}
|
|
|
|
/>
|
2024-05-08 06:36:45 -04:00
|
|
|
|
2024-05-16 04:31:46 -04:00
|
|
|
{(rawContent || formattedContent || window.user.alphaProgram) && (
|
2021-10-15 05:45:06 -04:00
|
|
|
<PdfLogEntryContent
|
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
|
|
|
extraInfoURL={extraInfoURL}
|
2024-05-08 06:36:45 -04:00
|
|
|
index={index}
|
|
|
|
logEntry={logEntry}
|
2021-10-15 05:45:06 -04:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</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,
|
2023-09-11 05:56:43 -04:00
|
|
|
headerTitle: PreviewLogEntryHeader.propTypes.headerTitle,
|
2021-10-15 05:45:06 -04:00
|
|
|
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,
|
2023-02-20 08:45:22 -05:00
|
|
|
contentDetails: PropTypes.arrayOf(PropTypes.string),
|
2021-10-15 05:45:06 -04:00
|
|
|
onSourceLocationClick: PropTypes.func,
|
|
|
|
onClose: PropTypes.func,
|
2024-05-08 06:36:45 -04:00
|
|
|
index: PropTypes.number,
|
|
|
|
logEntry: PropTypes.any,
|
2021-10-15 05:45:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfLogEntry)
|