1import { AnnotationQuery, BusEventBase, BusEventWithPayload, eventFactory } from '@grafana/data';
2import { IconName } from '@grafana/ui';
3
4/**
5 * Event Payloads
6 */
7
8export interface ShowDashSearchPayload {
9  query?: string;
10}
11
12export interface LocationChangePayload {
13  href: string;
14}
15
16export interface ShowModalPayload {
17  model?: any;
18  modalClass?: string;
19  src?: string;
20  templateHtml?: string;
21  backdrop?: any;
22  scope?: any;
23}
24
25export interface ShowModalReactPayload {
26  component: React.ComponentType<any>;
27  props?: any;
28}
29
30export interface ShowConfirmModalPayload {
31  title?: string;
32  text?: string;
33  text2?: string;
34  text2htmlBind?: boolean;
35  confirmText?: string;
36  altActionText?: string;
37  yesText?: string;
38  noText?: string;
39  icon?: IconName;
40
41  onConfirm?: () => void;
42  onAltAction?: () => void;
43}
44
45export interface DataSourceResponse<T> {
46  data: T;
47  readonly status: number;
48  readonly statusText: string;
49  readonly ok: boolean;
50  readonly headers: Headers;
51  readonly redirected: boolean;
52  readonly type: ResponseType;
53  readonly url: string;
54  readonly config: any;
55}
56
57type DataSourceResponsePayload = DataSourceResponse<any>;
58
59export interface ToggleKioskModePayload {
60  exit?: boolean;
61}
62
63export interface GraphClickedPayload {
64  pos: any;
65  panel: any;
66  item: any;
67}
68
69export interface ThresholdChangedPayload {
70  threshold: any;
71  handleIndex: any;
72}
73
74export interface DashScrollPayload {
75  restore?: boolean;
76  animate?: boolean;
77  pos?: number;
78}
79
80export interface PanelChangeViewPayload {}
81
82/**
83 * Events
84 */
85
86export const dsRequestResponse = eventFactory<DataSourceResponsePayload>('ds-request-response');
87export const dsRequestError = eventFactory<any>('ds-request-error');
88export const toggleSidemenuHidden = eventFactory('toggle-sidemenu-hidden');
89export const templateVariableValueUpdated = eventFactory('template-variable-value-updated');
90export const graphClicked = eventFactory<GraphClickedPayload>('graph-click');
91
92/**
93 * @internal
94 */
95export const thresholdChanged = eventFactory<ThresholdChangedPayload>('threshold-changed');
96
97/**
98 * Used for syncing queries badge count in panel edit queries tab
99 * Think we can get rid of this soon
100 */
101export class PanelQueriesChangedEvent extends BusEventBase {
102  static type = 'panel-queries-changed';
103}
104
105/**
106 * Used for syncing transformations badge count in panel edit transform tab
107 * Think we can get rid of this soon
108 */
109export class PanelTransformationsChangedEvent extends BusEventBase {
110  static type = 'panel-transformations-changed';
111}
112
113/**
114 * Used by panel editor to know when panel plugin it'self trigger option updates
115 */
116export class PanelOptionsChangedEvent extends BusEventBase {
117  static type = 'panels-options-changed';
118}
119
120/**
121 * Used internally by DashboardModel to commmunicate with DashboardGrid that it needs to re-render
122 */
123export class DashboardPanelsChangedEvent extends BusEventBase {
124  static type = 'dashboard-panels-changed';
125}
126
127export class PanelDirectiveReadyEvent extends BusEventBase {
128  static type = 'panel-directive-ready';
129}
130
131export class RenderEvent extends BusEventBase {
132  static type = 'render';
133}
134
135export class ZoomOutEvent extends BusEventWithPayload<number> {
136  static type = 'zoom-out';
137}
138
139export enum ShiftTimeEventPayload {
140  Left = -1,
141  Right = 1,
142}
143export class ShiftTimeEvent extends BusEventWithPayload<ShiftTimeEventPayload> {
144  static type = 'shift-time';
145}
146
147export class RemovePanelEvent extends BusEventWithPayload<number> {
148  static type = 'remove-panel';
149}
150
151/**
152 * @deprecated use ShowModalReactEvent instead that has this capability built in
153 */
154export class ShowModalEvent extends BusEventWithPayload<ShowModalPayload> {
155  static type = 'show-modal';
156}
157
158export class ShowConfirmModalEvent extends BusEventWithPayload<ShowConfirmModalPayload> {
159  static type = 'show-confirm-modal';
160}
161
162export class ShowModalReactEvent extends BusEventWithPayload<ShowModalReactPayload> {
163  static type = 'show-react-modal';
164}
165
166/**
167 * @deprecated use ShowModalReactEvent instead that has this capability built in
168 */
169export class HideModalEvent extends BusEventBase {
170  static type = 'hide-modal';
171}
172
173export class DashboardSavedEvent extends BusEventBase {
174  static type = 'dashboard-saved';
175}
176
177export class AnnotationQueryStarted extends BusEventWithPayload<AnnotationQuery> {
178  static type = 'annotation-query-started';
179}
180
181export class AnnotationQueryFinished extends BusEventWithPayload<AnnotationQuery> {
182  static type = 'annotation-query-finished';
183}
184
185export class PanelEditEnteredEvent extends BusEventWithPayload<number> {
186  static type = 'panel-edit-started';
187}
188
189export class PanelEditExitedEvent extends BusEventWithPayload<number> {
190  static type = 'panel-edit-finished';
191}
192