mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* Initial * WIP * wip * Refactor: fixing types * Refactor: Fixed more typings * Feature: Moves TestData to new API * Feature: Moves CloudMonitoringDatasource to new API * Feature: Moves PrometheusDatasource to new Variables API * Refactor: Clean up comments * Refactor: changes to QueryEditorProps instead * Refactor: cleans up testdata, prometheus and cloud monitoring variable support * Refactor: adds variableQueryRunner * Refactor: adds props to VariableQueryEditor * Refactor: reverted Loki editor * Refactor: refactor queryrunner into smaller pieces * Refactor: adds upgrade query thunk * Tests: Updates old tests * Docs: fixes build errors for exported api * Tests: adds guard tests * Tests: adds QueryRunner tests * Tests: fixes broken tests * Tests: adds variableQueryObserver tests * Test: adds tests for operator functions * Test: adds VariableQueryRunner tests * Refactor: renames dataSource * Refactor: adds definition for standard variable support * Refactor: adds cancellation to OptionPicker * Refactor: changes according to Dominiks suggestion * Refactor:tt * Refactor: adds tests for factories * Refactor: restructuring a bit * Refactor: renames variableQueryRunner.ts * Refactor: adds quick exit when runRequest returns errors * Refactor: using TextArea from grafana/ui * Refactor: changed from interfaces to classes instead * Tests: fixes broken test * Docs: fixes doc issue count * Docs: fixes doc issue count * Refactor: Adds check for self referencing queries * Tests: fixed unused variable * Refactor: Changes comments
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import React, { useCallback } from 'react';
|
|
import { DataQuery, DataSourceApi, DataSourceJsonData, QueryEditorProps, StandardVariableQuery } from '@grafana/data';
|
|
import { getTemplateSrv } from '@grafana/runtime';
|
|
|
|
import { LegacyVariableQueryEditor } from './LegacyVariableQueryEditor';
|
|
import {
|
|
hasCustomVariableSupport,
|
|
hasDatasourceVariableSupport,
|
|
hasLegacyVariableSupport,
|
|
hasStandardVariableSupport,
|
|
} from '../guard';
|
|
import { importDataSourcePlugin } from '../../plugins/plugin_loader';
|
|
import { VariableQueryEditorType } from '../types';
|
|
|
|
export async function getVariableQueryEditor<
|
|
TQuery extends DataQuery = DataQuery,
|
|
TOptions extends DataSourceJsonData = DataSourceJsonData,
|
|
VariableQuery extends DataQuery = TQuery
|
|
>(
|
|
datasource: DataSourceApi<TQuery, TOptions>,
|
|
importDataSourcePluginFunc = importDataSourcePlugin
|
|
): Promise<VariableQueryEditorType> {
|
|
if (hasCustomVariableSupport(datasource)) {
|
|
return datasource.variables.editor;
|
|
}
|
|
|
|
if (hasDatasourceVariableSupport(datasource)) {
|
|
const dsPlugin = await importDataSourcePluginFunc(datasource.meta!);
|
|
|
|
if (!dsPlugin.components.QueryEditor) {
|
|
throw new Error('Missing QueryEditor in plugin definition.');
|
|
}
|
|
|
|
return dsPlugin.components.QueryEditor ?? null;
|
|
}
|
|
|
|
if (hasStandardVariableSupport(datasource)) {
|
|
return StandardVariableQueryEditor;
|
|
}
|
|
|
|
if (hasLegacyVariableSupport(datasource)) {
|
|
const dsPlugin = await importDataSourcePluginFunc(datasource.meta!);
|
|
return dsPlugin.components.VariableQueryEditor ?? LegacyVariableQueryEditor;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function StandardVariableQueryEditor<
|
|
TQuery extends DataQuery = DataQuery,
|
|
TOptions extends DataSourceJsonData = DataSourceJsonData
|
|
>({
|
|
datasource: propsDatasource,
|
|
query: propsQuery,
|
|
onChange: propsOnChange,
|
|
}: QueryEditorProps<any, TQuery, TOptions, StandardVariableQuery>) {
|
|
const onChange = useCallback(
|
|
(query: any) => {
|
|
propsOnChange({ refId: 'StandardVariableQuery', query });
|
|
},
|
|
[propsOnChange]
|
|
);
|
|
|
|
return (
|
|
<LegacyVariableQueryEditor
|
|
query={propsQuery.query}
|
|
onChange={onChange}
|
|
datasource={propsDatasource}
|
|
templateSrv={getTemplateSrv()}
|
|
/>
|
|
);
|
|
}
|