2021-09-30 07:29:25 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import PreviewLogsPaneEntry from '../../preview/components/preview-logs-pane-entry'
|
2021-10-08 05:42:49 -04:00
|
|
|
import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries'
|
|
|
|
|
|
|
|
const LOG_PREVIEW_LIMIT = 100
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
function PdfLogsEntries({ entries }) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const syncToEntry = useCallback(entry => {
|
|
|
|
window.dispatchEvent(
|
|
|
|
new CustomEvent('synctex:sync-to-entry', {
|
|
|
|
detail: entry,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}, [])
|
|
|
|
|
2021-10-08 05:42:49 -04:00
|
|
|
const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT)
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
return (
|
|
|
|
<>
|
2021-10-08 05:42:49 -04:00
|
|
|
{entries.length > LOG_PREVIEW_LIMIT && (
|
|
|
|
<PreviewLogsPaneMaxEntries
|
|
|
|
key={`${entries.length}-${LOG_PREVIEW_LIMIT}`}
|
|
|
|
totalEntries={entries.length}
|
|
|
|
entriesShown={LOG_PREVIEW_LIMIT}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{logEntries.map(logEntry => (
|
2021-09-30 07:29:25 -04:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
key={logEntry.key}
|
|
|
|
headerTitle={logEntry.message}
|
|
|
|
rawContent={logEntry.content}
|
|
|
|
logType={logEntry.type}
|
|
|
|
formattedContent={logEntry.humanReadableHintComponent}
|
|
|
|
extraInfoURL={logEntry.extraInfoURL}
|
|
|
|
level={logEntry.level}
|
|
|
|
entryAriaLabel={t('log_entry_description', {
|
|
|
|
level: logEntry.level,
|
|
|
|
})}
|
|
|
|
sourceLocation={{
|
|
|
|
file: logEntry.file,
|
|
|
|
line: logEntry.line,
|
|
|
|
column: logEntry.column,
|
|
|
|
}}
|
|
|
|
onSourceLocationClick={syncToEntry}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
PdfLogsEntries.propTypes = {
|
|
|
|
entries: PropTypes.arrayOf(PropTypes.object),
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfLogsEntries)
|