Hide Value and Funtional boost for geolocation (#93683)

This commit is contained in:
Jason Stoltzfus 2021-03-04 17:06:03 -05:00 committed by GitHub
parent 0d4ca46cf0
commit 8381fdd60e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -64,6 +64,20 @@ describe('Boosts', () => {
expect(select.prop('options').map((o: any) => o.value)).toEqual(['add-boost', 'value']);
});
it('will not render functional or value options if "type" prop is "geolocation"', () => {
const wrapper = shallow(
<Boosts
{...{
...props,
type: 'geolocation' as SchemaTypes,
}}
/>
);
const select = wrapper.find(EuiSuperSelect);
expect(select.prop('options').map((o: any) => o.value)).toEqual(['add-boost', 'proximity']);
});
it('will add a boost of the selected type when a selection is made', () => {
const wrapper = shallow(<Boosts {...props} />);

View file

@ -13,7 +13,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiTitle, EuiSuperSelect } from '@
import { i18n } from '@kbn/i18n';
import { TEXT } from '../../../../shared/constants/field_types';
import { GEOLOCATION, TEXT } from '../../../../shared/constants/field_types';
import { SchemaTypes } from '../../../../shared/types';
import { BoostIcon } from '../boost_icon';
@ -68,6 +68,8 @@ const BASE_OPTIONS = [
const filterInvalidOptions = (value: BoostType, type: SchemaTypes) => {
// Proximity and Functional boost types are not valid for text fields
if (type === TEXT && [BoostType.Proximity, BoostType.Functional].includes(value)) return false;
// Value and Functional boost types are not valid for geolocation fields
if (type === GEOLOCATION && [BoostType.Functional, BoostType.Value].includes(value)) return false;
return true;
};