The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/runtime/init.ts

45 lines
1.3 KiB

import { PanelData } from '@grafana/data';
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
/**
* This will setup features that are accessible through the root window location
*
* This is useful for manipulating the application from external drivers like puppetter/cypress
*
* @internal and subject to change
*/
export function initWindowRuntime() {
(window as any).grafanaRuntime = {
/** Get info for the current dashboard. This will include the migrated dashboard JSON */
getDashboardSaveModel: () => {
const d = getDashboardSrv().getCurrent();
if (!d) {
return undefined;
}
return d.getSaveModelClone();
},
/** The selected time range */
getDashboardTimeRange: () => {
const tr = getTimeSrv().timeRange();
return {
from: tr.from.valueOf(),
to: tr.to.valueOf(),
raw: tr.raw,
};
},
/** Get the query results for the last loaded data */
getPanelData: () => {
const d = getDashboardSrv().getCurrent();
if (!d) {
return undefined;
}
return d.panels.reduce((acc, panel) => {
acc[panel.id] = panel.getQueryRunner().getLastResult();
return acc;
}, {} as Record<number, PanelData | undefined>);
},
};
}