2021-09-30 07:29:25 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-10-08 05:42:49 -04:00
|
|
|
import PreviewLogsPaneMaxEntries from '../../preview/components/preview-logs-pane-max-entries'
|
2021-10-15 05:45:06 -04:00
|
|
|
import PdfLogEntry from './pdf-log-entry'
|
2021-10-21 06:31:51 -04:00
|
|
|
import { useIdeContext } from '../../../shared/context/ide-context'
|
2022-01-10 10:46:05 -05:00
|
|
|
import useDetachAction from '../../../shared/hooks/use-detach-action'
|
2021-10-08 05:42:49 -04:00
|
|
|
|
|
|
|
const LOG_PREVIEW_LIMIT = 100
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2021-11-25 05:24:25 -05:00
|
|
|
function PdfLogsEntries({ entries, hasErrors }) {
|
2021-09-30 07:29:25 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-10-21 06:31:51 -04:00
|
|
|
const ide = useIdeContext()
|
|
|
|
|
2022-01-10 10:46:05 -05:00
|
|
|
const _syncToEntry = useCallback(
|
2021-10-21 06:31:51 -04:00
|
|
|
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]
|
|
|
|
)
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2022-01-10 10:46:05 -05:00
|
|
|
const syncToEntry = useDetachAction(
|
|
|
|
'sync-to-entry',
|
|
|
|
_syncToEntry,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
totalEntries={entries.length}
|
|
|
|
entriesShown={LOG_PREVIEW_LIMIT}
|
2021-11-25 05:24:25 -05:00
|
|
|
hasErrors={hasErrors}
|
2021-10-08 05:42:49 -04:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{logEntries.map(logEntry => (
|
2021-10-15 05:45:06 -04:00
|
|
|
<PdfLogEntry
|
2021-09-30 07:29:25 -04:00
|
|
|
key={logEntry.key}
|
2022-03-31 07:22:36 -04:00
|
|
|
ruleId={logEntry.ruleId}
|
2021-09-30 07:29:25 -04:00
|
|
|
headerTitle={logEntry.message}
|
|
|
|
rawContent={logEntry.content}
|
|
|
|
logType={logEntry.type}
|
|
|
|
level={logEntry.level}
|
2023-02-20 08:45:22 -05:00
|
|
|
contentDetails={logEntry.contentDetails}
|
2021-09-30 07:29:25 -04:00
|
|
|
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),
|
2021-11-25 05:24:25 -05:00
|
|
|
hasErrors: PropTypes.bool,
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfLogsEntries)
|