Skip to content

Commit 035477e

Browse files
DominikB2014andrewshie-sentry
authored andcommitted
fest(insights): add create alert button to backend overview page widgets (#93643)
1. Add create alert buttons to backend overview page widgets <img width="417" alt="image" src="https://github.com/user-attachments/assets/7728736e-c928-40f3-bf81-8faae556d684" /> 2. Update the platform widgets to use the insights standardized `BaseChartActionDropdown`
1 parent caf75db commit 035477e

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

static/app/views/insights/common/components/widgets/overviewApiLatencyChartWidget.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function OverviewApiLatencyChartWidget(props: LoadableChartWidget
7272
organization.features.includes('visibility-explore-view') &&
7373
!isEmpty && (
7474
<Toolbar
75+
showCreateAlert
7576
exploreParams={{
7677
mode: Mode.SAMPLES,
7778
visualize: [

static/app/views/insights/common/components/widgets/overviewJobsChartWidget.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import {Toolbar} from 'sentry/views/insights/pages/platform/shared/toolbar';
2828
import {useTransactionNameQuery} from 'sentry/views/insights/pages/platform/shared/useTransactionNameQuery';
2929
import {QueuesWidgetEmptyStateWarning} from 'sentry/views/performance/landing/widgets/components/selectableList';
3030

31+
const ALIASES = {
32+
'count(span.duration)': t('Jobs'),
33+
'trace_status_rate(internal_error)': t('Error Rate'),
34+
};
35+
3136
export default function OverviewJobsChartWidget(props: LoadableChartWidgetProps) {
3237
const organization = useOrganization();
3338
const {query} = useTransactionNameQuery();
@@ -54,11 +59,11 @@ export default function OverviewJobsChartWidget(props: LoadableChartWidgetProps)
5459
const plottables = useMemo(() => {
5560
return [
5661
new Bars(convertSeriesToTimeseries(data['count(span.duration)']), {
57-
alias: t('Jobs'),
62+
alias: ALIASES['count(span.duration)'],
5863
color: theme.gray200,
5964
}),
6065
new Line(convertSeriesToTimeseries(data['trace_status_rate(internal_error)']), {
61-
alias: t('Error Rate'),
66+
alias: ALIASES['trace_status_rate(internal_error)'],
6267
color: theme.error,
6368
}),
6469
];
@@ -139,6 +144,8 @@ export default function OverviewJobsChartWidget(props: LoadableChartWidgetProps)
139144
organization.features.includes('visibility-explore-view') &&
140145
!isEmpty && (
141146
<Toolbar
147+
showCreateAlert
148+
aliases={ALIASES}
142149
exploreParams={{
143150
mode: Mode.AGGREGATE,
144151
visualize: [

static/app/views/insights/pages/platform/shared/baseTrafficWidget.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export function BaseTrafficWidget({
5555
props.pageFilters
5656
);
5757

58+
const aliases = {
59+
'count(span.duration)': trafficSeriesName,
60+
'trace_status_rate(internal_error)': t('Error Rate'),
61+
};
62+
5863
const plottables = useMemo(() => {
5964
return [
6065
new Bars(convertSeriesToTimeseries(data['count(span.duration)']), {
@@ -100,6 +105,8 @@ export function BaseTrafficWidget({
100105
organization.features.includes('visibility-explore-view') &&
101106
!isEmpty && (
102107
<Toolbar
108+
aliases={aliases}
109+
showCreateAlert
103110
exploreParams={{
104111
mode: Mode.AGGREGATE,
105112
visualize: [

static/app/views/insights/pages/platform/shared/toolbar.tsx

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,68 @@
11
import {Button} from 'sentry/components/core/button';
2-
import {DropdownMenu} from 'sentry/components/dropdownMenu';
3-
import {IconEllipsis, IconExpand} from 'sentry/icons';
2+
import {IconExpand} from 'sentry/icons';
43
import {t} from 'sentry/locale';
54
import useOrganization from 'sentry/utils/useOrganization';
65
import usePageFilters from 'sentry/utils/usePageFilters';
6+
import {Dataset} from 'sentry/views/alerts/rules/metric/types';
77
import {Widget} from 'sentry/views/dashboards/widgets/widget/widget';
88
import {getExploreUrl} from 'sentry/views/explore/utils';
9+
import {BaseChartActionDropdown} from 'sentry/views/insights/common/components/chartActionDropdown';
910
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
11+
import {getAlertsUrl} from 'sentry/views/insights/common/utils/getAlertsUrl';
12+
import {useAlertsProject} from 'sentry/views/insights/common/utils/useAlertsProject';
1013

1114
type ExploreParams = Parameters<typeof getExploreUrl>[0];
1215

1316
interface ToolbarProps {
1417
onOpenFullScreen: () => void;
18+
aliases?: Record<string, string>;
1519
exploreParams?: Omit<ExploreParams, 'organization' | 'selection'>;
1620
loaderSource?: LoadableChartWidgetProps['loaderSource'];
21+
showCreateAlert?: boolean; // TODO: this is temporary so we can slowly add create alert functionality, in the future all charts that can open in explore can be alerted
1722
}
1823

19-
export function Toolbar({exploreParams, onOpenFullScreen, loaderSource}: ToolbarProps) {
24+
export function Toolbar({
25+
exploreParams,
26+
onOpenFullScreen,
27+
loaderSource,
28+
aliases,
29+
showCreateAlert = false,
30+
}: ToolbarProps) {
2031
const organization = useOrganization();
2132
const {selection} = usePageFilters();
33+
const project = useAlertsProject();
34+
2235
const exploreUrl =
2336
exploreParams && getExploreUrl({...exploreParams, organization, selection});
2437

38+
const yAxes = exploreParams?.visualize?.flatMap(v => v.yAxes) || [];
39+
40+
const alertsUrls = yAxes.map((yAxis, index) => {
41+
const label = aliases?.[yAxis] ?? yAxis;
42+
return {
43+
key: `${yAxis}-${index}`,
44+
label,
45+
to: getAlertsUrl({
46+
project,
47+
query: exploreParams?.query,
48+
dataset: Dataset.EVENTS_ANALYTICS_PLATFORM,
49+
pageFilters: selection,
50+
aggregate: yAxis,
51+
organization,
52+
}),
53+
};
54+
});
55+
2556
return (
2657
<Widget.WidgetToolbar>
2758
{exploreUrl ? (
28-
<DropdownMenu
29-
size="xs"
30-
position="bottom-end"
31-
trigger={triggerProps => (
32-
<Button
33-
{...triggerProps}
34-
size="xs"
35-
borderless
36-
icon={<IconEllipsis />}
37-
aria-label={t('More actions')}
38-
/>
39-
)}
40-
items={[
41-
{
42-
key: 'open-in-explore',
43-
label: t('Open in Explore'),
44-
to: exploreUrl,
45-
},
46-
]}
59+
<BaseChartActionDropdown
60+
exploreUrl={exploreUrl}
61+
alertMenuOptions={showCreateAlert ? alertsUrls : []}
62+
referrer={loaderSource || 'insights.platform.toolbar'}
4763
/>
4864
) : null}
65+
4966
{loaderSource !== 'releases-drawer' && (
5067
<Button
5168
size="xs"

0 commit comments

Comments
 (0)