traceActionsMenu.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {openModal} from 'sentry/actionCreators/modal';
  2. import {Button} from 'sentry/components/button';
  3. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  4. import {IconEllipsis} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import type {EventTransaction} from 'sentry/types/event';
  7. import {trackAnalytics} from 'sentry/utils/analytics';
  8. import type EventView from 'sentry/utils/discover/eventView';
  9. import {SavedQueryDatasets} from 'sentry/utils/discover/types';
  10. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  11. import type RequestError from 'sentry/utils/requestError/requestError';
  12. import {useNavigate} from 'sentry/utils/useNavigate';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import useProjects from 'sentry/utils/useProjects';
  15. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  16. import {traceAnalytics} from './traceAnalytics';
  17. import {getCustomInstrumentationLink} from './traceConfigurations';
  18. import {TraceShortcutsModal} from './traceShortcutsModal';
  19. import {useHasTraceNewUi} from './useHasTraceNewUi';
  20. function TraceActionsMenu({
  21. rootEventResults,
  22. traceEventView,
  23. }: {
  24. rootEventResults: UseApiQueryResult<EventTransaction, RequestError>;
  25. traceEventView: EventView;
  26. }) {
  27. const hasTraceNewUi = useHasTraceNewUi();
  28. const organization = useOrganization();
  29. const {projects} = useProjects();
  30. const navigate = useNavigate();
  31. if (!hasTraceNewUi) {
  32. return null;
  33. }
  34. const traceProject = rootEventResults.data
  35. ? projects.find(p => p.id === rootEventResults.data.projectID)
  36. : undefined;
  37. return (
  38. <DropdownMenu
  39. items={[
  40. {
  41. key: 'trace_events_in_discover_button',
  42. label: t('Open Events in Discover'),
  43. onAction: () => {
  44. trackAnalytics('performance_views.trace_view.open_in_discover', {
  45. organization,
  46. });
  47. const target = traceEventView.getResultsViewUrlTarget(
  48. organization.slug,
  49. false,
  50. hasDatasetSelector(organization)
  51. ? SavedQueryDatasets.TRANSACTIONS
  52. : undefined
  53. );
  54. navigate(target);
  55. },
  56. },
  57. {
  58. key: 'custom_instrumentation_button',
  59. label: t('Add Instrumentation'),
  60. onAction: () => {
  61. const docsLink = getCustomInstrumentationLink(traceProject);
  62. if (docsLink) {
  63. window.location.href = docsLink;
  64. }
  65. },
  66. },
  67. {
  68. key: 'shortcuts_button',
  69. label: t('See Shortcuts'),
  70. onAction: () => {
  71. traceAnalytics.trackViewShortcuts(organization);
  72. openModal(props => <TraceShortcutsModal {...props} />);
  73. },
  74. },
  75. ]}
  76. trigger={triggerProps => (
  77. <Button
  78. {...triggerProps}
  79. aria-label={t('Discover Context Menu')}
  80. size="xs"
  81. onClick={e => {
  82. e.stopPropagation();
  83. e.preventDefault();
  84. triggerProps.onClick?.(e);
  85. }}
  86. icon={<IconEllipsis />}
  87. />
  88. )}
  89. position="bottom-end"
  90. />
  91. );
  92. }
  93. export default TraceActionsMenu;