mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelEditor: allow access to the eventBus from panel options (#29327)
This commit is contained in:
parent
9dbf54eb61
commit
a33249fecc
@ -2,10 +2,12 @@ import { Registry, RegistryItem } from '../utils/Registry';
|
||||
import { ComponentType } from 'react';
|
||||
import { FieldConfigOptionsRegistry } from './FieldConfigOptionsRegistry';
|
||||
import { DataFrame, InterpolateFunction, VariableSuggestionsScope, VariableSuggestion } from '../types';
|
||||
import { EventBus } from '../events';
|
||||
|
||||
export interface StandardEditorContext<TOptions> {
|
||||
data?: DataFrame[]; // All results
|
||||
replaceVariables?: InterpolateFunction;
|
||||
eventBus?: EventBus;
|
||||
getSuggestions?: (scope?: VariableSuggestionsScope) => VariableSuggestion[];
|
||||
options?: TOptions;
|
||||
}
|
||||
|
@ -22,7 +22,9 @@ interface DataResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the results from `/api/ds/query
|
||||
* Parse the results from /api/ds/query into a DataQueryResponse
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function toDataQueryResponse(res: any): DataQueryResponse {
|
||||
const rsp: DataQueryResponse = { data: [], state: LoadingState.Done };
|
||||
@ -94,6 +96,8 @@ export function toDataQueryResponse(res: any): DataQueryResponse {
|
||||
/**
|
||||
* Convert an object into a DataQueryError -- if this is an HTTP response,
|
||||
* it will put the correct values in the error field
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function toDataQueryError(err: any): DataQueryError {
|
||||
const error = (err || {}) as DataQueryError;
|
||||
@ -119,7 +123,11 @@ export function toDataQueryError(err: any): DataQueryError {
|
||||
return error;
|
||||
}
|
||||
|
||||
/** Return the first string or non-time field as the value */
|
||||
/**
|
||||
* Return the first string or non-time field as the value
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
export function frameToMetricFindValue(frame: DataFrame): MetricFindValue[] {
|
||||
if (!frame || !frame.length) {
|
||||
return [];
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import {
|
||||
DataFrame,
|
||||
EventBus,
|
||||
InterpolateFunction,
|
||||
PanelOptionsEditorItem,
|
||||
PanelPlugin,
|
||||
@ -17,6 +18,7 @@ interface PanelOptionsEditorProps<TOptions> {
|
||||
plugin: PanelPlugin;
|
||||
data?: DataFrame[];
|
||||
replaceVariables: InterpolateFunction;
|
||||
eventBus: EventBus;
|
||||
options: TOptions;
|
||||
onChange: (options: TOptions) => void;
|
||||
}
|
||||
@ -26,6 +28,7 @@ export const PanelOptionsEditor: React.FC<PanelOptionsEditorProps<any>> = ({
|
||||
options,
|
||||
onChange,
|
||||
data,
|
||||
eventBus,
|
||||
replaceVariables,
|
||||
}) => {
|
||||
const optionEditors = useMemo<Record<string, PanelOptionsEditorItem[]>>(() => {
|
||||
@ -43,6 +46,7 @@ export const PanelOptionsEditor: React.FC<PanelOptionsEditorProps<any>> = ({
|
||||
data: data || [],
|
||||
replaceVariables,
|
||||
options,
|
||||
eventBus,
|
||||
getSuggestions: (scope?: VariableSuggestionsScope) => {
|
||||
return getPanelOptionsVariableSuggestions(plugin, data);
|
||||
},
|
||||
|
@ -88,6 +88,7 @@ export const PanelOptionsTab: FC<Props> = ({
|
||||
replaceVariables={panel.replaceVariables}
|
||||
plugin={plugin}
|
||||
data={data?.series}
|
||||
eventBus={dashboard.events}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user