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:
Josh Hunt 2022-04-07 14:45:14 +01:00 committed by GitHub
parent 29b8d5d295
commit b857f8339e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 9 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -9,7 +9,7 @@ export interface Scenario {
export interface TestDataQuery extends DataQuery {
alias?: string;
scenarioId: string;
scenarioId?: string;
stringInput?: string;
stream?: StreamingQuery;
pulseWave?: PulseWaveQuery;