Skip to content

Commit c4b7e2b

Browse files
authored
fix(metrics): Add to dashboard disabled state (#72126)
Properly disable the menu item. Add fallback for self-hosted. Closes #72125
1 parent 06c8955 commit c4b7e2b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

static/app/views/metrics/metricQueryContextMenu.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {useMemo} from 'react';
2-
import styled from '@emotion/styled';
32
import * as Sentry from '@sentry/react';
43

54
import {openAddToDashboardModal, openModal} from 'sentry/actionCreators/modal';
65
import {navigateTo} from 'sentry/actionCreators/navigation';
76
import Feature from 'sentry/components/acl/feature';
7+
import FeatureDisabled from 'sentry/components/acl/featureDisabled';
88
import type {MenuItemProps} from 'sentry/components/dropdownMenu';
99
import {DropdownMenu} from 'sentry/components/dropdownMenu';
10+
import {Hovercard} from 'sentry/components/hovercard';
1011
import {CreateMetricAlertFeature} from 'sentry/components/metrics/createMetricAlertFeature';
1112
import {
1213
IconClose,
@@ -66,6 +67,7 @@ export function MetricQueryContextMenu({
6667

6768
// At least one query must remain
6869
const canDelete = widgets.filter(isMetricsQueryWidget).length > 1;
70+
const hasDashboardFeature = organization.features.includes('dashboards-edit');
6971

7072
const items = useMemo<MenuItemProps[]>(
7173
() => [
@@ -103,15 +105,24 @@ export function MetricQueryContextMenu({
103105
organization={organization}
104106
hookName="feature-disabled:dashboards-edit"
105107
features="dashboards-edit"
106-
>
107-
{({hasFeature}) => (
108-
<AddToDashboardItem disabled={!hasFeature}>
109-
{t('Add to Dashboard')}
110-
</AddToDashboardItem>
108+
renderDisabled={p => (
109+
<Hovercard
110+
body={
111+
<FeatureDisabled
112+
features={p.features}
113+
hideHelpToggle
114+
featureName={t('Metric Alerts')}
115+
/>
116+
}
117+
>
118+
{typeof p.children === 'function' ? p.children(p) : p.children}
119+
</Hovercard>
111120
)}
121+
>
122+
<span>{t('Add to Dashboard')}</span>
112123
</Feature>
113124
),
114-
disabled: !createDashboardWidget,
125+
disabled: !createDashboardWidget || !hasDashboardFeature,
115126
onAction: () => {
116127
if (!organization.features.includes('dashboards-edit')) {
117128
return;
@@ -155,10 +166,11 @@ export function MetricQueryContextMenu({
155166
],
156167
[
157168
createAlert,
169+
organization,
158170
createDashboardWidget,
171+
hasDashboardFeature,
159172
metricsQuery.mri,
160173
canDelete,
161-
organization,
162174
duplicateWidget,
163175
widgetIndex,
164176
router,
@@ -235,7 +247,3 @@ export function useCreateDashboardWidget(
235247
});
236248
}, [metricsQuery, selection, displayType, organization, router]);
237249
}
238-
239-
const AddToDashboardItem = styled('div')<{disabled: boolean}>`
240-
color: ${p => (p.disabled ? p.theme.disabled : p.theme.textColor)};
241-
`;

0 commit comments

Comments
 (0)