pdf-logs-button-content.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from '../../../shared/components/icon'
  3. import PropTypes from 'prop-types'
  4. import { memo } from 'react'
  5. export function PdfLogsButtonContent({
  6. showLogs,
  7. logEntries,
  8. codeCheckFailed,
  9. }) {
  10. const { t } = useTranslation()
  11. if (showLogs) {
  12. return (
  13. <>
  14. <Icon type="file-pdf-o" />
  15. <span className="toolbar-text toolbar-hide-small">{t('view_pdf')}</span>
  16. </>
  17. )
  18. }
  19. if (codeCheckFailed) {
  20. return (
  21. <>
  22. <Icon type="exclamation-triangle" />
  23. <span className="toolbar-text toolbar-hide-small">
  24. {t('code_check_failed')}
  25. </span>
  26. </>
  27. )
  28. }
  29. const count = logEntries?.errors?.length || logEntries?.warnings?.length
  30. if (!count) {
  31. return (
  32. <>
  33. <Icon type="file-text-o" />
  34. <span className="toolbar-text toolbar-hide-small">
  35. {t('view_logs')}
  36. </span>
  37. </>
  38. )
  39. }
  40. return (
  41. <>
  42. <Icon type="file-text-o" />
  43. <span className="btn-toggle-logs-label toolbar-text toolbar-hide-small">
  44. {logEntries.errors?.length
  45. ? t('your_project_has_an_error', { count })
  46. : t('view_warning', { count })}
  47. <span className="sr-hidden">
  48. {count > 1 && ` (${count > 99 ? '99+' : count})`}
  49. </span>
  50. </span>
  51. </>
  52. )
  53. }
  54. PdfLogsButtonContent.propTypes = {
  55. codeCheckFailed: PropTypes.bool,
  56. showLogs: PropTypes.bool,
  57. logEntries: PropTypes.object,
  58. }
  59. export default memo(PdfLogsButtonContent)