import React from 'react'
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'
import { Dropdown } from 'react-bootstrap'
import PreviewLogsPaneEntry from './preview-logs-pane-entry'
import PreviewValidationIssue from './preview-validation-issue'
import PreviewDownloadFileList from './preview-download-file-list'
import PreviewError from './preview-error'
import Icon from '../../../shared/components/icon'
import usePersistedState from '../../../infrastructure/persisted-state-hook'
function PreviewLogsPane({
logEntries = { all: [], errors: [], warnings: [], typesetting: [] },
rawLog = '',
validationIssues = {},
errors = {},
outputFiles = [],
isClearingCache,
isCompiling = false,
autoCompileHasLintingError = false,
variantWithFirstErrorPopup,
onLogEntryLocationClick,
onClearCache,
}) {
const { t } = useTranslation()
const {
all: allCompilerIssues = [],
errors: compilerErrors = [],
warnings: compilerWarnings = [],
typesetting: compilerTypesettingIssues = [],
} = logEntries
const errorsUI = Object.keys(errors).map((name, index) => (
))
const validationIssuesUI = Object.keys(
validationIssues
).map((name, index) => (
))
const logEntriesUI = [
...compilerErrors,
...compilerWarnings,
...compilerTypesettingIssues,
].map((logEntry, idx) => (
))
const actionsUI = (
)
const rawLogUI = (
)
return (
{autoCompileHasLintingError ?
: null}
{errors ? errorsUI : null}
{validationIssues ? validationIssuesUI : null}
{allCompilerIssues.length > 0 ? logEntriesUI : null}
{rawLog && rawLog !== '' ? rawLogUI : null}
{actionsUI}
)
}
function AutoCompileLintingErrorEntry() {
const { t } = useTranslation()
return (
{t('code_check_failed_explanation')}
)
}
function LogsPaneInfoNotice({ variantWithFirstErrorPopup }) {
const { t } = useTranslation()
const [dismissedInfoNotice, setDismissedInfoNotice] = usePersistedState(
`logs_pane.dismissed_info_notice`,
false
)
const surveyLink = variantWithFirstErrorPopup
? 'https://forms.gle/AUbDDRvroQ7KFwHR9'
: 'https://forms.gle/bRxevtGzBHRk8BKw8'
function handleDismissButtonClick() {
setDismissedInfoNotice(true)
}
return dismissedInfoNotice ? null : (
)
}
LogsPaneInfoNotice.propTypes = {
variantWithFirstErrorPopup: PropTypes.bool,
}
PreviewLogsPane.propTypes = {
logEntries: PropTypes.shape({
all: PropTypes.array,
errors: PropTypes.array,
warning: PropTypes.array,
typesetting: PropTypes.array,
}),
autoCompileHasLintingError: PropTypes.bool,
rawLog: PropTypes.string,
outputFiles: PropTypes.array,
isClearingCache: PropTypes.bool,
isCompiling: PropTypes.bool,
variantWithFirstErrorPopup: PropTypes.bool,
onLogEntryLocationClick: PropTypes.func.isRequired,
onClearCache: PropTypes.func.isRequired,
validationIssues: PropTypes.object,
errors: PropTypes.object,
}
export default PreviewLogsPane