Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
lizozom and kibanamachine authored Mar 18, 2021
1 parent 2eb8c1c commit d74e0e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit d74e0e0

Please sign in to comment.