-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add support for runtime field types to mappings editor. #77420
Changes from 2 commits
02e43dd
1e7b0fc
ef9e325
a45b918
3f24754
a5214ac
90e1445
9af93bc
8a53f68
3ac63a6
4449800
ca02afb
1b01e7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { EuiFormRow } from '@elastic/eui'; | ||
|
||
import { CodeEditor, UseField } from '../../../shared_imports'; | ||
import { getFieldConfig } from '../../../lib'; | ||
|
||
export const PainlessScriptParameter = () => { | ||
return ( | ||
<UseField path="script.source" config={getFieldConfig('script')}> | ||
{(scriptField) => { | ||
return ( | ||
<EuiFormRow label={scriptField.label} fullWidth> | ||
<CodeEditor | ||
languageId="painless" | ||
// 99% width allows the editor to resize horizontally. 100% prevents it from resizing. | ||
width="99%" | ||
height="800px" | ||
value={scriptField.value as string} | ||
onChange={scriptField.setValue} | ||
options={{ | ||
fontSize: 12, | ||
minimap: { | ||
enabled: false, | ||
}, | ||
scrollBeyondLastLine: false, | ||
wordWrap: 'on', | ||
wrappingIndent: 'indent', | ||
automaticLayout: true, | ||
}} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}} | ||
</UseField> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFormRow, EuiComboBox, EuiSpacer } from '@elastic/eui'; | ||
|
||
import { UseField } from '../../../shared_imports'; | ||
import { DataType, ComboBoxOption } from '../../../types'; | ||
import { getFieldConfig } from '../../../lib'; | ||
import { RUNTIME_FIELD_OPTIONS, TYPE_DEFINITION } from '../../../constants'; | ||
import { FieldDescriptionSection } from '../fields/edit_field'; | ||
|
||
export const RuntimeTypeParameter = () => { | ||
return ( | ||
<UseField path="runtime_type" config={getFieldConfig('runtime_type')}> | ||
{(runtimeTypeField) => { | ||
const { label, value, setValue } = runtimeTypeField; | ||
const typeDefinition = TYPE_DEFINITION[(value as ComboBoxOption[])[0]!.value as DataType]; | ||
|
||
return ( | ||
<> | ||
<EuiFormRow label={label} fullWidth> | ||
<EuiComboBox | ||
placeholder={i18n.translate( | ||
'xpack.idxMgmt.mappingsEditor.runtimeTyeField.placeholderLabel', | ||
{ | ||
defaultMessage: 'Select a type', | ||
} | ||
)} | ||
singleSelection={{ asPlainText: true }} | ||
options={RUNTIME_FIELD_OPTIONS} | ||
selectedOptions={value as ComboBoxOption[]} | ||
onChange={setValue} | ||
isClearable={false} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
|
||
{/* Field description */} | ||
{typeDefinition && ( | ||
<> | ||
<FieldDescriptionSection isMultiField={false}> | ||
{typeDefinition.description?.() as JSX.Element} | ||
</FieldDescriptionSection> | ||
|
||
<EuiSpacer size="l" /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}} | ||
</UseField> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { RuntimeTypeParameter, PainlessScriptParameter } from '../../field_parameters'; | ||
import { BasicParametersSection } from '../edit_field'; | ||
|
||
export const RuntimeType = () => { | ||
return ( | ||
<> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unnecessary fragment |
||
<BasicParametersSection> | ||
<RuntimeTypeParameter /> | ||
<PainlessScriptParameter /> | ||
</BasicParametersSection> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,23 @@ import { documentationService } from '../../../services/documentation'; | |
import { MainType, SubType, DataType, DataTypeDefinition } from '../types'; | ||
|
||
export const TYPE_DEFINITION: { [key in DataType]: DataTypeDefinition } = { | ||
runtime: { | ||
value: 'runtime', | ||
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.runtimeFieldDescription', { | ||
defaultMessage: 'Runtime', | ||
}), | ||
documentation: { | ||
main: '/runtime_field.html', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that these docs don't exist yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we hold off on adding a value then? Or are we confident the doc url will eventually be |
||
}, | ||
description: () => ( | ||
<p> | ||
<FormattedMessage | ||
id="xpack.idxMgmt.mappingsEditor.dataType.runtimeFieldLongDescription" | ||
defaultMessage="Runtime fields define scripts that calculate field values at runtime." | ||
/> | ||
</p> | ||
), | ||
}, | ||
text: { | ||
value: 'text', | ||
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.textDescription', { | ||
|
@@ -838,6 +855,7 @@ export const MAIN_TYPES: MainType[] = [ | |
'range', | ||
'rank_feature', | ||
'rank_features', | ||
'runtime', | ||
'search_as_you_type', | ||
'shape', | ||
'text', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably more appropriate to use the EuiComboBoxOptionOption type now (and at some point remove
ComboBoxOption
).