Skip to content

Commit

Permalink
Merge pull request #82 from grafana/fix-ds-variable-state
Browse files Browse the repository at this point in the history
DataSourceVariable: Fix state property name to be more descriptive
  • Loading branch information
torkelo authored Mar 20, 2023
2 parents d2379e7 + 5d8fbef commit ff71727
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.22 ()

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

# 0.21 (2023-03-17)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: '',
pluginId: '',
});

await lastValueFrom(variable.validateAndUpdate());
Expand All @@ -92,7 +92,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: 'non-existant-datasource',
pluginId: 'non-existant-datasource',
});

await lastValueFrom(variable.validateAndUpdate());
Expand All @@ -113,7 +113,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: 'prometheus',
pluginId: 'prometheus',
});

await lastValueFrom(variable.validateAndUpdate());
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: 'prometheus',
pluginId: 'prometheus',
});

await lastValueFrom(variable.validateAndUpdate());
Expand All @@ -164,7 +164,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: 'prometheus',
pluginId: 'prometheus',
regex: 'slow.*',
});

Expand All @@ -181,7 +181,7 @@ describe('DataSourceVariable', () => {
options: [],
value: '',
text: '',
query: 'prometheus',
pluginId: 'prometheus',
regex: '$variable-1.*',
});

Expand All @@ -198,7 +198,7 @@ describe('DataSourceVariable', () => {
const variable = new DataSourceVariable({
name: 'test',
options: [],
query: 'prometheus',
pluginId: 'prometheus',
value: 'slow-prometheus-mocked',
text: 'slow-prometheus-mocked',
});
Expand All @@ -214,7 +214,7 @@ describe('DataSourceVariable', () => {
name: 'test',
options: [],
isMulti: true,
query: 'prometheus',
pluginId: 'prometheus',
value: ['prometheus-mocked', 'slow-prometheus-mocked', 'elastic-mocked'],
text: ['prometheus-mocked', 'slow-prometheus-mocked', 'elastic-mocked'],
});
Expand All @@ -230,7 +230,7 @@ describe('DataSourceVariable', () => {
name: 'test',
options: [],
isMulti: true,
query: 'elastic',
pluginId: 'elastic',
value: ['prometheus-mocked', 'slow-prometheus-mocked'],
text: ['prometheus-mocked', 'slow-prometheus-mocked'],
});
Expand Down
14 changes: 10 additions & 4 deletions packages/scenes/src/variables/variants/DataSourceVariable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { VariableValueOption } from '../types';
import { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';

export interface DataSourceVariableState extends MultiValueVariableState {
query: string;
/**
* Include all data source instances with this plugin id
*/
pluginId: string;
/**
* Filter data source instances based on name
*/
regex: string;
}

Expand All @@ -29,13 +35,13 @@ export class DataSourceVariable extends MultiValueVariable<DataSourceVariableSta
options: [],
name: '',
regex: '',
query: '',
pluginId: '',
...initialState,
});
}

public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {
if (!this.state.query) {
if (!this.state.pluginId) {
return of([]);
}

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

Expand Down

0 comments on commit ff71727

Please sign in to comment.