overleaf/services/web/frontend/js/features/pdf-preview/components/pdf-logs-entries.js
Miguel Serrano 7de1e6f979 Update log error ordering and wording on tips (#5873)
* Show bibtex errors with compile errors
* Update wording on error log tips

GitOrigin-RevId: 0e25a05418b241526958016f1b525334d33ad741
2021-11-26 09:03:07 +00:00

68 lines
1.9 KiB
JavaScript

import { memo, useCallback } from 'react'
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'
import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries'
import PdfLogEntry from './pdf-log-entry'
import { useIdeContext } from '../../../shared/context/ide-context'
const LOG_PREVIEW_LIMIT = 100
function PdfLogsEntries({ entries, hasErrors }) {
const { t } = useTranslation()
const ide = useIdeContext()
const syncToEntry = useCallback(
entry => {
const entity = ide.fileTreeManager.findEntityByPath(entry.file)
if (entity && entity.type === 'doc') {
ide.editorManager.openDoc(entity, {
gotoLine: entry.line ?? undefined,
gotoColumn: entry.column ?? undefined,
})
}
},
[ide]
)
const logEntries = entries.slice(0, LOG_PREVIEW_LIMIT)
return (
<>
{entries.length > LOG_PREVIEW_LIMIT && (
<PreviewLogsPaneMaxEntries
totalEntries={entries.length}
entriesShown={LOG_PREVIEW_LIMIT}
hasErrors={hasErrors}
/>
)}
{logEntries.map(logEntry => (
<PdfLogEntry
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),
hasErrors: PropTypes.bool,
}
export default memo(PdfLogsEntries)