traceShortcutsModal.tsx 2.9 KB

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