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 5094aa2763a0129..5b61ee0fdffead3 100644 --- a/x-pack/plugins/index_management/public/application/app_context.tsx +++ b/x-pack/plugins/index_management/public/application/app_context.tsx @@ -37,6 +37,7 @@ export interface AppDependencies { setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs']; uiSettings: CoreSetup['uiSettings']; urlGenerators: SharePluginStart['urlGenerators']; + docLinks: CoreStart['docLinks']; } export const AppContextProvider = ({ diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/analyzer_parameter.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/analyzer_parameter.tsx index 1457c4583aa0e8c..c613ddf282f0ad5 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/analyzer_parameter.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/analyzer_parameter.tsx @@ -16,7 +16,7 @@ import { SelectOption, SuperSelectOption, } from '../../../types'; -import { useIndexSettings } from '../../../index_settings_context'; +import { useConfig } from '../../../config_context'; import { AnalyzerParameterSelects } from './analyzer_parameter_selects'; interface Props { @@ -71,7 +71,9 @@ export const AnalyzerParameter = ({ allowsIndexDefaultOption = true, 'data-test-subj': dataTestSubj, }: Props) => { - const { value: indexSettings } = useIndexSettings(); + const { + value: { indexSettings }, + } = useConfig(); const customAnalyzers = getCustomAnalyzers(indexSettings); const analyzerOptions = allowsIndexDefaultOption ? ANALYZER_OPTIONS diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/runtime_fields/runtime_fields_list.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/runtime_fields/runtime_fields_list.tsx index b5a3fdf985a0026..e6dfd0143a7bab8 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/runtime_fields/runtime_fields_list.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/runtime_fields/runtime_fields_list.tsx @@ -15,6 +15,7 @@ import { RuntimeFieldEditorFlyoutContent, RuntimeFieldEditorFlyoutContentProps, } from '../../shared_imports'; +import { useConfig } from '../../config_context'; import { EmptyPrompt } from './empty_prompt'; import { RuntimeFieldsListItemContainer } from './runtimefields_list_item_container'; @@ -26,12 +27,18 @@ export const RuntimeFieldsList = () => { runtimeFields, runtimeFieldsList: { status, fieldToEdit }, } = useMappingsState(); + const dispatch = useDispatch(); + const { addContent: addContentToGlobalFlyout, removeContent: removeContentFromGlobalFlyout, } = useGlobalFlyout(); + const { + value: { docLinks }, + } = useConfig(); + const createField = useCallback(() => { dispatch({ type: 'runtimeFieldsList.createField' }); }, [dispatch]); @@ -66,11 +73,7 @@ export const RuntimeFieldsList = () => { onSave: saveRuntimeField, onCancel: exitEdit, defaultValue: fieldToEdit ? runtimeFields[fieldToEdit]?.source : undefined, - docLinks: { - DOC_LINK_VERSION: 'master', - ELASTIC_WEBSITE_URL: 'https://elastic.co', - links: {} as any, - }, + docLinks: docLinks!, }, flyoutProps: { 'data-test-subj': 'runtimeFieldEditor', @@ -87,6 +90,7 @@ export const RuntimeFieldsList = () => { status, fieldToEdit, runtimeFields, + docLinks, addContentToGlobalFlyout, removeContentFromGlobalFlyout, saveRuntimeField, diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/config_context.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/config_context.tsx new file mode 100644 index 000000000000000..84b42508f904a28 --- /dev/null +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/config_context.tsx @@ -0,0 +1,45 @@ +/* + * 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, { createContext, useContext, useState } from 'react'; + +import { DocLinksStart } from './shared_imports'; +import { IndexSettings } from './types'; + +interface ContextState { + indexSettings: IndexSettings; + docLinks?: DocLinksStart; +} + +interface Context { + value: ContextState; + update: (value: ContextState) => void; +} + +const ConfigContext = createContext(undefined); + +interface Props { + children: React.ReactNode; +} + +export const ConfigProvider = ({ children }: Props) => { + const [state, setState] = useState({ + indexSettings: {}, + }); + + return ( + + {children} + + ); +}; + +export const useConfig = () => { + const ctx = useContext(ConfigContext); + if (ctx === undefined) { + throw new Error('useConfig must be used within a '); + } + return ctx; +}; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/index_settings_context.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/index_settings_context.tsx deleted file mode 100644 index bd84c3a905ec8d8..000000000000000 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/index_settings_context.tsx +++ /dev/null @@ -1,34 +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; - * you may not use this file except in compliance with the Elastic License. - */ -import React, { createContext, useContext, useState } from 'react'; - -import { IndexSettings } from './types'; - -const IndexSettingsContext = createContext< - { value: IndexSettings; update: (value: IndexSettings) => void } | undefined ->(undefined); - -interface Props { - children: React.ReactNode; -} - -export const IndexSettingsProvider = ({ children }: Props) => { - const [state, setState] = useState({}); - - return ( - - {children} - - ); -}; - -export const useIndexSettings = () => { - const ctx = useContext(IndexSettingsContext); - if (ctx === undefined) { - throw new Error('useIndexSettings must be used within a '); - } - return ctx; -}; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor.tsx index 3c09a9bfae34342..a0bc1520bdaf749 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor.tsx @@ -27,7 +27,8 @@ import { import { extractMappingsDefinition } from './lib'; import { useMappingsState } from './mappings_state_context'; import { useMappingsStateListener } from './use_state_listener'; -import { useIndexSettings } from './index_settings_context'; +import { useConfig } from './config_context'; +import { DocLinksStart } from './shared_imports'; type TabName = 'fields' | 'runtimeFields' | 'advanced' | 'templates'; @@ -45,9 +46,10 @@ interface Props { onChange: OnUpdateHandler; value?: { [key: string]: any }; indexSettings?: IndexSettings; + docLinks: DocLinksStart; } -export const MappingsEditor = React.memo(({ onChange, value, indexSettings }: Props) => { +export const MappingsEditor = React.memo(({ onChange, value, docLinks, indexSettings }: Props) => { const { parsedDefaultValue, multipleMappingsDeclared } = useMemo< MappingsEditorParsedMetadata >(() => { @@ -99,12 +101,7 @@ export const MappingsEditor = React.memo(({ onChange, value, indexSettings }: Pr */ useMappingsStateListener({ onChange, value: parsedDefaultValue }); - // Update the Index settings context so it is available in the Global flyout - const { update: updateIndexSettings } = useIndexSettings(); - if (indexSettings !== undefined) { - updateIndexSettings(indexSettings); - } - + const { update: updateConfig } = useConfig(); const state = useMappingsState(); const [selectedTab, selectTab] = useState('fields'); @@ -119,6 +116,14 @@ export const MappingsEditor = React.memo(({ onChange, value, indexSettings }: Pr } }, [multipleMappingsDeclared, onChange, value]); + useEffect(() => { + // Update the the config context so it is available globally (e.g in our Global flyout) + updateConfig({ + docLinks, + indexSettings: indexSettings ?? {}, + }); + }, [updateConfig, docLinks, indexSettings]); + const changeTab = async (tab: TabName) => { if (selectedTab === 'advanced') { // When we navigate away we need to submit the form to validate if there are any errors. diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor_context.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor_context.tsx index 8e30d07c2262f2e..f4d827b631dd15d 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor_context.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/mappings_editor_context.tsx @@ -6,12 +6,12 @@ import React from 'react'; import { StateProvider } from './mappings_state_context'; -import { IndexSettingsProvider } from './index_settings_context'; +import { ConfigProvider } from './config_context'; export const MappingsEditorProvider: React.FC = ({ children }) => { return ( - {children} + {children} ); }; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/shared_imports.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/shared_imports.ts index 7ae024e039b806d..36f7fecbcff21ba 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/shared_imports.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/shared_imports.ts @@ -61,3 +61,5 @@ export { } from '../../../../../runtime_fields/public'; export { createKibanaReactContext } from '../../../../../../../src/plugins/kibana_react/public'; + +export { DocLinksStart } from '../../../../../../../src/core/public'; diff --git a/x-pack/plugins/index_management/public/application/components/shared/components/wizard_steps/step_mappings.tsx b/x-pack/plugins/index_management/public/application/components/shared/components/wizard_steps/step_mappings.tsx index bbf7a04080a28a9..aeb4eb793cde85f 100644 --- a/x-pack/plugins/index_management/public/application/components/shared/components/wizard_steps/step_mappings.tsx +++ b/x-pack/plugins/index_management/public/application/components/shared/components/wizard_steps/step_mappings.tsx @@ -16,6 +16,7 @@ import { } from '@elastic/eui'; import { Forms } from '../../../../../shared_imports'; +import { useAppContext } from '../../../../app_context'; import { MappingsEditor, OnUpdateHandler, @@ -33,6 +34,7 @@ interface Props { export const StepMappings: React.FunctionComponent = React.memo( ({ defaultValue = {}, onChange, indexSettings, esDocsBase }) => { const [mappings, setMappings] = useState(defaultValue); + const { docLinks } = useAppContext(); const onMappingsEditorUpdate = useCallback( ({ isValid, getData, validate }) => { @@ -107,6 +109,7 @@ export const StepMappings: React.FunctionComponent = React.memo( value={mappings} onChange={onMappingsEditorUpdate} indexSettings={indexSettings} + docLinks={docLinks} /> 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 c15af4f19827b9f..6707f3a7d937c2a 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 @@ -64,6 +64,7 @@ export async function mountManagementSection( setBreadcrumbs, uiSettings, urlGenerators, + docLinks, }; const unmountAppCallback = renderApp(element, { core, dependencies: appDependencies });