mirror of https://github.com/grafana/grafana
parent
5aa4e05038
commit
bdc588250e
@ -0,0 +1,36 @@ |
||||
import { Observable } from 'rxjs'; |
||||
|
||||
import { PluginExtensionComponent } from '@grafana/data'; |
||||
|
||||
type GetObservablePluginComponentsOptions = { |
||||
context?: object | Record<string, unknown>; |
||||
extensionPointId: string; |
||||
limitPerPlugin?: number; |
||||
}; |
||||
|
||||
export type GetObservablePluginComponents = ( |
||||
options: GetObservablePluginComponentsOptions |
||||
) => Observable<PluginExtensionComponent[]>; |
||||
|
||||
let singleton: GetObservablePluginComponents | undefined; |
||||
|
||||
export function setGetObservablePluginComponents(fn: GetObservablePluginComponents): void { |
||||
// We allow overriding the registry in tests
|
||||
if (singleton && process.env.NODE_ENV !== 'test') { |
||||
throw new Error( |
||||
'setGetObservablePluginComponents() function should only be called once, when Grafana is starting.' |
||||
); |
||||
} |
||||
|
||||
singleton = fn; |
||||
} |
||||
|
||||
export function getObservablePluginComponents( |
||||
options: GetObservablePluginComponentsOptions |
||||
): Observable<PluginExtensionComponent[]> { |
||||
if (!singleton) { |
||||
throw new Error('setGetObservablePluginComponents() can only be used after the Grafana instance has started.'); |
||||
} |
||||
|
||||
return singleton(options); |
||||
} |
@ -0,0 +1,30 @@ |
||||
import { Observable } from 'rxjs'; |
||||
|
||||
import { PluginExtensionLink } from '@grafana/data'; |
||||
|
||||
type GetObservablePluginLinksOptions = { |
||||
context?: object | Record<string | symbol, unknown>; |
||||
extensionPointId: string; |
||||
limitPerPlugin?: number; |
||||
}; |
||||
|
||||
export type GetObservablePluginLinks = (options: GetObservablePluginLinksOptions) => Observable<PluginExtensionLink[]>; |
||||
|
||||
let singleton: GetObservablePluginLinks | undefined; |
||||
|
||||
export function setGetObservablePluginLinks(fn: GetObservablePluginLinks): void { |
||||
// We allow overriding the registry in tests
|
||||
if (singleton && process.env.NODE_ENV !== 'test') { |
||||
throw new Error('setGetObservablePluginLinks() function should only be called once, when Grafana is starting.'); |
||||
} |
||||
|
||||
singleton = fn; |
||||
} |
||||
|
||||
export function getObservablePluginLinks(options: GetObservablePluginLinksOptions): Observable<PluginExtensionLink[]> { |
||||
if (!singleton) { |
||||
throw new Error('setGetObservablePluginLinks() can only be used after the Grafana instance has started.'); |
||||
} |
||||
|
||||
return singleton(options); |
||||
} |
Loading…
Reference in new issue