This commit is contained in:
Liza Katz 2021-03-17 17:02:21 +02:00 committed by GitHub
parent 78ac6f9713
commit e2f77240ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -31,6 +31,20 @@ describe('filterMatchesIndex', () => {
expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
it('should return true if custom filter for the same index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bara' }] } as IIndexPattern;
expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
it('should return false if custom filter for a different index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'food', fields: [{ name: 'bara' }] } as IIndexPattern;
expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});
it('should return false if the filter key does not match a field name', () => {
const filter = { meta: { index: 'foo', key: 'baz' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern;

View file

@ -18,5 +18,12 @@ export function filterMatchesIndex(filter: Filter, indexPattern?: IIndexPattern
if (!filter.meta?.key || !indexPattern) {
return true;
}
// Fixes https://github.com/elastic/kibana/issues/89878
// Custom filters may refer multiple fields. Validate the index id only.
if (filter.meta?.type === 'custom') {
return filter.meta.index === indexPattern.id;
}
return indexPattern.fields.some((field: IFieldType) => field.name === filter.meta.key);
}