mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 13:09:22 -06:00
SharedQuery: Fixes shared query editor now showing queries (#29849)
* SharedQuery: Fixes shared query editor now showing queries * fixed updating state when query change
This commit is contained in:
parent
8250b59dfe
commit
7adccf1e67
@ -43,55 +43,61 @@ export class DashboardQueryEditor extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
this.componentDidUpdate(this.props);
|
||||
await this.updateState();
|
||||
}
|
||||
|
||||
async componentDidUpdate(prevProps: Props) {
|
||||
const { panelData, queries } = this.props;
|
||||
|
||||
if (queries.length < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!prevProps || prevProps.panelData !== panelData) {
|
||||
const query = queries[0] as DashboardQuery;
|
||||
const defaultDS = await getDatasourceSrv().get();
|
||||
const dashboard = getDashboardSrv().getCurrent();
|
||||
const panel = dashboard.getPanelById(query.panelId ?? -124134);
|
||||
|
||||
if (!panel) {
|
||||
this.setState({ defaultDatasource: defaultDS.name });
|
||||
return;
|
||||
}
|
||||
|
||||
const mainDS = await getDatasourceSrv().get(panel.datasource);
|
||||
const info: ResultInfo[] = [];
|
||||
|
||||
for (const query of panel.targets) {
|
||||
const ds = query.datasource ? await getDatasourceSrv().get(query.datasource) : mainDS;
|
||||
const fmt = ds.getQueryDisplayText ? ds.getQueryDisplayText : getQueryDisplayText;
|
||||
|
||||
const qData = filterPanelDataToQuery(panelData, query.refId);
|
||||
const queryData = qData ? qData : panelData;
|
||||
|
||||
info.push({
|
||||
refId: query.refId,
|
||||
query: fmt(query),
|
||||
img: ds.meta.info.logos.small,
|
||||
data: queryData.series,
|
||||
error: queryData.error,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({ defaultDatasource: defaultDS.name, results: info });
|
||||
if (prevProps.panelData !== panelData || prevProps.queries !== queries) {
|
||||
await this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
async updateState() {
|
||||
const { panelData, queries } = this.props;
|
||||
|
||||
const query = queries[0] as DashboardQuery;
|
||||
const defaultDS = await getDatasourceSrv().get();
|
||||
const dashboard = getDashboardSrv().getCurrent();
|
||||
const panel = dashboard.getPanelById(query.panelId ?? -124134);
|
||||
|
||||
if (!panel) {
|
||||
this.setState({ defaultDatasource: defaultDS.name });
|
||||
return;
|
||||
}
|
||||
|
||||
const mainDS = await getDatasourceSrv().get(panel.datasource);
|
||||
const info: ResultInfo[] = [];
|
||||
|
||||
for (const query of panel.targets) {
|
||||
const ds = query.datasource ? await getDatasourceSrv().get(query.datasource) : mainDS;
|
||||
const fmt = ds.getQueryDisplayText ? ds.getQueryDisplayText : getQueryDisplayText;
|
||||
|
||||
const qData = filterPanelDataToQuery(panelData, query.refId);
|
||||
const queryData = qData ? qData : panelData;
|
||||
|
||||
info.push({
|
||||
refId: query.refId,
|
||||
query: fmt(query),
|
||||
img: ds.meta.info.logos.small,
|
||||
data: queryData.series,
|
||||
error: queryData.error,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({ defaultDatasource: defaultDS.name, results: info });
|
||||
}
|
||||
|
||||
onPanelChanged = (id: number) => {
|
||||
const { onChange } = this.props;
|
||||
const query = this.getQuery();
|
||||
query.panelId = id;
|
||||
onChange([query]);
|
||||
|
||||
this.props.onChange([
|
||||
{
|
||||
...query,
|
||||
panelId: id,
|
||||
} as DashboardQuery,
|
||||
]);
|
||||
};
|
||||
|
||||
renderQueryData(editURL: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user