Dashboards: Add a new variable type called "Switch" (#111366)
* feat: add schema changes for a switch type of dashboard variable * fix: generated go * feat: add support for a switch type of dashboard variable * chore: update `@grafana/scenes` to a canary version * feat: add variable editor for the switch variable * fix: remove unnecessary jest config change * chore: remove commented out code
This commit is contained in:
@@ -533,6 +533,7 @@ export {
|
||||
type QueryVariableModel,
|
||||
type TextBoxVariableModel,
|
||||
type ConstantVariableModel,
|
||||
type SwitchVariableModel,
|
||||
type VariableWithMultiSupport,
|
||||
type VariableWithOptions,
|
||||
type DashboardProps,
|
||||
|
||||
@@ -23,7 +23,8 @@ export type TypedVariableModel =
|
||||
| UserVariableModel
|
||||
| OrgVariableModel
|
||||
| DashboardVariableModel
|
||||
| SnapshotVariableModel;
|
||||
| SnapshotVariableModel
|
||||
| SwitchVariableModel;
|
||||
|
||||
export enum VariableRefresh {
|
||||
never, // removed from the UI
|
||||
@@ -130,6 +131,10 @@ export interface ConstantVariableModel extends VariableWithOptions {
|
||||
type: 'constant';
|
||||
}
|
||||
|
||||
export interface SwitchVariableModel extends VariableWithOptions {
|
||||
type: 'switch';
|
||||
}
|
||||
|
||||
export interface VariableWithMultiSupport extends VariableWithOptions {
|
||||
multi: boolean;
|
||||
includeAll: boolean;
|
||||
|
||||
@@ -596,6 +596,17 @@ export const versionedPages = {
|
||||
'11.0.0': 'data-testid ad-hoc filters variable mode toggle',
|
||||
},
|
||||
},
|
||||
SwitchVariable: {
|
||||
valuePairTypeSelect: {
|
||||
['12.3.0']: 'data-testid switch variable value pair type select',
|
||||
},
|
||||
enabledValueInput: {
|
||||
['12.3.0']: 'data-testid switch variable enabled value input',
|
||||
},
|
||||
disabledValueInput: {
|
||||
['12.3.0']: 'data-testid switch variable disabled value input',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -454,8 +454,9 @@ export const defaultAction: Partial<Action> = {
|
||||
* `textbox`: Display a free text input field with an optional default value.
|
||||
* `custom`: Define the variable options manually using a comma-separated list.
|
||||
* `system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables
|
||||
* `switch`: Boolean variables rendered as a switch
|
||||
*/
|
||||
export type VariableType = ('query' | 'adhoc' | 'groupby' | 'constant' | 'datasource' | 'interval' | 'textbox' | 'custom' | 'system' | 'snapshot');
|
||||
export type VariableType = ('query' | 'adhoc' | 'groupby' | 'constant' | 'datasource' | 'interval' | 'textbox' | 'custom' | 'system' | 'snapshot' | 'switch');
|
||||
|
||||
/**
|
||||
* Color mode for a field. You can specify a single color, or select a continuous (gradient) color schemes, based on a value.
|
||||
|
||||
@@ -1052,7 +1052,7 @@ export const defaultTimeRangeOption = (): TimeRangeOption => ({
|
||||
to: "now",
|
||||
});
|
||||
|
||||
export type VariableKind = QueryVariableKind | TextVariableKind | ConstantVariableKind | DatasourceVariableKind | IntervalVariableKind | CustomVariableKind | GroupByVariableKind | AdhocVariableKind;
|
||||
export type VariableKind = QueryVariableKind | TextVariableKind | ConstantVariableKind | DatasourceVariableKind | IntervalVariableKind | CustomVariableKind | GroupByVariableKind | AdhocVariableKind | SwitchVariableKind;
|
||||
|
||||
export const defaultVariableKind = (): VariableKind => (defaultQueryVariableKind());
|
||||
|
||||
@@ -1444,6 +1444,36 @@ export const defaultMetricFindValue = (): MetricFindValue => ({
|
||||
text: "",
|
||||
});
|
||||
|
||||
export interface SwitchVariableKind {
|
||||
kind: "SwitchVariable";
|
||||
spec: SwitchVariableSpec;
|
||||
}
|
||||
|
||||
export const defaultSwitchVariableKind = (): SwitchVariableKind => ({
|
||||
kind: "SwitchVariable",
|
||||
spec: defaultSwitchVariableSpec(),
|
||||
});
|
||||
|
||||
export interface SwitchVariableSpec {
|
||||
name: string;
|
||||
current: string;
|
||||
enabledValue: string;
|
||||
disabledValue: string;
|
||||
label?: string;
|
||||
hide: VariableHide;
|
||||
skipUrlSync: boolean;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export const defaultSwitchVariableSpec = (): SwitchVariableSpec => ({
|
||||
name: "",
|
||||
current: "false",
|
||||
enabledValue: "true",
|
||||
disabledValue: "false",
|
||||
hide: "dontHide",
|
||||
skipUrlSync: false,
|
||||
});
|
||||
|
||||
export interface Spec {
|
||||
annotations: AnnotationQueryKind[];
|
||||
// Configuration of dashboard cursor sync behavior.
|
||||
|
||||
Reference in New Issue
Block a user