Fix 89878 (#94793)
This commit is contained in:
parent
78ac6f9713
commit
e2f77240ba
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue