mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* navtree.go: update Data sources title and subtitle * DataSourceList: move add button to header * DataSourcesList: add buttons to items The action buttons are added inside `<Card.Tags>` so that they end up at the right end of the card, as it was designed. The "Build a Dashboard" button's functionality is not defined yet. * DataSourcesListHeader: add sort picker * fix css * tests: look for the updated "Add new data source" text * tests: use an async test method to verify component updates are wrapped in an act() * update e2e selector for add data source button * fix DataSourceList{,Page} tests * add comment for en dash character * simplify sorting * add link to Build a Dashboard button * fix test * test build a dashboard and explore buttons * test sorting data source elements * DataSourceAddButton: hide button when user has no permission * PageActionBar: remove unneeded '?' * DataSourcesList: hide explore button if user has no permission * DataSourcesListPage.test: make setup prop explicit * DataSourcesList: use theme.spacing * datasources: assure explore url includes appSubUrl * fix tests and add test case for missing permissions Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import { DataSourcePluginMeta, DataSourceSettings, UrlQueryValue } from '@grafana/data';
|
|
import { DataSourcesState } from 'app/types/datasources';
|
|
|
|
export const getDataSources = (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 = (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;
|