1
- import _ from 'lodash' ;
2
- import { isEqual } from 'lodash' ;
3
- import defaults from 'lodash/defaults' ;
1
+ import { isEqual , defaults , isNumber } from 'lodash' ;
4
2
5
3
import {
6
4
AnnotationEvent ,
@@ -11,8 +9,11 @@ import {
11
9
DataSourceInstanceSettings ,
12
10
ScopedVars ,
13
11
TimeRange ,
12
+ MutableDataFrame ,
13
+ dateTime ,
14
+ DataFrame ,
15
+ FieldType ,
14
16
} from '@grafana/data' ;
15
- import { dateTime , MutableDataFrame , FieldType , DataFrame } from '@grafana/data' ;
16
17
import { getTemplateSrv , DataSourceWithBackend } from '@grafana/runtime' ;
17
18
import { BackendSrv , getBackendSrv } from 'app/core/services/backend_srv' ;
18
19
@@ -42,6 +43,7 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
42
43
this . withCredentials = instanceSettings . withCredentials ;
43
44
44
45
console . log ( { instanceSettings } ) ;
46
+ // @ts -ignore
45
47
const url = instanceSettings . jsonData [ 'connection.url' ] ;
46
48
// const url = "http://localhost:8081/api/query"
47
49
this . url = url ;
@@ -147,6 +149,7 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
147
149
return dataPathArray ;
148
150
}
149
151
152
+ // @ts -ignore
150
153
async query ( options : DataQueryRequest < MyQuery > ) : Promise < DataQueryResponse > {
151
154
return Promise . all (
152
155
options . targets . map ( ( target ) => {
@@ -190,7 +193,7 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
190
193
let t : FieldType = FieldType . string ;
191
194
if ( fieldName === timePath || isRFC3339_ISO6801 ( String ( doc [ fieldName ] ) ) ) {
192
195
t = FieldType . time ;
193
- } else if ( _ . isNumber ( doc [ fieldName ] ) ) {
196
+ } else if ( isNumber ( doc [ fieldName ] ) ) {
194
197
t = FieldType . number ;
195
198
}
196
199
let title ;
@@ -215,6 +218,7 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
215
218
name : fieldName ,
216
219
type : t ,
217
220
config : { displayName : title } ,
221
+ // @ts -ignore
218
222
} ) . parse = ( v : any ) => {
219
223
return v || '' ;
220
224
} ;
@@ -234,6 +238,7 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
234
238
}
235
239
annotationQuery ( options : AnnotationQueryRequest < MyQuery > ) : Promise < AnnotationEvent [ ] > {
236
240
const query = defaults ( options . annotation , defaultQuery ) ;
241
+ // @ts -ignore
237
242
return Promise . all ( [ this . createQuery ( query , options . range ) ] ) . then ( ( results : any ) => {
238
243
const r : AnnotationEvent [ ] = [ ] ;
239
244
for ( const res of results ) {
@@ -257,15 +262,15 @@ export class FN_DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOp
257
262
const fieldValue = doc [ fieldName ] ;
258
263
const replaceKey = 'field_' + fieldName ;
259
264
const regex = new RegExp ( '\\$' + replaceKey , 'g' ) ;
260
- title = title . replace ( regex , fieldValue ) ;
261
- text = text . replace ( regex , fieldValue ) ;
262
- tags = tags . replace ( regex , fieldValue ) ;
265
+ title = title ? .replace ( regex , fieldValue ) ;
266
+ text = text ? .replace ( regex , fieldValue ) ;
267
+ tags = tags ? .replace ( regex , fieldValue ) ;
263
268
}
264
269
265
270
annotation . title = title ;
266
271
annotation . text = text ;
267
272
const tagsList : string [ ] = [ ] ;
268
- for ( const element of tags . split ( ',' ) ) {
273
+ for ( const element of ( tags || '' ) . split ( ',' ) ) {
269
274
const trimmed = element . trim ( ) ;
270
275
if ( trimmed ) {
271
276
tagsList . push ( trimmed ) ;
0 commit comments