2020-11-16 05:01:01 -05:00
|
|
|
import React, { useState } from 'react'
|
2020-09-28 06:51:15 -04:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import PreviewToolbar from './preview-toolbar'
|
|
|
|
import PreviewLogsPane from './preview-logs-pane'
|
2020-11-16 05:01:01 -05:00
|
|
|
import PreviewFirstErrorPopUp from './preview-first-error-pop-up'
|
2020-10-06 11:23:03 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
|
|
|
function PreviewPane({
|
|
|
|
compilerState,
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile,
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRunSyntaxCheckNow,
|
|
|
|
onSetAutoCompile,
|
|
|
|
onSetDraftMode,
|
|
|
|
onSetSyntaxCheck,
|
|
|
|
onToggleLogs,
|
2020-12-02 05:03:03 -05:00
|
|
|
onSetFullLayout,
|
|
|
|
onSetSplitLayout,
|
|
|
|
onStopCompilation,
|
2020-10-20 08:44:32 -04:00
|
|
|
outputFiles,
|
|
|
|
pdfDownloadUrl,
|
2020-11-16 05:01:01 -05:00
|
|
|
onLogEntryLocationClick,
|
2020-12-02 05:03:03 -05:00
|
|
|
showLogs,
|
2021-03-23 06:18:28 -04:00
|
|
|
variantWithFirstErrorPopup = true,
|
2020-12-02 05:03:03 -05:00
|
|
|
splitLayout
|
2020-09-28 06:51:15 -04:00
|
|
|
}) {
|
2020-10-06 11:23:03 -04:00
|
|
|
const { t } = useTranslation()
|
2020-11-16 05:01:01 -05:00
|
|
|
|
|
|
|
const [lastCompileTimestamp, setLastCompileTimestamp] = useState(
|
|
|
|
compilerState.lastCompileTimestamp
|
|
|
|
)
|
|
|
|
const [seenLogsForCurrentCompile, setSeenLogsForCurrentCompile] = useState(
|
|
|
|
false
|
|
|
|
)
|
|
|
|
const [dismissedFirstErrorPopUp, setDismissedFirstErrorPopUp] = useState(
|
|
|
|
false
|
|
|
|
)
|
|
|
|
|
|
|
|
if (lastCompileTimestamp < compilerState.lastCompileTimestamp) {
|
|
|
|
setLastCompileTimestamp(compilerState.lastCompileTimestamp)
|
|
|
|
setSeenLogsForCurrentCompile(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showLogs && !seenLogsForCurrentCompile) {
|
|
|
|
setSeenLogsForCurrentCompile(true)
|
|
|
|
}
|
|
|
|
|
2020-09-29 07:08:49 -04:00
|
|
|
const nErrors =
|
|
|
|
compilerState.logEntries && compilerState.logEntries.errors
|
|
|
|
? compilerState.logEntries.errors.length
|
|
|
|
: 0
|
|
|
|
const nWarnings =
|
|
|
|
compilerState.logEntries && compilerState.logEntries.warnings
|
|
|
|
? compilerState.logEntries.warnings.length
|
|
|
|
: 0
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
const hasCLSIErrors =
|
|
|
|
compilerState.errors &&
|
|
|
|
Object.keys(compilerState.errors).length > 0 &&
|
|
|
|
compilerState.compileFailed &&
|
|
|
|
!compilerState.isCompiling
|
|
|
|
|
|
|
|
const hasValidationIssues =
|
|
|
|
compilerState.validationIssues &&
|
|
|
|
Object.keys(compilerState.validationIssues).length > 0 &&
|
|
|
|
compilerState.compileFailed &&
|
|
|
|
!compilerState.isCompiling
|
|
|
|
|
2020-11-16 05:01:01 -05:00
|
|
|
const showFirstErrorPopUp =
|
2021-03-23 06:18:28 -04:00
|
|
|
variantWithFirstErrorPopup &&
|
2020-11-16 05:01:01 -05:00
|
|
|
nErrors > 0 &&
|
|
|
|
!seenLogsForCurrentCompile &&
|
|
|
|
!dismissedFirstErrorPopUp &&
|
|
|
|
!compilerState.isCompiling
|
|
|
|
|
|
|
|
function handleFirstErrorPopUpClose() {
|
|
|
|
setDismissedFirstErrorPopUp(true)
|
|
|
|
}
|
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PreviewToolbar
|
|
|
|
compilerState={compilerState}
|
2021-03-18 09:49:01 -04:00
|
|
|
logsState={{ nErrors, nWarnings }}
|
2020-09-29 07:08:49 -04:00
|
|
|
showLogs={showLogs}
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile={onRecompile}
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch={onRecompileFromScratch}
|
2020-09-28 06:51:15 -04:00
|
|
|
onRunSyntaxCheckNow={onRunSyntaxCheckNow}
|
|
|
|
onSetAutoCompile={onSetAutoCompile}
|
|
|
|
onSetDraftMode={onSetDraftMode}
|
|
|
|
onSetSyntaxCheck={onSetSyntaxCheck}
|
|
|
|
onToggleLogs={onToggleLogs}
|
2020-12-02 05:03:03 -05:00
|
|
|
onSetSplitLayout={onSetSplitLayout}
|
|
|
|
onSetFullLayout={onSetFullLayout}
|
|
|
|
onStopCompilation={onStopCompilation}
|
2020-10-20 08:44:32 -04:00
|
|
|
outputFiles={outputFiles}
|
|
|
|
pdfDownloadUrl={pdfDownloadUrl}
|
2020-12-02 05:03:03 -05:00
|
|
|
splitLayout={splitLayout}
|
2020-09-28 06:51:15 -04:00
|
|
|
/>
|
2020-11-26 04:58:42 -05:00
|
|
|
<span aria-live="polite" className="sr-only">
|
|
|
|
{hasCLSIErrors ? t('compile_error_description') : ''}
|
|
|
|
</span>
|
|
|
|
<span aria-live="polite" className="sr-only">
|
|
|
|
{hasValidationIssues ? t('validation_issue_description') : ''}
|
|
|
|
</span>
|
2020-10-06 11:23:03 -04:00
|
|
|
<span aria-live="polite" className="sr-only">
|
2020-10-07 06:43:54 -04:00
|
|
|
{nErrors && !compilerState.isCompiling
|
|
|
|
? t('n_errors', { count: nErrors })
|
|
|
|
: ''}
|
2020-10-06 11:23:03 -04:00
|
|
|
</span>
|
|
|
|
<span aria-live="polite" className="sr-only">
|
2020-10-07 06:43:54 -04:00
|
|
|
{nWarnings && !compilerState.isCompiling
|
|
|
|
? t('n_warnings', { count: nWarnings })
|
|
|
|
: ''}
|
2020-10-06 11:23:03 -04:00
|
|
|
</span>
|
2020-11-16 05:01:01 -05:00
|
|
|
{showFirstErrorPopUp ? (
|
|
|
|
<PreviewFirstErrorPopUp
|
|
|
|
logEntry={compilerState.logEntries.errors[0]}
|
|
|
|
onGoToErrorLocation={onLogEntryLocationClick}
|
|
|
|
onViewLogs={onToggleLogs}
|
|
|
|
onClose={handleFirstErrorPopUpClose}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-09-29 07:08:49 -04:00
|
|
|
{showLogs ? (
|
2020-11-05 05:22:05 -05:00
|
|
|
<PreviewLogsPane
|
2020-12-02 05:03:03 -05:00
|
|
|
logEntries={compilerState.logEntries}
|
2020-11-16 05:15:29 -05:00
|
|
|
rawLog={compilerState.rawLog}
|
2020-11-26 04:58:42 -05:00
|
|
|
validationIssues={compilerState.validationIssues}
|
|
|
|
errors={compilerState.errors}
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasLintingError={compilerState.autoCompileHasLintingError}
|
2020-12-02 05:03:03 -05:00
|
|
|
outputFiles={outputFiles}
|
2020-11-16 05:01:01 -05:00
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
2020-12-02 05:03:03 -05:00
|
|
|
isClearingCache={compilerState.isClearingCache}
|
|
|
|
isCompiling={compilerState.isCompiling}
|
2021-04-12 05:23:25 -04:00
|
|
|
variantWithFirstErrorPopup={variantWithFirstErrorPopup}
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache={onClearCache}
|
2020-11-05 05:22:05 -05:00
|
|
|
/>
|
2020-09-29 07:08:49 -04:00
|
|
|
) : null}
|
2020-09-28 06:51:15 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewPane.propTypes = {
|
|
|
|
compilerState: PropTypes.shape({
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasLintingError: PropTypes.bool,
|
2020-09-28 06:51:15 -04:00
|
|
|
isAutoCompileOn: PropTypes.bool.isRequired,
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
isDraftModeOn: PropTypes.bool.isRequired,
|
2020-09-29 07:08:49 -04:00
|
|
|
isSyntaxCheckOn: PropTypes.bool.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
isClearingCache: PropTypes.bool.isRequired,
|
2020-11-16 05:01:01 -05:00
|
|
|
lastCompileTimestamp: PropTypes.number,
|
2020-11-26 04:58:42 -05:00
|
|
|
logEntries: PropTypes.object,
|
|
|
|
validationIssues: PropTypes.object,
|
|
|
|
errors: PropTypes.object,
|
|
|
|
rawLog: PropTypes.string,
|
|
|
|
compileFailed: PropTypes.bool
|
2020-09-28 06:51:15 -04:00
|
|
|
}),
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache: PropTypes.func.isRequired,
|
2020-11-16 05:01:01 -05:00
|
|
|
onLogEntryLocationClick: PropTypes.func.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile: PropTypes.func.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch: PropTypes.func.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRunSyntaxCheckNow: PropTypes.func.isRequired,
|
|
|
|
onSetAutoCompile: PropTypes.func.isRequired,
|
|
|
|
onSetDraftMode: PropTypes.func.isRequired,
|
|
|
|
onSetSyntaxCheck: PropTypes.func.isRequired,
|
2020-12-02 05:03:03 -05:00
|
|
|
onSetSplitLayout: PropTypes.func.isRequired,
|
|
|
|
onSetFullLayout: PropTypes.func.isRequired,
|
|
|
|
onStopCompilation: PropTypes.func.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
onToggleLogs: PropTypes.func.isRequired,
|
2020-10-20 08:44:32 -04:00
|
|
|
outputFiles: PropTypes.array,
|
|
|
|
pdfDownloadUrl: PropTypes.string,
|
2020-12-02 05:03:03 -05:00
|
|
|
showLogs: PropTypes.bool.isRequired,
|
2021-03-23 06:18:28 -04:00
|
|
|
variantWithFirstErrorPopup: PropTypes.bool,
|
2020-12-02 05:03:03 -05:00
|
|
|
splitLayout: PropTypes.bool.isRequired
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewPane
|