Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (data: PanelData) => {
if (!data.request || done) {
return;
}
if (data.state !== LoadingState.Done && data.state !== LoadingState.Error) {
return;
}
const eventData: MetaAnalyticsEventPayload = {
datasourceName: datasource.name,
datasourceId: datasource.id,
panelId: data.request.panelId,
dashboardId: data.request.dashboardId,
// app: 'dashboard',
dataSize: 0,
duration: data.request.endTime - data.request.startTime,
eventName: 'data-request',
// sessionId: '',
};
// enrich with dashboard info
next: (data: PanelData) => {
if (data.state === LoadingState.Error) {
this.loading = false;
this.processDataError(data.error);
}
// Ignore data in loading state
if (data.state === LoadingState.Loading) {
this.loading = true;
this.angularDirtyCheck();
return;
}
if (data.request) {
const { timeInfo } = data.request;
if (timeInfo) {
this.timeInfo = timeInfo;
}
render() {
const { queryResponse, latency } = this.props;
const className =
queryResponse.state === LoadingState.Done || LoadingState.Error
? 'query-transaction'
: 'query-transaction query-transaction--loading';
return (
<div>
{/* <div>{transaction.resultType}:</div> */}
<div>
{queryResponse.state === LoadingState.Done || LoadingState.Error ? formatLatency(latency) : }
</div>
</div>
);
}
}
setError(err: any): PanelData {
if (!this.request.endTime) {
this.request.endTime = Date.now();
}
this.closeStreams(true);
this.response = {
...this.response, // Keep any existing data
state: LoadingState.Error,
error: toDataQueryError(err),
};
return this.validateStreamsAndGetPanelData();
}
}
const series = data.series.filter(series => series.refId === refId);
// No matching series
if (!series.length) {
return undefined;
}
// Don't pass the request if all requests are the same
const request: DataQueryRequest = undefined;
// TODO: look in sub-requets to match the info
// Only say this is an error if the error links to the query
let state = LoadingState.Done;
const error = data.error && data.error.refId === refId ? data.error : undefined;
if (error) {
state = LoadingState.Error;
}
const timeRange = data.timeRange;
return {
state,
series,
request,
error,
timeRange,
};
}
lodashMap(packets, (packet: DataQueryResponse) => {
if (packet.error) {
loadingState = LoadingState.Error;
error = packet.error;
}
return packet.data;
})
);
catchError(err =>
of({
...state.panelData,
state: LoadingState.Error,
error: processQueryError(err),
})
),
lodashMap(packets, (packet: DataQueryResponse) => {
if (packet.error) {
loadingState = LoadingState.Error;
error = packet.error;
}
return packet.data;
})
);
function getQueryError(msg: string): PanelData {
return {
state: LoadingState.Error,
series: [],
error: { message: msg },
timeRange: DefaultTimeRange,
};
}