Skip to content

Commit

Permalink
fix: surface persistently visible errors in query editor
Browse files Browse the repository at this point in the history
  • Loading branch information
amlmtl committed Apr 5, 2024
1 parent 15aa80e commit 1cee4c2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React, {PureComponent} from 'react';
import {Select, SelectCommonProps} from '@grafana/ui';
import {Alert, Select, SelectCommonProps} from '@grafana/ui';
import {QueryEditorProps, SelectableValue} from '@grafana/data';
import {DataSource} from '../datasource';
import {
Expand All @@ -26,6 +26,15 @@ interface ServersResponse {
data: Server[]
}

interface ServersErrorResponse {
data: {
error: string,
message: string
},
status: number,
statusText: string,
}

interface State {
isServerDataFetched: boolean;
serverOptions: Array<SelectableEspObject<Server>>;
Expand All @@ -38,6 +47,7 @@ interface State {
selectedCq: ContinuousQuery | null | undefined;
selectedWindow: Window | null | undefined;
selectedFields: Field[];
errorMessage: String | null | undefined;
}

export class QueryEditor extends PureComponent<Props> {
Expand All @@ -58,7 +68,8 @@ export class QueryEditor extends PureComponent<Props> {
selectedProject: undefined,
selectedCq: undefined,
selectedWindow: undefined,
selectedFields: []
selectedFields: [],
errorMessage: undefined
};

this.espQueryController = new EspQueryController(this.props.query, this.props.onChange, this.props.onRunQuery);
Expand All @@ -78,14 +89,20 @@ export class QueryEditor extends PureComponent<Props> {
selectedFields: fields
});
await this.updateServers(servers);
await this.setStateWithPromise({ isServerDataFetched: true });
await this.setStateWithPromise({ isServerDataFetched: true, errorMessage: undefined });
})
.catch(console.error);
.catch((serversErrorResponse: ServersErrorResponse) => {
this.setState({ errorMessage: serversErrorResponse.data.message});
});
}

render() {
const state = this.state;

if (state.errorMessage != null) {
return <Alert title={`${state.errorMessage}`} severity="error"/>;
}

if (!state.isServerDataFetched) {
return <span>Discovering ESP servers...</span>;
}
Expand Down

0 comments on commit 1cee4c2

Please sign in to comment.