selectors.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { DataSourceSettings, DataSourcePluginMeta } from '@grafana/ui/src/types';
  2. export const getDataSources = state => {
  3. const regex = new RegExp(state.searchQuery, 'i');
  4. return state.dataSources.filter(dataSource => {
  5. return regex.test(dataSource.name) || regex.test(dataSource.database);
  6. });
  7. };
  8. export const getDataSourceTypes = state => {
  9. const regex = new RegExp(state.dataSourceTypeSearchQuery, 'i');
  10. return state.dataSourceTypes.filter(type => {
  11. return regex.test(type.name);
  12. });
  13. };
  14. export const getDataSource = (state, dataSourceId): DataSourceSettings | null => {
  15. if (state.dataSource.id === parseInt(dataSourceId, 10)) {
  16. return state.dataSource;
  17. }
  18. return {} as DataSourceSettings;
  19. };
  20. export const getDataSourceMeta = (state, type): DataSourcePluginMeta => {
  21. if (state.dataSourceMeta.id === type) {
  22. return state.dataSourceMeta;
  23. }
  24. return {} as DataSourcePluginMeta;
  25. };
  26. export const getDataSourcesSearchQuery = state => state.searchQuery;
  27. export const getDataSourcesLayoutMode = state => state.layoutMode;
  28. export const getDataSourcesCount = state => state.dataSourcesCount;