traceShortcuts.tsx 2.6 KB

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