mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Runtime: Expose runRequest function (#60793)
This commit is contained in:
parent
b356526ebe
commit
aa0936127d
@ -28,7 +28,13 @@ export {
|
||||
export { PanelRenderer, type PanelRendererProps } from './components/PanelRenderer';
|
||||
export { PanelDataErrorView, type PanelDataErrorViewProps } from './components/PanelDataErrorView';
|
||||
export { toDataQueryError } from './utils/toDataQueryError';
|
||||
export { setQueryRunnerFactory, createQueryRunner, type QueryRunnerFactory } from './services/QueryRunner';
|
||||
export {
|
||||
setQueryRunnerFactory,
|
||||
createQueryRunner,
|
||||
type QueryRunnerFactory,
|
||||
setRunRequest,
|
||||
getRunRequest,
|
||||
} from './services/QueryRunner';
|
||||
export { PluginPage } from './components/PluginPage';
|
||||
export type { PluginPageType, PluginPageProps } from './components/PluginPage';
|
||||
export {
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { QueryRunner } from '@grafana/data';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { DataQueryRequest, DataSourceApi, PanelData, QueryRunner } from '@grafana/data';
|
||||
|
||||
let factory: QueryRunnerFactory | undefined;
|
||||
|
||||
@ -31,3 +33,30 @@ export const createQueryRunner = (): QueryRunner => {
|
||||
}
|
||||
return factory();
|
||||
};
|
||||
|
||||
type RunRequestFn = (
|
||||
datasource: DataSourceApi,
|
||||
request: DataQueryRequest,
|
||||
queryFunction?: typeof datasource.query
|
||||
) => Observable<PanelData>;
|
||||
|
||||
let runRequest: RunRequestFn | undefined;
|
||||
|
||||
/**
|
||||
* Used to exspose runRequest implementation to libraries, i.e. @grafana/scenes
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function setRunRequest(fn: RunRequestFn): void {
|
||||
if (runRequest) {
|
||||
throw new Error('runRequest function should only be set once, when Grafana is starting.');
|
||||
}
|
||||
runRequest = fn;
|
||||
}
|
||||
|
||||
export function getRunRequest(): RunRequestFn {
|
||||
if (!runRequest) {
|
||||
throw new Error('getRunRequest can only be used after Grafana instance has started.');
|
||||
}
|
||||
return runRequest;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import {
|
||||
setEchoSrv,
|
||||
setLocationSrv,
|
||||
setQueryRunnerFactory,
|
||||
setRunRequest,
|
||||
} from '@grafana/runtime';
|
||||
import { setPanelDataErrorView } from '@grafana/runtime/src/components/PanelDataErrorView';
|
||||
import { setPanelRenderer } from '@grafana/runtime/src/components/PanelRenderer';
|
||||
@ -69,6 +70,7 @@ import { PanelRenderer } from './features/panel/components/PanelRenderer';
|
||||
import { DatasourceSrv } from './features/plugins/datasource_srv';
|
||||
import { preloadPlugins } from './features/plugins/pluginPreloader';
|
||||
import { QueryRunner } from './features/query/state/QueryRunner';
|
||||
import { runRequest } from './features/query/state/runRequest';
|
||||
import { initWindowRuntime } from './features/runtime/init';
|
||||
import { variableAdapters } from './features/variables/adapters';
|
||||
import { createAdHocVariableAdapter } from './features/variables/adhoc/adapter';
|
||||
@ -140,6 +142,9 @@ export class GrafanaApp {
|
||||
setQueryRunnerFactory(() => new QueryRunner());
|
||||
setVariableQueryRunner(new VariableQueryRunner());
|
||||
|
||||
// Provide runRequest implementation to packages, @grafana/scenes in particular
|
||||
setRunRequest(runRequest);
|
||||
|
||||
locationUtil.initialize({
|
||||
config,
|
||||
getTimeRangeForUrl: getTimeSrv().timeRangeForUrl,
|
||||
|
Loading…
Reference in New Issue
Block a user