Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Controls vis - safely handle case where value can not be extracted from Kibana filter (#22885) #22899

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ export class PhraseFilterManager extends FilterManager {
return;
}

return kbnFilters
const values = kbnFilters
.map((kbnFilter) => {
return this._getValueFromFilter(kbnFilter);
})
.filter(value => value != null);

if (values.length === 0) {
return;
}

return values
.reduce((accumulator, currentValue) => {
return accumulator.concat(currentValue);
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ describe('PhraseFilterManager', function () {
]);
expect(filterManager.getValueFromFilterBar()).to.eql([{ value: 'ios', label: 'ios' }, { value: 'win xp', label: 'win xp' }]);
});

test('should return undefined when filter value can not be extracted from Kibana filter', function () {
filterManager.setMockFilters([
{
query: {
match: {
myFieldWhichIsNotField1: {
query: 'ios',
type: 'phrase'
}
}
}
}
]);
expect(filterManager.getValueFromFilterBar()).to.eql(undefined);
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ export class RangeFilterManager extends FilterManager {
return;
}

let range = null;
let range;
if (_.has(kbnFilters[0], 'script')) {
range = _.get(kbnFilters[0], 'script.script.params');
} else {
range = _.get(kbnFilters[0], ['range', this.fieldName]);
}

return fromRange(range);
if (!range) {
return;
}

return fromRange(range);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ describe('RangeFilterManager', function () {
expect(value).to.have.property('max');
expect(value.max).to.be(3);
});

test('should return undefined when filter value can not be extracted from Kibana filter', function () {
filterManager.setMockFilters([
{
range: {
myFieldWhichIsNotField1: {
gte: 1,
lte: 3
}
}
}
]);
expect(filterManager.getValueFromFilterBar()).to.eql(undefined);
});
});

});
Expand Down