2020-09-28 06:51:15 -04:00
|
|
|
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'
|
2021-10-06 04:33:18 -04:00
|
|
|
import PreviewLogsPaneMaxEntries from './preview-logs-pane-max-entries'
|
2020-11-26 04:58:42 -05:00
|
|
|
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-05-18 06:56:56 -04:00
|
|
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
2021-06-18 05:29:06 -04:00
|
|
|
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
2021-10-06 04:33:18 -04:00
|
|
|
const LOG_PREVIEW_LIMIT = 100
|
|
|
|
|
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,
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasLintingError = false,
|
2021-04-12 05:23:25 -04:00
|
|
|
variantWithFirstErrorPopup,
|
2020-12-02 05:03:03 -05:00
|
|
|
onLogEntryLocationClick,
|
2021-04-27 03:52:58 -04:00
|
|
|
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 = [],
|
2021-04-27 03:52:58 -04:00
|
|
|
typesetting: compilerTypesettingIssues = [],
|
2020-12-02 05:03:03 -05:00
|
|
|
} = logEntries
|
2021-07-05 09:56:24 -04:00
|
|
|
const allLogEntries = [
|
2020-12-02 05:03:03 -05:00
|
|
|
...compilerErrors,
|
|
|
|
...compilerWarnings,
|
2021-04-27 03:52:58 -04:00
|
|
|
...compilerTypesettingIssues,
|
2021-07-05 09:56:24 -04:00
|
|
|
]
|
2020-11-26 04:58:42 -05:00
|
|
|
|
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>
|
2021-06-18 05:29:06 -04:00
|
|
|
<ControlledDropdown
|
2020-12-02 05:03:03 -05:00
|
|
|
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>
|
2021-06-18 05:29:06 -04:00
|
|
|
</ControlledDropdown>
|
2020-12-02 05:03:03 -05:00
|
|
|
</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-04-12 05:23:25 -04:00
|
|
|
<LogsPaneInfoNotice
|
|
|
|
variantWithFirstErrorPopup={variantWithFirstErrorPopup}
|
|
|
|
/>
|
2021-03-18 09:49:01 -04:00
|
|
|
{autoCompileHasLintingError ? <AutoCompileLintingErrorEntry /> : null}
|
2021-07-05 09:56:24 -04:00
|
|
|
{errors ? <PreviewErrors errors={errors} /> : null}
|
|
|
|
{validationIssues ? (
|
|
|
|
<PreviewValidationIssues validationIssues={validationIssues} />
|
|
|
|
) : null}
|
|
|
|
{allCompilerIssues.length > 0 ? (
|
|
|
|
<PreviewLogEntries
|
|
|
|
logEntries={allLogEntries}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-12-02 05:03:03 -05:00
|
|
|
{rawLog && rawLog !== '' ? rawLogUI : null}
|
|
|
|
{actionsUI}
|
|
|
|
</div>
|
2020-09-28 06:51:15 -04:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:56:24 -04:00
|
|
|
const PreviewErrors = ({ errors }) => {
|
|
|
|
const nowTS = Date.now()
|
|
|
|
return Object.entries(errors).map(([name, exists], index) => {
|
|
|
|
return exists && <PreviewError key={`${nowTS}-${index}`} name={name} />
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const PreviewValidationIssues = ({ validationIssues }) => {
|
|
|
|
const nowTS = Date.now()
|
|
|
|
return Object.keys(validationIssues).map((name, index) => (
|
|
|
|
<PreviewValidationIssue
|
|
|
|
key={`${nowTS}-${index}`}
|
|
|
|
name={name}
|
|
|
|
details={validationIssues[name]}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
const PreviewLogEntries = ({ logEntries, onLogEntryLocationClick }) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const nowTS = Date.now()
|
2021-10-06 04:33:18 -04:00
|
|
|
|
|
|
|
const totalLogEntries = logEntries.length
|
|
|
|
|
|
|
|
if (totalLogEntries > LOG_PREVIEW_LIMIT) {
|
|
|
|
logEntries = logEntries.slice(0, 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
logEntries = logEntries.map((logEntry, index) => (
|
2021-07-05 09:56:24 -04:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
key={`${nowTS}-${index}`}
|
|
|
|
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={onLogEntryLocationClick}
|
|
|
|
/>
|
|
|
|
))
|
2021-10-06 04:33:18 -04:00
|
|
|
|
|
|
|
if (totalLogEntries > LOG_PREVIEW_LIMIT) {
|
|
|
|
// Prepend log limit exceeded message to logs array
|
|
|
|
logEntries = [
|
|
|
|
<PreviewLogsPaneMaxEntries
|
|
|
|
key={`${nowTS}-${LOG_PREVIEW_LIMIT}`}
|
|
|
|
totalEntries={totalLogEntries}
|
|
|
|
entriesShown={LOG_PREVIEW_LIMIT}
|
|
|
|
/>,
|
|
|
|
].concat(logEntries)
|
|
|
|
}
|
|
|
|
|
|
|
|
return logEntries
|
2021-07-05 09:56:24 -04:00
|
|
|
}
|
|
|
|
|
2021-03-18 09:49:01 -04:00
|
|
|
function AutoCompileLintingErrorEntry() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
return (
|
|
|
|
<div className="log-entry">
|
|
|
|
<div className="log-entry-header log-entry-header-error">
|
|
|
|
<div className="log-entry-header-icon-container">
|
|
|
|
<Icon type="exclamation-triangle" modifier="fw" />
|
|
|
|
</div>
|
|
|
|
<h3 className="log-entry-header-title">
|
|
|
|
{t('code_check_failed_explanation')}
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-12 05:23:25 -04:00
|
|
|
function LogsPaneInfoNotice({ variantWithFirstErrorPopup }) {
|
2021-01-21 07:21:22 -05:00
|
|
|
const { t } = useTranslation()
|
2021-04-12 05:23:25 -04:00
|
|
|
const [dismissedInfoNotice, setDismissedInfoNotice] = usePersistedState(
|
|
|
|
`logs_pane.dismissed_info_notice`,
|
2021-01-21 07:21:22 -05:00
|
|
|
false
|
|
|
|
)
|
|
|
|
|
2021-04-12 05:23:25 -04:00
|
|
|
const surveyLink = variantWithFirstErrorPopup
|
|
|
|
? 'https://forms.gle/AUbDDRvroQ7KFwHR9'
|
|
|
|
: 'https://forms.gle/bRxevtGzBHRk8BKw8'
|
2021-01-21 07:21:22 -05:00
|
|
|
function handleDismissButtonClick() {
|
2021-04-12 05:23:25 -04:00
|
|
|
setDismissedInfoNotice(true)
|
2021-01-21 07:21:22 -05:00
|
|
|
}
|
|
|
|
|
2021-04-12 05:23:25 -04:00
|
|
|
return dismissedInfoNotice ? null : (
|
2021-01-21 07:21:22 -05:00
|
|
|
<div className="log-entry">
|
|
|
|
<div className="log-entry-header log-entry-header-raw">
|
|
|
|
<div className="log-entry-header-icon-container">
|
2021-04-12 05:23:25 -04:00
|
|
|
<span className="info-badge" />
|
2021-01-21 07:21:22 -05:00
|
|
|
</div>
|
|
|
|
<h3 className="log-entry-header-title">
|
2021-04-12 05:23:25 -04:00
|
|
|
{t('logs_pane_info_message')}
|
2021-01-21 07:21:22 -05:00
|
|
|
</h3>
|
|
|
|
<a
|
2021-04-12 05:23:25 -04:00
|
|
|
href={surveyLink}
|
2021-01-21 07:21:22 -05:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:56:24 -04:00
|
|
|
PreviewErrors.propTypes = {
|
|
|
|
errors: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewValidationIssues.propTypes = {
|
|
|
|
validationIssues: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewLogEntries.propTypes = {
|
|
|
|
logEntries: PropTypes.array.isRequired,
|
|
|
|
onLogEntryLocationClick: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
2021-04-12 05:23:25 -04:00
|
|
|
LogsPaneInfoNotice.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
variantWithFirstErrorPopup: PropTypes.bool,
|
2021-04-12 05:23:25 -04:00
|
|
|
}
|
|
|
|
|
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,
|
2021-04-27 03:52:58 -04:00
|
|
|
typesetting: PropTypes.array,
|
2020-12-02 05:03:03 -05:00
|
|
|
}),
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasLintingError: PropTypes.bool,
|
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,
|
2021-04-12 05:23:25 -04:00
|
|
|
variantWithFirstErrorPopup: 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,
|
2021-04-27 03:52:58 -04:00
|
|
|
errors: PropTypes.object,
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewLogsPane
|