mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
TestData: Interpolate variables in more fields (#47158)
* TestData: Interpolate variables in more fields * only interpolate variables if the field is set * Correctly type scenarioId which can be undefined
This commit is contained in:
parent
29b8d5d295
commit
b857f8339e
@ -163,7 +163,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
|
||||
.sort((a, b) => a.label.localeCompare(b.label)),
|
||||
[scenarioList]
|
||||
);
|
||||
const showLabels = useMemo(() => showLabelsFor.includes(query.scenarioId), [query]);
|
||||
const showLabels = useMemo(() => showLabelsFor.includes(query.scenarioId ?? ''), [query]);
|
||||
|
||||
if (loading) {
|
||||
return null;
|
||||
|
@ -87,10 +87,6 @@ export class TestDataDataSource extends DataSourceWithBackend<TestDataQuery> {
|
||||
}
|
||||
|
||||
default:
|
||||
if (target.alias) {
|
||||
target.alias = this.templateSrv.replace(target.alias, options.scopedVars);
|
||||
}
|
||||
|
||||
backendQueries.push(target);
|
||||
}
|
||||
}
|
||||
@ -111,7 +107,24 @@ export class TestDataDataSource extends DataSourceWithBackend<TestDataQuery> {
|
||||
}
|
||||
|
||||
resolveTemplateVariables(query: TestDataQuery, scopedVars: ScopedVars) {
|
||||
query.labels = this.templateSrv.replace(query.labels!, scopedVars);
|
||||
if (query.labels) {
|
||||
query.labels = this.templateSrv.replace(query.labels, scopedVars);
|
||||
}
|
||||
if (query.alias) {
|
||||
query.alias = this.templateSrv.replace(query.alias, scopedVars);
|
||||
}
|
||||
if (query.scenarioId) {
|
||||
query.scenarioId = this.templateSrv.replace(query.scenarioId, scopedVars);
|
||||
}
|
||||
if (query.stringInput) {
|
||||
query.stringInput = this.templateSrv.replace(query.stringInput, scopedVars);
|
||||
}
|
||||
if (query.csvContent) {
|
||||
query.csvContent = this.templateSrv.replace(query.csvContent, scopedVars);
|
||||
}
|
||||
if (query.rawFrameContent) {
|
||||
query.rawFrameContent = this.templateSrv.replace(query.rawFrameContent, scopedVars);
|
||||
}
|
||||
}
|
||||
|
||||
annotationDataTopicTest(target: TestDataQuery, req: DataQueryRequest<TestDataQuery>): Observable<DataQueryResponse> {
|
||||
@ -145,10 +158,13 @@ export class TestDataDataSource extends DataSourceWithBackend<TestDataQuery> {
|
||||
}
|
||||
|
||||
getQueryDisplayText(query: TestDataQuery) {
|
||||
const scenario = query.scenarioId ?? 'Default scenario';
|
||||
|
||||
if (query.alias) {
|
||||
return query.scenarioId + ' as ' + query.alias;
|
||||
return scenario + ' as ' + query.alias;
|
||||
}
|
||||
return query.scenarioId;
|
||||
|
||||
return scenario;
|
||||
}
|
||||
|
||||
testDatasource() {
|
||||
|
@ -9,7 +9,7 @@ export interface Scenario {
|
||||
|
||||
export interface TestDataQuery extends DataQuery {
|
||||
alias?: string;
|
||||
scenarioId: string;
|
||||
scenarioId?: string;
|
||||
stringInput?: string;
|
||||
stream?: StreamingQuery;
|
||||
pulseWave?: PulseWaveQuery;
|
||||
|
Loading…
Reference in New Issue
Block a user