mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
9ae52d01e0
commit
b714b332fe
2 changed files with 21 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue