traceShortcutsModal.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {Fragment, useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import tracingKeyboardShortcuts from 'sentry-images/spot/tracing-keyboard-shortcuts.svg';
  4. import {type ModalRenderProps, openModal} from 'sentry/actionCreators/modal';
  5. import {Button} from 'sentry/components/button';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {traceAnalytics} from './traceAnalytics';
  10. import {useHasTraceNewUi} from './useHasTraceNewUi';
  11. export function TraceShortcuts() {
  12. const hasTraceNewUi = useHasTraceNewUi();
  13. const organization = useOrganization();
  14. const onOpenShortcutsClick = useCallback(() => {
  15. traceAnalytics.trackViewShortcuts(organization);
  16. openModal(props => <TraceShortcutsModal {...props} />);
  17. }, [organization]);
  18. if (hasTraceNewUi) {
  19. return null;
  20. }
  21. return (
  22. <Button size="xs" onClick={onOpenShortcutsClick} aria-label={t('Trace Shortcuts')}>
  23. Shortcuts
  24. </Button>
  25. );
  26. }
  27. const KEYBOARD_SHORTCUTS: [string, string][] = [
  28. ['\u2191 / \u2193', t('Navigate up or down')],
  29. ['\u2190 / \u2192', t('Collapse or expand')],
  30. [t('Shift') + ' + \u2191 / \u2193', t('Jump to first/last element')],
  31. ];
  32. const TIMELINE_SHORTCUTS: [string, string][] = [
  33. [t('Cmd / Ctrl + Scroll'), t('Zoom in/out at cursor')],
  34. [t('Shift + Scroll'), t('Scroll horizontally')],
  35. [t('Double click'), t('Zoom to fill')],
  36. ];
  37. export function TraceShortcutsModal({Header, Body}: ModalRenderProps) {
  38. return (
  39. <Fragment>
  40. <Header closeButton>
  41. <h2>{t('Shortcuts')}</h2>
  42. </Header>
  43. <Body>
  44. <ShortcutsLayout>
  45. <div>
  46. <Shortcuts>
  47. {KEYBOARD_SHORTCUTS.map(([key, description]) => (
  48. <Shortcut key={key}>
  49. <strong>{key}</strong>
  50. <div>{description}</div>
  51. </Shortcut>
  52. ))}
  53. {TIMELINE_SHORTCUTS.map(([key, description]) => (
  54. <Shortcut key={key}>
  55. <strong>{key}</strong>
  56. <div>{description}</div>
  57. </Shortcut>
  58. ))}
  59. </Shortcuts>
  60. </div>
  61. <div>
  62. <img src={tracingKeyboardShortcuts} alt={t('Sentry cant fix this')} />
  63. </div>
  64. </ShortcutsLayout>
  65. </Body>
  66. </Fragment>
  67. );
  68. }
  69. const ShortcutsLayout = styled('div')`
  70. display: grid;
  71. grid-template-columns: 1fr 38%;
  72. gap: ${space(2)};
  73. img {
  74. width: 100%;
  75. height: 100%;
  76. object-fit: cover;
  77. }
  78. `;
  79. const Shortcuts = styled('ul')`
  80. list-style-type: none;
  81. margin-bottom: 0;
  82. padding: 0;
  83. font-size: ${p => p.theme.fontSizeSmall};
  84. &:not(:last-child) {
  85. margin: 0 0 ${space(3)} 0;
  86. }
  87. `;
  88. const Shortcut = styled('li')`
  89. height: 28px;
  90. display: grid;
  91. grid-template-columns: min-content 1fr;
  92. strong {
  93. display: inline-block;
  94. min-width: 130px;
  95. color: ${p => p.theme.purple300};
  96. }
  97. `;