mirror of https://github.com/grafana/grafana
Plugin Extensions: Expose PluginMeta generic in usePluginContext (#107577)
* Plugin Extensions: Expose PluginMeta generic in usePluginContext * Plugin Extensions: Cast usePluginContext type on return * Plugin Extensions: Fix PluginContext exportpull/107744/head^2
parent
1e1fd3db38
commit
dbbd9f23d1
@ -1,14 +1,15 @@ |
||||
import { createContext } from 'react'; |
||||
|
||||
import { KeyValue } from '../../types/data'; |
||||
import { DataSourceInstanceSettings } from '../../types/datasource'; |
||||
import { PluginMeta } from '../../types/plugin'; |
||||
|
||||
export interface PluginContextType { |
||||
meta: PluginMeta; |
||||
export interface PluginContextType<T extends KeyValue = KeyValue> { |
||||
meta: PluginMeta<T>; |
||||
} |
||||
|
||||
export interface DataSourcePluginContextType extends PluginContextType { |
||||
export interface DataSourcePluginContextType<T extends KeyValue = KeyValue> extends PluginContextType<T> { |
||||
instanceSettings: DataSourceInstanceSettings; |
||||
} |
||||
|
||||
export const Context = createContext<PluginContextType | undefined>(undefined); |
||||
export const PluginContext = createContext<PluginContextType | undefined>(undefined); |
||||
|
@ -1,5 +1,9 @@ |
||||
import { KeyValue } from '../../types/data'; |
||||
|
||||
import { type DataSourcePluginContextType, type PluginContextType } from './PluginContext'; |
||||
|
||||
export function isDataSourcePluginContext(context: PluginContextType): context is DataSourcePluginContextType { |
||||
export function isDataSourcePluginContext<T extends KeyValue = KeyValue>( |
||||
context: PluginContextType<T> |
||||
): context is DataSourcePluginContextType<T> { |
||||
return 'instanceSettings' in context && 'meta' in context; |
||||
} |
||||
|
Loading…
Reference in new issue