Skip to content

Commit

Permalink
[Discover] Fix filtering selected sidebar fields (#91828) (#92773)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Feb 25, 2021
1 parent bc3c475 commit 56391db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function isFieldFiltered(
const scriptedOrMissing =
!filterState.missing ||
field.type === '_source' ||
field.type === 'unknown_selected' ||
field.scripted ||
fieldCounts[field.name] > 0;
const needle = filterState.name ? filterState.name.toLowerCase() : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ describe('group_fields', function () {
]);
});

it('should filter fields by a given name', function () {
const fieldFilterState = { ...getDefaultFieldFilter(), ...{ name: 'curr' } };

const actual1 = groupFields(
fields as IndexPatternField[],
['customer_birth_date', 'currency', 'unknown'],
5,
fieldCounts,
fieldFilterState,
false
);
expect(actual1.selected.map((field) => field.name)).toEqual(['currency']);
});

it('excludes unmapped fields if showUnmappedFields set to false', function () {
const fieldFilterState = getDefaultFieldFilter();
const fieldsWithUnmappedField = [...fields];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ export function groupFields(
}
}
}
// add columns, that are not part of the index pattern, to be removeable
// add selected columns, that are not part of the index pattern, to be removeable
for (const column of columns) {
if (!result.selected.find((field) => field.name === column)) {
result.selected.push({ name: column, displayName: column } as IndexPatternField);
const tmpField = {
name: column,
displayName: column,
type: 'unknown_selected',
} as IndexPatternField;
if (
!result.selected.find((field) => field.name === column) &&
isFieldFiltered(tmpField, fieldFilterState, fieldCounts)
) {
result.selected.push(tmpField);
}
}
result.selected.sort((a, b) => {
Expand Down

0 comments on commit 56391db

Please sign in to comment.