diff --git a/public/app/plugins/datasource/testdata/QueryEditor.tsx b/public/app/plugins/datasource/testdata/QueryEditor.tsx index ae68e35ffb8..a10116b875f 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.tsx @@ -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; diff --git a/public/app/plugins/datasource/testdata/datasource.ts b/public/app/plugins/datasource/testdata/datasource.ts index a92f578133f..b75d23016be 100644 --- a/public/app/plugins/datasource/testdata/datasource.ts +++ b/public/app/plugins/datasource/testdata/datasource.ts @@ -87,10 +87,6 @@ export class TestDataDataSource extends DataSourceWithBackend { } 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 { } 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): Observable { @@ -145,10 +158,13 @@ export class TestDataDataSource extends DataSourceWithBackend { } 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() { diff --git a/public/app/plugins/datasource/testdata/types.ts b/public/app/plugins/datasource/testdata/types.ts index 0f23a903de6..56ce9f569f4 100644 --- a/public/app/plugins/datasource/testdata/types.ts +++ b/public/app/plugins/datasource/testdata/types.ts @@ -9,7 +9,7 @@ export interface Scenario { export interface TestDataQuery extends DataQuery { alias?: string; - scenarioId: string; + scenarioId?: string; stringInput?: string; stream?: StreamingQuery; pulseWave?: PulseWaveQuery;