DashboardSchemaV2: add missing allowCustomValue property in variables (#105416)

* add missing allowCustomValue property to variables in schema V2

* fix K8s Codegen Check

* updade snapshots for backend tests
This commit is contained in:
Sergej-Vlasov
2025-05-20 11:50:46 +01:00
committed by GitHub
parent a7922912fe
commit 03f1bb950b
14 changed files with 180 additions and 82 deletions
@@ -747,6 +747,7 @@ QueryVariableSpec: {
includeAll: bool | *false
allValue?: string
placeholder?: string
allowCustomValue: bool | *true
}
// Query variable kind
@@ -813,6 +814,7 @@ DatasourceVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Datasource variable kind
@@ -859,6 +861,7 @@ CustomVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Custom variable kind
@@ -900,6 +903,7 @@ AdhocVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Define the MetricFindValue type
@@ -751,6 +751,7 @@ QueryVariableSpec: {
includeAll: bool | *false
allValue?: string
placeholder?: string
allowCustomValue: bool | *true
}
// Query variable kind
@@ -817,6 +818,7 @@ DatasourceVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Datasource variable kind
@@ -863,6 +865,7 @@ CustomVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Custom variable kind
@@ -904,6 +907,7 @@ AdhocVariableSpec: {
hide: VariableHide
skipUrlSync: bool | *false
description?: string
allowCustomValue: bool | *true
}
// Define the MetricFindValue type
@@ -1223,23 +1223,24 @@ func NewDashboardQueryVariableKind() *DashboardQueryVariableKind {
// Query variable specification
// +k8s:openapi-gen=true
type DashboardQueryVariableSpec struct {
Name string `json:"name"`
Current DashboardVariableOption `json:"current"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
Refresh DashboardVariableRefresh `json:"refresh"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
Datasource *DashboardDataSourceRef `json:"datasource,omitempty"`
Query DashboardDataQueryKind `json:"query"`
Regex string `json:"regex"`
Sort DashboardVariableSort `json:"sort"`
Definition *string `json:"definition,omitempty"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Placeholder *string `json:"placeholder,omitempty"`
Name string `json:"name"`
Current DashboardVariableOption `json:"current"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
Refresh DashboardVariableRefresh `json:"refresh"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
Datasource *DashboardDataSourceRef `json:"datasource,omitempty"`
Query DashboardDataQueryKind `json:"query"`
Regex string `json:"regex"`
Sort DashboardVariableSort `json:"sort"`
Definition *string `json:"definition,omitempty"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Placeholder *string `json:"placeholder,omitempty"`
AllowCustomValue bool `json:"allowCustomValue"`
}
// NewDashboardQueryVariableSpec creates a new DashboardQueryVariableSpec object.
@@ -1254,13 +1255,14 @@ func NewDashboardQueryVariableSpec() *DashboardQueryVariableSpec {
String: (func(input string) *string { return &input })(""),
},
},
Hide: DashboardVariableHideDontHide,
Refresh: DashboardVariableRefreshNever,
SkipUrlSync: false,
Query: *NewDashboardDataQueryKind(),
Regex: "",
Multi: false,
IncludeAll: false,
Hide: DashboardVariableHideDontHide,
Refresh: DashboardVariableRefreshNever,
SkipUrlSync: false,
Query: *NewDashboardDataQueryKind(),
Regex: "",
Multi: false,
IncludeAll: false,
AllowCustomValue: true,
}
}
@@ -1442,19 +1444,20 @@ func NewDashboardDatasourceVariableKind() *DashboardDatasourceVariableKind {
// Datasource variable specification
// +k8s:openapi-gen=true
type DashboardDatasourceVariableSpec struct {
Name string `json:"name"`
PluginId string `json:"pluginId"`
Refresh DashboardVariableRefresh `json:"refresh"`
Regex string `json:"regex"`
Current DashboardVariableOption `json:"current"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
Name string `json:"name"`
PluginId string `json:"pluginId"`
Refresh DashboardVariableRefresh `json:"refresh"`
Regex string `json:"regex"`
Current DashboardVariableOption `json:"current"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
AllowCustomValue bool `json:"allowCustomValue"`
}
// NewDashboardDatasourceVariableSpec creates a new DashboardDatasourceVariableSpec object.
@@ -1472,10 +1475,11 @@ func NewDashboardDatasourceVariableSpec() *DashboardDatasourceVariableSpec {
String: (func(input string) *string { return &input })(""),
},
},
Multi: false,
IncludeAll: false,
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
Multi: false,
IncludeAll: false,
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
AllowCustomValue: true,
}
}
@@ -1551,29 +1555,31 @@ func NewDashboardCustomVariableKind() *DashboardCustomVariableKind {
// Custom variable specification
// +k8s:openapi-gen=true
type DashboardCustomVariableSpec struct {
Name string `json:"name"`
Query string `json:"query"`
Current DashboardVariableOption `json:"current"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
Name string `json:"name"`
Query string `json:"query"`
Current DashboardVariableOption `json:"current"`
Options []DashboardVariableOption `json:"options"`
Multi bool `json:"multi"`
IncludeAll bool `json:"includeAll"`
AllValue *string `json:"allValue,omitempty"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
AllowCustomValue bool `json:"allowCustomValue"`
}
// NewDashboardCustomVariableSpec creates a new DashboardCustomVariableSpec object.
func NewDashboardCustomVariableSpec() *DashboardCustomVariableSpec {
return &DashboardCustomVariableSpec{
Name: "",
Query: "",
Current: *NewDashboardVariableOption(),
Multi: false,
IncludeAll: false,
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
Name: "",
Query: "",
Current: *NewDashboardVariableOption(),
Multi: false,
IncludeAll: false,
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
AllowCustomValue: true,
}
}
@@ -1642,23 +1648,25 @@ func NewDashboardAdhocVariableKind() *DashboardAdhocVariableKind {
// Adhoc variable specification
// +k8s:openapi-gen=true
type DashboardAdhocVariableSpec struct {
Name string `json:"name"`
Datasource *DashboardDataSourceRef `json:"datasource,omitempty"`
BaseFilters []DashboardAdHocFilterWithLabels `json:"baseFilters"`
Filters []DashboardAdHocFilterWithLabels `json:"filters"`
DefaultKeys []DashboardMetricFindValue `json:"defaultKeys"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
Name string `json:"name"`
Datasource *DashboardDataSourceRef `json:"datasource,omitempty"`
BaseFilters []DashboardAdHocFilterWithLabels `json:"baseFilters"`
Filters []DashboardAdHocFilterWithLabels `json:"filters"`
DefaultKeys []DashboardMetricFindValue `json:"defaultKeys"`
Label *string `json:"label,omitempty"`
Hide DashboardVariableHide `json:"hide"`
SkipUrlSync bool `json:"skipUrlSync"`
Description *string `json:"description,omitempty"`
AllowCustomValue bool `json:"allowCustomValue"`
}
// NewDashboardAdhocVariableSpec creates a new DashboardAdhocVariableSpec object.
func NewDashboardAdhocVariableSpec() *DashboardAdhocVariableSpec {
return &DashboardAdhocVariableSpec{
Name: "",
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
Name: "",
Hide: DashboardVariableHideDontHide,
SkipUrlSync: false,
AllowCustomValue: true,
}
}
@@ -513,8 +513,15 @@ func schema_pkg_apis_dashboard_v2alpha1_DashboardAdhocVariableSpec(ref common.Re
Format: "",
},
},
"allowCustomValue": {
SchemaProps: spec.SchemaProps{
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
},
Required: []string{"name", "baseFilters", "filters", "defaultKeys", "hide", "skipUrlSync"},
Required: []string{"name", "baseFilters", "filters", "defaultKeys", "hide", "skipUrlSync", "allowCustomValue"},
},
},
Dependencies: []string{
@@ -1344,8 +1351,15 @@ func schema_pkg_apis_dashboard_v2alpha1_DashboardCustomVariableSpec(ref common.R
Format: "",
},
},
"allowCustomValue": {
SchemaProps: spec.SchemaProps{
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
},
Required: []string{"name", "query", "current", "options", "multi", "includeAll", "hide", "skipUrlSync"},
Required: []string{"name", "query", "current", "options", "multi", "includeAll", "hide", "skipUrlSync", "allowCustomValue"},
},
},
Dependencies: []string{
@@ -1727,8 +1741,15 @@ func schema_pkg_apis_dashboard_v2alpha1_DashboardDatasourceVariableSpec(ref comm
Format: "",
},
},
"allowCustomValue": {
SchemaProps: spec.SchemaProps{
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
},
Required: []string{"name", "pluginId", "refresh", "regex", "current", "options", "multi", "includeAll", "hide", "skipUrlSync"},
Required: []string{"name", "pluginId", "refresh", "regex", "current", "options", "multi", "includeAll", "hide", "skipUrlSync", "allowCustomValue"},
},
},
Dependencies: []string{
@@ -3403,8 +3424,15 @@ func schema_pkg_apis_dashboard_v2alpha1_DashboardQueryVariableSpec(ref common.Re
Format: "",
},
},
"allowCustomValue": {
SchemaProps: spec.SchemaProps{
Default: false,
Type: []string{"boolean"},
Format: "",
},
},
},
Required: []string{"name", "current", "hide", "refresh", "skipUrlSync", "query", "regex", "sort", "options", "multi", "includeAll"},
Required: []string{"name", "current", "hide", "refresh", "skipUrlSync", "query", "regex", "sort", "options", "multi", "includeAll", "allowCustomValue"},
},
},
Dependencies: []string{
@@ -366,6 +366,7 @@ export const handyTestingSchema: Spec = {
regex: 'regex1',
skipUrlSync: false,
sort: 'disabled',
allowCustomValue: true,
},
},
{
@@ -396,6 +397,7 @@ export const handyTestingSchema: Spec = {
],
query: 'option1, option2',
skipUrlSync: false,
allowCustomValue: true,
},
},
{
@@ -416,6 +418,7 @@ export const handyTestingSchema: Spec = {
refresh: 'onDashboardLoad',
regex: 'regex1',
skipUrlSync: false,
allowCustomValue: true,
},
},
{
@@ -555,6 +558,7 @@ export const handyTestingSchema: Spec = {
label: 'Adhoc Variable',
name: 'adhocVar',
skipUrlSync: false,
allowCustomValue: true,
},
},
],
@@ -1030,6 +1030,7 @@ export interface QueryVariableSpec {
includeAll: boolean;
allValue?: string;
placeholder?: string;
allowCustomValue: boolean;
}
export const defaultQueryVariableSpec = (): QueryVariableSpec => ({
@@ -1044,6 +1045,7 @@ export const defaultQueryVariableSpec = (): QueryVariableSpec => ({
options: [],
multi: false,
includeAll: false,
allowCustomValue: true,
});
// Variable option specification
@@ -1177,6 +1179,7 @@ export interface DatasourceVariableSpec {
hide: VariableHide;
skipUrlSync: boolean;
description?: string;
allowCustomValue: boolean;
}
export const defaultDatasourceVariableSpec = (): DatasourceVariableSpec => ({
@@ -1190,6 +1193,7 @@ export const defaultDatasourceVariableSpec = (): DatasourceVariableSpec => ({
includeAll: false,
hide: "dontHide",
skipUrlSync: false,
allowCustomValue: true,
});
// Interval variable kind
@@ -1256,6 +1260,7 @@ export interface CustomVariableSpec {
hide: VariableHide;
skipUrlSync: boolean;
description?: string;
allowCustomValue: boolean;
}
export const defaultCustomVariableSpec = (): CustomVariableSpec => ({
@@ -1267,6 +1272,7 @@ export const defaultCustomVariableSpec = (): CustomVariableSpec => ({
includeAll: false,
hide: "dontHide",
skipUrlSync: false,
allowCustomValue: true,
});
// Group variable kind
@@ -1324,6 +1330,7 @@ export interface AdhocVariableSpec {
hide: VariableHide;
skipUrlSync: boolean;
description?: string;
allowCustomValue: boolean;
}
export const defaultAdhocVariableSpec = (): AdhocVariableSpec => ({
@@ -1333,6 +1340,7 @@ export const defaultAdhocVariableSpec = (): AdhocVariableSpec => ({
defaultKeys: [],
hide: "dontHide",
skipUrlSync: false,
allowCustomValue: true,
});
// Define the AdHocFilterWithLabels type
@@ -1141,9 +1141,14 @@
"filters",
"defaultKeys",
"hide",
"skipUrlSync"
"skipUrlSync",
"allowCustomValue"
],
"properties": {
"allowCustomValue": {
"type": "boolean",
"default": false
},
"baseFilters": {
"type": "array",
"items": {
@@ -1705,12 +1710,17 @@
"multi",
"includeAll",
"hide",
"skipUrlSync"
"skipUrlSync",
"allowCustomValue"
],
"properties": {
"allValue": {
"type": "string"
},
"allowCustomValue": {
"type": "boolean",
"default": false
},
"current": {
"default": {},
"allOf": [
@@ -1954,12 +1964,17 @@
"multi",
"includeAll",
"hide",
"skipUrlSync"
"skipUrlSync",
"allowCustomValue"
],
"properties": {
"allValue": {
"type": "string"
},
"allowCustomValue": {
"type": "boolean",
"default": false
},
"current": {
"default": {},
"allOf": [
@@ -3022,12 +3037,17 @@
"sort",
"options",
"multi",
"includeAll"
"includeAll",
"allowCustomValue"
],
"properties": {
"allValue": {
"type": "string"
},
"allowCustomValue": {
"type": "boolean",
"default": false
},
"current": {
"default": {},
"allOf": [
@@ -624,6 +624,7 @@ describe('DashboardSceneSerializer', () => {
value: 'region',
},
],
allowCustomValue: true,
},
},
],
@@ -822,6 +823,7 @@ describe('DashboardSceneSerializer', () => {
options: [],
query: 'app1',
skipUrlSync: false,
allowCustomValue: true,
},
},
]);
@@ -1293,6 +1295,7 @@ function setupV2(spec?: Partial<DashboardV2Spec>) {
query: 'app1',
allValue: '',
includeAll: false,
allowCustomValue: true,
},
},
],
@@ -212,6 +212,7 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
"kind": "QueryVariable",
"spec": {
"allValue": "*",
"allowCustomValue": true,
"current": {
"text": "text1",
"value": "value1",
@@ -245,6 +246,7 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
"kind": "CustomVariable",
"spec": {
"allValue": "All",
"allowCustomValue": true,
"current": {
"text": "option1",
"value": "option1",
@@ -274,6 +276,7 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
{
"kind": "DatasourceVariable",
"spec": {
"allowCustomValue": true,
"current": {
"text": "text1",
"value": "value1",
@@ -389,6 +392,7 @@ exports[`transformSceneToSaveModelSchemaV2 should transform scene to save model
{
"kind": "AdhocVariable",
"spec": {
"allowCustomValue": true,
"baseFilters": [
{
"condition": "AND",
@@ -881,6 +881,7 @@ describe('sceneVariablesSetToVariables', () => {
"kind": "QueryVariable",
"spec": {
"allValue": "test-all",
"allowCustomValue": true,
"current": {
"text": [
"selected-value-text",
@@ -945,6 +946,7 @@ describe('sceneVariablesSetToVariables', () => {
"kind": "CustomVariable",
"spec": {
"allValue": "test-all",
"allowCustomValue": true,
"current": {
"text": [
"test",
@@ -1009,6 +1011,7 @@ describe('sceneVariablesSetToVariables', () => {
"kind": "DatasourceVariable",
"spec": {
"allValue": "test-all",
"allowCustomValue": true,
"current": {
"text": [
"selected-ds-1-text",
@@ -1197,6 +1200,7 @@ describe('sceneVariablesSetToVariables', () => {
{
"kind": "AdhocVariable",
"spec": {
"allowCustomValue": true,
"baseFilters": [
{
"key": "baseFilterTest",
@@ -1272,6 +1276,7 @@ describe('sceneVariablesSetToVariables', () => {
{
"kind": "AdhocVariable",
"spec": {
"allowCustomValue": true,
"baseFilters": [
{
"key": "baseFilterTest",
@@ -314,6 +314,7 @@ export function sceneVariablesSetToSchemaV2Variables(
includeAll: variable.state.includeAll || false,
multi: variable.state.isMulti || false,
skipUrlSync: variable.state.skipUrlSync || false,
allowCustomValue: variable.state.allowCustomValue ?? true,
},
};
variables.push(queryVariable);
@@ -329,6 +330,7 @@ export function sceneVariablesSetToSchemaV2Variables(
multi: variable.state.isMulti || false,
allValue: variable.state.allValue,
includeAll: variable.state.includeAll ?? false,
allowCustomValue: variable.state.allowCustomValue ?? true,
},
};
variables.push(customVariable);
@@ -344,6 +346,7 @@ export function sceneVariablesSetToSchemaV2Variables(
pluginId: variable.state.pluginId,
multi: variable.state.isMulti || false,
includeAll: variable.state.includeAll || false,
allowCustomValue: variable.state.allowCustomValue ?? true,
},
};
@@ -436,6 +439,7 @@ export function sceneVariablesSetToSchemaV2Variables(
baseFilters: validateFiltersOrigin(variable.state.baseFilters),
filters: validateFiltersOrigin(variable.state.filters),
defaultKeys: variable.state.defaultKeys || [], //FIXME what is the default value?
allowCustomValue: variable.state.allowCustomValue ?? true,
},
};
variables.push(adhocVariable);
@@ -4,7 +4,7 @@ import { Controller, FieldErrors, UseFormReturn } from 'react-hook-form';
import { selectors } from '@grafana/e2e-selectors';
import { Trans, useTranslate } from '@grafana/i18n';
import { ExpressionDatasourceRef } from '@grafana/runtime/internal';
import { DashboardV2Spec } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0';
import { Spec as DashboardV2Spec } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen';
import { Button, Field, FormFieldErrors, FormsOnSubmit, Stack, Input } from '@grafana/ui';
import { FolderPicker } from 'app/core/components/Select/FolderPicker';
import { SaveDashboardCommand } from 'app/features/dashboard/components/SaveDashboard/types';
@@ -2,8 +2,10 @@ import { useState } from 'react';
import { locationUtil } from '@grafana/data';
import { locationService, reportInteraction } from '@grafana/runtime';
import { DashboardV2Spec } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0';
import { AnnotationQueryKind } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen';
import {
AnnotationQueryKind,
Spec as DashboardV2Spec,
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen';
import { Form } from 'app/core/components/Form/Form';
import { getDashboardAPI } from 'app/features/dashboard/api/dashboard_api';
import { SaveDashboardCommand } from 'app/features/dashboard/components/SaveDashboard/types';
@@ -515,6 +515,7 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
kind: v.datasource?.type || getDefaultDatasourceType(),
spec: query,
},
allowCustomValue: v.allowCustomValue ?? true,
},
};
variables.push(qv);
@@ -541,6 +542,7 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
refresh: transformVariableRefreshToEnum(v.refresh),
pluginId,
regex: v.regex || '',
allowCustomValue: v.allowCustomValue ?? true,
},
};
variables.push(dv);
@@ -559,6 +561,7 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
multi: v.multi,
includeAll: v.includeAll,
...(v.allValue && { allValue: v.allValue }),
allowCustomValue: v.allowCustomValue ?? true,
},
};
variables.push(cv);
@@ -572,6 +575,7 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
baseFilters: v.baseFilters || [],
filters: v.filters || [],
defaultKeys: v.defaultKeys || [],
allowCustomValue: v.allowCustomValue ?? true,
},
};
variables.push(av);