mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* AzureMonitor: Remove anys from datasource to get the inferred type * AzureMonitor: Cast some datasource types TODO: we want proper types for these * AzureMonitor: Initial react Metrics editor components * start dimension fields * replace replaceTemplateVariable with datasource.replace, and rename onQueryChange to onChange * actually just do template variable replacement in the datasource * don't use azureMonitorIsConfigured * Refactors, mainly around the metric metadata - Convert all the metric metadata options for the Select before its set into state - Stop using SelectableValue because it's basically any when all the properties are optional - the onChange function passed to the fields now just accepts the direct value, rather than wrapped in a SelectableValue * added proper fields, and adding and removing for DimensionFields * Update query with Dimension changes * Width * subscription and query type fields * Should be feature complete now, more or less * fix missing import * fix lint issues * set default subscription ID * Starting to write some tests * tests for query editor * Remove subscription ID from the label in Metrics But we keep it there for the angular stuff * MetricsQueryEditor tests * Update index.test.tsx * fix tests * add template variables to dropdowns * clean up * update tests * Reorganise react components * Group query fields into rows * Rename Option type, add Azure response type * Refactor Metrics metric metadata - Types the Azure API - Moves default metadata values into datasource * nit * update test
20 lines
857 B
TypeScript
20 lines
857 B
TypeScript
import { rangeUtil } from '@grafana/data';
|
|
import TimegrainConverter from '../time_grain_converter';
|
|
import { AzureMonitorOption } from '../types';
|
|
|
|
// Defaults to returning a fallback option so the UI still shows the value while the API is loading
|
|
export const findOption = (options: AzureMonitorOption[], value: string) =>
|
|
options.find((v) => v.value === value) ?? { value, label: value };
|
|
|
|
export const toOption = (v: { text: string; value: string }) => ({ value: v.value, label: v.text });
|
|
|
|
export function convertTimeGrainsToMs<T extends { value: string }>(timeGrains: T[]) {
|
|
const allowedTimeGrainsMs: number[] = [];
|
|
timeGrains.forEach((tg: any) => {
|
|
if (tg.value !== 'auto') {
|
|
allowedTimeGrainsMs.push(rangeUtil.intervalToMs(TimegrainConverter.createKbnUnitFromISO8601Duration(tg.value)));
|
|
}
|
|
});
|
|
return allowedTimeGrainsMs;
|
|
}
|