mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: Advanced DS picker search is case sensitive (#67420)
This commit is contained in:
@@ -16,7 +16,7 @@ import { DataSourceList } from './DataSourceList';
|
|||||||
import { DataSourceLogo, DataSourceLogoPlaceHolder } from './DataSourceLogo';
|
import { DataSourceLogo, DataSourceLogoPlaceHolder } from './DataSourceLogo';
|
||||||
import { DataSourceModal } from './DataSourceModal';
|
import { DataSourceModal } from './DataSourceModal';
|
||||||
import { PickerContentProps, DataSourceDropdownProps } from './types';
|
import { PickerContentProps, DataSourceDropdownProps } from './types';
|
||||||
import { dataSourceLabel } from './utils';
|
import { dataSourceLabel, matchDataSourceWithSearch } from './utils';
|
||||||
|
|
||||||
const INTERACTION_EVENT_NAME = 'dashboards_dspicker_clicked';
|
const INTERACTION_EVENT_NAME = 'dashboards_dspicker_clicked';
|
||||||
const INTERACTION_ITEM = {
|
const INTERACTION_ITEM = {
|
||||||
@@ -166,7 +166,7 @@ const PickerContent = React.forwardRef<HTMLDivElement, PickerContentProps>((prop
|
|||||||
{...props}
|
{...props}
|
||||||
current={current}
|
current={current}
|
||||||
onChange={changeCallback}
|
onChange={changeCallback}
|
||||||
filter={(ds) => ds.name.toLowerCase().includes(filterTerm?.toLowerCase() ?? '')}
|
filter={(ds) => matchDataSourceWithSearch(ds, filterTerm)}
|
||||||
></DataSourceList>
|
></DataSourceList>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { DATASOURCES_ROUTES } from 'app/features/datasources/constants';
|
|||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
|
|
||||||
import { DataSourceList } from './DataSourceList';
|
import { DataSourceList } from './DataSourceList';
|
||||||
|
import { matchDataSourceWithSearch } from './utils';
|
||||||
|
|
||||||
const INTERACTION_EVENT_NAME = 'dashboards_dspickermodal_clicked';
|
const INTERACTION_EVENT_NAME = 'dashboards_dspickermodal_clicked';
|
||||||
const INTERACTION_ITEM = {
|
const INTERACTION_ITEM = {
|
||||||
@@ -107,7 +108,7 @@ export function DataSourceModal({
|
|||||||
dashboard={false}
|
dashboard={false}
|
||||||
mixed={false}
|
mixed={false}
|
||||||
variables
|
variables
|
||||||
filter={(ds) => ds.name.includes(search) && !ds.meta.builtIn}
|
filter={(ds) => matchDataSourceWithSearch(ds, search) && !ds.meta.builtIn}
|
||||||
onChange={onChangeDataSource}
|
onChange={onChangeDataSource}
|
||||||
current={current}
|
current={current}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { DataSourceInstanceSettings, DataSourceRef } from '@grafana/data';
|
import { DataSourceInstanceSettings, DataSourceRef } from '@grafana/data';
|
||||||
|
|
||||||
import { isDataSourceMatch, getDataSourceCompareFn } from './utils';
|
import { isDataSourceMatch, getDataSourceCompareFn, matchDataSourceWithSearch } from './utils';
|
||||||
|
|
||||||
describe('isDataSourceMatch', () => {
|
describe('isDataSourceMatch', () => {
|
||||||
const dataSourceInstanceSettings = { uid: 'a' } as DataSourceInstanceSettings;
|
const dataSourceInstanceSettings = { uid: 'a' } as DataSourceInstanceSettings;
|
||||||
@@ -93,3 +93,39 @@ describe('getDataSouceCompareFn', () => {
|
|||||||
] as DataSourceInstanceSettings[]);
|
] as DataSourceInstanceSettings[]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('matchDataSourceWithSearch', () => {
|
||||||
|
let dataSource: DataSourceInstanceSettings;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dataSource = {
|
||||||
|
name: 'My SQL DB',
|
||||||
|
} as DataSourceInstanceSettings;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when the search term matches the data source name', () => {
|
||||||
|
const searchTerm = 'My SQL';
|
||||||
|
expect(matchDataSourceWithSearch(dataSource, searchTerm)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when the search term matches part of the data source name', () => {
|
||||||
|
const searchTerm = 'SQL';
|
||||||
|
expect(matchDataSourceWithSearch(dataSource, searchTerm)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when the search term does not match the data source name', () => {
|
||||||
|
const searchTerm = 'Oracle';
|
||||||
|
expect(matchDataSourceWithSearch(dataSource, searchTerm)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when the search term is empty', () => {
|
||||||
|
const searchTerm = '';
|
||||||
|
expect(matchDataSourceWithSearch(dataSource, searchTerm)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore case when matching the search term', () => {
|
||||||
|
dataSource.name = 'PostgreSQL DB';
|
||||||
|
const searchTerm = 'postgre';
|
||||||
|
expect(matchDataSourceWithSearch(dataSource, searchTerm)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -87,3 +87,14 @@ export function getDataSourceCompareFn(
|
|||||||
|
|
||||||
return cmpDataSources;
|
return cmpDataSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a data source and a search term, returns true if the data source matches the search term.
|
||||||
|
* Useful to filter data sources by name containing an string.
|
||||||
|
* @param ds
|
||||||
|
* @param searchTerm
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function matchDataSourceWithSearch(ds: DataSourceInstanceSettings, searchTerm = '') {
|
||||||
|
return ds.name.toLowerCase().includes(searchTerm.toLowerCase());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user