From a33249fecc7cbdbf0b42751925b6d11eeecc38b1 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 25 Nov 2020 11:32:14 -0800 Subject: [PATCH] PanelEditor: allow access to the eventBus from panel options (#29327) --- .../src/field/standardFieldConfigEditorRegistry.ts | 2 ++ packages/grafana-runtime/src/utils/queryResponse.ts | 12 ++++++++++-- .../components/PanelEditor/PanelOptionsEditor.tsx | 4 ++++ .../components/PanelEditor/PanelOptionsTab.tsx | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts b/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts index 2fe708b94c4..e0a09bea22e 100644 --- a/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts +++ b/packages/grafana-data/src/field/standardFieldConfigEditorRegistry.ts @@ -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 { data?: DataFrame[]; // All results replaceVariables?: InterpolateFunction; + eventBus?: EventBus; getSuggestions?: (scope?: VariableSuggestionsScope) => VariableSuggestion[]; options?: TOptions; } diff --git a/packages/grafana-runtime/src/utils/queryResponse.ts b/packages/grafana-runtime/src/utils/queryResponse.ts index c010fa534bb..cce18f4dac9 100644 --- a/packages/grafana-runtime/src/utils/queryResponse.ts +++ b/packages/grafana-runtime/src/utils/queryResponse.ts @@ -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 []; diff --git a/public/app/features/dashboard/components/PanelEditor/PanelOptionsEditor.tsx b/public/app/features/dashboard/components/PanelEditor/PanelOptionsEditor.tsx index d3dc335c762..b758fc7a03c 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelOptionsEditor.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelOptionsEditor.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { DataFrame, + EventBus, InterpolateFunction, PanelOptionsEditorItem, PanelPlugin, @@ -17,6 +18,7 @@ interface PanelOptionsEditorProps { plugin: PanelPlugin; data?: DataFrame[]; replaceVariables: InterpolateFunction; + eventBus: EventBus; options: TOptions; onChange: (options: TOptions) => void; } @@ -26,6 +28,7 @@ export const PanelOptionsEditor: React.FC> = ({ options, onChange, data, + eventBus, replaceVariables, }) => { const optionEditors = useMemo>(() => { @@ -43,6 +46,7 @@ export const PanelOptionsEditor: React.FC> = ({ data: data || [], replaceVariables, options, + eventBus, getSuggestions: (scope?: VariableSuggestionsScope) => { return getPanelOptionsVariableSuggestions(plugin, data); }, diff --git a/public/app/features/dashboard/components/PanelEditor/PanelOptionsTab.tsx b/public/app/features/dashboard/components/PanelEditor/PanelOptionsTab.tsx index b3274cfe82d..977abc41bf1 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelOptionsTab.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelOptionsTab.tsx @@ -88,6 +88,7 @@ export const PanelOptionsTab: FC = ({ replaceVariables={panel.replaceVariables} plugin={plugin} data={data?.series} + eventBus={dashboard.events} /> ); }