|
1 | 1 | 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'; |
4 | 3 | import {t} from 'sentry/locale';
|
5 | 4 | import useOrganization from 'sentry/utils/useOrganization';
|
6 | 5 | import usePageFilters from 'sentry/utils/usePageFilters';
|
| 6 | +import {Dataset} from 'sentry/views/alerts/rules/metric/types'; |
7 | 7 | import {Widget} from 'sentry/views/dashboards/widgets/widget/widget';
|
8 | 8 | import {getExploreUrl} from 'sentry/views/explore/utils';
|
| 9 | +import {BaseChartActionDropdown} from 'sentry/views/insights/common/components/chartActionDropdown'; |
9 | 10 | 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'; |
10 | 13 |
|
11 | 14 | type ExploreParams = Parameters<typeof getExploreUrl>[0];
|
12 | 15 |
|
13 | 16 | interface ToolbarProps {
|
14 | 17 | onOpenFullScreen: () => void;
|
| 18 | + aliases?: Record<string, string>; |
15 | 19 | exploreParams?: Omit<ExploreParams, 'organization' | 'selection'>;
|
16 | 20 | 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 |
17 | 22 | }
|
18 | 23 |
|
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) { |
20 | 31 | const organization = useOrganization();
|
21 | 32 | const {selection} = usePageFilters();
|
| 33 | + const project = useAlertsProject(); |
| 34 | + |
22 | 35 | const exploreUrl =
|
23 | 36 | exploreParams && getExploreUrl({...exploreParams, organization, selection});
|
24 | 37 |
|
| 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 | + |
25 | 56 | return (
|
26 | 57 | <Widget.WidgetToolbar>
|
27 | 58 | {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'} |
47 | 63 | />
|
48 | 64 | ) : null}
|
| 65 | + |
49 | 66 | {loaderSource !== 'releases-drawer' && (
|
50 | 67 | <Button
|
51 | 68 | size="xs"
|
|
0 commit comments