From ef9e325f9365d824b9f8b4cc0284176560483970 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 15 Sep 2020 16:17:34 -0700 Subject: [PATCH] Require runtime type to be defined before adding the field to the tree. --- .../runtime_type_parameter.tsx | 35 +++++++++++-------- .../fields/create_field/create_field.tsx | 8 ++--- .../required_parameters_forms/index.ts | 4 ++- .../runtime_type.tsx | 13 +++++++ .../fields/field_types/runtime_type.tsx | 10 +++--- .../constants/data_types_definition.tsx | 7 ++-- .../constants/parameters_definition.tsx | 2 +- .../components/mappings_editor/lib/utils.ts | 5 ++- .../public/application/index.tsx | 1 + 9 files changed, 52 insertions(+), 33 deletions(-) create mode 100644 x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/runtime_type.tsx diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/runtime_type_parameter.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/runtime_type_parameter.tsx index 04e5c9ee17e02..8aece425388b9 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/runtime_type_parameter.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/runtime_type_parameter.tsx @@ -6,34 +6,43 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { EuiFormRow, EuiComboBox, EuiSpacer } from '@elastic/eui'; +import { EuiFormRow, EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; import { UseField } from '../../../shared_imports'; -import { DataType, ComboBoxOption } from '../../../types'; +import { DataType } from '../../../types'; import { getFieldConfig } from '../../../lib'; import { RUNTIME_FIELD_OPTIONS, TYPE_DEFINITION } from '../../../constants'; -import { FieldDescriptionSection } from '../fields/edit_field'; +import { EditFieldFormRow, FieldDescriptionSection } from '../fields/edit_field'; export const RuntimeTypeParameter = () => { return ( {(runtimeTypeField) => { const { label, value, setValue } = runtimeTypeField; - const typeDefinition = TYPE_DEFINITION[(value as ComboBoxOption[])[0]!.value as DataType]; + const typeDefinition = + TYPE_DEFINITION[(value as EuiComboBoxOptionOption[])[0]!.value as DataType]; return ( - <> + { {/* Field description */} {typeDefinition && ( - <> - - {typeDefinition.description?.() as JSX.Element} - - - - + + {typeDefinition.description?.() as JSX.Element} + )} - + ); }} diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/create_field.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/create_field.tsx index a8170b1d59fbb..c8129c4634515 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/create_field.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/create_field.tsx @@ -22,7 +22,7 @@ import { useDispatch } from '../../../../mappings_state_context'; import { fieldSerializer } from '../../../../lib'; import { Field, NormalizedFields } from '../../../../types'; import { NameParameter, TypeParameter, SubTypeParameter } from '../../field_parameters'; -import { getParametersFormForType } from './required_parameters_forms'; +import { getRequiredParametersFormForType } from './required_parameters_forms'; const formWrapper = (props: any) =>
; @@ -195,18 +195,18 @@ export const CreateField = React.memo(function CreateFieldComponent({ {({ type, subType }) => { - const ParametersForm = getParametersFormForType( + const RequiredParametersForm = getRequiredParametersFormForType( type?.[0].value, subType?.[0].value ); - if (!ParametersForm) { + if (!RequiredParametersForm) { return null; } return (
- +
); }} diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/index.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/index.ts index 1112bf99713ed..5c04b2fbb336c 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/index.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/index.ts @@ -11,6 +11,7 @@ import { AliasTypeRequiredParameters } from './alias_type'; import { TokenCountTypeRequiredParameters } from './token_count_type'; import { ScaledFloatTypeRequiredParameters } from './scaled_float_type'; import { DenseVectorRequiredParameters } from './dense_vector_type'; +import { RuntimeTypeRequiredParameters } from './runtime_type'; export interface ComponentProps { allFields: NormalizedFields['byId']; @@ -21,9 +22,10 @@ const typeToParametersFormMap: { [key in DataType]?: ComponentType } = { token_count: TokenCountTypeRequiredParameters, scaled_float: ScaledFloatTypeRequiredParameters, dense_vector: DenseVectorRequiredParameters, + runtime: RuntimeTypeRequiredParameters, }; -export const getParametersFormForType = ( +export const getRequiredParametersFormForType = ( type: MainType, subType?: SubType ): ComponentType | undefined => diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/runtime_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/runtime_type.tsx new file mode 100644 index 0000000000000..63a6fc0ffe62a --- /dev/null +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/create_field/required_parameters_forms/runtime_type.tsx @@ -0,0 +1,13 @@ +/* + * 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 } from '../../../field_parameters'; + +export const RuntimeTypeRequiredParameters = () => { + return ; +}; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/runtime_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/runtime_type.tsx index 4c8a1322e4d60..5381b9bb390eb 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/runtime_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/runtime_type.tsx @@ -11,11 +11,9 @@ import { BasicParametersSection } from '../edit_field'; export const RuntimeType = () => { return ( - <> - - - - - + + + + ); }; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/constants/data_types_definition.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/constants/data_types_definition.tsx index c22b936f9631f..55939bdf22afb 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/constants/data_types_definition.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/constants/data_types_definition.tsx @@ -18,9 +18,10 @@ export const TYPE_DEFINITION: { [key in DataType]: DataTypeDefinition } = { label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.runtimeFieldDescription', { defaultMessage: 'Runtime', }), - documentation: { - main: '/runtime_field.html', - }, + // TODO: Add this once the page exists. + // documentation: { + // main: '/runtime_field.html', + // }, description: () => (

{ diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts index d690c999dc0d1..d96f20683216a 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts @@ -78,12 +78,11 @@ const getTypeLabel = (type?: DataType): string => { }; export const getTypeLabelFromField = (field: Field) => { - // eslint-disable-next-line @typescript-eslint/naming-convention - const { type, runtime_type } = field; + const { type, runtime_type: runtimeType } = field; const typeLabel = getTypeLabel(type); if (type === 'runtime') { - const runtimeTypeLabel = getTypeLabel(runtime_type); + const runtimeTypeLabel = getTypeLabel(runtimeType); return `${typeLabel} ${runtimeTypeLabel}`; } diff --git a/x-pack/plugins/index_management/public/application/index.tsx b/x-pack/plugins/index_management/public/application/index.tsx index 26a2d1fd45387..d8b5da8361c43 100644 --- a/x-pack/plugins/index_management/public/application/index.tsx +++ b/x-pack/plugins/index_management/public/application/index.tsx @@ -32,6 +32,7 @@ export const renderApp = ( const { Context: I18nContext } = i18n; const { services, history, setBreadcrumbs, uiSettings } = dependencies; + // uiSettings is required by the CodeEditor component used to edit runtime field Painless scripts. const { Provider: KibanaReactContextProvider } = createKibanaReactContext({ uiSettings, });