2020-09-28 06:51:15 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classNames from 'classnames'
|
2020-11-05 05:22:05 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import useExpandCollapse from '../../../shared/hooks/use-expand-collapse'
|
2020-09-29 07:08:49 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
function PreviewLogsPaneEntry({
|
|
|
|
headerTitle,
|
|
|
|
rawContent,
|
|
|
|
formattedContent,
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL,
|
|
|
|
level,
|
2020-11-26 04:58:42 -05:00
|
|
|
sourceLocation,
|
|
|
|
showSourceLocationLink = true,
|
2020-11-16 05:01:01 -05:00
|
|
|
showCloseButton = false,
|
2020-11-26 04:58:42 -05:00
|
|
|
entryAriaLabel = null,
|
|
|
|
onSourceLocationClick,
|
2020-11-16 05:01:01 -05:00
|
|
|
onClose
|
2020-11-05 05:22:05 -05:00
|
|
|
}) {
|
|
|
|
function handleLogEntryLinkClick() {
|
2020-11-26 04:58:42 -05:00
|
|
|
onSourceLocationClick(sourceLocation)
|
2020-11-05 05:22:05 -05:00
|
|
|
}
|
2020-11-26 04:58:42 -05:00
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
return (
|
2020-11-26 04:58:42 -05:00
|
|
|
<div className="log-entry" aria-label={entryAriaLabel}>
|
2020-11-05 05:22:05 -05:00
|
|
|
<PreviewLogEntryHeader
|
|
|
|
level={level}
|
2020-11-26 04:58:42 -05:00
|
|
|
sourceLocation={sourceLocation}
|
|
|
|
headerTitle={headerTitle}
|
|
|
|
showSourceLocationLink={showSourceLocationLink}
|
|
|
|
onSourceLocationClick={handleLogEntryLinkClick}
|
2020-11-16 05:01:01 -05:00
|
|
|
showCloseButton={showCloseButton}
|
|
|
|
onClose={onClose}
|
2020-11-05 05:22:05 -05:00
|
|
|
/>
|
2020-11-26 04:58:42 -05:00
|
|
|
{rawContent || formattedContent ? (
|
2020-11-05 05:22:05 -05:00
|
|
|
<PreviewLogEntryContent
|
2020-11-26 04:58:42 -05:00
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL={extraInfoURL}
|
|
|
|
/>
|
2020-09-28 06:51:15 -04:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-05 05:22:05 -05:00
|
|
|
function PreviewLogEntryHeader({
|
2020-11-26 04:58:42 -05:00
|
|
|
sourceLocation,
|
2020-11-05 05:22:05 -05:00
|
|
|
level,
|
2020-11-26 04:58:42 -05:00
|
|
|
headerTitle,
|
|
|
|
showSourceLocationLink = true,
|
2020-11-16 05:01:01 -05:00
|
|
|
showCloseButton = false,
|
2020-11-26 04:58:42 -05:00
|
|
|
onSourceLocationClick,
|
2020-11-16 05:01:01 -05:00
|
|
|
onClose
|
2020-11-05 05:22:05 -05:00
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
2020-11-26 04:58:42 -05:00
|
|
|
const file = sourceLocation ? sourceLocation.file : null
|
|
|
|
const line = sourceLocation ? sourceLocation.line : null
|
2020-11-05 05:22:05 -05:00
|
|
|
const logEntryHeaderClasses = classNames('log-entry-header', {
|
|
|
|
'log-entry-header-error': level === 'error',
|
|
|
|
'log-entry-header-warning': level === 'warning',
|
2020-11-16 05:15:29 -05:00
|
|
|
'log-entry-header-typesetting': level === 'typesetting',
|
|
|
|
'log-entry-header-raw': level === 'raw'
|
2020-11-05 05:22:05 -05:00
|
|
|
})
|
2020-11-16 05:01:01 -05:00
|
|
|
const headerLogLocationTitle = t('navigate_log_source', {
|
2020-11-05 05:22:05 -05:00
|
|
|
location: file + (line ? `, ${line}` : '')
|
|
|
|
})
|
2020-11-16 05:01:01 -05:00
|
|
|
|
2020-11-05 05:22:05 -05:00
|
|
|
return (
|
|
|
|
<header className={logEntryHeaderClasses}>
|
2020-11-26 04:58:42 -05:00
|
|
|
<h3 className="log-entry-header-title">{headerTitle}</h3>
|
|
|
|
{showSourceLocationLink && file ? (
|
2020-11-05 05:22:05 -05:00
|
|
|
<button
|
|
|
|
className="btn-inline-link log-entry-header-link"
|
|
|
|
type="button"
|
2020-11-16 05:01:01 -05:00
|
|
|
title={headerLogLocationTitle}
|
2020-11-26 04:58:42 -05:00
|
|
|
onClick={onSourceLocationClick}
|
2020-11-05 05:22:05 -05:00
|
|
|
>
|
|
|
|
<Icon type="chain" />
|
|
|
|
|
|
|
|
<span>{file}</span>
|
|
|
|
{line ? <span>, {line}</span> : null}
|
|
|
|
</button>
|
|
|
|
) : null}
|
2020-11-26 04:58:42 -05:00
|
|
|
{showCloseButton ? (
|
2020-11-16 05:01:01 -05:00
|
|
|
<button
|
|
|
|
className="btn-inline-link log-entry-header-link"
|
|
|
|
type="button"
|
|
|
|
aria-label={t('dismiss_error_popup')}
|
|
|
|
onClick={onClose}
|
|
|
|
>
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
) : null}
|
2020-11-05 05:22:05 -05:00
|
|
|
</header>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function PreviewLogEntryContent({
|
2020-11-26 04:58:42 -05:00
|
|
|
rawContent,
|
|
|
|
formattedContent,
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL
|
|
|
|
}) {
|
|
|
|
const { isExpanded, expandableProps, toggleProps } = useExpandCollapse({
|
|
|
|
collapsedSize: 150,
|
|
|
|
classes: {
|
|
|
|
container: 'log-entry-content-raw-expandable-container'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const logContentClasses = classNames('log-entry-content-raw', {
|
|
|
|
'log-entry-content-raw-collapsed': !isExpanded
|
|
|
|
})
|
|
|
|
const buttonContainerClasses = classNames(
|
|
|
|
'log-entry-content-button-container',
|
|
|
|
{
|
|
|
|
'log-entry-content-button-container-collapsed': !isExpanded
|
|
|
|
}
|
|
|
|
)
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="log-entry-content">
|
2020-11-26 04:58:42 -05:00
|
|
|
{rawContent ? (
|
|
|
|
<div {...expandableProps}>
|
|
|
|
<pre className={logContentClasses}>{rawContent.trim()}</pre>
|
|
|
|
<div className={buttonContainerClasses}>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-xs btn-default log-entry-btn-expand-collapse"
|
|
|
|
{...toggleProps}
|
|
|
|
>
|
|
|
|
{isExpanded ? (
|
|
|
|
<>
|
|
|
|
<Icon type="angle-up" /> {t('collapse')}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Icon type="angle-down" /> {t('expand')}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-11-05 05:22:05 -05:00
|
|
|
</div>
|
|
|
|
) : null}
|
2020-11-26 04:58:42 -05:00
|
|
|
{formattedContent ? (
|
|
|
|
<div className="log-entry-formatted-content">{formattedContent}</div>
|
|
|
|
) : null}
|
2020-11-05 05:22:05 -05:00
|
|
|
{extraInfoURL ? (
|
2020-11-26 04:58:42 -05:00
|
|
|
<div className="log-entry-content-link">
|
|
|
|
<a href={extraInfoURL} target="_blank">
|
2020-11-05 05:22:05 -05:00
|
|
|
{t('log_hint_extra_info')}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewLogEntryHeader.propTypes = {
|
2020-11-26 04:58:42 -05:00
|
|
|
sourceLocation: PropTypes.shape({
|
|
|
|
file: PropTypes.string,
|
|
|
|
// `line should be either a number or null (i.e. not required), but currently sometimes we get
|
|
|
|
// an empty string (from BibTeX errors), which is why we're using `any` here. We should revert
|
|
|
|
// to PropTypes.number (not required) once we fix that.
|
|
|
|
line: PropTypes.any,
|
|
|
|
column: PropTypes.any
|
|
|
|
}),
|
2020-11-05 05:22:05 -05:00
|
|
|
level: PropTypes.string.isRequired,
|
2020-11-26 04:58:42 -05:00
|
|
|
headerTitle: PropTypes.string,
|
|
|
|
showSourceLocationLink: PropTypes.bool,
|
2020-11-16 05:01:01 -05:00
|
|
|
showCloseButton: PropTypes.bool,
|
2020-11-26 04:58:42 -05:00
|
|
|
onSourceLocationClick: PropTypes.func,
|
2020-11-16 05:01:01 -05:00
|
|
|
onClose: PropTypes.func
|
2020-11-05 05:22:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewLogEntryContent.propTypes = {
|
2020-11-26 04:58:42 -05:00
|
|
|
rawContent: PropTypes.string,
|
|
|
|
formattedContent: PropTypes.node,
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL: PropTypes.string
|
|
|
|
}
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
PreviewLogsPaneEntry.propTypes = {
|
|
|
|
sourceLocation: PreviewLogEntryHeader.propTypes.sourceLocation,
|
|
|
|
headerTitle: PropTypes.string,
|
|
|
|
rawContent: PropTypes.string,
|
|
|
|
formattedContent: PropTypes.node,
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL: PropTypes.string,
|
2020-11-16 05:15:29 -05:00
|
|
|
level: PropTypes.oneOf(['error', 'warning', 'typesetting', 'raw']).isRequired,
|
2020-11-26 04:58:42 -05:00
|
|
|
showSourceLocationLink: PropTypes.bool,
|
2020-11-16 05:01:01 -05:00
|
|
|
showCloseButton: PropTypes.bool,
|
2020-11-26 04:58:42 -05:00
|
|
|
entryAriaLabel: PropTypes.string,
|
|
|
|
onSourceLocationClick: PropTypes.func,
|
2020-11-16 05:01:01 -05:00
|
|
|
onClose: PropTypes.func
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
export default PreviewLogsPaneEntry
|