Skip to content

Commit

Permalink
Merge branch '1.3' into 1.3-5594
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarrrr authored Dec 13, 2023
2 parents e1de952 + bec6c33 commit 270f129
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ describe('filterMatchesIndex', () => {

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});

it('should return false if the custom filter is a different index id', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'bar', fields: [{ name: 'foo' }] } as IIndexPattern;

expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});

it('should return true if the custom filter is the same index id', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'barf' }] } as IIndexPattern;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import { IIndexPattern, IFieldType } from '../../index_patterns';
import { Filter } from '../filters';

/*
* TODO: We should base this on something better than `filter.meta.key`. We should probably modify
* this to check if `filter.meta.index` matches `indexPattern.id` instead, but that's a breaking
* change.
*/
export function filterMatchesIndex(filter: Filter, indexPattern?: IIndexPattern | null) {
if (!filter.meta?.key || !indexPattern) {
return true;
}

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 270f129

Please sign in to comment.