-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
cca5857
commit ac81b19
Showing
9 changed files
with
335 additions
and
10 deletions.
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
.../components/mappings_editor/__jest__/client_integration/datatypes/point_datatype.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { componentHelpers, MappingsEditorTestBed } from '../helpers'; | ||
|
||
const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor; | ||
|
||
// Parameters automatically added to the point datatype when saved (with the default values) | ||
export const defaultPointParameters = { | ||
type: 'point', | ||
ignore_malformed: false, | ||
ignore_z_value: true, | ||
}; | ||
|
||
describe('Mappings editor: point datatype', () => { | ||
/** | ||
* Variable to store the mappings data forwarded to the consumer component | ||
*/ | ||
let data: any; | ||
let onChangeHandler: jest.Mock = jest.fn(); | ||
let getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
let testBed: MappingsEditorTestBed; | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
beforeEach(() => { | ||
onChangeHandler = jest.fn(); | ||
getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
}); | ||
|
||
test('initial view and default parameters values', async () => { | ||
const defaultMappings = { | ||
properties: { | ||
myField: { | ||
type: 'point', | ||
}, | ||
}, | ||
}; | ||
|
||
const updatedMappings = { ...defaultMappings }; | ||
|
||
await act(async () => { | ||
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }); | ||
}); | ||
testBed.component.update(); | ||
|
||
const { | ||
component, | ||
actions: { startEditField, updateFieldAndCloseFlyout }, | ||
} = testBed; | ||
|
||
// Open the flyout to edit the field | ||
await startEditField('myField'); | ||
|
||
// Save the field and close the flyout | ||
await updateFieldAndCloseFlyout(); | ||
|
||
// It should have the default parameters values added | ||
updatedMappings.properties.myField = defaultPointParameters; | ||
|
||
({ data } = await getMappingsEditorData(component)); | ||
expect(data).toEqual(updatedMappings); | ||
}); | ||
|
||
describe('meta parameter', () => { | ||
const defaultMappings = { | ||
properties: { | ||
myField: { | ||
type: 'point', | ||
}, | ||
}, | ||
}; | ||
|
||
const updatedMappings = { ...defaultMappings }; | ||
|
||
const metaParameter = { | ||
meta: { | ||
my_metadata: 'foobar', | ||
}, | ||
}; | ||
|
||
beforeEach(async () => { | ||
await act(async () => { | ||
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }); | ||
}); | ||
testBed.component.update(); | ||
}); | ||
|
||
test('valid meta object', async () => { | ||
const { | ||
component, | ||
actions: { | ||
startEditField, | ||
updateFieldAndCloseFlyout, | ||
showAdvancedSettings, | ||
toggleFormRow, | ||
updateJsonEditor, | ||
}, | ||
} = testBed; | ||
|
||
// Open the flyout to edit the field | ||
await startEditField('myField'); | ||
await showAdvancedSettings(); | ||
|
||
// Enable the meta parameter and add value | ||
toggleFormRow('metaParameter'); | ||
await act(async () => { | ||
updateJsonEditor('metaParameterEditor', metaParameter.meta); | ||
}); | ||
component.update(); | ||
|
||
// Save the field and close the flyout | ||
await updateFieldAndCloseFlyout(); | ||
|
||
// It should have the default parameters values added, plus metadata | ||
updatedMappings.properties.myField = { | ||
...defaultPointParameters, | ||
...metaParameter, | ||
}; | ||
|
||
({ data } = await getMappingsEditorData(component)); | ||
expect(data).toEqual(updatedMappings); | ||
}); | ||
|
||
test('strip empty string', async () => { | ||
const { | ||
component, | ||
actions: { startEditField, updateFieldAndCloseFlyout, showAdvancedSettings, toggleFormRow }, | ||
} = testBed; | ||
|
||
// Open the flyout to edit the field | ||
await startEditField('myField'); | ||
await showAdvancedSettings(); | ||
|
||
// Enable the meta parameter | ||
toggleFormRow('metaParameter'); | ||
|
||
// Save the field and close the flyout without adding any values to meta parameter | ||
await updateFieldAndCloseFlyout(); | ||
|
||
// It should have the default parameters values added | ||
updatedMappings.properties.myField = defaultPointParameters; | ||
|
||
({ data } = await getMappingsEditorData(component)); | ||
expect(data).toEqual(updatedMappings); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...n/components/mappings_editor/components/document_fields/fields/field_types/point_type.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React, { FunctionComponent } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { NormalizedField, Field as FieldType, ParameterName } from '../../../../types'; | ||
import { UseField, TextAreaField } from '../../../../shared_imports'; | ||
import { getFieldConfig } from '../../../../lib'; | ||
import { | ||
IgnoreMalformedParameter, | ||
IgnoreZValueParameter, | ||
NullValueParameter, | ||
MetaParameter, | ||
} from '../../field_parameters'; | ||
import { AdvancedParametersSection, BasicParametersSection } from '../edit_field'; | ||
|
||
interface Props { | ||
field: NormalizedField; | ||
} | ||
|
||
const getDefaultToggleValue = (param: ParameterName, field: FieldType) => { | ||
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue; | ||
}; | ||
|
||
export const PointType: FunctionComponent<Props> = ({ field }) => { | ||
return ( | ||
<> | ||
<BasicParametersSection> | ||
<IgnoreMalformedParameter | ||
description={i18n.translate( | ||
'xpack.idxMgmt.mappingsEditor.point.ignoreMalformedFieldDescription', | ||
{ | ||
defaultMessage: | ||
'By default, documents that contain malformed points are not indexed. If enabled, these documents are indexed, but fields with malformed points are filtered out. Be careful: if too many documents are indexed this way, queries on the field become meaningless.', | ||
} | ||
)} | ||
/> | ||
</BasicParametersSection> | ||
|
||
<AdvancedParametersSection> | ||
<IgnoreZValueParameter | ||
description={i18n.translate( | ||
'xpack.idxMgmt.mappingsEditor.point.ignoreZValueFieldDescription', | ||
{ | ||
defaultMessage: | ||
'Three dimension points will be accepted, but only x and y values will be indexed; the third dimension is ignored.', | ||
} | ||
)} | ||
/> | ||
|
||
<NullValueParameter | ||
defaultToggleValue={getDefaultToggleValue('null_value', field.source)} | ||
description={i18n.translate( | ||
'xpack.idxMgmt.mappingsEditor.point.nullValueFieldDescription', | ||
{ | ||
defaultMessage: | ||
'Replace explicit null values with a point value so that it can be indexed and searched.', | ||
} | ||
)} | ||
> | ||
<UseField | ||
path="null_value" | ||
component={TextAreaField} | ||
config={getFieldConfig('null_value_point')} | ||
/> | ||
</NullValueParameter> | ||
|
||
<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} /> | ||
</AdvancedParametersSection> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.