flamegraphOptionsContextMenu.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. 'by frequency',
  24. ];
  25. const FLAMEGRAPH_VIEW_OPTIONS: FlamegraphViewOptions = ['top down', 'bottom up'];
  26. const FLAMEGRAPH_SORTING_OPTIONS: FlamegraphSorting = ['left heavy', 'call order'];
  27. const FLAMEGRAPH_AXIS_OPTIONS: FlamegraphAxisOptions = ['standalone', 'transaction'];
  28. interface FlameGraphOptionsContextMenuProps {
  29. contextMenu: ReturnType<typeof useContextMenu>;
  30. }
  31. export function FlamegraphOptionsContextMenu(props: FlameGraphOptionsContextMenuProps) {
  32. const [preferences, dispatch] = useFlamegraphPreferences();
  33. return props.contextMenu.open ? (
  34. <Fragment>
  35. <ProfilingContextMenuLayer onClick={() => props.contextMenu.setOpen(false)} />
  36. <ProfilingContextMenu
  37. {...props.contextMenu.getMenuProps()}
  38. style={{
  39. position: 'absolute',
  40. left: props.contextMenu.position?.left ?? -9999,
  41. top: props.contextMenu.position?.top ?? -9999,
  42. maxHeight: props.contextMenu.containerCoordinates?.height ?? 'auto',
  43. }}
  44. >
  45. <ProfilingContextMenuGroup>
  46. <ProfilingContextMenuHeading>{t('Color Coding')}</ProfilingContextMenuHeading>
  47. {FLAMEGRAPH_COLOR_CODINGS.map((coding, idx) => (
  48. <ProfilingContextMenuItemCheckbox
  49. key={idx}
  50. {...props.contextMenu.getMenuItemProps()}
  51. onClick={() => dispatch({type: 'set color coding', payload: coding})}
  52. checked={preferences.colorCoding === coding}
  53. >
  54. {coding}
  55. </ProfilingContextMenuItemCheckbox>
  56. ))}
  57. </ProfilingContextMenuGroup>
  58. <ProfilingContextMenuGroup>
  59. <ProfilingContextMenuHeading>{t('View')}</ProfilingContextMenuHeading>
  60. {FLAMEGRAPH_VIEW_OPTIONS.map((view, idx) => (
  61. <ProfilingContextMenuItemCheckbox
  62. key={idx}
  63. {...props.contextMenu.getMenuItemProps()}
  64. onClick={() => dispatch({type: 'set view', payload: view})}
  65. checked={preferences.view === view}
  66. >
  67. {view}
  68. </ProfilingContextMenuItemCheckbox>
  69. ))}
  70. </ProfilingContextMenuGroup>
  71. <ProfilingContextMenuGroup>
  72. <ProfilingContextMenuHeading>{t('Sorting')}</ProfilingContextMenuHeading>
  73. {FLAMEGRAPH_SORTING_OPTIONS.map((sorting, idx) => (
  74. <ProfilingContextMenuItemCheckbox
  75. key={idx}
  76. {...props.contextMenu.getMenuItemProps()}
  77. onClick={() => dispatch({type: 'set sorting', payload: sorting})}
  78. checked={preferences.sorting === sorting}
  79. >
  80. {sorting}
  81. </ProfilingContextMenuItemCheckbox>
  82. ))}
  83. </ProfilingContextMenuGroup>
  84. <ProfilingContextMenuGroup>
  85. <ProfilingContextMenuHeading>{t('X Axis')}</ProfilingContextMenuHeading>
  86. {FLAMEGRAPH_AXIS_OPTIONS.map((axis, idx) => (
  87. <ProfilingContextMenuItemCheckbox
  88. key={idx}
  89. {...props.contextMenu.getMenuItemProps()}
  90. onClick={() => dispatch({type: 'set xAxis', payload: axis})}
  91. checked={preferences.xAxis === axis}
  92. >
  93. {axis}
  94. </ProfilingContextMenuItemCheckbox>
  95. ))}
  96. </ProfilingContextMenuGroup>
  97. </ProfilingContextMenu>
  98. </Fragment>
  99. ) : null;
  100. }