@ -1,3 +1,5 @@
import React from 'react' ;
import { DataQuery } from '@grafana/schema' ;
import { ScopedVars } from './ScopedVars' ;
@ -9,9 +11,10 @@ import { RawTimeRange, TimeZone } from './time';
export enum PluginExtensionTypes {
link = 'link' ,
component = 'component' ,
}
export type PluginExtension = {
type PluginExtensionBase = {
id : string ;
type : PluginExtensionTypes ;
title : string ;
@ -19,37 +22,64 @@ export type PluginExtension = {
pluginId : string ;
} ;
export type PluginExtensionLink = PluginExtension & {
export type PluginExtensionLink = PluginExtensionBase & {
type : PluginExtensionTypes . link ;
path? : string ;
onClick ? : ( event? : React.MouseEvent ) = > void ;
} ;
export type PluginExtensionComponent = PluginExtensionBase & {
type : PluginExtensionTypes . component ;
component : React.ComponentType ;
} ;
export type PluginExtension = PluginExtensionLink | PluginExtensionComponent ;
// Objects used for registering extensions (in app plugins)
// --------------------------------------------------------
export type PluginExtensionLinkConfig < Context extends object = object > = {
type : PluginExtensionTypes . link ;
title : string ;
description : string ;
// A URL path that will be used as the href for the rendered link extension
// (It is optional, because in some cases the action will be handled by the `onClick` handler instead of navigating to a new page)
path? : string ;
// A function that will be called when the link is clicked
// (It is called with the original event object)
onClick ? : ( event : React.MouseEvent | undefined , helpers : PluginExtensionEventHelpers < Context > ) = > void ;
// The unique identifier of the Extension Point
// (Core Grafana extension point ids are available in the `PluginExtensionPoints` enum)
extensionPointId : string ;
// (Optional) A function that can be used to configure the extension dynamically based on the extension point's context
configure ? : ( context? : Readonly < Context > ) = >
| Partial < {
title : string ;
description : string ;
path : string ;
onClick : ( event : React.MouseEvent | undefined , helpers : PluginExtensionEventHelpers < Context > ) = > void ;
} >
| undefined ;
} ;
export type PluginExtensionComponentConfig < Context extends object = object > = {
type : PluginExtensionTypes . component ;
title : string ;
description : string ;
// The React component that will be rendered as the extension
// (This component receives the context as a prop when it is rendered. You can just return `null` from the component to hide for certain contexts)
component : React.ComponentType ;
// The unique identifier of the Extension Point
// (Core Grafana extension point ids are available in the `PluginExtensionPoints` enum)
extensionPointId : string ;
} ;
export type PluginExtensionConfig < Context extends object = object , ExtraProps extends object = object > = Pick <
PluginExtension ,
'title' | 'description'
> &
ExtraProps & {
// The unique identifier of the Extension Point
// (Core Grafana extension point ids are available in the `PluginExtensionPoints` enum)
extensionPointId : string ;
// (Optional) A function that can be used to configure the extension dynamically based on the extension point's context
configure ? : (
context? : Readonly < Context >
) = > Partial < { title : string ; description : string } & ExtraProps > | undefined ;
} ;
export type PluginExtensionLinkConfig < Context extends object = object > = PluginExtensionConfig <
Context ,
Pick < PluginExtensionLink , ' path ' > & {
type : PluginExtensionTypes . link ;
onClick ? : ( event : React.MouseEvent | undefined , helpers : PluginExtensionEventHelpers < Context > ) = > void ;
}
> ;
export type PluginExtensionConfig = PluginExtensionLinkConfig | PluginExtensionComponentConfig ;
export type PluginExtensionEventHelpers < Context extends object = object > = {
context? : Readonly < Context > ;
@ -68,6 +98,7 @@ export type PluginExtensionEventHelpers<Context extends object = object> = {
// Extension Points available in core Grafana
export enum PluginExtensionPoints {
DashboardPanelMenu = 'grafana/dashboard/panel/menu' ,
DataSourceConfig = 'grafana/datasources/config' ,
}
export type PluginExtensionPanelContext = {