From 12020b0d4bc1b715b200a641a88bff610eb3cf8d Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 13 Dec 2023 17:13:43 +0100 Subject: [PATCH 01/12] Move FeatureFeedbackButton to obs shared to make it sharable between infra and APM --- .../infra/public/pages/metrics/hosts/index.tsx | 10 ++++++++-- .../components/survey_kubernetes.tsx | 12 +++++++++++- .../components/survey_section.tsx | 9 ++++++++- .../pages/metrics/metrics_explorer/index.tsx | 10 ++++++++-- .../feature_feedback_button.tsx | 17 +++++++++++------ .../observability_shared/public/index.ts | 1 + 6 files changed, 47 insertions(+), 12 deletions(-) rename x-pack/plugins/{infra/public/components => observability_shared/public/components/feature_feedback_button}/feature_feedback_button.tsx (82%) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx index 7d170ee9e9cea..f679712edab02 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx @@ -7,11 +7,11 @@ import { EuiErrorBoundary } from '@elastic/eui'; import React from 'react'; -import { useTrackPageview } from '@kbn/observability-shared-plugin/public'; +import { useTrackPageview, FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; import { APP_WRAPPER_CLASS } from '@kbn/core/public'; import { css } from '@emotion/react'; import { i18n } from '@kbn/i18n'; -import { FeatureFeedbackButton } from '../../../components/feature_feedback_button'; +import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { SourceErrorPage } from '../../../components/source_error_page'; import { SourceLoadingPage } from '../../../components/source_loading_page'; import { useSourceContext } from '../../../containers/metrics_source'; @@ -29,6 +29,9 @@ const HOSTS_FEEDBACK_LINK = export const HostsPage = () => { const { isLoading, loadSourceFailureMessage, loadSource, source } = useSourceContext(); + const { + services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + } = useKibanaContextForPlugin(); useTrackPageview({ app: 'infra_metrics', path: 'hosts' }); useTrackPageview({ app: 'infra_metrics', path: 'hosts', delay: 15000 }); @@ -84,6 +87,9 @@ export const HostsPage = () => { , ], }} diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx index c213e08a064f1..6172e01a483e3 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx @@ -9,7 +9,8 @@ import { EuiFlexGroup, EuiFlexItem, EuiGlobalToastList } from '@elastic/eui'; import React from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import useLocalStorage from 'react-use/lib/useLocalStorage'; -import { FeatureFeedbackButton } from '../../../../components/feature_feedback_button'; +import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; +import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana'; const KUBERNETES_TOAST_STORAGE_KEY = 'kubernetesToastKey'; const KUBERNETES_FEEDBACK_LINK = 'https://ela.st/k8s-feedback'; @@ -17,12 +18,18 @@ const KUBERNETES_FEEDBACK_LINK = 'https://ela.st/k8s-feedback'; export const SurveyKubernetes = () => { const [isToastSeen, setIsToastSeen] = useLocalStorage(KUBERNETES_TOAST_STORAGE_KEY, false); const markToastAsSeen = () => setIsToastSeen(true); + const { + services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + } = useKibanaContextForPlugin(); return ( <> { data-test-subj="infra-toast-kubernetes-survey-start" onClickCapture={markToastAsSeen} defaultButton={true} + kibanaVersion={kibanaVersion} + isCloudEnv={isCloudEnv} + isServerlessEnv={isServerlessEnv} surveyButtonText={ , ], }} diff --git a/x-pack/plugins/infra/public/components/feature_feedback_button.tsx b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx similarity index 82% rename from x-pack/plugins/infra/public/components/feature_feedback_button.tsx rename to x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx index f550fb0337bb4..ad1733dc69e79 100644 --- a/x-pack/plugins/infra/public/components/feature_feedback_button.tsx +++ b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx @@ -8,12 +8,11 @@ import React, { ReactElement } from 'react'; import { EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import { useKibanaContextForPlugin } from '../hooks/use_kibana'; const KIBANA_VERSION_QUERY_PARAM = 'entry.548460210'; const KIBANA_DEPLOYMENT_TYPE_PARAM = 'entry.573002982'; -const getDeploymentType = (isCloudEnv: boolean, isServerlessEnv: boolean): string | undefined => { +const getDeploymentType = (isCloudEnv?: boolean, isServerlessEnv?: boolean): string | undefined => { if (isServerlessEnv) { return 'Serverless (fully-managed projects)'; } @@ -41,6 +40,9 @@ interface FeatureFeedbackButtonProps { surveyButtonText?: ReactElement; onClickCapture?: () => void; defaultButton?: boolean; + kibanaVersion?: string; + isCloudEnv?: boolean; + isServerlessEnv?: boolean; } export const FeatureFeedbackButton = ({ @@ -48,6 +50,9 @@ export const FeatureFeedbackButton = ({ 'data-test-subj': dts, onClickCapture, defaultButton, + kibanaVersion, + isCloudEnv, + isServerlessEnv, surveyButtonText = ( ), }: FeatureFeedbackButtonProps) => { - const { - services: { kibanaVersion, isCloudEnv, isServerlessEnv }, - } = useKibanaContextForPlugin(); + const deploymentType = + isCloudEnv !== undefined || isServerlessEnv !== undefined + ? getDeploymentType(isCloudEnv, isServerlessEnv) + : undefined; - const deploymentType = getDeploymentType(isCloudEnv, isServerlessEnv); return ( Date: Mon, 18 Dec 2023 17:21:16 +0100 Subject: [PATCH 02/12] [WIP] APM feedback link --- .../routing/templates/apm_main_template.tsx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx index 5f9a68c0852dc..5b30d0594cc12 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx @@ -11,6 +11,7 @@ import { ObservabilityPageTemplateProps } from '@kbn/observability-shared-plugin import type { KibanaPageTemplateProps } from '@kbn/shared-ux-page-kibana-template'; import React from 'react'; import { useLocation } from 'react-router-dom'; +import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; import { EnvironmentsContextProvider } from '../../../context/environments_context/environments_context'; import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher'; import { ApmPluginStartDeps } from '../../../plugin'; @@ -19,9 +20,11 @@ import { ServiceGroupsButtonGroup } from '../../app/service_groups/service_group import { ApmEnvironmentFilter } from '../../shared/environment_filter'; import { getNoDataConfig } from './no_data_config'; import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context'; +// import { useDiagnosticsContext } from '../../app/diagnostics/context/use_diagnostics'; // Paths that must skip the no data screen const bypassNoDataScreenPaths = ['/settings', '/diagnostics']; +const APM_FEEDBACK_LINK = 'https://ela.st/services-feedback'; /* * This template contains: @@ -54,6 +57,7 @@ export function ApmMainTemplate({ } & KibanaPageTemplateProps & Pick) { const location = useLocation(); + // const { diagnosticsBundle } = useDiagnosticsContext(); const { services } = useKibana(); const { http, docLinks, observabilityShared, application } = services; @@ -66,7 +70,7 @@ export function ApmMainTemplate({ return callApmApi('GET /internal/apm/has_data'); }, []); - // create static data view on inital load + // create static data view on initial load useFetcher( (callApmApi) => { const canCreateDataView = @@ -115,7 +119,22 @@ export function ApmMainTemplate({ {pageHeader?.pageTitle ?? pageTitle} - {environmentFilter && } + + + + + + {environmentFilter && } + + ); From d9ff619d8da0081ab4be2feaa45f23b9ada91a8a Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 19 Dec 2023 16:43:32 +0100 Subject: [PATCH 03/12] Add kibana version and cluster type to APM feedback link --- .../routing/templates/apm_main_template.tsx | 18 +++++++++----- x-pack/plugins/apm/public/plugin.ts | 24 ++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx index 5b30d0594cc12..06b76a847c276 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx @@ -60,7 +60,15 @@ export function ApmMainTemplate({ // const { diagnosticsBundle } = useDiagnosticsContext(); const { services } = useKibana(); - const { http, docLinks, observabilityShared, application } = services; + const { + http, + docLinks, + observabilityShared, + application, + kibanaVersion, + isCloudEnv, + isServerlessEnv, + } = services; const basePath = http?.basePath.get(); const { config } = useApmPluginContext(); @@ -124,11 +132,9 @@ export function ApmMainTemplate({ diff --git a/x-pack/plugins/apm/public/plugin.ts b/x-pack/plugins/apm/public/plugin.ts index 173e52e5955cd..ac8e392b983fc 100644 --- a/x-pack/plugins/apm/public/plugin.ts +++ b/x-pack/plugins/apm/public/plugin.ts @@ -72,6 +72,7 @@ import { UsageCollectionStart } from '@kbn/usage-collection-plugin/public'; import { DashboardStart } from '@kbn/dashboard-plugin/public'; import { from } from 'rxjs'; import { map } from 'rxjs/operators'; +import type { CloudSetup } from '@kbn/cloud-plugin/public'; import type { ConfigSchema } from '.'; import { registerApmRuleTypes } from './components/alerting/rule_types/register_apm_rule_types'; import { @@ -104,6 +105,7 @@ export interface ApmPluginSetupDeps { share: SharePluginSetup; uiActions: UiActionsSetup; profiling?: ProfilingPluginSetup; + cloud?: CloudSetup; } export interface ApmServices { @@ -137,6 +139,9 @@ export interface ApmPluginStartDeps { observabilityAIAssistant: ObservabilityAIAssistantPluginStart; dashboard: DashboardStart; metricsDataAccess: MetricsDataPluginStart; + kibanaVersion?: string; + isCloudEnv: boolean; + isServerlessEnv: boolean; } const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', { @@ -187,11 +192,16 @@ const apmTutorialTitle = i18n.translate( export class ApmPlugin implements Plugin { private telemetry: TelemetryService; + private kibanaVersion: string; + private isServerlessEnv: boolean; constructor( private readonly initializerContext: PluginInitializerContext ) { this.initializerContext = initializerContext; this.telemetry = new TelemetryService(); + this.kibanaVersion = initializerContext.env.packageInfo.version; + this.isServerlessEnv = + initializerContext.env.packageInfo.buildFlavor === 'serverless'; } public setup(core: CoreSetup, plugins: ApmPluginSetupDeps) { @@ -393,18 +403,26 @@ export class ApmPlugin implements Plugin { { id: 'tutorial', title: apmTutorialTitle, path: '/tutorial' }, ], - async mount(appMountParameters: AppMountParameters) { + mount: async (appMountParameters: AppMountParameters) => { // Load application bundle and Get start services const [{ renderApp }, [coreStart, pluginsStart]] = await Promise.all([ import('./application'), core.getStartServices(), ]); + const isCloudEnv = !!pluginSetupDeps.cloud?.isCloudEnabled; + const isServerlessEnv = + pluginSetupDeps.cloud?.isServerlessEnabled || this.isServerlessEnv; return renderApp({ coreStart, - pluginsSetup: pluginSetupDeps, + pluginsSetup: pluginSetupDeps as ApmPluginSetupDeps, appMountParameters, config, - pluginsStart: pluginsStart as ApmPluginStartDeps, + pluginsStart: { + ...pluginsStart, + isCloudEnv, + isServerlessEnv, + kibanaVersion: this.kibanaVersion, + } as ApmPluginStartDeps, observabilityRuleTypeRegistry, apmServices: { telemetry, From ab3f1c4150eaf89a0dddfa083d2ed4ca1a573238 Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 19 Dec 2023 19:34:36 +0100 Subject: [PATCH 04/12] Add sanitized path to the feedback url --- .../routing/templates/apm_main_template.tsx | 5 +- .../utils/get_path_for_feedback.test.ts | 56 +++++++++++++++++++ .../apm/public/utils/get_path_for_feedback.ts | 26 +++++++++ .../feature_feedback_button.tsx | 15 ++++- 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 x-pack/plugins/apm/public/utils/get_path_for_feedback.test.ts create mode 100644 x-pack/plugins/apm/public/utils/get_path_for_feedback.ts diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx index 06b76a847c276..e46ede5ca96e6 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx @@ -12,6 +12,7 @@ import type { KibanaPageTemplateProps } from '@kbn/shared-ux-page-kibana-templat import React from 'react'; import { useLocation } from 'react-router-dom'; import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; +import { getPathForFeedback } from '../../../utils/get_path_for_feedback'; import { EnvironmentsContextProvider } from '../../../context/environments_context/environments_context'; import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher'; import { ApmPluginStartDeps } from '../../../plugin'; @@ -20,7 +21,6 @@ import { ServiceGroupsButtonGroup } from '../../app/service_groups/service_group import { ApmEnvironmentFilter } from '../../shared/environment_filter'; import { getNoDataConfig } from './no_data_config'; import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context'; -// import { useDiagnosticsContext } from '../../app/diagnostics/context/use_diagnostics'; // Paths that must skip the no data screen const bypassNoDataScreenPaths = ['/settings', '/diagnostics']; @@ -57,7 +57,6 @@ export function ApmMainTemplate({ } & KibanaPageTemplateProps & Pick) { const location = useLocation(); - // const { diagnosticsBundle } = useDiagnosticsContext(); const { services } = useKibana(); const { @@ -123,6 +122,7 @@ export function ApmMainTemplate({ ...(showServiceGroupSaveButton ? [] : []), ]; + const sanitizedPath = getPathForFeedback(window.location.pathname); const pageHeaderTitle = ( {pageHeader?.pageTitle ?? pageTitle} @@ -135,6 +135,7 @@ export function ApmMainTemplate({ kibanaVersion={kibanaVersion} isCloudEnv={isCloudEnv} isServerlessEnv={isServerlessEnv} + sanitizedPath={sanitizedPath} /> diff --git a/x-pack/plugins/apm/public/utils/get_path_for_feedback.test.ts b/x-pack/plugins/apm/public/utils/get_path_for_feedback.test.ts new file mode 100644 index 0000000000000..d8ee4c771a660 --- /dev/null +++ b/x-pack/plugins/apm/public/utils/get_path_for_feedback.test.ts @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import { getPathForFeedback } from './get_path_for_feedback'; + +describe('getPathForFeedback ', () => { + const testData = [ + { value: `/ftw/app/apm/traces`, result: '/app/apm/traces' }, + { value: `/app/apm/traces`, result: '/app/apm/traces' }, + { + value: `/ftw/app/apm/traces/frontend/transactions/view`, + result: '/app/apm/traces*', + }, + { value: `/app/apm/services`, result: '/app/apm/services' }, + { + value: `/longer/path/before/app/apm/services`, + result: '/app/apm/services', + }, + { + value: `/ftw/app/apm/services/long/path/after/services`, + result: '/app/apm/services*', + }, + { + value: `/ftw/app/apm/dependencies/frontend/transactions/view`, + result: '/app/apm/dependencies*', + }, + { value: `/app/apm/dependencies`, result: '/app/apm/dependencies' }, + { + value: `/ftw/app/apm/dependencies/frontend/transactions/view`, + result: '/app/apm/dependencies*', + }, + { + value: `/ftw/app/apm/settings/frontend/transactions/view`, + result: '/app/apm/settings*', + }, + { + value: `/app/apm/some-page/frontend/transactions/view`, + result: '/app/apm/some-page*', + }, + { + value: `/app/apm/settings`, + result: '/app/apm/settings', + }, + ]; + + it.each(testData)( + 'Returns correct path for the feedback form $value -> $result', + ({ value, result }) => { + expect(getPathForFeedback(value)).toBe(result); + } + ); +}); diff --git a/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts b/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts new file mode 100644 index 0000000000000..7bd86c672aeeb --- /dev/null +++ b/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts @@ -0,0 +1,26 @@ +/* + * 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 shortenPath = (path: string, pathStart: string) => { + if (path.startsWith(pathStart)) { + return path; + } + const indexOfPathStart = path.indexOf(pathStart); + return path.substring(indexOfPathStart); +}; + +export const getPathForFeedback = (path: string) => { + const pathStartingFromApp = shortenPath(path, '/app'); + const pathParts = pathStartingFromApp.split('/'); + const constructPath = `/${[pathParts[1], pathParts[2], pathParts[3]].join( + '/' + )}`; + if (pathStartingFromApp === constructPath) { + return pathStartingFromApp; + } + return `${constructPath}*`; +}; diff --git a/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx index ad1733dc69e79..4be7848cd0403 100644 --- a/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx +++ b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx @@ -11,6 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; const KIBANA_VERSION_QUERY_PARAM = 'entry.548460210'; const KIBANA_DEPLOYMENT_TYPE_PARAM = 'entry.573002982'; +const SANITIZED_PATH_PARAM = 'entry.1876422621'; const getDeploymentType = (isCloudEnv?: boolean, isServerlessEnv?: boolean): string | undefined => { if (isServerlessEnv) { @@ -22,7 +23,12 @@ const getDeploymentType = (isCloudEnv?: boolean, isServerlessEnv?: boolean): str return 'Self-Managed (you manage)'; }; -const getSurveyFeedbackURL = (formUrl: string, kibanaVersion?: string, deploymentType?: string) => { +const getSurveyFeedbackURL = ( + formUrl: string, + kibanaVersion?: string, + deploymentType?: string, + sanitizedPath?: string +) => { const url = new URL(formUrl); if (kibanaVersion) { url.searchParams.append(KIBANA_VERSION_QUERY_PARAM, kibanaVersion); @@ -30,6 +36,9 @@ const getSurveyFeedbackURL = (formUrl: string, kibanaVersion?: string, deploymen if (deploymentType) { url.searchParams.append(KIBANA_DEPLOYMENT_TYPE_PARAM, deploymentType); } + if (sanitizedPath) { + url.searchParams.append(SANITIZED_PATH_PARAM, sanitizedPath); + } return url.href; }; @@ -43,6 +52,7 @@ interface FeatureFeedbackButtonProps { kibanaVersion?: string; isCloudEnv?: boolean; isServerlessEnv?: boolean; + sanitizedPath?: string; } export const FeatureFeedbackButton = ({ @@ -53,6 +63,7 @@ export const FeatureFeedbackButton = ({ kibanaVersion, isCloudEnv, isServerlessEnv, + sanitizedPath, surveyButtonText = ( Date: Wed, 20 Dec 2023 16:59:22 +0100 Subject: [PATCH 05/12] Update translation key --- .../feature_feedback_button/feature_feedback_button.tsx | 2 +- x-pack/plugins/translations/translations/fr-FR.json | 2 +- x-pack/plugins/translations/translations/ja-JP.json | 2 +- x-pack/plugins/translations/translations/zh-CN.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx index 4be7848cd0403..c8e684294dc0f 100644 --- a/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx +++ b/x-pack/plugins/observability_shared/public/components/feature_feedback_button/feature_feedback_button.tsx @@ -66,7 +66,7 @@ export const FeatureFeedbackButton = ({ sanitizedPath, surveyButtonText = ( ), diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 11753ac3dc20d..23b65d663aa80 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -20185,7 +20185,7 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "Voir les instructions de configuration", "xpack.infra.homePage.settingsTabTitle": "Paramètres", "xpack.infra.homePage.tellUsWhatYouThinkK8sLink": "Dites-nous ce que vous pensez ! (K8s)", - "xpack.infra.homePage.tellUsWhatYouThinkLink": "Dites-nous ce que vous pensez !", + "xpack.observabilityShared.featureFeedbackButton.tellUsWhatYouThinkLink": "Dites-nous ce que vous pensez !", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "Rechercher des données d'infrastructure… (par exemple host.name:host-1)", "xpack.infra.hostFlyout.explainProcessMessageTitle": "Quel est ce processus ?", "xpack.infra.hosts.searchPlaceholder": "Rechercher dans les hôtes (par ex. cloud.provider:gcp AND system.load.1 > 0.5)", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 0e37dee1b2e73..4314f14b69366 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -20198,7 +20198,7 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "セットアップの手順を表示", "xpack.infra.homePage.settingsTabTitle": "設定", "xpack.infra.homePage.tellUsWhatYouThinkK8sLink": "ご意見をお聞かせください。(K8s)", - "xpack.infra.homePage.tellUsWhatYouThinkLink": "ご意見をお聞かせください。", + "xpack.observabilityShared.featureFeedbackButton.tellUsWhatYouThinkLink": "ご意見をお聞かせください。", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "インフラストラクチャーデータを検索…(例:host.name:host-1)", "xpack.infra.hostFlyout.explainProcessMessageTitle": "このプロセスの概要", "xpack.infra.hosts.searchPlaceholder": "ホストを検索(例:cloud.provider:gcp AND system.load.1 > 0.5)", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 42adf8d8f7172..b893b4dcf59c0 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -20198,7 +20198,7 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "查看设置说明", "xpack.infra.homePage.settingsTabTitle": "设置", "xpack.infra.homePage.tellUsWhatYouThinkK8sLink": "告诉我们您的看法!(K8s)", - "xpack.infra.homePage.tellUsWhatYouThinkLink": "告诉我们您的看法!", + "xpack.observabilityShared.featureFeedbackButton.tellUsWhatYouThinkLink": "告诉我们您的看法!", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "搜索基础设施数据……(例如 host.name:host-1)", "xpack.infra.hostFlyout.explainProcessMessageTitle": "此进程是什么?", "xpack.infra.hosts.searchPlaceholder": "搜索主机(例如,cloud.provider:gcp AND system.load.1 > 0.5)", From c496655efa2fb1a1550546e8bd6aa27f9f9d0bef Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 21 Dec 2023 14:20:16 +0100 Subject: [PATCH 06/12] CR Changes --- x-pack/plugins/apm/public/utils/get_path_for_feedback.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts b/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts index 7bd86c672aeeb..a8fafc0949629 100644 --- a/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts +++ b/x-pack/plugins/apm/public/utils/get_path_for_feedback.ts @@ -5,6 +5,8 @@ * 2.0. */ +const APP_BASE_PATH = '/app'; + export const shortenPath = (path: string, pathStart: string) => { if (path.startsWith(pathStart)) { return path; @@ -14,11 +16,9 @@ export const shortenPath = (path: string, pathStart: string) => { }; export const getPathForFeedback = (path: string) => { - const pathStartingFromApp = shortenPath(path, '/app'); + const pathStartingFromApp = shortenPath(path, APP_BASE_PATH); const pathParts = pathStartingFromApp.split('/'); - const constructPath = `/${[pathParts[1], pathParts[2], pathParts[3]].join( - '/' - )}`; + const constructPath = `/${pathParts.slice(1, 4).join('/')}`; if (pathStartingFromApp === constructPath) { return pathStartingFromApp; } From aaadb14d60cd9da76ea4a523148061201324a36e Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 21 Dec 2023 16:33:35 +0100 Subject: [PATCH 07/12] CR change: extract to kibanaEnvironment --- .../kibana_react/public/context/context.tsx | 25 ++++++++++++++----- .../kibana_react/public/context/types.ts | 8 +++++- .../components/routing/app_root/index.tsx | 5 ++++ .../routing/templates/apm_main_template.tsx | 13 +++------- .../plugins/infra/public/hooks/use_kibana.tsx | 18 ++++++++----- .../public/pages/metrics/hosts/index.tsx | 2 +- .../components/survey_kubernetes.tsx | 2 +- .../components/survey_section.tsx | 2 +- .../pages/metrics/metrics_explorer/index.tsx | 2 +- 9 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/plugins/kibana_react/public/context/context.tsx b/src/plugins/kibana_react/public/context/context.tsx index 8c32bdab69b31..fd81bb34e9861 100644 --- a/src/plugins/kibana_react/public/context/context.tsx +++ b/src/plugins/kibana_react/public/context/context.tsx @@ -7,7 +7,12 @@ */ import * as React from 'react'; -import { KibanaReactContext, KibanaReactContextValue, KibanaServices } from './types'; +import type { + KibanaEnvironment, + KibanaReactContext, + KibanaReactContextValue, + KibanaServices, +} from './types'; import { createReactOverlays } from '../overlays'; import { createNotifications } from '../notifications'; @@ -15,6 +20,7 @@ const { useMemo, useContext, createElement, createContext } = React; const defaultContextValue = { services: {}, + kibanaEnvironment: {}, overlays: createReactOverlays({}), notifications: createNotifications({}), }; @@ -37,22 +43,29 @@ export const withKibana = } }; export const createKibanaReactContext = ( - services: Services + services: Services, + kibanaEnvironment?: KibanaEnvironment ): KibanaReactContext => { const value: KibanaReactContextValue = { services, overlays: createReactOverlays(services), notifications: createNotifications(services), + kibanaEnvironment: kibanaEnvironment ?? {}, }; - const Provider: React.FC<{ services?: Services }> = ({ + const Provider: React.FC<{ services?: Services; kibanaEnvironment?: KibanaEnvironment }> = ({ services: newServices = {}, + kibanaEnvironment: newKibanaEnvironment = {}, children, }) => { const oldValue = useKibana(); const { value: newValue } = useMemo( - () => createKibanaReactContext({ ...services, ...oldValue.services, ...newServices }), - [services, oldValue, newServices] + () => + createKibanaReactContext( + { ...services, ...oldValue.services, ...newServices }, + { ...kibanaEnvironment, ...oldValue.kibanaEnvironment, ...newKibanaEnvironment } + ), + [services, oldValue, newServices, kibanaEnvironment, newKibanaEnvironment] ); const newProvider = createElement(context.Provider, { @@ -70,4 +83,4 @@ export const createKibanaReactContext = ( }; }; -export const { Provider: KibanaContextProvider } = createKibanaReactContext({}); +export const { Provider: KibanaContextProvider } = createKibanaReactContext({}, {}); diff --git a/src/plugins/kibana_react/public/context/types.ts b/src/plugins/kibana_react/public/context/types.ts index 4962267974d79..7307611defe59 100644 --- a/src/plugins/kibana_react/public/context/types.ts +++ b/src/plugins/kibana_react/public/context/types.ts @@ -12,15 +12,21 @@ import { KibanaReactOverlays } from '../overlays'; import { KibanaReactNotifications } from '../notifications'; export type KibanaServices = Partial; +export interface KibanaEnvironment { + kibanaVersion?: string; + isCloudEnv?: boolean; + isServerlessEnv?: boolean; +} export interface KibanaReactContextValue { readonly services: Services; + readonly kibanaEnvironment: KibanaEnvironment; readonly overlays: KibanaReactOverlays; readonly notifications: KibanaReactNotifications; } export interface KibanaReactContext { value: KibanaReactContextValue; - Provider: React.FC<{ services?: T }>; + Provider: React.FC<{ services?: T; kibanaEnvironment?: KibanaEnvironment }>; Consumer: React.Consumer>; } diff --git a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx index 85df672363ce1..b4ff66d12629d 100644 --- a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx @@ -72,6 +72,11 @@ export function ApmAppRoot({ diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx index e46ede5ca96e6..a9ad169aa23a6 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx @@ -58,16 +58,9 @@ export function ApmMainTemplate({ Pick) { const location = useLocation(); - const { services } = useKibana(); - const { - http, - docLinks, - observabilityShared, - application, - kibanaVersion, - isCloudEnv, - isServerlessEnv, - } = services; + const { services, kibanaEnvironment } = useKibana(); + const { http, docLinks, observabilityShared, application } = services; + const { kibanaVersion, isCloudEnv, isServerlessEnv } = kibanaEnvironment; const basePath = http?.basePath.get(); const { config } = useApmPluginContext(); diff --git a/x-pack/plugins/infra/public/hooks/use_kibana.tsx b/x-pack/plugins/infra/public/hooks/use_kibana.tsx index 0055d01a23bec..f1b83f6a229f5 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana.tsx +++ b/x-pack/plugins/infra/public/hooks/use_kibana.tsx @@ -22,11 +22,18 @@ export const createKibanaContextForPlugin = ( plugins: InfraClientStartDeps, pluginStart: InfraClientStartExports ) => - createKibanaReactContext({ - ...core, - ...plugins, - ...pluginStart, - }); + createKibanaReactContext( + { + ...core, + ...plugins, + ...pluginStart, + }, + { + kibanaVersion: plugins.kibanaVersion, + isCloudEnv: plugins.isCloudEnv, + isServerlessEnv: plugins.isServerlessEnv, + } + ); export const useKibanaContextForPlugin = useKibana as () => KibanaReactContextValue; @@ -40,7 +47,6 @@ export const useKibanaContextForPluginProvider = ( () => createKibanaContextForPlugin(core, plugins, pluginStart), [core, pluginStart, plugins] ); - return Provider; }; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx index f679712edab02..726f501c6be71 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx @@ -30,7 +30,7 @@ const HOSTS_FEEDBACK_LINK = export const HostsPage = () => { const { isLoading, loadSourceFailureMessage, loadSource, source } = useSourceContext(); const { - services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, } = useKibanaContextForPlugin(); useTrackPageview({ app: 'infra_metrics', path: 'hosts' }); diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx index 6172e01a483e3..3f0448942f738 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx @@ -19,7 +19,7 @@ export const SurveyKubernetes = () => { const [isToastSeen, setIsToastSeen] = useLocalStorage(KUBERNETES_TOAST_STORAGE_KEY, false); const markToastAsSeen = () => setIsToastSeen(true); const { - services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, } = useKibanaContextForPlugin(); return ( diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx index 96f3a68cad800..840522efa1722 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx @@ -17,7 +17,7 @@ const INVENTORY_FEEDBACK_LINK = 'https://ela.st/survey-infra-inventory?usp=pp_ur export const SurveySection = () => { const { nodeType } = useWaffleOptionsContext(); const { - services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, } = useKibanaContextForPlugin(); return ( diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx index fbd64757ed97d..061768e2a8042 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx @@ -53,7 +53,7 @@ export const MetricsExplorerPage = ({ source, derivedIndexPattern }: MetricsExpl const { currentView } = useMetricsExplorerViews(); const { source: sourceContext, metricIndicesExist } = useSourceContext(); const { - services: { kibanaVersion, isCloudEnv, isServerlessEnv }, + kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, } = useKibanaContextForPlugin(); useTrackPageview({ app: 'infra_metrics', path: 'metrics_explorer' }); From 894d6886b68377b4790f11770e0cdbcff44b60e2 Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 3 Jan 2024 14:29:15 +0100 Subject: [PATCH 08/12] Move KibanaEnvironmentContext to apm and infra --- .../kibana_react/public/context/context.tsx | 25 ++---- .../kibana_react/public/context/types.ts | 8 +- .../components/routing/app_root/index.tsx | 88 +++++++++---------- .../routing/templates/apm_main_template.tsx | 6 +- .../kibana_environment_context.tsx | 16 ++++ .../use_kibana_environment_context.tsx | 40 +++++++++ .../infra/public/apps/common_providers.tsx | 15 +++- .../plugins/infra/public/hooks/use_kibana.tsx | 52 ++++++++--- .../public/pages/metrics/hosts/index.tsx | 8 +- .../components/survey_kubernetes.tsx | 9 +- .../components/survey_section.tsx | 8 +- .../pages/metrics/metrics_explorer/index.tsx | 8 +- 12 files changed, 174 insertions(+), 109 deletions(-) create mode 100644 x-pack/plugins/apm/public/context/kibana_environment_context/kibana_environment_context.tsx create mode 100644 x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx diff --git a/src/plugins/kibana_react/public/context/context.tsx b/src/plugins/kibana_react/public/context/context.tsx index fd81bb34e9861..8c32bdab69b31 100644 --- a/src/plugins/kibana_react/public/context/context.tsx +++ b/src/plugins/kibana_react/public/context/context.tsx @@ -7,12 +7,7 @@ */ import * as React from 'react'; -import type { - KibanaEnvironment, - KibanaReactContext, - KibanaReactContextValue, - KibanaServices, -} from './types'; +import { KibanaReactContext, KibanaReactContextValue, KibanaServices } from './types'; import { createReactOverlays } from '../overlays'; import { createNotifications } from '../notifications'; @@ -20,7 +15,6 @@ const { useMemo, useContext, createElement, createContext } = React; const defaultContextValue = { services: {}, - kibanaEnvironment: {}, overlays: createReactOverlays({}), notifications: createNotifications({}), }; @@ -43,29 +37,22 @@ export const withKibana = } }; export const createKibanaReactContext = ( - services: Services, - kibanaEnvironment?: KibanaEnvironment + services: Services ): KibanaReactContext => { const value: KibanaReactContextValue = { services, overlays: createReactOverlays(services), notifications: createNotifications(services), - kibanaEnvironment: kibanaEnvironment ?? {}, }; - const Provider: React.FC<{ services?: Services; kibanaEnvironment?: KibanaEnvironment }> = ({ + const Provider: React.FC<{ services?: Services }> = ({ services: newServices = {}, - kibanaEnvironment: newKibanaEnvironment = {}, children, }) => { const oldValue = useKibana(); const { value: newValue } = useMemo( - () => - createKibanaReactContext( - { ...services, ...oldValue.services, ...newServices }, - { ...kibanaEnvironment, ...oldValue.kibanaEnvironment, ...newKibanaEnvironment } - ), - [services, oldValue, newServices, kibanaEnvironment, newKibanaEnvironment] + () => createKibanaReactContext({ ...services, ...oldValue.services, ...newServices }), + [services, oldValue, newServices] ); const newProvider = createElement(context.Provider, { @@ -83,4 +70,4 @@ export const createKibanaReactContext = ( }; }; -export const { Provider: KibanaContextProvider } = createKibanaReactContext({}, {}); +export const { Provider: KibanaContextProvider } = createKibanaReactContext({}); diff --git a/src/plugins/kibana_react/public/context/types.ts b/src/plugins/kibana_react/public/context/types.ts index 7307611defe59..4962267974d79 100644 --- a/src/plugins/kibana_react/public/context/types.ts +++ b/src/plugins/kibana_react/public/context/types.ts @@ -12,21 +12,15 @@ import { KibanaReactOverlays } from '../overlays'; import { KibanaReactNotifications } from '../notifications'; export type KibanaServices = Partial; -export interface KibanaEnvironment { - kibanaVersion?: string; - isCloudEnv?: boolean; - isServerlessEnv?: boolean; -} export interface KibanaReactContextValue { readonly services: Services; - readonly kibanaEnvironment: KibanaEnvironment; readonly overlays: KibanaReactOverlays; readonly notifications: KibanaReactNotifications; } export interface KibanaReactContext { value: KibanaReactContextValue; - Provider: React.FC<{ services?: T; kibanaEnvironment?: KibanaEnvironment }>; + Provider: React.FC<{ services?: T }>; Consumer: React.Consumer>; } diff --git a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx index 0a18ebb584898..d540730dfbca0 100644 --- a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx @@ -21,6 +21,7 @@ import { RouteRenderer, RouterProvider } from '@kbn/typed-react-router-config'; import { euiDarkVars, euiLightVars } from '@kbn/ui-theme'; import React from 'react'; import { DefaultTheme, ThemeProvider } from 'styled-components'; +import { useKibanaEnvironmentContextProvider } from '../../../context/kibana_environment_context/use_kibana_environment_context'; import { AnomalyDetectionJobsContextProvider } from '../../../context/anomaly_detection_jobs/anomaly_detection_jobs_context'; import { ApmPluginContext, @@ -55,6 +56,8 @@ export function ApmAppRoot({ apmServices: ApmServices; }) { const { appMountParameters, core } = apmPluginContextValue; + const KibanaEnvironmentContextProvider = + useKibanaEnvironmentContextProvider(pluginsStart); const { history } = appMountParameters; const i18nCore = core.i18n; @@ -72,52 +75,49 @@ export function ApmAppRoot({ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx index a9ad169aa23a6..5e2e0964be791 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_main_template.tsx @@ -9,9 +9,10 @@ import { EuiFlexGroup, EuiFlexItem, EuiPageHeaderProps } from '@elastic/eui'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { ObservabilityPageTemplateProps } from '@kbn/observability-shared-plugin/public'; import type { KibanaPageTemplateProps } from '@kbn/shared-ux-page-kibana-template'; -import React from 'react'; +import React, { useContext } from 'react'; import { useLocation } from 'react-router-dom'; import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; +import { KibanaEnvironmentContext } from '../../../context/kibana_environment_context/kibana_environment_context'; import { getPathForFeedback } from '../../../utils/get_path_for_feedback'; import { EnvironmentsContextProvider } from '../../../context/environments_context/environments_context'; import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher'; @@ -58,7 +59,8 @@ export function ApmMainTemplate({ Pick) { const location = useLocation(); - const { services, kibanaEnvironment } = useKibana(); + const { services } = useKibana(); + const kibanaEnvironment = useContext(KibanaEnvironmentContext); const { http, docLinks, observabilityShared, application } = services; const { kibanaVersion, isCloudEnv, isServerlessEnv } = kibanaEnvironment; const basePath = http?.basePath.get(); diff --git a/x-pack/plugins/apm/public/context/kibana_environment_context/kibana_environment_context.tsx b/x-pack/plugins/apm/public/context/kibana_environment_context/kibana_environment_context.tsx new file mode 100644 index 0000000000000..acf974d4d2dae --- /dev/null +++ b/x-pack/plugins/apm/public/context/kibana_environment_context/kibana_environment_context.tsx @@ -0,0 +1,16 @@ +/* + * 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. + */ + +import { createContext } from 'react'; + +export interface KibanaEnvContext { + kibanaVersion?: string; + isCloudEnv?: boolean; + isServerlessEnv?: boolean; +} + +export const KibanaEnvironmentContext = createContext({}); diff --git a/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx b/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx new file mode 100644 index 0000000000000..01a4b22bc0890 --- /dev/null +++ b/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import React, { useMemo, createElement } from 'react'; +import { ApmPluginStartDeps } from '../../plugin'; +import { + KibanaEnvironmentContext, + type KibanaEnvContext, +} from './kibana_environment_context'; + +export const useKibanaEnvironmentContextProvider = ( + plugins: ApmPluginStartDeps +) => { + const value = useMemo( + () => ({ + kibanaVersion: plugins.kibanaVersion, + isCloudEnv: plugins.isCloudEnv, + isServerlessEnv: plugins.isServerlessEnv, + }), + [plugins] + ); + + const Provider: React.FC<{ kibanaEnvironment?: KibanaEnvContext }> = ({ + kibanaEnvironment = {}, + children, + }) => { + const newProvider = createElement(KibanaEnvironmentContext.Provider, { + value: { ...kibanaEnvironment, ...value }, + children, + }); + + return newProvider; + }; + + return Provider; +}; diff --git a/x-pack/plugins/infra/public/apps/common_providers.tsx b/x-pack/plugins/infra/public/apps/common_providers.tsx index 158e0b95293e9..9ee0053c79e6a 100644 --- a/x-pack/plugins/infra/public/apps/common_providers.tsx +++ b/x-pack/plugins/infra/public/apps/common_providers.tsx @@ -13,7 +13,10 @@ import type { ObservabilityAIAssistantPluginStart } from '@kbn/observability-ai- import { Storage } from '@kbn/kibana-utils-plugin/public'; import { NavigationWarningPromptProvider } from '@kbn/observability-shared-plugin/public'; import { TriggersAndActionsUIPublicPluginStart } from '@kbn/triggers-actions-ui-plugin/public'; -import { useKibanaContextForPluginProvider } from '../hooks/use_kibana'; +import { + useKibanaContextForPluginProvider, + useKibanaEnvironmentContextProvider, +} from '../hooks/use_kibana'; import { InfraClientStartDeps, InfraClientStartExports } from '../types'; import { HeaderActionMenuProvider } from '../utils/header_action_menu_provider'; import { TriggersActionsProvider } from '../utils/triggers_actions_context'; @@ -70,11 +73,15 @@ export const CoreProviders: React.FC = ({ pluginStart ); + const MyEnvContextForPluginProvider = useKibanaEnvironmentContextProvider(plugins); + return ( - - {children} - + + + {children} + + ); }; diff --git a/x-pack/plugins/infra/public/hooks/use_kibana.tsx b/x-pack/plugins/infra/public/hooks/use_kibana.tsx index f1b83f6a229f5..f8e9c7dab48fd 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana.tsx +++ b/x-pack/plugins/infra/public/hooks/use_kibana.tsx @@ -6,7 +6,7 @@ */ import type { PropsOf } from '@elastic/eui'; -import React, { useMemo } from 'react'; +import React, { useMemo, createElement, createContext } from 'react'; import { CoreStart } from '@kbn/core/public'; import { createKibanaReactContext, @@ -17,23 +17,24 @@ import { InfraClientCoreSetup, InfraClientStartDeps, InfraClientStartExports } f export type PluginKibanaContextValue = CoreStart & InfraClientStartDeps & InfraClientStartExports; +interface KibanaEnvContext { + kibanaVersion?: string; + isCloudEnv?: boolean; + isServerlessEnv?: boolean; +} + export const createKibanaContextForPlugin = ( core: CoreStart, plugins: InfraClientStartDeps, pluginStart: InfraClientStartExports ) => - createKibanaReactContext( - { - ...core, - ...plugins, - ...pluginStart, - }, - { - kibanaVersion: plugins.kibanaVersion, - isCloudEnv: plugins.isCloudEnv, - isServerlessEnv: plugins.isServerlessEnv, - } - ); + createKibanaReactContext({ + ...core, + ...plugins, + ...pluginStart, + }); + +export const KibanaEnvironmentContext = createContext({}); export const useKibanaContextForPlugin = useKibana as () => KibanaReactContextValue; @@ -50,6 +51,31 @@ export const useKibanaContextForPluginProvider = ( return Provider; }; +export const useKibanaEnvironmentContextProvider = (plugins: InfraClientStartDeps) => { + const value = useMemo( + () => ({ + kibanaVersion: plugins.kibanaVersion, + isCloudEnv: plugins.isCloudEnv, + isServerlessEnv: plugins.isServerlessEnv, + }), + [plugins] + ); + + const Provider: React.FC<{ kibanaEnvironment?: KibanaEnvContext }> = ({ + kibanaEnvironment = {}, + children, + }) => { + const newProvider = createElement(KibanaEnvironmentContext.Provider, { + value: { ...kibanaEnvironment, ...value }, + children, + }); + + return newProvider; + }; + + return Provider; +}; + export const createLazyComponentWithKibanaContext = >( coreSetup: InfraClientCoreSetup, lazyComponentFactory: () => Promise<{ default: T }> diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx index 726f501c6be71..8766a8bdddf2e 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx @@ -6,12 +6,12 @@ */ import { EuiErrorBoundary } from '@elastic/eui'; -import React from 'react'; +import React, { useContext } from 'react'; import { useTrackPageview, FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; import { APP_WRAPPER_CLASS } from '@kbn/core/public'; import { css } from '@emotion/react'; import { i18n } from '@kbn/i18n'; -import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; +import { KibanaEnvironmentContext } from '../../../hooks/use_kibana'; import { SourceErrorPage } from '../../../components/source_error_page'; import { SourceLoadingPage } from '../../../components/source_loading_page'; import { useSourceContext } from '../../../containers/metrics_source'; @@ -29,9 +29,7 @@ const HOSTS_FEEDBACK_LINK = export const HostsPage = () => { const { isLoading, loadSourceFailureMessage, loadSource, source } = useSourceContext(); - const { - kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, - } = useKibanaContextForPlugin(); + const { kibanaVersion, isCloudEnv, isServerlessEnv } = useContext(KibanaEnvironmentContext); useTrackPageview({ app: 'infra_metrics', path: 'hosts' }); useTrackPageview({ app: 'infra_metrics', path: 'hosts', delay: 15000 }); diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx index 3f0448942f738..c5524bae4eb41 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_kubernetes.tsx @@ -6,11 +6,11 @@ */ import { EuiFlexGroup, EuiFlexItem, EuiGlobalToastList } from '@elastic/eui'; -import React from 'react'; +import React, { useContext } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import useLocalStorage from 'react-use/lib/useLocalStorage'; import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; -import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana'; +import { KibanaEnvironmentContext } from '../../../../hooks/use_kibana'; const KUBERNETES_TOAST_STORAGE_KEY = 'kubernetesToastKey'; const KUBERNETES_FEEDBACK_LINK = 'https://ela.st/k8s-feedback'; @@ -18,9 +18,8 @@ const KUBERNETES_FEEDBACK_LINK = 'https://ela.st/k8s-feedback'; export const SurveyKubernetes = () => { const [isToastSeen, setIsToastSeen] = useLocalStorage(KUBERNETES_TOAST_STORAGE_KEY, false); const markToastAsSeen = () => setIsToastSeen(true); - const { - kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, - } = useKibanaContextForPlugin(); + + const { kibanaVersion, isCloudEnv, isServerlessEnv } = useContext(KibanaEnvironmentContext); return ( <> diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx index 840522efa1722..d32fd722c8391 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/survey_section.tsx @@ -5,9 +5,9 @@ * 2.0. */ -import React from 'react'; +import React, { useContext } from 'react'; import { FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; -import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana'; +import { KibanaEnvironmentContext } from '../../../../hooks/use_kibana'; import { useWaffleOptionsContext } from '../hooks/use_waffle_options'; import { SurveyKubernetes } from './survey_kubernetes'; @@ -16,9 +16,7 @@ const INVENTORY_FEEDBACK_LINK = 'https://ela.st/survey-infra-inventory?usp=pp_ur export const SurveySection = () => { const { nodeType } = useWaffleOptionsContext(); - const { - kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, - } = useKibanaContextForPlugin(); + const { kibanaVersion, isCloudEnv, isServerlessEnv } = useContext(KibanaEnvironmentContext); return ( <> diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx index 061768e2a8042..d7764c14c4364 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/index.tsx @@ -7,9 +7,9 @@ import { EuiErrorBoundary } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import React, { useEffect, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { useTrackPageview, FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public'; -import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; +import { KibanaEnvironmentContext } from '../../../hooks/use_kibana'; import { SourceLoadingPage } from '../../../components/source_loading_page'; import { useMetricsExplorerViews } from '../../../hooks/use_metrics_explorer_views'; import { MetricsSourceConfigurationProperties } from '../../../../common/metrics_sources'; @@ -52,9 +52,7 @@ export const MetricsExplorerPage = ({ source, derivedIndexPattern }: MetricsExpl } = useMetricsExplorerState(source, derivedIndexPattern, enabled); const { currentView } = useMetricsExplorerViews(); const { source: sourceContext, metricIndicesExist } = useSourceContext(); - const { - kibanaEnvironment: { kibanaVersion, isCloudEnv, isServerlessEnv }, - } = useKibanaContextForPlugin(); + const { kibanaVersion, isCloudEnv, isServerlessEnv } = useContext(KibanaEnvironmentContext); useTrackPageview({ app: 'infra_metrics', path: 'metrics_explorer' }); useTrackPageview({ app: 'infra_metrics', path: 'metrics_explorer', delay: 15000 }); From b2ad1c340370c5d6c04daac700ab902ea11d02de Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 4 Jan 2024 15:37:28 +0100 Subject: [PATCH 09/12] Move kibana env from start deps in APM --- x-pack/plugins/apm/public/application/index.tsx | 4 ++++ .../components/routing/app_root/index.tsx | 8 +++++--- .../context/apm_plugin/apm_plugin_context.tsx | 2 ++ .../use_kibana_environment_context.tsx | 17 +++++++++-------- x-pack/plugins/apm/public/plugin.ts | 9 +++------ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/apm/public/application/index.tsx b/x-pack/plugins/apm/public/application/index.tsx index 9e62f0257f489..c79dbb44c8349 100644 --- a/x-pack/plugins/apm/public/application/index.tsx +++ b/x-pack/plugins/apm/public/application/index.tsx @@ -20,6 +20,7 @@ import { createCallApmApi } from '../services/rest/create_call_apm_api'; import { setHelpExtension } from '../set_help_extension'; import { setReadonlyBadge } from '../update_badge'; import { ApmAppRoot } from '../components/routing/app_root'; +import type { KibanaEnvContext } from '../context/kibana_environment_context/kibana_environment_context'; /** * This module is rendered asynchronously in the Kibana platform. @@ -32,6 +33,7 @@ export const renderApp = ({ pluginsStart, observabilityRuleTypeRegistry, apmServices, + kibanaEnvironment, }: { coreStart: CoreStart; pluginsSetup: ApmPluginSetupDeps; @@ -40,6 +42,7 @@ export const renderApp = ({ pluginsStart: ApmPluginStartDeps; observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry; apmServices: ApmServices; + kibanaEnvironment: KibanaEnvContext; }) => { const { element, theme$ } = appMountParameters; const apmPluginContextValue = { @@ -58,6 +61,7 @@ export const renderApp = ({ uiActions: pluginsStart.uiActions, observabilityAIAssistant: pluginsStart.observabilityAIAssistant, share: pluginsSetup.share, + kibanaEnvironment, }; // render APM feedback link in global help menu diff --git a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx index d540730dfbca0..6f95463f619b6 100644 --- a/x-pack/plugins/apm/public/components/routing/app_root/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/app_root/index.tsx @@ -55,9 +55,9 @@ export function ApmAppRoot({ pluginsStart: ApmPluginStartDeps; apmServices: ApmServices; }) { - const { appMountParameters, core } = apmPluginContextValue; + const { appMountParameters, kibanaEnvironment, core } = apmPluginContextValue; const KibanaEnvironmentContextProvider = - useKibanaEnvironmentContextProvider(pluginsStart); + useKibanaEnvironmentContextProvider(kibanaEnvironment); const { history } = appMountParameters; const i18nCore = core.i18n; @@ -76,7 +76,9 @@ export function ApmAppRoot({ - + diff --git a/x-pack/plugins/apm/public/context/apm_plugin/apm_plugin_context.tsx b/x-pack/plugins/apm/public/context/apm_plugin/apm_plugin_context.tsx index 9440a5e1c13f5..3fb8f3bacb767 100644 --- a/x-pack/plugins/apm/public/context/apm_plugin/apm_plugin_context.tsx +++ b/x-pack/plugins/apm/public/context/apm_plugin/apm_plugin_context.tsx @@ -19,6 +19,7 @@ import type { ObservabilityAIAssistantPluginStart } from '@kbn/observability-ai- import { SharePluginSetup } from '@kbn/share-plugin/public'; import type { ApmPluginSetupDeps } from '../../plugin'; import type { ConfigSchema } from '../..'; +import type { KibanaEnvContext } from '../kibana_environment_context/kibana_environment_context'; export interface ApmPluginContextValue { appMountParameters: AppMountParameters; @@ -34,6 +35,7 @@ export interface ApmPluginContextValue { uiActions: UiActionsStart; observabilityAIAssistant: ObservabilityAIAssistantPluginStart; share: SharePluginSetup; + kibanaEnvironment: KibanaEnvContext; } export const ApmPluginContext = createContext({} as ApmPluginContextValue); diff --git a/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx b/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx index 01a4b22bc0890..db9694e717c35 100644 --- a/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx +++ b/x-pack/plugins/apm/public/context/kibana_environment_context/use_kibana_environment_context.tsx @@ -6,22 +6,23 @@ */ import React, { useMemo, createElement } from 'react'; -import { ApmPluginStartDeps } from '../../plugin'; import { KibanaEnvironmentContext, type KibanaEnvContext, } from './kibana_environment_context'; -export const useKibanaEnvironmentContextProvider = ( - plugins: ApmPluginStartDeps -) => { +export const useKibanaEnvironmentContextProvider = ({ + kibanaVersion, + isCloudEnv, + isServerlessEnv, +}: KibanaEnvContext) => { const value = useMemo( () => ({ - kibanaVersion: plugins.kibanaVersion, - isCloudEnv: plugins.isCloudEnv, - isServerlessEnv: plugins.isServerlessEnv, + kibanaVersion, + isCloudEnv, + isServerlessEnv, }), - [plugins] + [kibanaVersion, isCloudEnv, isServerlessEnv] ); const Provider: React.FC<{ kibanaEnvironment?: KibanaEnvContext }> = ({ diff --git a/x-pack/plugins/apm/public/plugin.ts b/x-pack/plugins/apm/public/plugin.ts index 886bd4bfa049f..476a4e1fd5b82 100644 --- a/x-pack/plugins/apm/public/plugin.ts +++ b/x-pack/plugins/apm/public/plugin.ts @@ -141,9 +141,6 @@ export interface ApmPluginStartDeps { observabilityAIAssistant: ObservabilityAIAssistantPluginStart; dashboard: DashboardStart; metricsDataAccess: MetricsDataPluginStart; - kibanaVersion?: string; - isCloudEnv: boolean; - isServerlessEnv: boolean; uiSettings: IUiSettingsClient; } @@ -420,12 +417,12 @@ export class ApmPlugin implements Plugin { pluginsSetup: pluginSetupDeps as ApmPluginSetupDeps, appMountParameters, config, - pluginsStart: { - ...pluginsStart, + kibanaEnvironment: { isCloudEnv, isServerlessEnv, kibanaVersion: this.kibanaVersion, - } as ApmPluginStartDeps, + }, + pluginsStart: pluginsStart as ApmPluginStartDeps, observabilityRuleTypeRegistry, apmServices: { telemetry, From c13ed0336f6ee87b5c1c5e59c0e1d754eb2dd445 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 4 Jan 2024 17:14:42 +0100 Subject: [PATCH 10/12] Move kibana env from start deps in Infra --- .../infra/public/apps/common_providers.tsx | 9 ++++++--- x-pack/plugins/infra/public/apps/metrics_app.tsx | 13 ++++++++++++- x-pack/plugins/infra/public/hooks/use_kibana.tsx | 16 ++++++++++------ x-pack/plugins/infra/public/plugin.ts | 7 ++++++- x-pack/plugins/infra/public/types.ts | 3 --- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/infra/public/apps/common_providers.tsx b/x-pack/plugins/infra/public/apps/common_providers.tsx index 9ee0053c79e6a..c05fd4fabb04e 100644 --- a/x-pack/plugins/infra/public/apps/common_providers.tsx +++ b/x-pack/plugins/infra/public/apps/common_providers.tsx @@ -14,6 +14,7 @@ import { Storage } from '@kbn/kibana-utils-plugin/public'; import { NavigationWarningPromptProvider } from '@kbn/observability-shared-plugin/public'; import { TriggersAndActionsUIPublicPluginStart } from '@kbn/triggers-actions-ui-plugin/public'; import { + type KibanaEnvContext, useKibanaContextForPluginProvider, useKibanaEnvironmentContextProvider, } from '../hooks/use_kibana'; @@ -58,12 +59,14 @@ export interface CoreProvidersProps { pluginStart: InfraClientStartExports; plugins: InfraClientStartDeps; theme$: AppMountParameters['theme$']; + kibanaEnvironment: KibanaEnvContext; } export const CoreProviders: React.FC = ({ children, core, pluginStart, + kibanaEnvironment, plugins, theme$, }) => { @@ -73,15 +76,15 @@ export const CoreProviders: React.FC = ({ pluginStart ); - const MyEnvContextForPluginProvider = useKibanaEnvironmentContextProvider(plugins); + const KibanaEnvContextForPluginProvider = useKibanaEnvironmentContextProvider(kibanaEnvironment); return ( - + {children} - + ); }; diff --git a/x-pack/plugins/infra/public/apps/metrics_app.tsx b/x-pack/plugins/infra/public/apps/metrics_app.tsx index 17d93311deb4b..e93958141db25 100644 --- a/x-pack/plugins/infra/public/apps/metrics_app.tsx +++ b/x-pack/plugins/infra/public/apps/metrics_app.tsx @@ -22,12 +22,14 @@ import { CommonInfraProviders, CoreProviders } from './common_providers'; import { prepareMountElement } from './common_styles'; import { SourceProvider } from '../containers/metrics_source'; import { PluginConfigProvider } from '../containers/plugin_config_context'; +import type { KibanaEnvContext } from '../hooks/use_kibana'; export const METRICS_APP_DATA_TEST_SUBJ = 'infraMetricsPage'; export const renderApp = ( core: CoreStart, plugins: InfraClientStartDeps, + kibanaEnvironment: KibanaEnvContext, pluginStart: InfraClientStartExports, pluginConfig: InfraPublicConfig, { element, history, setHeaderActionMenu, theme$ }: AppMountParameters @@ -46,6 +48,7 @@ export const renderApp = ( setHeaderActionMenu={setHeaderActionMenu} storage={storage} theme$={theme$} + kibanaEnvironment={kibanaEnvironment} />, element ); @@ -66,6 +69,7 @@ const MetricsApp: React.FC<{ setHeaderActionMenu: AppMountParameters['setHeaderActionMenu']; storage: Storage; theme$: AppMountParameters['theme$']; + kibanaEnvironment: KibanaEnvContext; }> = ({ core, history, @@ -75,11 +79,18 @@ const MetricsApp: React.FC<{ setHeaderActionMenu, storage, theme$, + kibanaEnvironment, }) => { const uiCapabilities = core.application.capabilities; return ( - + { +export const useKibanaEnvironmentContextProvider = ({ + kibanaVersion, + isCloudEnv, + isServerlessEnv, +}: KibanaEnvContext) => { const value = useMemo( () => ({ - kibanaVersion: plugins.kibanaVersion, - isCloudEnv: plugins.isCloudEnv, - isServerlessEnv: plugins.isServerlessEnv, + kibanaVersion, + isCloudEnv, + isServerlessEnv, }), - [plugins] + [kibanaVersion, isCloudEnv, isServerlessEnv] ); const Provider: React.FC<{ kibanaEnvironment?: KibanaEnvContext }> = ({ diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts index a25e553faa2cf..f44ec7de29f40 100644 --- a/x-pack/plugins/infra/public/plugin.ts +++ b/x-pack/plugins/infra/public/plugin.ts @@ -316,7 +316,12 @@ export class Plugin implements InfraClientPluginClass { const isServerlessEnv = pluginsSetup.cloud?.isServerlessEnabled || this.isServerlessEnv; return renderApp( coreStart, - { ...plugins, kibanaVersion: this.kibanaVersion, isCloudEnv, isServerlessEnv }, + { ...plugins }, + { + kibanaVersion: this.kibanaVersion, + isCloudEnv, + isServerlessEnv, + }, pluginStart, this.config, params diff --git a/x-pack/plugins/infra/public/types.ts b/x-pack/plugins/infra/public/types.ts index 946ee4a7b1943..94c8a067f879e 100644 --- a/x-pack/plugins/infra/public/types.ts +++ b/x-pack/plugins/infra/public/types.ts @@ -88,9 +88,6 @@ export interface InfraClientStartDeps { dataViews: DataViewsPublicPluginStart; discover: DiscoverStart; embeddable?: EmbeddableStart; - kibanaVersion?: string; - isCloudEnv: boolean; - isServerlessEnv: boolean; lens: LensPublicStart; logsShared: LogsSharedClientStartExports; ml: MlPluginStart; From bba1419aebc7f52c7e182c694eeb7df1a443efe8 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 5 Jan 2024 11:01:08 +0100 Subject: [PATCH 11/12] Make KibanaEnv optional in common providers --- .../infra/public/apps/common_providers.tsx | 4 ++-- .../plugins/infra/public/apps/metrics_app.tsx | 4 ++-- x-pack/plugins/infra/public/plugin.ts | 17 +++++------------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/infra/public/apps/common_providers.tsx b/x-pack/plugins/infra/public/apps/common_providers.tsx index c05fd4fabb04e..001c4ce44ca0c 100644 --- a/x-pack/plugins/infra/public/apps/common_providers.tsx +++ b/x-pack/plugins/infra/public/apps/common_providers.tsx @@ -59,16 +59,16 @@ export interface CoreProvidersProps { pluginStart: InfraClientStartExports; plugins: InfraClientStartDeps; theme$: AppMountParameters['theme$']; - kibanaEnvironment: KibanaEnvContext; + kibanaEnvironment?: KibanaEnvContext; } export const CoreProviders: React.FC = ({ children, core, pluginStart, - kibanaEnvironment, plugins, theme$, + kibanaEnvironment, }) => { const KibanaContextProviderForPlugin = useKibanaContextForPluginProvider( core, diff --git a/x-pack/plugins/infra/public/apps/metrics_app.tsx b/x-pack/plugins/infra/public/apps/metrics_app.tsx index e93958141db25..d47aaa62adcec 100644 --- a/x-pack/plugins/infra/public/apps/metrics_app.tsx +++ b/x-pack/plugins/infra/public/apps/metrics_app.tsx @@ -29,10 +29,10 @@ export const METRICS_APP_DATA_TEST_SUBJ = 'infraMetricsPage'; export const renderApp = ( core: CoreStart, plugins: InfraClientStartDeps, - kibanaEnvironment: KibanaEnvContext, pluginStart: InfraClientStartExports, pluginConfig: InfraPublicConfig, - { element, history, setHeaderActionMenu, theme$ }: AppMountParameters + { element, history, setHeaderActionMenu, theme$ }: AppMountParameters, + kibanaEnvironment: KibanaEnvContext ) => { const storage = new Storage(window.localStorage); diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts index f44ec7de29f40..7d717cf9057e4 100644 --- a/x-pack/plugins/infra/public/plugin.ts +++ b/x-pack/plugins/infra/public/plugin.ts @@ -314,18 +314,11 @@ export class Plugin implements InfraClientPluginClass { const isCloudEnv = !!pluginsSetup.cloud?.isCloudEnabled; const isServerlessEnv = pluginsSetup.cloud?.isServerlessEnabled || this.isServerlessEnv; - return renderApp( - coreStart, - { ...plugins }, - { - kibanaVersion: this.kibanaVersion, - isCloudEnv, - isServerlessEnv, - }, - pluginStart, - this.config, - params - ); + return renderApp(coreStart, { ...plugins }, pluginStart, this.config, params, { + kibanaVersion: this.kibanaVersion, + isCloudEnv, + isServerlessEnv, + }); }, }); From b3355d2fe8c71395d0ae08e634866e1983b96df9 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 5 Jan 2024 12:01:56 +0100 Subject: [PATCH 12/12] Make KibanaEnv optional in common providers and fix logs page --- .../infra/public/apps/common_providers.tsx | 2 +- .../plugins/infra/public/hooks/use_kibana.tsx | 21 +++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/infra/public/apps/common_providers.tsx b/x-pack/plugins/infra/public/apps/common_providers.tsx index 001c4ce44ca0c..3915446edaeee 100644 --- a/x-pack/plugins/infra/public/apps/common_providers.tsx +++ b/x-pack/plugins/infra/public/apps/common_providers.tsx @@ -80,7 +80,7 @@ export const CoreProviders: React.FC = ({ return ( - + {children} diff --git a/x-pack/plugins/infra/public/hooks/use_kibana.tsx b/x-pack/plugins/infra/public/hooks/use_kibana.tsx index 912d557375631..25ef6595c734a 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana.tsx +++ b/x-pack/plugins/infra/public/hooks/use_kibana.tsx @@ -51,26 +51,19 @@ export const useKibanaContextForPluginProvider = ( return Provider; }; -export const useKibanaEnvironmentContextProvider = ({ - kibanaVersion, - isCloudEnv, - isServerlessEnv, -}: KibanaEnvContext) => { +export const useKibanaEnvironmentContextProvider = (kibanaEnvironment?: KibanaEnvContext) => { const value = useMemo( () => ({ - kibanaVersion, - isCloudEnv, - isServerlessEnv, + kibanaVersion: kibanaEnvironment?.kibanaVersion, + isCloudEnv: kibanaEnvironment?.isCloudEnv, + isServerlessEnv: kibanaEnvironment?.isServerlessEnv, }), - [kibanaVersion, isCloudEnv, isServerlessEnv] + [kibanaEnvironment] ); - const Provider: React.FC<{ kibanaEnvironment?: KibanaEnvContext }> = ({ - kibanaEnvironment = {}, - children, - }) => { + const Provider: React.FC<{ kibanaEnv?: KibanaEnvContext }> = ({ kibanaEnv = {}, children }) => { const newProvider = createElement(KibanaEnvironmentContext.Provider, { - value: { ...kibanaEnvironment, ...value }, + value: { ...kibanaEnv, ...value }, children, });