mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelInspector: Fixed issue in panel inspector (#22302)
This commit is contained in:
parent
e6c59d0729
commit
0dbe5323d7
@ -55,32 +55,6 @@ interface State {
|
|||||||
drawerWidth: string;
|
drawerWidth: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStyles = stylesFactory(() => {
|
|
||||||
return {
|
|
||||||
toolbar: css`
|
|
||||||
display: flex;
|
|
||||||
margin: 8px 0;
|
|
||||||
justify-content: flex-end;
|
|
||||||
align-items: center;
|
|
||||||
`,
|
|
||||||
dataFrameSelect: css`
|
|
||||||
flex-grow: 2;
|
|
||||||
`,
|
|
||||||
downloadCsv: css`
|
|
||||||
margin-left: 16px;
|
|
||||||
`,
|
|
||||||
tabContent: css`
|
|
||||||
height: calc(100% - 32px);
|
|
||||||
`,
|
|
||||||
dataTabContent: css`
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
`,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
export class PanelInspector extends PureComponent<Props, State> {
|
export class PanelInspector extends PureComponent<Props, State> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -96,12 +70,14 @@ export class PanelInspector extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const { panel } = this.props;
|
const { panel } = this.props;
|
||||||
|
|
||||||
if (!panel) {
|
if (!panel) {
|
||||||
this.onDismiss(); // Try to close the component
|
this.onDismiss(); // Try to close the component
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastResult = panel.getQueryRunner().getLastResult();
|
const lastResult = panel.getQueryRunner().getLastResult();
|
||||||
|
|
||||||
if (!lastResult) {
|
if (!lastResult) {
|
||||||
this.onDismiss(); // Usually opened from refresh?
|
this.onDismiss(); // Usually opened from refresh?
|
||||||
return;
|
return;
|
||||||
@ -118,14 +94,17 @@ export class PanelInspector extends PureComponent<Props, State> {
|
|||||||
// Find the first DataSource wanting to show custom metadata
|
// Find the first DataSource wanting to show custom metadata
|
||||||
if (data && targets.length) {
|
if (data && targets.length) {
|
||||||
const queries: Record<string, DataQuery> = {};
|
const queries: Record<string, DataQuery> = {};
|
||||||
|
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
queries[target.refId] = target;
|
queries[target.refId] = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const frame of data) {
|
for (const frame of data) {
|
||||||
const q = queries[frame.refId];
|
const q = queries[frame.refId];
|
||||||
if (q && frame.meta.custom) {
|
|
||||||
|
if (q && frame.meta && frame.meta.custom) {
|
||||||
const dataSource = await getDataSourceSrv().get(q.datasource);
|
const dataSource = await getDataSourceSrv().get(q.datasource);
|
||||||
|
|
||||||
if (dataSource && dataSource.components?.MetadataInspector) {
|
if (dataSource && dataSource.components?.MetadataInspector) {
|
||||||
metaDS = dataSource;
|
metaDS = dataSource;
|
||||||
break;
|
break;
|
||||||
@ -198,6 +177,7 @@ export class PanelInspector extends PureComponent<Props, State> {
|
|||||||
if (!data || !data.length) {
|
if (!data || !data.length) {
|
||||||
return <div>No Data</div>;
|
return <div>No Data</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const choices = data.map((frame, index) => {
|
const choices = data.map((frame, index) => {
|
||||||
return {
|
return {
|
||||||
value: index,
|
value: index,
|
||||||
@ -284,15 +264,19 @@ export class PanelInspector extends PureComponent<Props, State> {
|
|||||||
const { tab, last, stats } = this.state;
|
const { tab, last, stats } = this.state;
|
||||||
const error = last?.error;
|
const error = last?.error;
|
||||||
const tabs = [];
|
const tabs = [];
|
||||||
|
|
||||||
if (last && last?.series?.length > 0) {
|
if (last && last?.series?.length > 0) {
|
||||||
tabs.push({ label: 'Data', value: InspectTab.Data });
|
tabs.push({ label: 'Data', value: InspectTab.Data });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.metaDS) {
|
if (this.state.metaDS) {
|
||||||
tabs.push({ label: 'Meta Data', value: InspectTab.Meta });
|
tabs.push({ label: 'Meta Data', value: InspectTab.Meta });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error && error.message) {
|
if (error && error.message) {
|
||||||
tabs.push({ label: 'Error', value: InspectTab.Error });
|
tabs.push({ label: 'Error', value: InspectTab.Error });
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs.push({ label: 'Raw JSON', value: InspectTab.Raw });
|
tabs.push({ label: 'Raw JSON', value: InspectTab.Raw });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -341,3 +325,29 @@ export class PanelInspector extends PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getStyles = stylesFactory(() => {
|
||||||
|
return {
|
||||||
|
toolbar: css`
|
||||||
|
display: flex;
|
||||||
|
margin: 8px 0;
|
||||||
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
`,
|
||||||
|
dataFrameSelect: css`
|
||||||
|
flex-grow: 2;
|
||||||
|
`,
|
||||||
|
downloadCsv: css`
|
||||||
|
margin-left: 16px;
|
||||||
|
`,
|
||||||
|
tabContent: css`
|
||||||
|
height: calc(100% - 32px);
|
||||||
|
`,
|
||||||
|
dataTabContent: css`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user