mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* try upgrading react-redux * memoize getNavModel selector, don't return a new object in command palette selector * use createSelector to memoize some alert manager selectors correctly * memoize selectors correctly in appNotifications * memoize some datasource selectors * use fake timers to avoid the debounce causing flakiness * remove duplicate import * just use memoize-one
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import memoizeOne from 'memoize-one';
|
|
|
|
import { DataSourcePluginMeta, DataSourceSettings, UrlQueryValue } from '@grafana/data';
|
|
import { DataSourcesState } from 'app/types/datasources';
|
|
|
|
export const getDataSources = memoizeOne((state: DataSourcesState) => {
|
|
const regex = new RegExp(state.searchQuery, 'i');
|
|
|
|
const filteredDataSources = state.dataSources.filter((dataSource: DataSourceSettings) => {
|
|
return regex.test(dataSource.name) || regex.test(dataSource.database) || regex.test(dataSource.type);
|
|
});
|
|
|
|
return filteredDataSources.sort((a, b) =>
|
|
state.isSortAscending ? a.name.localeCompare(b.name) : b.name.localeCompare(a.name)
|
|
);
|
|
});
|
|
|
|
export const getFilteredDataSourcePlugins = memoizeOne((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;
|
|
export const getDataSourcesSort = (state: DataSourcesState) => state.isSortAscending;
|