Files
grafana/public/app/features/datasources/state/selectors.ts
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

39 lines
1.4 KiB
TypeScript

import { DataSourcePluginMeta, DataSourceSettings, UrlQueryValue } from '@grafana/data';
import { DataSourcesState } from '../../../types/datasources';
export const getDataSources = (state: DataSourcesState) => {
const regex = new RegExp(state.searchQuery, 'i');
return state.dataSources.filter((dataSource: DataSourceSettings) => {
return regex.test(dataSource.name) || regex.test(dataSource.database) || regex.test(dataSource.type);
});
};
export const getDataSourcePlugins = (state: DataSourcesState) => {
const regex = new RegExp(state.dataSourceTypeSearchQuery, 'i');
return state.plugins.filter((type: DataSourcePluginMeta) => {
return regex.test(type.name);
});
};
export const getDataSource = (state: DataSourcesState, dataSourceId: UrlQueryValue): DataSourceSettings => {
if (state.dataSource.uid === dataSourceId) {
return state.dataSource;
}
return {} as DataSourceSettings;
};
export const getDataSourceMeta = (state: DataSourcesState, type: string): DataSourcePluginMeta => {
if (state.dataSourceMeta.id === type) {
return state.dataSourceMeta;
}
return {} as DataSourcePluginMeta;
};
export const getDataSourcesSearchQuery = (state: DataSourcesState) => state.searchQuery;
export const getDataSourcesLayoutMode = (state: DataSourcesState) => state.layoutMode;
export const getDataSourcesCount = (state: DataSourcesState) => state.dataSourcesCount;