2020-09-28 06:51:15 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-11-16 05:15:29 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-12-02 05:03:03 -05:00
|
|
|
import { Dropdown } from 'react-bootstrap'
|
2020-11-26 04:58:42 -05:00
|
|
|
import PreviewLogsPaneEntry from './preview-logs-pane-entry'
|
|
|
|
import PreviewValidationIssue from './preview-validation-issue'
|
2020-12-02 05:03:03 -05:00
|
|
|
import PreviewDownloadFileList from './preview-download-file-list'
|
2020-11-26 04:58:42 -05:00
|
|
|
import PreviewError from './preview-error'
|
2020-12-02 05:03:03 -05:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
function PreviewLogsPane({
|
2020-12-02 05:03:03 -05:00
|
|
|
logEntries = { all: [], errors: [], warnings: [], typesetting: [] },
|
2020-11-26 04:58:42 -05:00
|
|
|
rawLog = '',
|
|
|
|
validationIssues = {},
|
|
|
|
errors = {},
|
2020-12-02 05:03:03 -05:00
|
|
|
outputFiles = [],
|
|
|
|
isClearingCache,
|
|
|
|
isCompiling = false,
|
|
|
|
onLogEntryLocationClick,
|
|
|
|
onClearCache
|
2020-11-26 04:58:42 -05:00
|
|
|
}) {
|
2020-11-16 05:15:29 -05:00
|
|
|
const { t } = useTranslation()
|
2020-12-02 05:03:03 -05:00
|
|
|
const {
|
|
|
|
all: allCompilerIssues = [],
|
|
|
|
errors: compilerErrors = [],
|
|
|
|
warnings: compilerWarnings = [],
|
|
|
|
typesetting: compilerTypesettingIssues = []
|
|
|
|
} = logEntries
|
2020-11-16 05:15:29 -05:00
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
const errorsUI = Object.keys(errors).map((name, index) => (
|
|
|
|
<PreviewError key={index} name={name} />
|
|
|
|
))
|
|
|
|
|
|
|
|
const validationIssuesUI = Object.keys(validationIssues).map(
|
|
|
|
(name, index) => (
|
|
|
|
<PreviewValidationIssue
|
|
|
|
key={index}
|
|
|
|
name={name}
|
|
|
|
details={validationIssues[name]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-12-02 05:03:03 -05:00
|
|
|
const logEntriesUI = [
|
|
|
|
...compilerErrors,
|
|
|
|
...compilerWarnings,
|
|
|
|
...compilerTypesettingIssues
|
|
|
|
].map((logEntry, idx) => (
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
key={idx}
|
|
|
|
headerTitle={logEntry.message}
|
|
|
|
rawContent={logEntry.content}
|
|
|
|
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={onLogEntryLocationClick}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
|
2020-12-02 05:03:03 -05:00
|
|
|
const actionsUI = (
|
|
|
|
<div className="logs-pane-actions">
|
|
|
|
<button
|
|
|
|
className="btn btn-sm btn-danger logs-pane-actions-clear-cache"
|
|
|
|
onClick={onClearCache}
|
|
|
|
disabled={isClearingCache || isCompiling}
|
|
|
|
>
|
|
|
|
{isClearingCache ? (
|
|
|
|
<Icon type="refresh" spin />
|
|
|
|
) : (
|
|
|
|
<Icon type="trash-o" />
|
|
|
|
)}
|
|
|
|
|
|
|
|
<span>{t('clear_cached_files')}</span>
|
|
|
|
</button>
|
|
|
|
<Dropdown
|
|
|
|
id="dropdown-files-logs-pane"
|
|
|
|
dropup
|
|
|
|
pullRight
|
|
|
|
disabled={isCompiling}
|
|
|
|
>
|
|
|
|
<Dropdown.Toggle
|
|
|
|
className="btn btn-sm btn-info dropdown-toggle"
|
|
|
|
title={t('other_logs_and_files')}
|
|
|
|
bsStyle="info"
|
|
|
|
/>
|
|
|
|
<Dropdown.Menu id="dropdown-files-logs-pane-list">
|
|
|
|
<PreviewDownloadFileList fileList={outputFiles} />
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
const rawLogUI = (
|
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
headerTitle={t('raw_logs')}
|
|
|
|
rawContent={rawLog}
|
|
|
|
entryAriaLabel={t('raw_logs_description')}
|
|
|
|
level="raw"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
return (
|
2020-11-05 05:22:05 -05:00
|
|
|
<div className="logs-pane">
|
2020-12-02 05:03:03 -05:00
|
|
|
<div className="logs-pane-content">
|
|
|
|
{errors ? errorsUI : null}
|
|
|
|
{validationIssues ? validationIssuesUI : null}
|
|
|
|
{allCompilerIssues.length > 0 ? logEntriesUI : null}
|
|
|
|
{rawLog && rawLog !== '' ? rawLogUI : null}
|
|
|
|
{actionsUI}
|
|
|
|
</div>
|
2020-09-28 06:51:15 -04:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewLogsPane.propTypes = {
|
2020-12-02 05:03:03 -05:00
|
|
|
logEntries: PropTypes.shape({
|
|
|
|
all: PropTypes.array,
|
|
|
|
errors: PropTypes.array,
|
|
|
|
warning: PropTypes.array,
|
|
|
|
typesetting: PropTypes.array
|
|
|
|
}),
|
2020-11-16 05:15:29 -05:00
|
|
|
rawLog: PropTypes.string,
|
2020-12-02 05:03:03 -05:00
|
|
|
outputFiles: PropTypes.array,
|
|
|
|
isClearingCache: PropTypes.bool,
|
|
|
|
isCompiling: PropTypes.bool,
|
2020-11-26 04:58:42 -05:00
|
|
|
onLogEntryLocationClick: PropTypes.func.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache: PropTypes.func.isRequired,
|
2020-11-26 04:58:42 -05:00
|
|
|
validationIssues: PropTypes.object,
|
|
|
|
errors: PropTypes.object
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewLogsPane
|