Skip to content

Commit ff71727

Browse files
authored
Merge pull request #82 from grafana/fix-ds-variable-state
DataSourceVariable: Fix state property name to be more descriptive
2 parents d2379e7 + 5d8fbef commit ff71727

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 0.22 ()
22

33
* Removal of isEditing from SceneComponentProps (also $editor from SceneObjectState, and sceneGraph.getSceneEditor)
4+
* DataSourceVariable state change, query property is now named pluginId
45

56
# 0.21 (2023-03-17)
67

packages/scenes/src/variables/variants/DataSourceVariable.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('DataSourceVariable', () => {
7474
options: [],
7575
value: '',
7676
text: '',
77-
query: '',
77+
pluginId: '',
7878
});
7979

8080
await lastValueFrom(variable.validateAndUpdate());
@@ -92,7 +92,7 @@ describe('DataSourceVariable', () => {
9292
options: [],
9393
value: '',
9494
text: '',
95-
query: 'non-existant-datasource',
95+
pluginId: 'non-existant-datasource',
9696
});
9797

9898
await lastValueFrom(variable.validateAndUpdate());
@@ -113,7 +113,7 @@ describe('DataSourceVariable', () => {
113113
options: [],
114114
value: '',
115115
text: '',
116-
query: 'prometheus',
116+
pluginId: 'prometheus',
117117
});
118118

119119
await lastValueFrom(variable.validateAndUpdate());
@@ -142,7 +142,7 @@ describe('DataSourceVariable', () => {
142142
options: [],
143143
value: '',
144144
text: '',
145-
query: 'prometheus',
145+
pluginId: 'prometheus',
146146
});
147147

148148
await lastValueFrom(variable.validateAndUpdate());
@@ -164,7 +164,7 @@ describe('DataSourceVariable', () => {
164164
options: [],
165165
value: '',
166166
text: '',
167-
query: 'prometheus',
167+
pluginId: 'prometheus',
168168
regex: 'slow.*',
169169
});
170170

@@ -181,7 +181,7 @@ describe('DataSourceVariable', () => {
181181
options: [],
182182
value: '',
183183
text: '',
184-
query: 'prometheus',
184+
pluginId: 'prometheus',
185185
regex: '$variable-1.*',
186186
});
187187

@@ -198,7 +198,7 @@ describe('DataSourceVariable', () => {
198198
const variable = new DataSourceVariable({
199199
name: 'test',
200200
options: [],
201-
query: 'prometheus',
201+
pluginId: 'prometheus',
202202
value: 'slow-prometheus-mocked',
203203
text: 'slow-prometheus-mocked',
204204
});
@@ -214,7 +214,7 @@ describe('DataSourceVariable', () => {
214214
name: 'test',
215215
options: [],
216216
isMulti: true,
217-
query: 'prometheus',
217+
pluginId: 'prometheus',
218218
value: ['prometheus-mocked', 'slow-prometheus-mocked', 'elastic-mocked'],
219219
text: ['prometheus-mocked', 'slow-prometheus-mocked', 'elastic-mocked'],
220220
});
@@ -230,7 +230,7 @@ describe('DataSourceVariable', () => {
230230
name: 'test',
231231
options: [],
232232
isMulti: true,
233-
query: 'elastic',
233+
pluginId: 'elastic',
234234
value: ['prometheus-mocked', 'slow-prometheus-mocked'],
235235
text: ['prometheus-mocked', 'slow-prometheus-mocked'],
236236
});

packages/scenes/src/variables/variants/DataSourceVariable.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { VariableValueOption } from '../types';
1212
import { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';
1313

1414
export interface DataSourceVariableState extends MultiValueVariableState {
15-
query: string;
15+
/**
16+
* Include all data source instances with this plugin id
17+
*/
18+
pluginId: string;
19+
/**
20+
* Filter data source instances based on name
21+
*/
1622
regex: string;
1723
}
1824

@@ -29,13 +35,13 @@ export class DataSourceVariable extends MultiValueVariable<DataSourceVariableSta
2935
options: [],
3036
name: '',
3137
regex: '',
32-
query: '',
38+
pluginId: '',
3339
...initialState,
3440
});
3541
}
3642

3743
public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {
38-
if (!this.state.query) {
44+
if (!this.state.pluginId) {
3945
return of([]);
4046
}
4147

@@ -52,7 +58,7 @@ export class DataSourceVariable extends MultiValueVariable<DataSourceVariableSta
5258
for (let i = 0; i < dataSourceTypes.length; i++) {
5359
const source = dataSourceTypes[i];
5460
// must match on type
55-
if (source.meta.id !== this.state.query) {
61+
if (source.meta.id !== this.state.pluginId) {
5662
continue;
5763
}
5864

0 commit comments

Comments
 (0)