mirror of
https://github.com/grafana/grafana.git
synced 2025-12-20 19:44:55 +08:00
Compare commits
1 Commits
andrew/ela
...
fix/groupb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d88d213ce7 |
@@ -258,6 +258,23 @@
|
||||
"multi": true,
|
||||
"skipUrlSync": false
|
||||
},
|
||||
{
|
||||
"name": "groupby_var_no_multi",
|
||||
"type": "groupby",
|
||||
"label": "Group By Without Multi",
|
||||
"description": "GroupBy variable without explicit multi - should default to true",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "existing-ref-uid"
|
||||
},
|
||||
"current": {
|
||||
"text": [],
|
||||
"value": []
|
||||
},
|
||||
"options": [],
|
||||
"hide": 0,
|
||||
"skipUrlSync": false
|
||||
},
|
||||
{
|
||||
"name": "switch_var",
|
||||
"type": "switch",
|
||||
@@ -354,4 +371,4 @@
|
||||
},
|
||||
"links": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +277,23 @@
|
||||
"skipUrlSync": false,
|
||||
"type": "groupby"
|
||||
},
|
||||
{
|
||||
"current": {
|
||||
"text": [],
|
||||
"value": []
|
||||
},
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "existing-ref-uid"
|
||||
},
|
||||
"description": "GroupBy variable without explicit multi - should default to true",
|
||||
"hide": 0,
|
||||
"label": "Group By Without Multi",
|
||||
"name": "groupby_var_no_multi",
|
||||
"options": [],
|
||||
"skipUrlSync": false,
|
||||
"type": "groupby"
|
||||
},
|
||||
{
|
||||
"current": {
|
||||
"selected": false,
|
||||
|
||||
@@ -317,6 +317,26 @@
|
||||
"description": "Group results by field"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "GroupByVariable",
|
||||
"spec": {
|
||||
"name": "groupby_var_no_multi",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "existing-ref-uid"
|
||||
},
|
||||
"current": {
|
||||
"text": [],
|
||||
"value": []
|
||||
},
|
||||
"options": [],
|
||||
"multi": true,
|
||||
"label": "Group By Without Multi",
|
||||
"hide": "dontHide",
|
||||
"skipUrlSync": false,
|
||||
"description": "GroupBy variable without explicit multi - should default to true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "SwitchVariable",
|
||||
"spec": {
|
||||
|
||||
@@ -318,6 +318,26 @@
|
||||
"description": "Group results by field"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "GroupByVariable",
|
||||
"group": "prometheus",
|
||||
"datasource": {
|
||||
"name": "existing-ref-uid"
|
||||
},
|
||||
"spec": {
|
||||
"name": "groupby_var_no_multi",
|
||||
"current": {
|
||||
"text": [],
|
||||
"value": []
|
||||
},
|
||||
"options": [],
|
||||
"multi": true,
|
||||
"label": "Group By Without Multi",
|
||||
"hide": "dontHide",
|
||||
"skipUrlSync": false,
|
||||
"description": "GroupBy variable without explicit multi - should default to true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "SwitchVariable",
|
||||
"spec": {
|
||||
|
||||
@@ -1713,7 +1713,8 @@ func buildGroupByVariable(ctx context.Context, varMap map[string]interface{}, co
|
||||
Hide: commonProps.Hide,
|
||||
SkipUrlSync: commonProps.SkipUrlSync,
|
||||
Current: buildVariableCurrent(varMap["current"]),
|
||||
Multi: getBoolField(varMap, "multi", false),
|
||||
// GroupBy variables are multi-select by default in Grafana
|
||||
Multi: getBoolField(varMap, "multi", true),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ export const handyTestingSchema: Spec = {
|
||||
description: 'A group by variable',
|
||||
hide: 'dontHide',
|
||||
label: 'Group By Variable',
|
||||
multi: false,
|
||||
multi: true,
|
||||
name: 'groupByVar',
|
||||
options: [
|
||||
{
|
||||
|
||||
@@ -305,6 +305,7 @@ describe('ResponseTransformers', () => {
|
||||
description: 'groupby var description',
|
||||
skipUrlSync: false,
|
||||
hide: 0,
|
||||
multi: true,
|
||||
datasource: {
|
||||
type: 'prometheus',
|
||||
uid: 'abc',
|
||||
@@ -315,6 +316,21 @@ describe('ResponseTransformers', () => {
|
||||
],
|
||||
current: { value: ['1'], text: ['1'] },
|
||||
},
|
||||
// GroupBy variable without explicit multi - should default to true
|
||||
{
|
||||
type: 'groupby',
|
||||
name: 'var8_no_multi',
|
||||
label: 'groupby var without multi',
|
||||
skipUrlSync: false,
|
||||
hide: 0,
|
||||
// Note: no multi property - GroupBy variables are multi by default
|
||||
datasource: {
|
||||
type: 'prometheus',
|
||||
uid: 'abc',
|
||||
},
|
||||
options: [],
|
||||
current: { value: [], text: [] },
|
||||
},
|
||||
// Query variable with minimal props and without current
|
||||
{
|
||||
datasource: { type: 'prometheus', uid: 'abc' },
|
||||
@@ -562,6 +578,17 @@ describe('ResponseTransformers', () => {
|
||||
validateVariablesV1ToV2(spec.variables[7], dashboardV1.templating?.list?.[7]);
|
||||
validateVariablesV1ToV2(spec.variables[8], dashboardV1.templating?.list?.[8]);
|
||||
validateVariablesV1ToV2(spec.variables[9], dashboardV1.templating?.list?.[9]);
|
||||
validateVariablesV1ToV2(spec.variables[10], dashboardV1.templating?.list?.[10]);
|
||||
|
||||
// Verify GroupBy variable without explicit multi defaults to true
|
||||
const groupByNoMulti = dashboardV1.templating?.list?.[8];
|
||||
expect(groupByNoMulti?.type).toBe('groupby');
|
||||
expect(groupByNoMulti?.multi).toBeUndefined();
|
||||
|
||||
const v2GroupByNoMulti = spec.variables[8];
|
||||
expect(v2GroupByNoMulti.kind).toBe('GroupByVariable');
|
||||
// @ts-expect-error
|
||||
expect(v2GroupByNoMulti.spec.multi).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1224,6 +1251,8 @@ describe('ResponseTransformers', () => {
|
||||
expect(v2.datasource?.name).toEqual(v1.datasource?.uid);
|
||||
expect(v2.group).toEqual(v1.datasource?.type);
|
||||
expect(v2.spec.options).toEqual(v1.options);
|
||||
// GroupBy variables default to multi: true when not specified
|
||||
expect(v2.spec.multi).toEqual(v1.multi ?? true);
|
||||
}
|
||||
|
||||
if (v2.kind === 'SwitchVariable') {
|
||||
|
||||
@@ -812,7 +812,8 @@ function getVariables(vars: TypedVariableModel[]): DashboardV2Spec['variables']
|
||||
value: v.current.value,
|
||||
text: v.current.text,
|
||||
},
|
||||
multi: v.multi,
|
||||
// GroupBy variables are multi-select by default in Grafana
|
||||
multi: v.multi ?? true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1013,6 +1014,7 @@ function getVariablesV1(vars: DashboardV2Spec['variables']): VariableModel[] {
|
||||
},
|
||||
current: v.spec.current,
|
||||
options: v.spec.options,
|
||||
multi: v.spec.multi,
|
||||
};
|
||||
variables.push(gv);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user