show-history-button.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useTranslation } from 'react-i18next'
  2. import OLIconButton from '@/shared/components/ol/ol-icon-button'
  3. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  4. import { useLayoutContext } from '@/shared/context/layout-context'
  5. import { useCallback } from 'react'
  6. import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
  7. export default function ShowHistoryButton() {
  8. const { t } = useTranslation()
  9. const { view, setView, restoreView } = useLayoutContext()
  10. const { sendEvent } = useEditorAnalytics()
  11. const toggleHistoryOpen = useCallback(() => {
  12. const action = view === 'history' ? 'close' : 'open'
  13. sendEvent('navigation-clicked-history', { action })
  14. if (view === 'history') {
  15. restoreView()
  16. } else {
  17. setView('history')
  18. }
  19. }, [view, setView, sendEvent, restoreView])
  20. return (
  21. <div className="ide-redesign-toolbar-button-container">
  22. <OLTooltip
  23. id="tooltip-open-history"
  24. description={t('history')}
  25. overlayProps={{ delay: 0, placement: 'bottom' }}
  26. >
  27. <OLIconButton
  28. icon="history"
  29. className="ide-redesign-toolbar-button-subdued ide-redesign-toolbar-button-icon"
  30. onClick={toggleHistoryOpen}
  31. accessibilityLabel={t('history')}
  32. />
  33. </OLTooltip>
  34. </div>
  35. )
  36. }