[UA] Add searching by index and node to UI, fixes #32075 (#33065) (#33087)

This commit is contained in:
Josh Dover 2019-03-13 11:20:28 -05:00 committed by GitHub
parent b32b852afa
commit 4a45262d20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 4 deletions

View file

@ -22,11 +22,47 @@ describe('filterDeps', () => {
expect(fd({ level: 'warning' } as DeprecationInfo)).toBe(false);
});
test('filters on search', () => {
test('filters on title search', () => {
const fd = filterDeps(LevelFilterOption.critical, 'wow');
expect(fd({ level: 'critical', message: 'the wow error' } as DeprecationInfo)).toBe(true);
expect(fd({ level: 'critical', message: 'other error' } as DeprecationInfo)).toBe(false);
});
test('filters on index search', () => {
const fd = filterDeps(LevelFilterOption.critical, 'myIndex');
expect(
fd({
level: 'critical',
message: 'the wow error',
index: 'myIndex-2',
} as EnrichedDeprecationInfo)
).toBe(true);
expect(
fd({
level: 'critical',
message: 'other error',
index: 'notIndex',
} as EnrichedDeprecationInfo)
).toBe(false);
});
test('filters on node search', () => {
const fd = filterDeps(LevelFilterOption.critical, 'myNode');
expect(
fd({
level: 'critical',
message: 'the wow error',
index: 'myNode-123',
} as EnrichedDeprecationInfo)
).toBe(true);
expect(
fd({
level: 'critical',
message: 'other error',
index: 'notNode',
} as EnrichedDeprecationInfo)
).toBe(false);
});
});
describe('GroupedDeprecations', () => {

View file

@ -28,7 +28,7 @@ import { DeprecationList } from './list';
// exported only for testing
export const filterDeps = (level: LevelFilterOption, search: string = '') => {
const conditions: Array<(dep: DeprecationInfo) => boolean> = [];
const conditions: Array<(dep: EnrichedDeprecationInfo) => boolean> = [];
if (level !== LevelFilterOption.all) {
conditions.push((dep: DeprecationInfo) => dep.level === level);
@ -41,7 +41,9 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
const searchReg = new RegExp(search.toLowerCase());
return Boolean(
dep.message.toLowerCase().match(searchReg) ||
(dep.details && dep.details.match(searchReg))
(dep.details && dep.details.toLowerCase().match(searchReg)) ||
(dep.index && dep.index.toLowerCase().match(searchReg)) ||
(dep.node && dep.node.toLowerCase().match(searchReg))
);
} catch (e) {
// ignore any regexp errors.
@ -51,7 +53,7 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
}
// Return true if every condition function returns true (boolean AND)
return (dep: DeprecationInfo) => conditions.map(c => c(dep)).every(t => t);
return (dep: EnrichedDeprecationInfo) => conditions.map(c => c(dep)).every(t => t);
};
/**