PanelEditor: allow access to the eventBus from panel options (#29327)

This commit is contained in:
Ryan McKinley 2020-11-25 11:32:14 -08:00 committed by GitHub
parent 9dbf54eb61
commit a33249fecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

@ -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 [];

View File

@ -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);
},

View File

@ -88,6 +88,7 @@ export const PanelOptionsTab: FC<Props> = ({
replaceVariables={panel.replaceVariables}
plugin={plugin}
data={data?.series}
eventBus={dashboard.events}
/>
);
}