mirror of https://github.com/grafana/grafana
AzureMonitor: Remove Angular query editor (#37532)
* Remove angular query editor * call debounced onRunQuery, and set some default query valuesjoshhunt/azure-monitor-remove-angular
parent
44c7e65fac
commit
f41f45f6bf
@ -0,0 +1,35 @@ |
||||
import { useEffect, useMemo } from 'react'; |
||||
import { AzureMonitorQuery, AzureQueryType } from '../../types'; |
||||
|
||||
const DEFAULT_QUERY_TYPE = AzureQueryType.AzureMonitor; |
||||
|
||||
const createQueryWithDefaults = (query: AzureMonitorQuery) => { |
||||
// A quick and easy way to set just the default query type. If we want to set any other defaults,
|
||||
// we might want to look into something more robust
|
||||
if (!query.queryType) { |
||||
return { |
||||
...query, |
||||
queryType: query.queryType ?? DEFAULT_QUERY_TYPE, |
||||
}; |
||||
} |
||||
|
||||
return query; |
||||
}; |
||||
|
||||
/** |
||||
* Returns queries with some defaults, and calls onChange function to notify if it changes |
||||
*/ |
||||
const useDefaultQuery = (query: AzureMonitorQuery, onChangeQuery: (newQuery: AzureMonitorQuery) => void) => { |
||||
const queryWithDefaults = useMemo(() => createQueryWithDefaults(query), [query]); |
||||
|
||||
useEffect(() => { |
||||
if (queryWithDefaults !== query) { |
||||
console.log('changing default query'); |
||||
onChangeQuery(queryWithDefaults); |
||||
} |
||||
}, [queryWithDefaults, query, onChangeQuery]); |
||||
|
||||
return queryWithDefaults; |
||||
}; |
||||
|
||||
export default useDefaultQuery; |
@ -1,11 +1,11 @@ |
||||
import { DataSourcePlugin } from '@grafana/data'; |
||||
import { AzureMonitorQueryCtrl } from './query_ctrl'; |
||||
import Datasource from './datasource'; |
||||
import { ConfigEditor } from './components/ConfigEditor'; |
||||
import AzureMonitorQueryEditor from './components/QueryEditor'; |
||||
import { AzureMonitorAnnotationsQueryCtrl } from './annotations_query_ctrl'; |
||||
import { AzureMonitorQuery, AzureDataSourceJsonData } from './types'; |
||||
|
||||
export const plugin = new DataSourcePlugin<Datasource, AzureMonitorQuery, AzureDataSourceJsonData>(Datasource) |
||||
.setConfigEditor(ConfigEditor) |
||||
.setQueryCtrl(AzureMonitorQueryCtrl) |
||||
.setQueryEditor(AzureMonitorQueryEditor) |
||||
.setAnnotationQueryCtrl(AzureMonitorAnnotationsQueryCtrl); |
Loading…
Reference in new issue