preview-logs-pane.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import { useTranslation } from 'react-i18next'
  4. import { Dropdown } from 'react-bootstrap'
  5. import PreviewLogsPaneEntry from './preview-logs-pane-entry'
  6. import PreviewValidationIssue from './preview-validation-issue'
  7. import PreviewDownloadFileList from './preview-download-file-list'
  8. import PreviewError from './preview-error'
  9. import Icon from '../../../shared/components/icon'
  10. function PreviewLogsPane({
  11. logEntries = { all: [], errors: [], warnings: [], typesetting: [] },
  12. rawLog = '',
  13. validationIssues = {},
  14. errors = {},
  15. outputFiles = [],
  16. isClearingCache,
  17. isCompiling = false,
  18. onLogEntryLocationClick,
  19. onClearCache
  20. }) {
  21. const { t } = useTranslation()
  22. const {
  23. all: allCompilerIssues = [],
  24. errors: compilerErrors = [],
  25. warnings: compilerWarnings = [],
  26. typesetting: compilerTypesettingIssues = []
  27. } = logEntries
  28. const errorsUI = Object.keys(errors).map((name, index) => (
  29. <PreviewError key={index} name={name} />
  30. ))
  31. const validationIssuesUI = Object.keys(validationIssues).map(
  32. (name, index) => (
  33. <PreviewValidationIssue
  34. key={index}
  35. name={name}
  36. details={validationIssues[name]}
  37. />
  38. )
  39. )
  40. const logEntriesUI = [
  41. ...compilerErrors,
  42. ...compilerWarnings,
  43. ...compilerTypesettingIssues
  44. ].map((logEntry, idx) => (
  45. <PreviewLogsPaneEntry
  46. key={idx}
  47. headerTitle={logEntry.message}
  48. rawContent={logEntry.content}
  49. formattedContent={logEntry.humanReadableHintComponent}
  50. extraInfoURL={logEntry.extraInfoURL}
  51. level={logEntry.level}
  52. entryAriaLabel={t('log_entry_description', {
  53. level: logEntry.level
  54. })}
  55. sourceLocation={{
  56. file: logEntry.file,
  57. line: logEntry.line,
  58. column: logEntry.column
  59. }}
  60. onSourceLocationClick={onLogEntryLocationClick}
  61. />
  62. ))
  63. const actionsUI = (
  64. <div className="logs-pane-actions">
  65. <button
  66. className="btn btn-sm btn-danger logs-pane-actions-clear-cache"
  67. onClick={onClearCache}
  68. disabled={isClearingCache || isCompiling}
  69. >
  70. {isClearingCache ? (
  71. <Icon type="refresh" spin />
  72. ) : (
  73. <Icon type="trash-o" />
  74. )}
  75. &nbsp;
  76. <span>{t('clear_cached_files')}</span>
  77. </button>
  78. <Dropdown
  79. id="dropdown-files-logs-pane"
  80. dropup
  81. pullRight
  82. disabled={isCompiling}
  83. >
  84. <Dropdown.Toggle
  85. className="btn btn-sm btn-info dropdown-toggle"
  86. title={t('other_logs_and_files')}
  87. bsStyle="info"
  88. />
  89. <Dropdown.Menu id="dropdown-files-logs-pane-list">
  90. <PreviewDownloadFileList fileList={outputFiles} />
  91. </Dropdown.Menu>
  92. </Dropdown>
  93. </div>
  94. )
  95. const rawLogUI = (
  96. <PreviewLogsPaneEntry
  97. headerTitle={t('raw_logs')}
  98. rawContent={rawLog}
  99. entryAriaLabel={t('raw_logs_description')}
  100. level="raw"
  101. />
  102. )
  103. return (
  104. <div className="logs-pane">
  105. <div className="logs-pane-content">
  106. {errors ? errorsUI : null}
  107. {validationIssues ? validationIssuesUI : null}
  108. {allCompilerIssues.length > 0 ? logEntriesUI : null}
  109. {rawLog && rawLog !== '' ? rawLogUI : null}
  110. {actionsUI}
  111. </div>
  112. </div>
  113. )
  114. }
  115. PreviewLogsPane.propTypes = {
  116. logEntries: PropTypes.shape({
  117. all: PropTypes.array,
  118. errors: PropTypes.array,
  119. warning: PropTypes.array,
  120. typesetting: PropTypes.array
  121. }),
  122. rawLog: PropTypes.string,
  123. outputFiles: PropTypes.array,
  124. isClearingCache: PropTypes.bool,
  125. isCompiling: PropTypes.bool,
  126. onLogEntryLocationClick: PropTypes.func.isRequired,
  127. onClearCache: PropTypes.func.isRequired,
  128. validationIssues: PropTypes.object,
  129. errors: PropTypes.object
  130. }
  131. export default PreviewLogsPane