mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Inspect: Should not subscribe to transformed data * PQR- allow controll whether or not field overrides and transformations should be applied * UI for inspector data options * fix * Null check fix * Refactor PanelInspector * TS fix * Merge fix * fix test * Update public/app/features/dashboard/components/Inspector/InspectDataTab.tsx Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> * review batch 1 * Update API of usePanelLatestData * css * review batch 2 * Update usePanelLatestData hook Co-authored-by: Torkel Ödegaard <torkel@grafana.com> Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { DataQueryError, DataSourceApi, PanelData, PanelPlugin } from '@grafana/data';
|
|
import useAsync from 'react-use/lib/useAsync';
|
|
import { getDataSourceSrv } from '@grafana/runtime';
|
|
import { DashboardModel } from 'app/features/dashboard/state';
|
|
import { useMemo } from 'react';
|
|
import { supportsDataQuery } from '../PanelEditor/utils';
|
|
import { InspectTab } from './types';
|
|
|
|
/**
|
|
* Given PanelData return first data source supporting metadata inspector
|
|
*/
|
|
export const useDatasourceMetadata = (data?: PanelData) => {
|
|
const state = useAsync<DataSourceApi | undefined>(async () => {
|
|
const targets = data?.request?.targets || [];
|
|
|
|
if (data && data.series && targets.length) {
|
|
for (const frame of data.series) {
|
|
if (frame.meta && frame.meta.custom) {
|
|
// get data source from first query
|
|
const dataSource = await getDataSourceSrv().get(targets[0].datasource);
|
|
if (dataSource && dataSource.components?.MetadataInspector) {
|
|
return dataSource;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}, [data]);
|
|
return state.value;
|
|
};
|
|
|
|
/**
|
|
* Configures tabs for PanelInspector
|
|
*/
|
|
export const useInspectTabs = (
|
|
plugin: PanelPlugin,
|
|
dashboard: DashboardModel,
|
|
error?: DataQueryError,
|
|
metaDs?: DataSourceApi
|
|
) => {
|
|
return useMemo(() => {
|
|
const tabs = [];
|
|
if (supportsDataQuery(plugin)) {
|
|
tabs.push({ label: 'Data', value: InspectTab.Data });
|
|
tabs.push({ label: 'Stats', value: InspectTab.Stats });
|
|
}
|
|
|
|
if (metaDs) {
|
|
tabs.push({ label: 'Meta Data', value: InspectTab.Meta });
|
|
}
|
|
|
|
tabs.push({ label: 'JSON', value: InspectTab.JSON });
|
|
|
|
if (error && error.message) {
|
|
tabs.push({ label: 'Error', value: InspectTab.Error });
|
|
}
|
|
|
|
if (dashboard.meta.canEdit && supportsDataQuery(plugin)) {
|
|
tabs.push({ label: 'Query', value: InspectTab.Query });
|
|
}
|
|
return tabs;
|
|
}, [plugin, metaDs, dashboard, error]);
|
|
};
|