mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 05:51:51 +08:00

* Implement getDefaultQuery for cloudwatch logs and metrics * Fix bug with query reference in queryMigrations and replace tests * Move migrate functions to /migrations, remove onChange from LogsQueryField * [EMPTY] Retry CI * Fix naming
26 lines
677 B
TypeScript
26 lines
677 B
TypeScript
import { useEffect, useMemo } from 'react';
|
|
|
|
import { CloudWatchMetricsQuery } from '../types';
|
|
|
|
import { migrateMetricQuery } from './metricQueryMigrations';
|
|
|
|
/**
|
|
* Returns queries with migrations, and calls onChange function to notify if it changes
|
|
*/
|
|
const useMigratedMetricsQuery = (
|
|
query: CloudWatchMetricsQuery,
|
|
onChangeQuery: (newQuery: CloudWatchMetricsQuery) => void
|
|
) => {
|
|
const migratedQUery = useMemo(() => migrateMetricQuery(query), [query]);
|
|
|
|
useEffect(() => {
|
|
if (migratedQUery !== query) {
|
|
onChangeQuery(migratedQUery);
|
|
}
|
|
}, [migratedQUery, query, onChangeQuery]);
|
|
|
|
return migratedQUery;
|
|
};
|
|
|
|
export default useMigratedMetricsQuery;
|