@@ -11,61 +11,40 @@ import { replaceVariables } from 'utils';
1111
1212import { MetricFindQuery , RequestSpec } from './RequestSpec' ;
1313import RestApiBackend from './backend/rest' ;
14- import { BACKEND_TYPE , Backend } from './backend/types' ;
15- import WebApiBackend from './backend/web' ;
1614import { Settings } from './settings' ;
17- import { Backend as BackendType , CmkQuery , DataSourceOptions , Edition , ResponseDataAutocomplete } from './types' ;
15+ import { CmkQuery , DataSourceOptions , Edition , ResponseDataAutocomplete , type WebApiResponse } from './types' ;
1816import { AutoCompleteParams } from './ui/autocomplete' ;
1917import { createCmkContext } from './utils' ;
20- import { WebApiResponse } from './webapi' ;
2118
2219export class DataSource extends DataSourceApi < CmkQuery > {
23- webBackend : WebApiBackend ;
2420 restBackend : RestApiBackend ;
2521 settings : Settings ;
26- autocompleteBackend : BACKEND_TYPE | null = null ;
2722
2823 constructor ( private instanceSettings : DataSourceInstanceSettings < DataSourceOptions > ) {
2924 super ( instanceSettings ) ;
30- this . webBackend = new WebApiBackend ( this ) ;
3125 this . restBackend = new RestApiBackend ( this ) ;
3226 this . settings = new Settings ( instanceSettings . jsonData ) ;
3327 }
3428
35- protected async setAutocompleteBackend ( ) {
36- this . autocompleteBackend = await this . getBackend ( ) . getAutocompleteBackend ( ) ;
37- }
38-
3929 async query ( dataQueryRequest : DataQueryRequest < CmkQuery > ) : Promise < DataQueryResponse > {
4030 for ( const target of dataQueryRequest . targets ) {
4131 target . requestSpec = replaceVariables ( target . requestSpec , dataQueryRequest . scopedVars ) ;
4232 }
43- return this . getBackend ( ) . query ( dataQueryRequest ) ;
33+ return this . restBackend . query ( dataQueryRequest ) ;
4434 }
4535
4636 async metricFindQuery ( query : MetricFindQuery , options ?: unknown ) : Promise < MetricFindValue [ ] > {
47- if ( query . objectType === 'site' ) {
48- // rest-api site endpoint were added in 2.2.0 so we have to use the web-api here
49- // TODO: clean up (remove filterSites from Backend) with end of 2.1.0
50- return await this . getBackend ( ) . listSites ( ) ;
51- }
52- // we use the rest backend for both web and rest backend, because those endpoints are already implement in 2.1.0
5337 return await this . restBackend . metricFindQuery ( query ) ;
5438 }
39+
5540 async testDatasource ( ) : Promise < TestDataSourceResponse > {
56- return this . getBackend ( ) . testDatasource ( ) ;
41+ return this . restBackend . testDatasource ( ) ;
5742 }
5843
5944 async autocompleterRequest (
6045 api_url : string ,
6146 data : unknown
6247 ) : Promise < FetchResponse < WebApiResponse < ResponseDataAutocomplete > > > {
63- this . autocompleteBackend === null && ( await this . setAutocompleteBackend ( ) ) ;
64-
65- if ( this . autocompleteBackend === BACKEND_TYPE . WEB ) {
66- return this . webBackend . autocompleterRequest ( api_url , data ) ;
67- }
68-
6948 return this . restBackend . autocompleterRequest ( api_url , data ) ;
7049 }
7150
@@ -75,26 +54,8 @@ export class DataSource extends DataSourceApi<CmkQuery> {
7554 prefix : string ,
7655 params : Partial < AutoCompleteParams >
7756 ) : Promise < Array < { value : string ; label : string ; isDisabled : boolean } > > {
78- if ( ident === 'label' && this . getBackendType ( ) === 'web' ) {
79- // we have a 2.1.0 version without werk #15074 so label autocompleter is a special edge case
80- // can be removed after we stop supporting 2.1.0
81- const response = await this . webBackend . autocompleterRequest < Array < { value : string } > > (
82- 'ajax_autocomplete_labels.py' ,
83- {
84- world : params . world ,
85- search_label : prefix ,
86- }
87- ) ;
88- return response . data . result . map ( ( val : { value : string } ) => ( {
89- value : val . value ,
90- label : val . value ,
91- isDisabled : false ,
92- } ) ) ;
93- }
94- const context = createCmkContext (
95- replaceVariables ( partialRequestSpec ) ,
96- this . getBackendType ( ) === 'rest' ? 'latest' : '2.1.0'
97- ) ;
57+ const context = createCmkContext ( replaceVariables ( partialRequestSpec ) ) ;
58+
9859 const response = await this . autocompleterRequest ( 'ajax_vs_autocomplete.py' , {
9960 ident,
10061 value : prefix ,
@@ -118,17 +79,6 @@ export class DataSource extends DataSourceApi<CmkQuery> {
11879 return this . settings . edition ;
11980 }
12081
121- getBackendType ( ) : BackendType {
122- return this . settings . backend ;
123- }
124-
125- getBackend ( ) : Backend {
126- if ( this . getBackendType ( ) === 'web' ) {
127- return this . webBackend as Backend ;
128- }
129- return this . restBackend as Backend ;
130- }
131-
13282 getUsername ( ) : string {
13383 return this . settings . username ;
13484 }
0 commit comments