traceShortcutsModal.tsx 2.8 KB

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