selectors.ts 1.4 KB

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