diff --git a/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_field.ts b/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_field.ts index af6904dbacdd9..dedc390c47719 100644 --- a/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_field.ts +++ b/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_field.ts @@ -504,18 +504,21 @@ export const useField = ( const { resetValue = true, defaultValue: updatedDefaultValue } = resetOptions; setPristine(true); - setIsModified(false); - setValidating(false); - setIsChangingValue(false); - setIsValidated(false); - setStateErrors([]); - - if (resetValue) { - hasBeenReset.current = true; - const newValue = deserializeValue(updatedDefaultValue ?? defaultValue); - // updateStateIfMounted('value', newValue); - setValue(newValue); - return newValue; + + if (isMounted.current) { + setIsModified(false); + setValidating(false); + setIsChangingValue(false); + setIsValidated(false); + setStateErrors([]); + + if (resetValue) { + hasBeenReset.current = true; + const newValue = deserializeValue(updatedDefaultValue ?? defaultValue); + // updateStateIfMounted('value', newValue); + setValue(newValue); + return newValue; + } } }, [deserializeValue, defaultValue, setValue, setStateErrors] diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/constants.ts b/x-pack/plugins/index_management/__jest__/client_integration/helpers/constants.ts deleted file mode 100644 index e241dfebd08ee..0000000000000 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/constants.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const MAJOR_VERSION = '7.16.0'; diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx index 3066742d4c0e0..9f8199215df5b 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx @@ -14,9 +14,12 @@ import { SemVer } from 'semver'; import { notificationServiceMock, docLinksServiceMock, + uiSettingsServiceMock, } from '../../../../../../src/core/public/mocks'; import { GlobalFlyout } from '../../../../../../src/plugins/es_ui_shared/public'; +import { createKibanaReactContext } from '../../../../../../src/plugins/kibana_react/public'; +import { MAJOR_VERSION } from '../../../common'; import { AppContextProvider } from '../../../public/application/app_context'; import { httpService } from '../../../public/application/services/http'; import { breadcrumbService } from '../../../public/application/services/breadcrumbs'; @@ -32,13 +35,10 @@ import { } from '../../../public/application/components'; import { componentTemplatesMockDependencies } from '../../../public/application/components/component_templates/__jest__'; import { init as initHttpRequests } from './http_requests'; -import { MAJOR_VERSION } from './constants'; const mockHttpClient = axios.create({ adapter: axiosXhrAdapter }); const { GlobalFlyoutProvider } = GlobalFlyout; -export const kibanaVersion = new SemVer(MAJOR_VERSION); - export const services = { extensionsService: new ExtensionsService(), uiMetricService: new UiMetricService('index_management'), @@ -54,6 +54,15 @@ const appDependencies = { plugins: {}, } as any; +export const kibanaVersion = new SemVer(MAJOR_VERSION); + +const { Provider: KibanaReactContextProvider } = createKibanaReactContext({ + uiSettings: uiSettingsServiceMock.createSetupContract(), + kibanaVersion: { + get: () => kibanaVersion, + }, +}); + export const setupEnvironment = () => { // Mock initialization of services // @ts-ignore @@ -75,14 +84,16 @@ export const WithAppDependencies = (props: any) => { const mergedDependencies = merge({}, appDependencies, overridingDependencies); return ( - - - - - - - - - + + + + + + + + + + + ); }; diff --git a/x-pack/plugins/index_management/common/constants/index.ts b/x-pack/plugins/index_management/common/constants/index.ts index a2ad51e5c89f0..373044aef9d45 100644 --- a/x-pack/plugins/index_management/common/constants/index.ts +++ b/x-pack/plugins/index_management/common/constants/index.ts @@ -53,3 +53,5 @@ export { UIM_TEMPLATE_CLONE, UIM_TEMPLATE_SIMULATE, } from './ui_metric'; + +export { MAJOR_VERSION } from './plugin'; diff --git a/x-pack/plugins/index_management/common/constants/plugin.ts b/x-pack/plugins/index_management/common/constants/plugin.ts index 605dbf3859a0e..d52b3cf28bb4a 100644 --- a/x-pack/plugins/index_management/common/constants/plugin.ts +++ b/x-pack/plugins/index_management/common/constants/plugin.ts @@ -17,3 +17,9 @@ export const PLUGIN = { defaultMessage: 'Index Management', }), }; + +// Ideally we want to access the Kibana major version from core +// "PluginInitializerContext.env.packageInfo.version". In some cases it is not possible +// to dynamically inject that version without a huge refactor on the code base. +// We will then keep this single constant to declare on which major branch we are. +export const MAJOR_VERSION = '7.16.0'; diff --git a/x-pack/plugins/index_management/common/index.ts b/x-pack/plugins/index_management/common/index.ts index ed8fd87643946..127123609b186 100644 --- a/x-pack/plugins/index_management/common/index.ts +++ b/x-pack/plugins/index_management/common/index.ts @@ -8,7 +8,7 @@ // TODO: https://github.com/elastic/kibana/issues/110892 /* eslint-disable @kbn/eslint/no_export_all */ -export { API_BASE_PATH, BASE_PATH } from './constants'; +export { API_BASE_PATH, BASE_PATH, MAJOR_VERSION } from './constants'; export { getTemplateParameter } from './lib'; diff --git a/x-pack/plugins/index_management/public/application/app_context.tsx b/x-pack/plugins/index_management/public/application/app_context.tsx index f8ebfdf7c46b7..f562ab9d15a8b 100644 --- a/x-pack/plugins/index_management/public/application/app_context.tsx +++ b/x-pack/plugins/index_management/public/application/app_context.tsx @@ -7,6 +7,7 @@ import React, { createContext, useContext } from 'react'; import { ScopedHistory } from 'kibana/public'; +import { SemVer } from 'semver'; import { ManagementAppMountParams } from 'src/plugins/management/public'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/public'; @@ -37,6 +38,7 @@ export interface AppDependencies { uiSettings: CoreSetup['uiSettings']; url: SharePluginStart['url']; docLinks: CoreStart['docLinks']; + kibanaVersion: SemVer; } export const AppContextProvider = ({ diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/scaled_float_datatype.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/scaled_float_datatype.test.tsx index b6af657ee5f96..17e7317e098cc 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/scaled_float_datatype.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/scaled_float_datatype.test.tsx @@ -7,7 +7,7 @@ import { act } from 'react-dom/test-utils'; -import { componentHelpers, MappingsEditorTestBed } from '../helpers'; +import { componentHelpers, MappingsEditorTestBed, kibanaVersion } from '../helpers'; const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor; @@ -92,6 +92,13 @@ describe('Mappings editor: scaled float datatype', () => { await updateFieldAndCloseFlyout(); expect(exists('mappingsEditorFieldEdit')).toBe(false); + if (kibanaVersion.major < 7) { + expect(exists('boostParameterToggle')).toBe(true); + } else { + // Since 8.x the boost parameter is deprecated + expect(exists('boostParameterToggle')).toBe(false); + } + // It should have the default parameters values added, plus the scaling factor updatedMappings.properties.myField = { ...defaultScaledFloatParameters, diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/text_datatype.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/text_datatype.test.tsx index ebca896de0b86..db8678478aa3d 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/text_datatype.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/text_datatype.test.tsx @@ -7,7 +7,7 @@ import { act } from 'react-dom/test-utils'; -import { componentHelpers, MappingsEditorTestBed } from '../helpers'; +import { componentHelpers, MappingsEditorTestBed, kibanaVersion } from '../helpers'; import { getFieldConfig } from '../../../lib'; const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor; @@ -64,6 +64,7 @@ describe('Mappings editor: text datatype', () => { const { component, + exists, actions: { startEditField, getToggleValue, updateFieldAndCloseFlyout }, } = testBed; @@ -74,6 +75,13 @@ describe('Mappings editor: text datatype', () => { const indexFieldConfig = getFieldConfig('index'); expect(getToggleValue('indexParameter.formRowToggle')).toBe(indexFieldConfig.defaultValue); + if (kibanaVersion.major < 7) { + expect(exists('boostParameterToggle')).toBe(true); + } else { + // Since 8.x the boost parameter is deprecated + expect(exists('boostParameterToggle')).toBe(false); + } + // Save the field and close the flyout await updateFieldAndCloseFlyout(); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/index.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/index.ts index bec4e5a5c88a1..fbe24557ae6a1 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/index.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/index.ts @@ -13,6 +13,7 @@ import { } from './mappings_editor.helpers'; export { nextTick, getRandomString, findTestSubject, TestBed } from '@kbn/test/jest'; +export { kibanaVersion } from './setup_environment'; export const componentHelpers = { mappingsEditor: { setup: mappingsEditorSetup, getMappingsEditorDataFactory }, diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx index 3110b3ce24041..074d96e9be4c1 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx @@ -123,12 +123,10 @@ const createActions = (testBed: TestBed) => { component.update(); - if (subType !== undefined) { + if (subType !== undefined && type === 'other') { await act(async () => { - if (type === 'other') { - // subType is a text input - form.setInputValue('createFieldForm.fieldSubType', subType); - } + // subType is a text input + form.setInputValue('createFieldForm.fieldSubType', subType); }); } diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx index 7055dcc74ce7b..5e3ae3c1544ae 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx @@ -6,6 +6,8 @@ */ import React from 'react'; +import { SemVer } from 'semver'; + /* eslint-disable-next-line @kbn/eslint/no-restricted-paths */ import '../../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor/jest_mock'; import { GlobalFlyout } from '../../../../../../../../../../src/plugins/es_ui_shared/public'; @@ -13,9 +15,12 @@ import { docLinksServiceMock, uiSettingsServiceMock, } from '../../../../../../../../../../src/core/public/mocks'; +import { MAJOR_VERSION } from '../../../../../../../common'; import { MappingsEditorProvider } from '../../../mappings_editor_context'; import { createKibanaReactContext } from '../../../shared_imports'; +export const kibanaVersion = new SemVer(MAJOR_VERSION); + jest.mock('@elastic/eui', () => { const original = jest.requireActual('@elastic/eui'); @@ -72,6 +77,9 @@ const { GlobalFlyoutProvider } = GlobalFlyout; const { Provider: KibanaReactContextProvider } = createKibanaReactContext({ uiSettings: uiSettingsServiceMock.createSetupContract(), + kibanaVersion: { + get: () => kibanaVersion, + }, }); const defaultProps = { diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/boost_parameter.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/boost_parameter.tsx index edafb57ad2e57..07156611461d6 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/boost_parameter.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/boost_parameter.tsx @@ -33,6 +33,7 @@ export const BoostParameter = ({ defaultToggleValue }: Props) => ( href: documentationService.getBoostLink(), }} defaultToggleValue={defaultToggleValue} + data-test-subj="boostParameter" > {/* Boost level */} , which wrapps the form with @@ -50,161 +52,164 @@ export interface Props { // the height calculaction and does not render the footer position correctly. const FormWrapper: React.FC = ({ children }) => <>{children}; -export const EditField = React.memo(({ form, field, allFields, exitEdit, updateField }: Props) => { - const submitForm = async () => { - const { isValid, data } = await form.submit(); - - if (isValid) { - updateField({ ...field, source: data }); - } - }; - - const { isMultiField } = field; - - return ( -
- - - - {/* We need an extra div to get out of flex grow */} -
- {/* Title */} - -

- {isMultiField - ? i18n.translate('xpack.idxMgmt.mappingsEditor.editMultiFieldTitle', { - defaultMessage: "Edit multi-field '{fieldName}'", - values: { - fieldName: limitStringLength(field.source.name), - }, - }) - : i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldTitle', { - defaultMessage: "Edit field '{fieldName}'", +export const EditField = React.memo( + ({ form, field, allFields, exitEdit, updateField, kibanaVersion }: Props) => { + const submitForm = async () => { + const { isValid, data } = await form.submit(); + + if (isValid) { + updateField({ ...field, source: data }); + } + }; + + const { isMultiField } = field; + + return ( + + + + + {/* We need an extra div to get out of flex grow */} +
+ {/* Title */} + +

+ {isMultiField + ? i18n.translate('xpack.idxMgmt.mappingsEditor.editMultiFieldTitle', { + defaultMessage: "Edit multi-field '{fieldName}'", + values: { + fieldName: limitStringLength(field.source.name), + }, + }) + : i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldTitle', { + defaultMessage: "Edit field '{fieldName}'", + values: { + fieldName: limitStringLength(field.source.name), + }, + })} +

+
+
+
+ + {/* Documentation link */} + + {({ type, subType }) => { + const linkDocumentation = + documentationService.getTypeDocLink(subType?.[0]?.value) || + documentationService.getTypeDocLink(type?.[0]?.value); + + if (!linkDocumentation) { + return null; + } + + const typeDefinition = TYPE_DEFINITION[type[0].value as MainType]; + const subTypeDefinition = TYPE_DEFINITION[subType?.[0].value as SubType]; + + return ( + + + {i18n.translate('xpack.idxMgmt.mappingsEditor.editField.typeDocumentation', { + defaultMessage: '{type} documentation', values: { - fieldName: limitStringLength(field.source.name), + type: subTypeDefinition ? subTypeDefinition.label : typeDefinition.label, }, })} -

-
-
-
+ + + ); + }} + +
+ + {/* Field path */} + + + {field.path.join(' > ')} + + +
+ + + - {/* Documentation link */} {({ type, subType }) => { - const linkDocumentation = - documentationService.getTypeDocLink(subType?.[0]?.value) || - documentationService.getTypeDocLink(type?.[0]?.value); + const ParametersForm = getParametersFormForType(type?.[0].value, subType?.[0].value); - if (!linkDocumentation) { + if (!ParametersForm) { return null; } - const typeDefinition = TYPE_DEFINITION[type[0].value as MainType]; - const subTypeDefinition = TYPE_DEFINITION[subType?.[0].value as SubType]; - return ( - - - {i18n.translate('xpack.idxMgmt.mappingsEditor.editField.typeDocumentation', { - defaultMessage: '{type} documentation', - values: { - type: subTypeDefinition ? subTypeDefinition.label : typeDefinition.label, - }, - })} - - + ); }} - - - {/* Field path */} - - - {field.path.join(' > ')} - - - - - - - - - {({ type, subType }) => { - const ParametersForm = getParametersFormForType(type?.[0].value, subType?.[0].value); - - if (!ParametersForm) { - return null; - } - - return ( - + + + {form.isSubmitted && !form.isValid && ( + <> + - ); - }} - - - - - {form.isSubmitted && !form.isValid && ( - <> - - - - )} - - - - - {i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldCancelButtonLabel', { - defaultMessage: 'Cancel', - })} - - - - - {i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldUpdateButtonLabel', { - defaultMessage: 'Update', - })} - - - - - - ); -}); + + + )} + + + + + {i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldCancelButtonLabel', { + defaultMessage: 'Cancel', + })} + + + + + {i18n.translate('xpack.idxMgmt.mappingsEditor.editFieldUpdateButtonLabel', { + defaultMessage: 'Update', + })} + + + + + + ); + } +); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/edit_field/edit_field_container.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/edit_field/edit_field_container.tsx index 9a9e1179db237..2db0d2b6c544b 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/edit_field/edit_field_container.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/edit_field/edit_field_container.tsx @@ -7,6 +7,7 @@ import React, { useEffect, useMemo } from 'react'; +import { useKibana } from '../../../../../../index'; import { useForm } from '../../../../shared_imports'; import { useDispatch, useMappingsState } from '../../../../mappings_state_context'; import { Field } from '../../../../types'; @@ -30,6 +31,9 @@ export const EditFieldContainer = React.memo(({ exitEdit }: Props) => { const { fields, documentFields } = useMappingsState(); const dispatch = useDispatch(); const { updateField, modal } = useUpdateField(); + const { + services: { kibanaVersion }, + } = useKibana(); const { status, fieldToEdit } = documentFields; const isEditing = status === 'editingField'; @@ -73,6 +77,7 @@ export const EditFieldContainer = React.memo(({ exitEdit }: Props) => { allFields={fields.byId} exitEdit={exitEdit} updateField={updateField} + kibanaVersion={kibanaVersion.get()} /> {renderModal()} diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/boolean_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/boolean_type.tsx index 2cba31279b270..ad7f7e6d93c41 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/boolean_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/boolean_type.tsx @@ -6,6 +6,7 @@ */ import React from 'react'; +import { SemVer } from 'semver'; import { i18n } from '@kbn/i18n'; @@ -57,9 +58,10 @@ const nullValueOptions = [ interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const BooleanType = ({ field }: Props) => { +export const BooleanType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -96,7 +98,10 @@ export const BooleanType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/date_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/date_type.tsx index eed3c48804266..ea71e7fcce5d2 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/date_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/date_type.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; - +import { SemVer } from 'semver'; import { i18n } from '@kbn/i18n'; import { NormalizedField, Field as FieldType } from '../../../../types'; @@ -43,9 +43,10 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const DateType = ({ field }: Props) => { +export const DateType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -79,7 +80,10 @@ export const DateType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/flattened_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/flattened_type.tsx index 6759f66e0db38..0f58c75ca9cb7 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/flattened_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/flattened_type.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; +import { SemVer } from 'semver'; import { NormalizedField, Field as FieldType } from '../../../../types'; import { UseField, Field } from '../../../../shared_imports'; @@ -27,6 +28,7 @@ import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } f interface Props { field: NormalizedField; + kibanaVersion: SemVer; } const getDefaultToggleValue = (param: string, field: FieldType) => { @@ -45,7 +47,7 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { } }; -export const FlattenedType = React.memo(({ field }: Props) => { +export const FlattenedType = React.memo(({ field, kibanaVersion }: Props) => { return ( <> @@ -89,7 +91,10 @@ export const FlattenedType = React.memo(({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/index.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/index.ts index c7aab6fbe09ae..f62a19e55a835 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/index.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/index.ts @@ -6,6 +6,8 @@ */ import { ComponentType } from 'react'; +import { SemVer } from 'semver'; + import { MainType, SubType, DataType, NormalizedField, NormalizedFields } from '../../../../types'; import { AliasType } from './alias_type'; @@ -75,6 +77,7 @@ export const getParametersFormForType = ( field: NormalizedField; allFields: NormalizedFields['byId']; isMultiField: boolean; + kibanaVersion: SemVer; }> | undefined => subType === undefined diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/ip_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/ip_type.tsx index d3f2ae5c6bf0e..3ea56805829d5 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/ip_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/ip_type.tsx @@ -6,6 +6,7 @@ */ import React from 'react'; +import { SemVer } from 'semver'; import { NormalizedField, Field as FieldType } from '../../../../types'; import { getFieldConfig } from '../../../../lib'; @@ -36,9 +37,10 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const IpType = ({ field }: Props) => { +export const IpType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -54,7 +56,10 @@ export const IpType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/keyword_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/keyword_type.tsx index 30329925f844f..9d820c1b07636 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/keyword_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/keyword_type.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; - +import { SemVer } from 'semver'; import { i18n } from '@kbn/i18n'; import { documentationService } from '../../../../../../services/documentation'; @@ -48,9 +48,10 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const KeywordType = ({ field }: Props) => { +export const KeywordType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -104,7 +105,10 @@ export const KeywordType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/numeric_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/numeric_type.tsx index 9d9778b14b954..7035a730f15f4 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/numeric_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/numeric_type.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; +import { SemVer } from 'semver'; import { NormalizedField, Field as FieldType, ComboBoxOption } from '../../../../types'; import { getFieldConfig } from '../../../../lib'; @@ -43,9 +44,10 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const NumericType = ({ field }: Props) => { +export const NumericType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -102,7 +104,10 @@ export const NumericType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/range_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/range_type.tsx index ccfa049d9e777..9b8dae490d819 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/range_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/range_type.tsx @@ -6,6 +6,7 @@ */ import React from 'react'; +import { SemVer } from 'semver'; import { NormalizedField, @@ -32,9 +33,10 @@ const getDefaultToggleValue = (param: ParameterName, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const RangeType = ({ field }: Props) => { +export const RangeType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -67,7 +69,10 @@ export const RangeType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/text_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/text_type.tsx index 2a007e7741d4a..6857e20dc1ec4 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/text_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/text_type.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { EuiSpacer, EuiDualRange, EuiFormRow, EuiCallOut } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { SemVer } from 'semver'; import { documentationService } from '../../../../../../services/documentation'; import { NormalizedField, Field as FieldType } from '../../../../types'; @@ -36,6 +37,7 @@ import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } f interface Props { field: NormalizedField; + kibanaVersion: SemVer; } const getDefaultToggleValue = (param: string, field: FieldType) => { @@ -73,7 +75,7 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { } }; -export const TextType = React.memo(({ field }: Props) => { +export const TextType = React.memo(({ field, kibanaVersion }: Props) => { const onIndexPrefixesChanage = (minField: FieldHook, maxField: FieldHook) => ([min, max]: any) => { @@ -246,7 +248,10 @@ export const TextType = React.memo(({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/token_count_type.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/token_count_type.tsx index 2c56100ede037..3c0e8a28f3090 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/token_count_type.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/fields/field_types/token_count_type.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; - +import { SemVer } from 'semver'; import { i18n } from '@kbn/i18n'; import { documentationService } from '../../../../../../services/documentation'; @@ -43,9 +43,10 @@ const getDefaultToggleValue = (param: string, field: FieldType) => { interface Props { field: NormalizedField; + kibanaVersion: SemVer; } -export const TokenCountType = ({ field }: Props) => { +export const TokenCountType = ({ field, kibanaVersion }: Props) => { return ( <> @@ -113,7 +114,10 @@ export const TokenCountType = ({ field }: Props) => { - + {/* The "boost" parameter is deprecated since 8.x */} + {kibanaVersion.major < 8 && ( + + )} ); diff --git a/x-pack/plugins/index_management/public/application/index.tsx b/x-pack/plugins/index_management/public/application/index.tsx index 758470604fc5a..fc64dad0ae7ba 100644 --- a/x-pack/plugins/index_management/public/application/index.tsx +++ b/x-pack/plugins/index_management/public/application/index.tsx @@ -8,11 +8,16 @@ import React from 'react'; import { Provider } from 'react-redux'; import { render, unmountComponentAtNode } from 'react-dom'; +import { SemVer } from 'semver'; -import { CoreStart } from '../../../../../src/core/public'; +import { CoreStart, CoreSetup } from '../../../../../src/core/public'; import { API_BASE_PATH } from '../../common'; -import { createKibanaReactContext, GlobalFlyout } from '../shared_imports'; +import { + createKibanaReactContext, + GlobalFlyout, + useKibana as useKibanaReactPlugin, +} from '../shared_imports'; import { AppContextProvider, AppDependencies } from './app_context'; import { App } from './app'; @@ -31,12 +36,16 @@ export const renderApp = ( const { i18n, docLinks, notifications, application } = core; const { Context: I18nContext } = i18n; - const { services, history, setBreadcrumbs, uiSettings } = dependencies; + const { services, history, setBreadcrumbs, uiSettings, kibanaVersion } = dependencies; // uiSettings is required by the CodeEditor component used to edit runtime field Painless scripts. - const { Provider: KibanaReactContextProvider } = createKibanaReactContext({ - uiSettings, - }); + const { Provider: KibanaReactContextProvider } = + createKibanaReactContext({ + uiSettings, + kibanaVersion: { + get: () => kibanaVersion, + }, + }); const componentTemplateProviderValues = { httpClient: services.httpService.httpClient, @@ -72,4 +81,16 @@ export const renderApp = ( }; }; -export { AppDependencies }; +interface KibanaReactContextServices { + uiSettings: CoreSetup['uiSettings']; + kibanaVersion: { + get: () => SemVer; + }; +} + +// We override useKibana() from the react plugin to return a typed version for this app +const useKibana = () => { + return useKibanaReactPlugin(); +}; + +export { AppDependencies, useKibana }; diff --git a/x-pack/plugins/index_management/public/application/lib/indices.ts b/x-pack/plugins/index_management/public/application/lib/indices.ts index 71c3cc8e2a3c3..fc93aa6f54448 100644 --- a/x-pack/plugins/index_management/public/application/lib/indices.ts +++ b/x-pack/plugins/index_management/public/application/lib/indices.ts @@ -4,11 +4,12 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import SemVer from 'semver/classes/semver'; +import { SemVer } from 'semver'; + +import { MAJOR_VERSION } from '../../../common'; import { Index } from '../../../common'; -const version = '7.16.0'; -const kibanaVersion = new SemVer(version); +const kibanaVersion = new SemVer(MAJOR_VERSION); export const isHiddenIndex = (index: Index): boolean => { if (kibanaVersion.major < 8) { diff --git a/x-pack/plugins/index_management/public/application/mount_management_section.ts b/x-pack/plugins/index_management/public/application/mount_management_section.ts index 083a8831291dd..17ac095128a76 100644 --- a/x-pack/plugins/index_management/public/application/mount_management_section.ts +++ b/x-pack/plugins/index_management/public/application/mount_management_section.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { SemVer } from 'semver'; import { CoreSetup } from 'src/core/public'; import { ManagementAppMountParams } from 'src/plugins/management/public/'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/public'; @@ -50,7 +51,8 @@ export async function mountManagementSection( usageCollection: UsageCollectionSetup, params: ManagementAppMountParams, extensionsService: ExtensionsService, - isFleetEnabled: boolean + isFleetEnabled: boolean, + kibanaVersion: SemVer ) { const { element, setBreadcrumbs, history } = params; const [core, startDependencies] = await coreSetup.getStartServices(); @@ -88,6 +90,7 @@ export async function mountManagementSection( uiSettings, url, docLinks, + kibanaVersion, }; const unmountAppCallback = renderApp(element, { core, dependencies: appDependencies }); diff --git a/x-pack/plugins/index_management/public/application/store/selectors/indices_filter.test.ts b/x-pack/plugins/index_management/public/application/store/selectors/indices_filter.test.ts index 3e62878706a28..b32f2736a9684 100644 --- a/x-pack/plugins/index_management/public/application/store/selectors/indices_filter.test.ts +++ b/x-pack/plugins/index_management/public/application/store/selectors/indices_filter.test.ts @@ -4,15 +4,16 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import SemVer from 'semver/classes/semver'; +import { SemVer } from 'semver'; + +import { MAJOR_VERSION } from '../../../../common'; import { ExtensionsService } from '../../../services'; import { getFilteredIndices } from '.'; // @ts-ignore import { defaultTableState } from '../reducers/table_state'; import { setExtensionsService } from './extension_service'; -const version = '7.16.0'; -const kibanaVersion = new SemVer(version); +const kibanaVersion = new SemVer(MAJOR_VERSION); describe('getFilteredIndices selector', () => { let extensionService: ExtensionsService; diff --git a/x-pack/plugins/index_management/public/index.ts b/x-pack/plugins/index_management/public/index.ts index 10feabf0a9d0f..f9ccc788a36c0 100644 --- a/x-pack/plugins/index_management/public/index.ts +++ b/x-pack/plugins/index_management/public/index.ts @@ -6,11 +6,12 @@ */ import './index.scss'; +import { PluginInitializerContext } from 'src/core/public'; import { IndexMgmtUIPlugin } from './plugin'; /** @public */ -export const plugin = () => { - return new IndexMgmtUIPlugin(); +export const plugin = (ctx: PluginInitializerContext) => { + return new IndexMgmtUIPlugin(ctx); }; export { IndexManagementPluginSetup } from './types'; diff --git a/x-pack/plugins/index_management/public/plugin.ts b/x-pack/plugins/index_management/public/plugin.ts index 44854a9de9a0f..b7e810b15dbf9 100644 --- a/x-pack/plugins/index_management/public/plugin.ts +++ b/x-pack/plugins/index_management/public/plugin.ts @@ -6,8 +6,9 @@ */ import { i18n } from '@kbn/i18n'; +import { SemVer } from 'semver'; -import { CoreSetup } from '../../../../src/core/public'; +import { CoreSetup, PluginInitializerContext } from '../../../../src/core/public'; import { setExtensionsService } from './application/store/selectors/extension_service'; import { ExtensionsService } from './services'; @@ -20,7 +21,7 @@ import { PLUGIN } from '../common/constants/plugin'; export class IndexMgmtUIPlugin { private extensionsService = new ExtensionsService(); - constructor() { + constructor(private ctx: PluginInitializerContext) { // Temporary hack to provide the service instances in module files in order to avoid a big refactor // For the selectors we should expose them through app dependencies and read them from there on each container component. setExtensionsService(this.extensionsService); @@ -31,6 +32,7 @@ export class IndexMgmtUIPlugin { plugins: SetupDependencies ): IndexManagementPluginSetup { const { fleet, usageCollection, management } = plugins; + const kibanaVersion = new SemVer(this.ctx.env.packageInfo.version); management.sections.section.data.registerApp({ id: PLUGIN.id, @@ -43,7 +45,8 @@ export class IndexMgmtUIPlugin { usageCollection, params, this.extensionsService, - Boolean(fleet) + Boolean(fleet), + kibanaVersion ); }, }); diff --git a/x-pack/plugins/index_management/public/shared_imports.ts b/x-pack/plugins/index_management/public/shared_imports.ts index 275f8af818caf..4e1c420795904 100644 --- a/x-pack/plugins/index_management/public/shared_imports.ts +++ b/x-pack/plugins/index_management/public/shared_imports.ts @@ -56,4 +56,5 @@ export { isJSON } from '../../../../src/plugins/es_ui_shared/static/validators/s export { createKibanaReactContext, reactRouterNavigate, + useKibana, } from '../../../../src/plugins/kibana_react/public';