flamegraphOptionsContextMenu.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {Fragment} from 'react';
  2. import {t} from 'sentry/locale';
  3. import {
  4. FlamegraphAxisOptions,
  5. FlamegraphColorCodings,
  6. FlamegraphSorting,
  7. FlamegraphViewOptions,
  8. } from 'sentry/utils/profiling/flamegraph/flamegraphStateProvider/flamegraphPreferences';
  9. import {useFlamegraphPreferences} from 'sentry/utils/profiling/flamegraph/useFlamegraphPreferences';
  10. import {useContextMenu} from 'sentry/utils/profiling/hooks/useContextMenu';
  11. import {
  12. ProfilingContextMenu,
  13. ProfilingContextMenuGroup,
  14. ProfilingContextMenuHeading,
  15. ProfilingContextMenuItemCheckbox,
  16. ProfilingContextMenuLayer,
  17. } from './ProfilingContextMenu/profilingContextMenu';
  18. const FLAMEGRAPH_COLOR_CODINGS: FlamegraphColorCodings = [
  19. 'by symbol name',
  20. 'by system / application',
  21. 'by library',
  22. 'by recursion',
  23. ];
  24. const FLAMEGRAPH_VIEW_OPTIONS: FlamegraphViewOptions = ['top down', 'bottom up'];
  25. const FLAMEGRAPH_SORTING_OPTIONS: FlamegraphSorting = ['left heavy', 'call order'];
  26. const FLAMEGRAPH_AXIS_OPTIONS: FlamegraphAxisOptions = ['standalone', 'transaction'];
  27. interface FlameGraphOptionsContextMenuProps {
  28. contextMenu: ReturnType<typeof useContextMenu>;
  29. }
  30. export function FlamegraphOptionsContextMenu(props: FlameGraphOptionsContextMenuProps) {
  31. const [preferences, dispatch] = useFlamegraphPreferences();
  32. return props.contextMenu.open ? (
  33. <Fragment>
  34. <ProfilingContextMenuLayer onClick={() => props.contextMenu.setOpen(false)} />
  35. <ProfilingContextMenu
  36. {...props.contextMenu.getMenuProps()}
  37. style={{
  38. position: 'absolute',
  39. left: props.contextMenu.position?.left ?? -9999,
  40. top: props.contextMenu.position?.top ?? -9999,
  41. maxHeight: props.contextMenu.containerCoordinates?.height ?? 'auto',
  42. }}
  43. >
  44. <ProfilingContextMenuGroup>
  45. <ProfilingContextMenuHeading>{t('Color Coding')}</ProfilingContextMenuHeading>
  46. {FLAMEGRAPH_COLOR_CODINGS.map((coding, idx) => (
  47. <ProfilingContextMenuItemCheckbox
  48. key={idx}
  49. {...props.contextMenu.getMenuItemProps()}
  50. onClick={() => dispatch({type: 'set color coding', payload: coding})}
  51. checked={preferences.colorCoding === coding}
  52. >
  53. {coding}
  54. </ProfilingContextMenuItemCheckbox>
  55. ))}
  56. </ProfilingContextMenuGroup>
  57. <ProfilingContextMenuGroup>
  58. <ProfilingContextMenuHeading>{t('View')}</ProfilingContextMenuHeading>
  59. {FLAMEGRAPH_VIEW_OPTIONS.map((view, idx) => (
  60. <ProfilingContextMenuItemCheckbox
  61. key={idx}
  62. {...props.contextMenu.getMenuItemProps()}
  63. onClick={() => dispatch({type: 'set view', payload: view})}
  64. checked={preferences.view === view}
  65. >
  66. {view}
  67. </ProfilingContextMenuItemCheckbox>
  68. ))}
  69. </ProfilingContextMenuGroup>
  70. <ProfilingContextMenuGroup>
  71. <ProfilingContextMenuHeading>{t('Sorting')}</ProfilingContextMenuHeading>
  72. {FLAMEGRAPH_SORTING_OPTIONS.map((sorting, idx) => (
  73. <ProfilingContextMenuItemCheckbox
  74. key={idx}
  75. {...props.contextMenu.getMenuItemProps()}
  76. onClick={() => dispatch({type: 'set sorting', payload: sorting})}
  77. checked={preferences.sorting === sorting}
  78. >
  79. {sorting}
  80. </ProfilingContextMenuItemCheckbox>
  81. ))}
  82. </ProfilingContextMenuGroup>
  83. <ProfilingContextMenuGroup>
  84. <ProfilingContextMenuHeading>{t('X Axis')}</ProfilingContextMenuHeading>
  85. {FLAMEGRAPH_AXIS_OPTIONS.map((axis, idx) => (
  86. <ProfilingContextMenuItemCheckbox
  87. key={idx}
  88. {...props.contextMenu.getMenuItemProps()}
  89. onClick={() => dispatch({type: 'set xAxis', payload: axis})}
  90. checked={preferences.xAxis === axis}
  91. >
  92. {axis}
  93. </ProfilingContextMenuItemCheckbox>
  94. ))}
  95. </ProfilingContextMenuGroup>
  96. </ProfilingContextMenu>
  97. </Fragment>
  98. ) : null;
  99. }