pdf-compile-button-inner.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Button } from 'react-bootstrap'
  2. import PropTypes from 'prop-types'
  3. import Tooltip from '../../../shared/components/tooltip'
  4. import Icon from '../../../shared/components/icon'
  5. import { useTranslation } from 'react-i18next'
  6. import { memo, useCallback } from 'react'
  7. import { useSplitTestContext } from '../../../shared/context/split-test-context'
  8. import * as eventTracking from '../../../infrastructure/event-tracking'
  9. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  10. type PdfCompileButtonInnerProps = {
  11. startCompile: () => void
  12. compiling: boolean
  13. }
  14. function PdfCompileButtonInner({
  15. startCompile,
  16. compiling,
  17. }: PdfCompileButtonInnerProps) {
  18. const { t } = useTranslation()
  19. const { splitTestVariants } = useSplitTestContext({
  20. splitTestVariants: PropTypes.object,
  21. })
  22. const recompileButtonTextVariant = splitTestVariants['recompile-button-text']
  23. let compileButtonLabel
  24. if (compiling) {
  25. compileButtonLabel = t('compiling') + '…'
  26. } else if (splitTestVariants['recompile-button-text'] === 'recompile-pdf') {
  27. compileButtonLabel = t('recompile') + ' PDF'
  28. } else {
  29. compileButtonLabel = t('recompile')
  30. }
  31. const handleRecompileButtonClick = useCallback(() => {
  32. if (recompileButtonTextVariant != null) {
  33. // Only send the event when the user is targeted by the
  34. // recompile-button-text split test
  35. eventTracking.sendMB('recompile-pdf-clicked')
  36. }
  37. startCompile()
  38. }, [recompileButtonTextVariant, startCompile])
  39. return (
  40. <Tooltip
  41. id="logs-toggle"
  42. description={
  43. <>
  44. {t('recompile_pdf')}{' '}
  45. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  46. </>
  47. }
  48. tooltipProps={{ className: 'keyboard-tooltip' }}
  49. overlayProps={{ delayShow: 500 }}
  50. >
  51. <Button
  52. className="btn-recompile"
  53. bsStyle="primary"
  54. onClick={handleRecompileButtonClick}
  55. aria-label={compileButtonLabel}
  56. disabled={compiling}
  57. data-ol-loading={compiling}
  58. >
  59. <Icon type="refresh" spin={compiling} />
  60. <span className="toolbar-hide-medium toolbar-hide-small btn-recompile-label">
  61. {compileButtonLabel}
  62. </span>
  63. </Button>
  64. </Tooltip>
  65. )
  66. }
  67. export default memo(PdfCompileButtonInner)