Commit 7adccf1e by Torkel Ödegaard Committed by GitHub

SharedQuery: Fixes shared query editor now showing queries (#29849)

* SharedQuery: Fixes shared query editor now showing queries

* fixed updating state when query change
parent 8250b59d
......@@ -43,17 +43,20 @@ 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.panelData !== panelData || prevProps.queries !== queries) {
await this.updateState();
}
}
if (!prevProps || prevProps.panelData !== panelData) {
async updateState() {
const { panelData, queries } = this.props;
const query = queries[0] as DashboardQuery;
const defaultDS = await getDatasourceSrv().get();
const dashboard = getDashboardSrv().getCurrent();
......@@ -85,13 +88,16 @@ export class DashboardQueryEditor extends PureComponent<Props, State> {
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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment