@grafana/data#DataSourceSelectItem TypeScript Examples
The following examples show how to use
@grafana/data#DataSourceSelectItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueriesTab.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
onChangeDataSource = (datasource: DataSourceSelectItem) => {
const { panel } = this.props;
const { currentDS } = this.state;
// switching to mixed
if (datasource.meta.mixed) {
// Set the datasource on all targets
panel.targets.forEach(target => {
if (target.datasource !== ExpressionDatasourceID) {
target.datasource = panel.datasource;
if (!target.datasource) {
target.datasource = config.defaultDatasource;
}
}
});
} else if (currentDS) {
// if switching from mixed
if (currentDS.meta.mixed) {
// Remove the explicit datasource
for (const target of panel.targets) {
if (target.datasource !== ExpressionDatasourceID) {
delete target.datasource;
}
}
} else if (currentDS.meta.id !== datasource.meta.id) {
// we are changing data source type, clear queries
panel.targets = [{ refId: 'A' }];
}
}
panel.datasource = datasource.value;
panel.refresh();
this.setState({
currentDS: datasource,
});
};
Example #2
Source File: selectors.ts From grafana-chinese with Apache License 2.0 | 6 votes |
getExploreDatasources = (): DataSourceSelectItem[] => {
return getDatasourceSrv()
.getExternal()
.map(
(ds: any) =>
({
value: ds.name,
name: ds.name,
meta: ds.meta,
} as DataSourceSelectItem)
);
}
Example #3
Source File: actions.ts From grafana-chinese with Apache License 2.0 | 6 votes |
initQueryVariableEditor = (identifier: VariableIdentifier): ThunkResult<void> => async (
dispatch,
getState
) => {
const dataSources: DataSourceSelectItem[] = getDatasourceSrv()
.getMetricSources()
.filter(ds => !ds.meta.mixed && ds.value !== null);
const defaultDatasource: DataSourceSelectItem = { name: '', value: '', meta: {} as DataSourcePluginMeta, sort: '' };
const allDataSources = [defaultDatasource].concat(dataSources);
dispatch(changeVariableEditorExtended({ propName: 'dataSources', propValue: allDataSources }));
const variable = getVariable<QueryVariableModel>(identifier.uuid!, getState());
if (!variable.datasource) {
return;
}
dispatch(changeQueryVariableDataSource(toVariableIdentifier(variable), variable.datasource));
}
Example #4
Source File: QueriesTab.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
findCurrentDataSource(): DataSourceSelectItem {
const { panel } = this.props;
return this.datasources.find(datasource => datasource.value === panel.datasource) || this.datasources[0];
}
Example #5
Source File: QueriesTab.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
datasources: DataSourceSelectItem[] = getDatasourceSrv().getMetricSources();
Example #6
Source File: datasource_srv.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getMetricSources(options?: { skipVariables?: boolean }) {
const metricSources: DataSourceSelectItem[] = [];
Object.entries(config.datasources).forEach(([key, value]) => {
if (value.meta?.metrics) {
let metricSource = { value: key, name: key, meta: value.meta, sort: key };
//Make sure grafana and mixed are sorted at the bottom
if (value.meta.id === 'grafana') {
metricSource.sort = String.fromCharCode(253);
} else if (value.meta.id === 'dashboard') {
metricSource.sort = String.fromCharCode(254);
} else if (value.meta.id === 'mixed') {
metricSource.sort = String.fromCharCode(255);
}
metricSources.push(metricSource);
if (key === config.defaultDatasource) {
metricSource = { value: null, name: 'default', meta: value.meta, sort: key };
metricSources.push(metricSource);
}
}
});
if (!options || !options.skipVariables) {
this.addDataSourceVariables(metricSources);
}
metricSources.sort((a, b) => {
if (a.sort.toLowerCase() > b.sort.toLowerCase()) {
return 1;
}
if (a.sort.toLowerCase() < b.sort.toLowerCase()) {
return -1;
}
return 0;
});
return metricSources;
}
Example #7
Source File: GraphPanelEditor.tsx From loudml-grafana-app with MIT License | 5 votes |
datasources: DataSourceSelectItem[] = getDataSourceSrv().getMetricSources();