mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 08:02:27 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
20 lines
757 B
TypeScript
20 lines
757 B
TypeScript
import { useMemo } from 'react';
|
|
|
|
import { BucketAggregation } from '../components/QueryEditor/BucketAggregationsEditor/aggregations';
|
|
import { useQuery } from '../components/QueryEditor/ElasticsearchQueryContext';
|
|
import { MetricAggregation } from '../components/QueryEditor/MetricAggregationsEditor/aggregations';
|
|
|
|
const toId = <T extends { id: unknown }>(e: T): T['id'] => e.id;
|
|
|
|
const toInt = (idString: string) => parseInt(idString, 10);
|
|
|
|
export const useNextId = (): MetricAggregation['id'] | BucketAggregation['id'] => {
|
|
const { metrics, bucketAggs } = useQuery();
|
|
|
|
return useMemo(
|
|
() =>
|
|
(Math.max(...[...(metrics?.map(toId) || ['0']), ...(bucketAggs?.map(toId) || ['0'])].map(toInt)) + 1).toString(),
|
|
[metrics, bucketAggs]
|
|
);
|
|
};
|