import {Fragment} from 'react'; import {IconCopy} from 'sentry/icons'; import {t} from 'sentry/locale'; import { FlamegraphAxisOptions, FlamegraphColorCodings, FlamegraphSorting, FlamegraphViewOptions, } from 'sentry/utils/profiling/flamegraph/flamegraphStateProvider/reducers/flamegraphPreferences'; import {useFlamegraphPreferences} from 'sentry/utils/profiling/flamegraph/hooks/useFlamegraphPreferences'; import {useDispatchFlamegraphState} from 'sentry/utils/profiling/flamegraph/hooks/useFlamegraphState'; import {FlamegraphFrame} from 'sentry/utils/profiling/flamegraphFrame'; import {useContextMenu} from 'sentry/utils/profiling/hooks/useContextMenu'; import { ProfilingContextMenu, ProfilingContextMenuGroup, ProfilingContextMenuHeading, ProfilingContextMenuItemButton, ProfilingContextMenuItemCheckbox, ProfilingContextMenuLayer, } from './ProfilingContextMenu/profilingContextMenu'; const FLAMEGRAPH_COLOR_CODINGS: FlamegraphColorCodings = [ 'by symbol name', 'by system / application', 'by library', 'by recursion', 'by frequency', ]; const FLAMEGRAPH_VIEW_OPTIONS: FlamegraphViewOptions = ['top down', 'bottom up']; const FLAMEGRAPH_SORTING_OPTIONS: FlamegraphSorting = ['left heavy', 'call order']; const FLAMEGRAPH_AXIS_OPTIONS: FlamegraphAxisOptions = ['standalone', 'transaction']; interface FlameGraphOptionsContextMenuProps { contextMenu: ReturnType; hoveredNode: FlamegraphFrame | null; isHighlightingAllOccurences: boolean; onCopyFunctionNameClick: () => void; onHighlightAllOccurencesClick: () => void; } export function FlamegraphOptionsContextMenu(props: FlameGraphOptionsContextMenuProps) { const preferences = useFlamegraphPreferences(); const dispatch = useDispatchFlamegraphState(); return props.contextMenu.open ? ( props.contextMenu.setOpen(false)} /> {props.hoveredNode ? ( {t('Frame')} {t('Highlight all occurrences')} { props.onCopyFunctionNameClick(); // This is a button, so close the context menu. props.contextMenu.setOpen(false); }, })} icon={} > {t('Copy function name')} ) : null} {t('Color Coding')} {FLAMEGRAPH_COLOR_CODINGS.map((coding, idx) => ( dispatch({type: 'set color coding', payload: coding}), })} onClick={() => dispatch({type: 'set color coding', payload: coding})} checked={preferences.colorCoding === coding} > {coding} ))} {t('View')} {FLAMEGRAPH_VIEW_OPTIONS.map((view, idx) => ( dispatch({type: 'set view', payload: view}), })} onClick={() => dispatch({type: 'set view', payload: view})} checked={preferences.view === view} > {view} ))} {t('Sorting')} {FLAMEGRAPH_SORTING_OPTIONS.map((sorting, idx) => ( dispatch({type: 'set sorting', payload: sorting}), })} onClick={() => dispatch({type: 'set sorting', payload: sorting})} checked={preferences.sorting === sorting} > {sorting} ))} {t('X Axis')} {FLAMEGRAPH_AXIS_OPTIONS.map((axis, idx) => ( dispatch({type: 'set xAxis', payload: axis}), })} onClick={() => dispatch({type: 'set xAxis', payload: axis})} checked={preferences.xAxis === axis} > {axis} ))} ) : null; }