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'
|
2021-01-21 07:21:22 -05:00
|
|
|
import usePersistedState from '../../../infrastructure/persisted-state-hook'
|
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} />
|
|
|
|
))
|
|
|
|
|
2020-12-15 05:23:54 -05:00
|
|
|
const validationIssuesUI = Object.keys(
|
|
|
|
validationIssues
|
|
|
|
).map((name, index) => (
|
|
|
|
<PreviewValidationIssue
|
|
|
|
key={index}
|
|
|
|
name={name}
|
|
|
|
details={validationIssues[name]}
|
|
|
|
/>
|
|
|
|
))
|
2020-11-26 04:58:42 -05:00
|
|
|
|
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}
|
2021-01-05 05:56:38 -05:00
|
|
|
logType={logEntry.type}
|
2020-11-26 04:58:42 -05:00
|
|
|
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">
|
2021-01-21 07:21:22 -05:00
|
|
|
<LogsPaneBetaNotice />
|
2020-12-02 05:03:03 -05:00
|
|
|
{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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-21 07:21:22 -05:00
|
|
|
function LogsPaneBetaNotice() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const [dismissedBetaNotice, setDismissedBetaNotice] = usePersistedState(
|
|
|
|
`logs_pane.dismissed_beta_notice`,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
|
|
|
|
function handleDismissButtonClick() {
|
|
|
|
setDismissedBetaNotice(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
return dismissedBetaNotice ? null : (
|
|
|
|
<div className="log-entry">
|
|
|
|
<div className="log-entry-header log-entry-header-raw">
|
|
|
|
<div className="log-entry-header-icon-container">
|
|
|
|
<span className="beta-badge" />
|
|
|
|
</div>
|
|
|
|
<h3 className="log-entry-header-title">
|
|
|
|
{t('logs_pane_beta_message')}
|
|
|
|
</h3>
|
|
|
|
<a
|
|
|
|
href="/beta/participate"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="log-entry-header-link log-entry-header-link-raw"
|
|
|
|
>
|
|
|
|
<span className="log-entry-header-link-location">
|
|
|
|
{t('give_feedback')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
<button
|
|
|
|
className="btn-inline-link log-entry-header-link"
|
|
|
|
type="button"
|
|
|
|
aria-label={t('dismiss')}
|
|
|
|
onClick={handleDismissButtonClick}
|
|
|
|
>
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
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
|