QueryVariable: Add static options input (#107514)

* static options for query variable

* add toggle

* fix and add tests

* run the hack codegen thing

* more test fixes

* make betterer happier

* also make typecheck happy

* make betterer happier

* fix i18n key

* tranalte static variables sort label

* gen translations

* update snapshot
This commit is contained in:
Domas authored and GitHub committed 2025-07-14 16:05:56 +03:00
1 parent baa89f3eac
commit 8eef17cb37
26 files changed
+680 -28

No files matched your search

@@ -116,6 +116,8 @@ export interface QueryVariableModel extends VariableWithMultiSupport {
query: any;
regex: string;
refresh: VariableRefresh;
staticOptions?: VariableOption[];
staticOptionsOrder?: 'before' | 'after' | 'sorted';
}
export interface TextBoxVariableModel extends VariableWithOptions {
@@ -489,6 +489,27 @@ export const versionedPages = {
queryOptionsQueryInput: {
'10.4.0': 'data-testid Variable editor Form Default Variable Query Editor textarea',
},
queryOptionsStaticOptionsRow: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options row',
},
queryOptionsStaticOptionsToggle: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options toggle',
},
queryOptionsStaticOptionsLabelInput: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options Label input',
},
queryOptionsStaticOptionsValueInput: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options Value input',
},
queryOptionsStaticOptionsDeleteButton: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options Delete button',
},
queryOptionsStaticOptionsAddButton: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options Add button',
},
queryOptionsStaticOptionsOrderDropdown: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query Static Options Order dropdown',
},
valueGroupsTagsEnabledSwitch: {
[MIN_GRAFANA_VERSION]: 'Variable editor Form Query UseTags switch',
},
@@ -191,6 +191,14 @@ export interface VariableModel {
* Options sort order
*/
sort?: VariableSort;
/**
* Additional static options for query variable
*/
staticOptions?: Array<VariableOption>;
/**
* Ordering of static options in relation to options returned from data source for query variable
*/
staticOptionsOrder?: ('before' | 'after' | 'sorted');
/**
* Type of variable
*/
@@ -203,6 +211,7 @@ export const defaultVariableModel: Partial<VariableModel> = {
multi: false,
options: [],
skipUrlSync: false,
staticOptions: [],
};
/**
@@ -1005,6 +1005,8 @@ export interface QueryVariableSpec {
allValue?: string;
placeholder?: string;
allowCustomValue: boolean;
staticOptions?: VariableOption[];
staticOptionsOrder?: "before" | "after" | "sorted";
}
export const defaultQueryVariableSpec = (): QueryVariableSpec => ({