import {useMemo} from 'react'; import * as Sentry from '@sentry/react'; import type {MenuItemProps} from 'sentry/components/dropdownMenu'; import {DropdownMenu} from 'sentry/components/dropdownMenu'; import {IconClose, IconCopy, IconEllipsis} from 'sentry/icons'; import {t} from 'sentry/locale'; import {trackAnalytics} from 'sentry/utils/analytics'; import {hasDDMFeature} from 'sentry/utils/metrics/features'; import useOrganization from 'sentry/utils/useOrganization'; import {useDDMContext} from 'sentry/views/ddm/context'; type ContextMenuProps = { widgetIndex: number; }; export function MetricFormulaContextMenu({widgetIndex}: ContextMenuProps) { const organization = useOrganization(); const {removeWidget, duplicateWidget, widgets} = useDDMContext(); const canDelete = widgets.length > 1; const items = useMemo( () => [ { leadingItems: [], key: 'duplicate', label: t('Duplicate'), onAction: () => { trackAnalytics('ddm.widget.duplicate', { organization, }); Sentry.metrics.increment('ddm.widget.duplicate'); duplicateWidget(widgetIndex); }, }, { leadingItems: [], key: 'delete', label: t('Remove Query'), disabled: !canDelete, onAction: () => { Sentry.metrics.increment('ddm.widget.delete'); removeWidget(widgetIndex); }, }, ], [canDelete, organization, duplicateWidget, widgetIndex, removeWidget] ); if (!hasDDMFeature(organization)) { return null; } return ( , }} position="bottom-end" /> ); }