Import: fix dashboard imports with expressions (#43630)

This commit is contained in:
Ryan McKinley 2022-01-04 11:42:18 -05:00 committed by GitHub
parent 238345b62d
commit b09d498484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"regexp"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/plugins"
)
@ -47,6 +48,13 @@ func (e *DashTemplateEvaluator) Eval() (*simplejson.Json, error) {
inputType := inputDefJson.Get("type").MustString()
input := e.findInput(inputName, inputType)
// force expressions value to `__expr__`
if inputDefJson.Get("pluginId").MustString() == expr.DatasourceType {
input = &plugins.ImportDashboardInput{
Value: expr.DatasourceType,
}
}
if input == nil {
return nil, &DashboardInputMissingError{VariableName: inputName}
}

View File

@ -11,6 +11,7 @@ import {
Legend,
} from '@grafana/ui';
import { DataSourcePicker } from '@grafana/runtime';
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { selectors } from '@grafana/e2e-selectors';
import { FolderPicker } from 'app/core/components/Select/FolderPicker';
@ -107,6 +108,9 @@ export const ImportDashboardForm: FC<Props> = ({
</Field>
{inputs.dataSources &&
inputs.dataSources.map((input: DataSourceInput, index: number) => {
if (input.pluginId === ExpressionDatasourceRef.type) {
return null;
}
const dataSourceOption = `dataSources[${index}]`;
const current = watchDataSources ?? [];
return (