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,
|
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
|
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,
|
2021-04-27 03:52:58 -04:00
|
|
|
...compilerTypesettingIssues,
|
2020-12-02 05:03:03 -05:00
|
|
|
].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', {
|
2021-04-27 03:52:58 -04:00
|
|
|
level: logEntry.level,
|
2020-11-26 04:58:42 -05:00
|
|
|
})}
|
|
|
|
sourceLocation={{
|
|
|
|
file: logEntry.file,
|
|
|
|
line: logEntry.line,
|
2021-04-27 03:52:58 -04:00
|
|
|
column: logEntry.column,
|
2020-11-26 04:58:42 -05:00
|
|
|
}}
|
|
|
|
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-04-12 05:23:25 -04:00
|
|
|
<LogsPaneInfoNotice
|
|
|
|
variantWithFirstErrorPopup={variantWithFirstErrorPopup}
|
|
|
|
/>
|
2021-03-18 09:49:01 -04:00
|
|
|
{autoCompileHasLintingError ? <AutoCompileLintingErrorEntry /> : null}
|
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-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-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
|