From 3925c210dcc586bf153a004d9b972350e6ddbade Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Thu, 21 Nov 2024 11:30:31 +0100 Subject: [PATCH 01/18] Fix missing executionContext --- .../kibana_context/root/root_provider.test.tsx | 6 ++++++ .../kibana_context/root/root_provider.tsx | 18 ++++++++++++------ packages/shared-ux/router/impl/services.ts | 8 ++++---- .../router/impl/use_execution_context.ts | 4 ++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/react/kibana_context/root/root_provider.test.tsx b/packages/react/kibana_context/root/root_provider.test.tsx index 919adb09581d5..92ef14117d31b 100644 --- a/packages/react/kibana_context/root/root_provider.test.tsx +++ b/packages/react/kibana_context/root/root_provider.test.tsx @@ -17,6 +17,8 @@ import { mountWithIntl } from '@kbn/test-jest-helpers'; import type { KibanaTheme } from '@kbn/react-kibana-context-common'; import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks'; +import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; +import { executionContextServiceMock } from '@kbn/core-execution-context-browser-mocks'; import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks'; import { KibanaRootContextProvider } from './root_provider'; import { I18nStart } from '@kbn/core-i18n-browser'; @@ -25,11 +27,13 @@ describe('KibanaRootContextProvider', () => { let euiTheme: UseEuiTheme | undefined; let i18nMock: I18nStart; let analytics: AnalyticsServiceStart; + let executionContext: ExecutionContextStart; beforeEach(() => { euiTheme = undefined; analytics = analyticsServiceMock.createAnalyticsServiceStart(); i18nMock = i18nServiceMock.createStartContract(); + executionContext = executionContextServiceMock.createStartContract(); }); const flushPromises = async () => { @@ -64,6 +68,7 @@ describe('KibanaRootContextProvider', () => { @@ -82,6 +87,7 @@ describe('KibanaRootContextProvider', () => { diff --git a/packages/react/kibana_context/root/root_provider.tsx b/packages/react/kibana_context/root/root_provider.tsx index f2c109fc62835..f37c49c504597 100644 --- a/packages/react/kibana_context/root/root_provider.tsx +++ b/packages/react/kibana_context/root/root_provider.tsx @@ -11,6 +11,8 @@ import React, { FC, PropsWithChildren } from 'react'; import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; import type { I18nStart } from '@kbn/core-i18n-browser'; +import { SharedUXContext } from '@kbn/shared-ux-router/services'; +import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; // @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types import { useIsNestedEuiProvider } from '@elastic/eui/lib/components/provider/nested'; @@ -25,6 +27,8 @@ export interface KibanaRootContextProviderProps extends KibanaEuiProviderProps { i18n: I18nStart; /** The `AnalyticsServiceStart` API from `CoreStart`. */ analytics?: Pick; + /** The `ExecutionContextStart` API from `CoreStart`. */ + executionContext?: ExecutionContextStart; } /** @@ -44,20 +48,22 @@ export interface KibanaRootContextProviderProps extends KibanaEuiProviderProps { export const KibanaRootContextProvider: FC> = ({ children, i18n, + executionContext, ...props }) => { const hasEuiProvider = useIsNestedEuiProvider(); + const rootContextProvider = ( + + {children} + + ); if (hasEuiProvider) { emitEuiProviderWarning( 'KibanaRootContextProvider has likely been nested in this React tree, either by direct reference or by KibanaRenderContextProvider. The result of this nesting is a nesting of EuiProvider, which has negative effects. Check your React tree for nested Kibana context providers.' ); - return {children}; + return rootContextProvider; } else { - return ( - - {children} - - ); + return {rootContextProvider}; } }; diff --git a/packages/shared-ux/router/impl/services.ts b/packages/shared-ux/router/impl/services.ts index c3ad2ab06e06d..c3c22d352e058 100644 --- a/packages/shared-ux/router/impl/services.ts +++ b/packages/shared-ux/router/impl/services.ts @@ -8,6 +8,7 @@ */ import { Observable } from 'rxjs'; +import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; import { createContext, useContext } from 'react'; import { SharedUXExecutionContext } from './types'; @@ -49,8 +50,7 @@ export interface SharedUXExecutionContextSetup { * https://github.com/Microsoft/web-build-tools/issues/1237 */ export interface SharedUXExecutionContextSetup { - /** {@link SharedUXExecutionContextSetup} */ - executionContext: SharedUXExecutionContextStart; + executionContext: ExecutionContextStart; } export type KibanaServices = Partial; @@ -63,12 +63,12 @@ const defaultContextValue = { services: {}, }; -export const sharedUXContext = +export const SharedUXContext = createContext>(defaultContextValue); export const useKibanaSharedUX = (): SharedUXRouterContextValue< KibanaServices & Extra > => useContext( - sharedUXContext as unknown as React.Context> + SharedUXContext as unknown as React.Context> ); diff --git a/packages/shared-ux/router/impl/use_execution_context.ts b/packages/shared-ux/router/impl/use_execution_context.ts index d460d4df30805..b922ab4f3d6b4 100644 --- a/packages/shared-ux/router/impl/use_execution_context.ts +++ b/packages/shared-ux/router/impl/use_execution_context.ts @@ -8,7 +8,7 @@ */ import useDeepCompareEffect from 'react-use/lib/useDeepCompareEffect'; -import { SharedUXExecutionContextSetup } from './services'; +import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; import { SharedUXExecutionContext } from './types'; /** @@ -17,7 +17,7 @@ import { SharedUXExecutionContext } from './types'; * @param context */ export function useSharedUXExecutionContext( - executionContext: SharedUXExecutionContextSetup | undefined, + executionContext: ExecutionContextStart | undefined, context: SharedUXExecutionContext ) { useDeepCompareEffect(() => { From d0b0d51fb2dca420421dddec7cc75a63bc0d1cfd Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Thu, 21 Nov 2024 14:04:55 +0100 Subject: [PATCH 02/18] Revert ExecutionContextStart directly --- packages/react/kibana_context/root/root_provider.tsx | 2 +- packages/react/kibana_context/root/tsconfig.json | 3 +++ packages/shared-ux/router/impl/index.ts | 2 ++ packages/shared-ux/router/impl/services.ts | 4 ++-- packages/shared-ux/router/impl/use_execution_context.ts | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/react/kibana_context/root/root_provider.tsx b/packages/react/kibana_context/root/root_provider.tsx index f37c49c504597..48d9c98eb7ae4 100644 --- a/packages/react/kibana_context/root/root_provider.tsx +++ b/packages/react/kibana_context/root/root_provider.tsx @@ -11,8 +11,8 @@ import React, { FC, PropsWithChildren } from 'react'; import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; import type { I18nStart } from '@kbn/core-i18n-browser'; -import { SharedUXContext } from '@kbn/shared-ux-router/services'; import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; +import { SharedUXContext } from '@kbn/shared-ux-router'; // @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types import { useIsNestedEuiProvider } from '@elastic/eui/lib/components/provider/nested'; diff --git a/packages/react/kibana_context/root/tsconfig.json b/packages/react/kibana_context/root/tsconfig.json index 27ea0566f36a7..2290e3c818d0b 100644 --- a/packages/react/kibana_context/root/tsconfig.json +++ b/packages/react/kibana_context/root/tsconfig.json @@ -23,5 +23,8 @@ "@kbn/core-base-common", "@kbn/core-analytics-browser", "@kbn/core-analytics-browser-mocks", + "@kbn/core-execution-context-browser", + "@kbn/core-execution-context-browser-mocks", + "@kbn/shared-ux-router", ] } diff --git a/packages/shared-ux/router/impl/index.ts b/packages/shared-ux/router/impl/index.ts index a8bef1b8499df..63d8916624091 100644 --- a/packages/shared-ux/router/impl/index.ts +++ b/packages/shared-ux/router/impl/index.ts @@ -10,3 +10,5 @@ export { Route } from './route'; export { HashRouter, BrowserRouter, MemoryRouter, Router } from './router'; export { Routes } from './routes'; + +export { SharedUXContext } from './services'; diff --git a/packages/shared-ux/router/impl/services.ts b/packages/shared-ux/router/impl/services.ts index c3c22d352e058..825d4485802f8 100644 --- a/packages/shared-ux/router/impl/services.ts +++ b/packages/shared-ux/router/impl/services.ts @@ -8,7 +8,6 @@ */ import { Observable } from 'rxjs'; -import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; import { createContext, useContext } from 'react'; import { SharedUXExecutionContext } from './types'; @@ -50,7 +49,8 @@ export interface SharedUXExecutionContextSetup { * https://github.com/Microsoft/web-build-tools/issues/1237 */ export interface SharedUXExecutionContextSetup { - executionContext: ExecutionContextStart; + /** {@link SharedUXExecutionContextSetup} */ + executionContext?: SharedUXExecutionContextStart; } export type KibanaServices = Partial; diff --git a/packages/shared-ux/router/impl/use_execution_context.ts b/packages/shared-ux/router/impl/use_execution_context.ts index b922ab4f3d6b4..5e088fc3eac77 100644 --- a/packages/shared-ux/router/impl/use_execution_context.ts +++ b/packages/shared-ux/router/impl/use_execution_context.ts @@ -8,7 +8,7 @@ */ import useDeepCompareEffect from 'react-use/lib/useDeepCompareEffect'; -import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; +import type { SharedUXExecutionContextSetup } from './services'; import { SharedUXExecutionContext } from './types'; /** @@ -17,7 +17,7 @@ import { SharedUXExecutionContext } from './types'; * @param context */ export function useSharedUXExecutionContext( - executionContext: ExecutionContextStart | undefined, + executionContext: SharedUXExecutionContextSetup | undefined, context: SharedUXExecutionContext ) { useDeepCompareEffect(() => { From b0c621c33e368a195e5fdd7245659d8f608eebbf Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Thu, 21 Nov 2024 15:18:53 +0100 Subject: [PATCH 03/18] add router to bazel --- .../react/kibana_context/root/BUILD.bazel | 1 + packages/shared-ux/router/impl/BUILD.bazel | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 packages/shared-ux/router/impl/BUILD.bazel diff --git a/packages/react/kibana_context/root/BUILD.bazel b/packages/react/kibana_context/root/BUILD.bazel index 1c47c25bc20a9..fc073da074a61 100644 --- a/packages/react/kibana_context/root/BUILD.bazel +++ b/packages/react/kibana_context/root/BUILD.bazel @@ -26,6 +26,7 @@ DEPS = [ "@npm//tslib", "@npm//@elastic/eui", "//packages/core/base/core-base-common", + "//packages/shared-ux/router/impl:shared-ux-router", ] js_library( diff --git a/packages/shared-ux/router/impl/BUILD.bazel b/packages/shared-ux/router/impl/BUILD.bazel new file mode 100644 index 0000000000000..224bebcf72e4a --- /dev/null +++ b/packages/shared-ux/router/impl/BUILD.bazel @@ -0,0 +1,34 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") + +SRCS = glob( + [ + "**/*.ts", + "**/*.tsx", + ], + exclude = [ + "**/test_helpers.ts", + "**/*.config.js", + "**/*.mock.*", + "**/*.test.*", + "**/*.stories.*", + "**/__snapshots__/**", + "**/integration_tests/**", + "**/mocks/**", + "**/scripts/**", + "**/storybook/**", + "**/test_fixtures/**", + "**/test_helpers/**", + ], +) + +DEPS = [ + +] + +js_library( + name = "shared-ux-router", + package_name = "@kbn/shared-ux-router", + srcs = ["package.json"] + SRCS, + deps = DEPS, + visibility = ["//visibility:public"], +) From 68cae607fe7ab8c27501492844f53f920ef841d6 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 25 Nov 2024 11:17:19 +0100 Subject: [PATCH 04/18] Add temporary TODOs --- .../public/dashboard_listing/dashboard_listing_table.tsx | 1 + src/plugins/discover/public/application/context/context_app.tsx | 1 + .../public/visualize_app/components/visualize_editor.tsx | 1 + x-pack/plugins/aiops/public/hooks/use_data.ts | 1 + x-pack/plugins/cross_cluster_replication/public/app/index.tsx | 1 + x-pack/plugins/data_quality/public/application.tsx | 1 + .../data_visualizer/public/application/common/hooks/use_data.ts | 1 + .../public/application/sections/home/index_list/index_list.tsx | 1 + x-pack/plugins/lens/public/app_plugin/app.tsx | 1 + .../plugins/ml/public/application/routing/use_active_route.tsx | 1 + .../app_root/update_execution_context_on_route_change.ts | 2 +- x-pack/plugins/rollup/public/application.tsx | 1 + .../public/common/hooks/use_update_execution_context.ts | 1 + .../application/sections/home/policy_list/policy_list.tsx | 1 + x-pack/plugins/upgrade_assistant/public/application/app.tsx | 1 + 15 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx index 96d9025f822ff..8e8ac992a830a 100644 --- a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx @@ -30,6 +30,7 @@ export const DashboardListingTable = ({ urlStateEnabled, showCreateDashboardButton = true, }: DashboardListingProps) => { + // TODO: Remove this comment after testing useExecutionContext(coreServices.executionContext, { type: 'application', page: 'list', diff --git a/src/plugins/discover/public/application/context/context_app.tsx b/src/plugins/discover/public/application/context/context_app.tsx index b0fc1342a8f72..1a5a781f3e4bb 100644 --- a/src/plugins/discover/public/application/context/context_app.tsx +++ b/src/plugins/discover/public/application/context/context_app.tsx @@ -102,6 +102,7 @@ export const ContextApp = ({ dataView, anchorId, referrer }: ContextAppProps) => }); }, [locator, referrer, services]); + // TODO: Remove this comment after testing useExecutionContext(core.executionContext, { type: 'application', page: 'context', diff --git a/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx b/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx index 9afc76fb468f7..404143edd61f9 100644 --- a/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx +++ b/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx @@ -68,6 +68,7 @@ export const VisualizeEditor = ({ onAppLeave }: VisualizeAppProps) => { ); const editorName = savedVisInstance?.vis.type.title.toLowerCase().replace(' ', '_') || ''; + // TODO: Remove this comment after testing useExecutionContext(services.executionContext, { type: 'application', page: `editor${editorName ? `:${editorName}` : ''}`, diff --git a/x-pack/plugins/aiops/public/hooks/use_data.ts b/x-pack/plugins/aiops/public/hooks/use_data.ts index 9d54dfaac1eaf..ce72f9b6e8085 100644 --- a/x-pack/plugins/aiops/public/hooks/use_data.ts +++ b/x-pack/plugins/aiops/public/hooks/use_data.ts @@ -41,6 +41,7 @@ export const useData = ( ) => { const { executionContext, uiSettings } = useAiopsAppContext(); + // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: AIOPS_PLUGIN_ID, type: 'application', diff --git a/x-pack/plugins/cross_cluster_replication/public/app/index.tsx b/x-pack/plugins/cross_cluster_replication/public/app/index.tsx index 8b9fab7258055..6e1d90d4d6af9 100644 --- a/x-pack/plugins/cross_cluster_replication/public/app/index.tsx +++ b/x-pack/plugins/cross_cluster_replication/public/app/index.tsx @@ -34,6 +34,7 @@ const AppWithExecutionContext = ({ getUrlForApp: ApplicationStart['getUrlForApp']; executionContext: ExecutionContextStart; }) => { + // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'crossClusterReplication', diff --git a/x-pack/plugins/data_quality/public/application.tsx b/x-pack/plugins/data_quality/public/application.tsx index de4c6ba524a08..1273ca6b095fa 100644 --- a/x-pack/plugins/data_quality/public/application.tsx +++ b/x-pack/plugins/data_quality/public/application.tsx @@ -44,6 +44,7 @@ const AppWithExecutionContext = ({ }) => { const { executionContext } = core; + // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: PLUGIN_ID, diff --git a/x-pack/plugins/data_visualizer/public/application/common/hooks/use_data.ts b/x-pack/plugins/data_visualizer/public/application/common/hooks/use_data.ts index 622e7371b5bc2..41b844a11507c 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/hooks/use_data.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/hooks/use_data.ts @@ -49,6 +49,7 @@ export const useData = ( }, } = useDataVisualizerKibana(); + // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: 'data_visualizer', type: 'application', diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx index 4969a51d857a4..23c4770771c54 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx @@ -19,6 +19,7 @@ export const IndexList: React.FunctionComponent = ({ histor core: { executionContext }, } = useAppContext(); + // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'indexManagementIndicesTab', diff --git a/x-pack/plugins/lens/public/app_plugin/app.tsx b/x-pack/plugins/lens/public/app_plugin/app.tsx index 60e1b0dfdb668..a305c852f8305 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.tsx @@ -150,6 +150,7 @@ export function App({ setIndicateNoData(true); }, [setIndicateNoData]); + // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', id: savedObjectId || 'new', // TODO: this doesn't consider when lens is saved by value diff --git a/x-pack/plugins/ml/public/application/routing/use_active_route.tsx b/x-pack/plugins/ml/public/application/routing/use_active_route.tsx index 5827cc036ddf4..738edfd2691b2 100644 --- a/x-pack/plugins/ml/public/application/routing/use_active_route.tsx +++ b/x-pack/plugins/ml/public/application/routing/use_active_route.tsx @@ -98,6 +98,7 @@ export const useActiveRoute = (routesList: MlRoute[]): MlRoute => { [activeRoute, overlays, pathname, startServices] ); + // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: PLUGIN_ID, type: 'application', diff --git a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts index d264e72685dc1..4dc1544a270c9 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts +++ b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts @@ -21,7 +21,7 @@ export function UpdateExecutionContextOnRouteChange({ useExecutionContext(core.executionContext, { type: 'application', name: 'apm', - page: lastMatch?.match?.path, + page: 'mary-test', }); return children; diff --git a/x-pack/plugins/rollup/public/application.tsx b/x-pack/plugins/rollup/public/application.tsx index f6f554790c47c..b225f419aaf83 100644 --- a/x-pack/plugins/rollup/public/application.tsx +++ b/x-pack/plugins/rollup/public/application.tsx @@ -30,6 +30,7 @@ const AppWithExecutionContext = ({ history: ManagementAppMountParams['history']; executionContext: ExecutionContextStart; }) => { + // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'rollup', diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts b/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts index 84badfae5413c..967212ad9459c 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts @@ -16,6 +16,7 @@ export const useUpdateExecutionContext = () => { useEffect(() => { // setImmediate is required to ensure that EBT telemetry for the previous page is shipped before the new page is updated setImmediate(() => { + // TODO: Remove this comment after testing executionContext.set({ page: pathname }); }); }, [pathname, executionContext]); diff --git a/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx b/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx index aa7a35bb2c0b2..1ccb934736f1f 100644 --- a/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx @@ -87,6 +87,7 @@ export const PolicyList: React.FunctionComponent { core: { application, http, executionContext, ...startServices }, } = dependencies.services; + // TODO: Remove this comment after testing executionContext.set({ type: 'application', page: 'upgradeAssistant' }); return ( From 87ae813fe0b1e9b88e5c62242f663684212ae893 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 25 Nov 2024 12:02:45 +0100 Subject: [PATCH 05/18] Revert useExecutionContext test in APM --- .../app_root/update_execution_context_on_route_change.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts index 4dc1544a270c9..d264e72685dc1 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts +++ b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/update_execution_context_on_route_change.ts @@ -21,7 +21,7 @@ export function UpdateExecutionContextOnRouteChange({ useExecutionContext(core.executionContext, { type: 'application', name: 'apm', - page: 'mary-test', + page: lastMatch?.match?.path, }); return children; From 89b004ba32d20330c566873c9837963aa06ec1fa Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Mon, 25 Nov 2024 17:32:02 -0400 Subject: [PATCH 06/18] Remove TODO from src/plugins/discover/public/application/context/context_app.tsx --- src/plugins/discover/public/application/context/context_app.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/discover/public/application/context/context_app.tsx b/src/plugins/discover/public/application/context/context_app.tsx index 1a5a781f3e4bb..b0fc1342a8f72 100644 --- a/src/plugins/discover/public/application/context/context_app.tsx +++ b/src/plugins/discover/public/application/context/context_app.tsx @@ -102,7 +102,6 @@ export const ContextApp = ({ dataView, anchorId, referrer }: ContextAppProps) => }); }, [locator, referrer, services]); - // TODO: Remove this comment after testing useExecutionContext(core.executionContext, { type: 'application', page: 'context', From 81a712c71eab969a2a7c7c232315b806e8b849a5 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Tue, 26 Nov 2024 12:50:38 +0100 Subject: [PATCH 07/18] fix(dataset-quality): remove TODO --- x-pack/plugins/data_quality/public/application.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/data_quality/public/application.tsx b/x-pack/plugins/data_quality/public/application.tsx index 1273ca6b095fa..de4c6ba524a08 100644 --- a/x-pack/plugins/data_quality/public/application.tsx +++ b/x-pack/plugins/data_quality/public/application.tsx @@ -44,7 +44,6 @@ const AppWithExecutionContext = ({ }) => { const { executionContext } = core; - // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: PLUGIN_ID, From 2a5a780b0e0c9fb3e8f28966c94b312b0380b3f4 Mon Sep 17 00:00:00 2001 From: Elena Stoeva Date: Thu, 28 Nov 2024 13:31:53 +0000 Subject: [PATCH 08/18] Remove comments for IM, Snapshot restore, UA --- .../public/application/sections/home/index_list/index_list.tsx | 1 - .../public/application/sections/home/policy_list/policy_list.tsx | 1 - x-pack/plugins/upgrade_assistant/public/application/app.tsx | 1 - 3 files changed, 3 deletions(-) diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx index 23c4770771c54..4969a51d857a4 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx @@ -19,7 +19,6 @@ export const IndexList: React.FunctionComponent = ({ histor core: { executionContext }, } = useAppContext(); - // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'indexManagementIndicesTab', diff --git a/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx b/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx index 1ccb934736f1f..aa7a35bb2c0b2 100644 --- a/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/sections/home/policy_list/policy_list.tsx @@ -87,7 +87,6 @@ export const PolicyList: React.FunctionComponent { core: { application, http, executionContext, ...startServices }, } = dependencies.services; - // TODO: Remove this comment after testing executionContext.set({ type: 'application', page: 'upgradeAssistant' }); return ( From a83ff91a04e9cb7cca15f2601d89f9377eadcba0 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 16 Dec 2024 17:33:00 +0100 Subject: [PATCH 09/18] Allow disabling default execution context tracking if there is a custom implementation --- .../kibana_context/root/root_provider.tsx | 4 +- packages/shared-ux/router/impl/route.tsx | 11 ++-- packages/shared-ux/router/impl/routes.tsx | 62 ++++++++++--------- .../shared-ux/router/impl/routes_context.ts | 18 ++++++ packages/shared-ux/router/impl/types.ts | 8 +++ .../data_quality/public/application.tsx | 2 +- 6 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 packages/shared-ux/router/impl/routes_context.ts diff --git a/packages/react/kibana_context/root/root_provider.tsx b/packages/react/kibana_context/root/root_provider.tsx index 438798122ab5f..77771f39ccf53 100644 --- a/packages/react/kibana_context/root/root_provider.tsx +++ b/packages/react/kibana_context/root/root_provider.tsx @@ -25,10 +25,10 @@ import { KibanaEuiProvider, type KibanaEuiProviderProps } from './eui_provider'; export interface KibanaRootContextProviderProps extends KibanaEuiProviderProps { /** The `I18nStart` API from `CoreStart`. */ i18n: I18nStart; + /** The `ExecutionContextStart` API from `CoreStart`. */ + executionContext: ExecutionContextStart; /** The `AnalyticsServiceStart` API from `CoreStart`. */ analytics?: Pick; - /** The `ExecutionContextStart` API from `CoreStart`. */ - executionContext?: ExecutionContextStart; } /** diff --git a/packages/shared-ux/router/impl/route.tsx b/packages/shared-ux/router/impl/route.tsx index 3535ff7aecec8..1fc130d082433 100644 --- a/packages/shared-ux/router/impl/route.tsx +++ b/packages/shared-ux/router/impl/route.tsx @@ -15,6 +15,7 @@ import { RouteProps, useRouteMatch, } from 'react-router-dom'; +import { useSharedUXRoutesContext } from './routes_context'; import { useKibanaSharedUX } from './services'; import { useSharedUXExecutionContext } from './use_execution_context'; @@ -30,17 +31,19 @@ export const Route = ({ render, ...rest }: RouteProps) => { + const { disableExecutionContextTracking } = useSharedUXRoutesContext(); + const enableDefaultTracking = !disableExecutionContextTracking; const component = useMemo(() => { if (!Component) { return undefined; } return (props: RouteComponentProps) => ( <> - + {enableDefaultTracking && } ); - }, [Component]); + }, [Component, enableDefaultTracking]); if (component) { return ; @@ -52,7 +55,7 @@ export const Route = ({ {...rest} render={(props) => ( <> - + {enableDefaultTracking && } {/* @ts-ignore else condition exists if renderFunction is undefined*/} {renderFunction(props)} @@ -62,7 +65,7 @@ export const Route = ({ } return ( - + {enableDefaultTracking && } {children} ); diff --git a/packages/shared-ux/router/impl/routes.tsx b/packages/shared-ux/router/impl/routes.tsx index 9c1a97de65830..972067081e835 100644 --- a/packages/shared-ux/router/impl/routes.tsx +++ b/packages/shared-ux/router/impl/routes.tsx @@ -13,6 +13,7 @@ import React, { Children } from 'react'; import { Switch, useRouteMatch } from 'react-router-dom'; import { Routes as ReactRouterRoutes, Route } from 'react-router-dom-v5-compat'; import { Route as LegacyRoute, MatchPropagator } from './route'; +import { SharedUXRoutesContext } from './routes_context'; type RouterElementChildren = Array< React.ReactElement< @@ -28,42 +29,47 @@ type RouterElementChildren = Array< export const Routes = ({ legacySwitch = true, + disableExecutionContextTracking = false, children, }: { legacySwitch?: boolean; + disableExecutionContextTracking?: boolean; children: React.ReactNode; }) => { const match = useRouteMatch(); return legacySwitch ? ( - {children} + + {children} + ) : ( - - {Children.map(children as RouterElementChildren, (child) => { - if (React.isValidElement(child) && child.type === LegacyRoute) { - const path = replace(child?.props.path, match.url + '/', ''); - const renderFunction = - typeof child?.props.children === 'function' - ? child?.props.children - : child?.props.render; - - return ( - - - {(child?.props?.component && ) || - (renderFunction && renderFunction()) || - children} - - } - /> - ); - } else { - return child; - } - })} - + + + {Children.map(children as RouterElementChildren, (child) => { + if (React.isValidElement(child) && child.type === LegacyRoute) { + const path = replace(child?.props.path, match.url + '/', ''); + const renderFunction = + typeof child?.props.children === 'function' + ? child?.props.children + : child?.props.render; + return ( + + {!disableExecutionContextTracking && } + {(child?.props?.component && ) || + (renderFunction && renderFunction()) || + children} + + } + /> + ); + } else { + return child; + } + })} + + ); }; diff --git a/packages/shared-ux/router/impl/routes_context.ts b/packages/shared-ux/router/impl/routes_context.ts new file mode 100644 index 0000000000000..115a5df7780d5 --- /dev/null +++ b/packages/shared-ux/router/impl/routes_context.ts @@ -0,0 +1,18 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { createContext, useContext } from 'react'; +import { SharedUXRoutesContextType } from './types'; + +const defaultContextValue = {}; + +export const SharedUXRoutesContext = createContext(defaultContextValue); + +export const useSharedUXRoutesContext = (): SharedUXRoutesContextType => + useContext(SharedUXRoutesContext as unknown as React.Context); diff --git a/packages/shared-ux/router/impl/types.ts b/packages/shared-ux/router/impl/types.ts index 833c5bdd0c816..8e5f5fb498ac6 100644 --- a/packages/shared-ux/router/impl/types.ts +++ b/packages/shared-ux/router/impl/types.ts @@ -33,3 +33,11 @@ export declare interface SharedUXExecutionContext { /** an inner context spawned from the current context. */ child?: SharedUXExecutionContext; } + +export declare interface SharedUXRoutesContextType { + /** + * This flag is used to disable the default execution context tracking for a specific router. + * Disable this flag in case you have a custom implementation for execution context tracking. + * */ + readonly disableExecutionContextTracking?: boolean; +} diff --git a/x-pack/plugins/data_quality/public/application.tsx b/x-pack/plugins/data_quality/public/application.tsx index de4c6ba524a08..9bbd9e1b29c60 100644 --- a/x-pack/plugins/data_quality/public/application.tsx +++ b/x-pack/plugins/data_quality/public/application.tsx @@ -53,7 +53,7 @@ const AppWithExecutionContext = ({ - + } /> } /> From 899a3fe3f69ad81ccb7a02fbc6e65709a251c9d5 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 16 Dec 2024 17:40:15 +0100 Subject: [PATCH 10/18] Change disableExecutionContextTracking to enableExecutionContextTracking --- packages/shared-ux/router/impl/route.tsx | 11 +++++------ packages/shared-ux/router/impl/routes.tsx | 10 +++++----- packages/shared-ux/router/impl/types.ts | 2 +- x-pack/plugins/data_quality/public/application.tsx | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/shared-ux/router/impl/route.tsx b/packages/shared-ux/router/impl/route.tsx index 1fc130d082433..1ab02ef10e12d 100644 --- a/packages/shared-ux/router/impl/route.tsx +++ b/packages/shared-ux/router/impl/route.tsx @@ -31,19 +31,18 @@ export const Route = ({ render, ...rest }: RouteProps) => { - const { disableExecutionContextTracking } = useSharedUXRoutesContext(); - const enableDefaultTracking = !disableExecutionContextTracking; + const { enableExecutionContextTracking } = useSharedUXRoutesContext(); const component = useMemo(() => { if (!Component) { return undefined; } return (props: RouteComponentProps) => ( <> - {enableDefaultTracking && } + {enableExecutionContextTracking && } ); - }, [Component, enableDefaultTracking]); + }, [Component, enableExecutionContextTracking]); if (component) { return ; @@ -55,7 +54,7 @@ export const Route = ({ {...rest} render={(props) => ( <> - {enableDefaultTracking && } + {enableExecutionContextTracking && } {/* @ts-ignore else condition exists if renderFunction is undefined*/} {renderFunction(props)} @@ -65,7 +64,7 @@ export const Route = ({ } return ( - {enableDefaultTracking && } + {enableExecutionContextTracking && } {children} ); diff --git a/packages/shared-ux/router/impl/routes.tsx b/packages/shared-ux/router/impl/routes.tsx index 972067081e835..9377562246276 100644 --- a/packages/shared-ux/router/impl/routes.tsx +++ b/packages/shared-ux/router/impl/routes.tsx @@ -29,21 +29,21 @@ type RouterElementChildren = Array< export const Routes = ({ legacySwitch = true, - disableExecutionContextTracking = false, + enableExecutionContextTracking = false, children, }: { legacySwitch?: boolean; - disableExecutionContextTracking?: boolean; + enableExecutionContextTracking?: boolean; children: React.ReactNode; }) => { const match = useRouteMatch(); return legacySwitch ? ( - + {children} ) : ( - + {Children.map(children as RouterElementChildren, (child) => { if (React.isValidElement(child) && child.type === LegacyRoute) { @@ -57,7 +57,7 @@ export const Routes = ({ path={path} element={ <> - {!disableExecutionContextTracking && } + {enableExecutionContextTracking && } {(child?.props?.component && ) || (renderFunction && renderFunction()) || children} diff --git a/packages/shared-ux/router/impl/types.ts b/packages/shared-ux/router/impl/types.ts index 8e5f5fb498ac6..2dd2fa2d92067 100644 --- a/packages/shared-ux/router/impl/types.ts +++ b/packages/shared-ux/router/impl/types.ts @@ -39,5 +39,5 @@ export declare interface SharedUXRoutesContextType { * This flag is used to disable the default execution context tracking for a specific router. * Disable this flag in case you have a custom implementation for execution context tracking. * */ - readonly disableExecutionContextTracking?: boolean; + readonly enableExecutionContextTracking?: boolean; } diff --git a/x-pack/plugins/data_quality/public/application.tsx b/x-pack/plugins/data_quality/public/application.tsx index 9bbd9e1b29c60..de4c6ba524a08 100644 --- a/x-pack/plugins/data_quality/public/application.tsx +++ b/x-pack/plugins/data_quality/public/application.tsx @@ -53,7 +53,7 @@ const AppWithExecutionContext = ({ - + } /> } /> From 1fc0b38e21b686e4812ff9575c36e0520da8dcc1 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 12:03:33 +0100 Subject: [PATCH 11/18] Fix executionContext dep and enable tracking for observability --- packages/react/kibana_context/render/render_provider.tsx | 4 ++-- .../plugins/observability/public/application/index.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react/kibana_context/render/render_provider.tsx b/packages/react/kibana_context/render/render_provider.tsx index 233abb42834b9..345a0993bb9e4 100644 --- a/packages/react/kibana_context/render/render_provider.tsx +++ b/packages/react/kibana_context/render/render_provider.tsx @@ -25,11 +25,11 @@ export type KibanaRenderContextProviderProps = Omit > = ({ children, ...props }) => { - const { analytics, i18n, theme, userProfile, colorMode, modify } = props; + const { analytics, executionContext, i18n, theme, userProfile, colorMode, modify } = props; return ( {children} diff --git a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx index 3ae624d2f8ea1..54b8b4044e64e 100644 --- a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx @@ -28,7 +28,7 @@ import { HideableReactQueryDevTools } from './hideable_react_query_dev_tools'; function App() { return ( <> - + {Object.keys(routes).map((key) => { const path = key as keyof typeof routes; const { handler, exact } = routes[path]; From 7a04db2c776b93cdb8fb100ce6b8b3d8aa108460 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 12:08:14 +0100 Subject: [PATCH 12/18] Remove comments --- .../public/dashboard_listing/dashboard_listing_table.tsx | 1 - .../public/visualize_app/components/visualize_editor.tsx | 1 - .../private/cross_cluster_replication/public/app/index.tsx | 1 - .../data_visualizer/public/application/common/hooks/use_data.ts | 1 - x-pack/platform/plugins/private/rollup/public/application.tsx | 1 - x-pack/platform/plugins/shared/aiops/public/hooks/use_data.ts | 1 - .../shared/ml/public/application/routing/use_active_route.tsx | 1 - x-pack/plugins/lens/public/app_plugin/app.tsx | 1 - .../public/common/hooks/use_update_execution_context.ts | 1 - .../plugins/observability/public/application/index.tsx | 2 +- 10 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx index 6deecc4c71883..efcc0fe2cc644 100644 --- a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx @@ -34,7 +34,6 @@ export const DashboardListingTable = ({ urlStateEnabled, showCreateDashboardButton = true, }: DashboardListingProps) => { - // TODO: Remove this comment after testing useExecutionContext(coreServices.executionContext, { type: 'application', page: 'list', diff --git a/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx b/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx index 404143edd61f9..9afc76fb468f7 100644 --- a/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx +++ b/src/plugins/visualizations/public/visualize_app/components/visualize_editor.tsx @@ -68,7 +68,6 @@ export const VisualizeEditor = ({ onAppLeave }: VisualizeAppProps) => { ); const editorName = savedVisInstance?.vis.type.title.toLowerCase().replace(' ', '_') || ''; - // TODO: Remove this comment after testing useExecutionContext(services.executionContext, { type: 'application', page: `editor${editorName ? `:${editorName}` : ''}`, diff --git a/x-pack/platform/plugins/private/cross_cluster_replication/public/app/index.tsx b/x-pack/platform/plugins/private/cross_cluster_replication/public/app/index.tsx index 36df096bfd772..c28cc3d453309 100644 --- a/x-pack/platform/plugins/private/cross_cluster_replication/public/app/index.tsx +++ b/x-pack/platform/plugins/private/cross_cluster_replication/public/app/index.tsx @@ -34,7 +34,6 @@ const AppWithExecutionContext = ({ getUrlForApp: ApplicationStart['getUrlForApp']; executionContext: ExecutionContextStart; }) => { - // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'crossClusterReplication', diff --git a/x-pack/platform/plugins/private/data_visualizer/public/application/common/hooks/use_data.ts b/x-pack/platform/plugins/private/data_visualizer/public/application/common/hooks/use_data.ts index 41b844a11507c..622e7371b5bc2 100644 --- a/x-pack/platform/plugins/private/data_visualizer/public/application/common/hooks/use_data.ts +++ b/x-pack/platform/plugins/private/data_visualizer/public/application/common/hooks/use_data.ts @@ -49,7 +49,6 @@ export const useData = ( }, } = useDataVisualizerKibana(); - // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: 'data_visualizer', type: 'application', diff --git a/x-pack/platform/plugins/private/rollup/public/application.tsx b/x-pack/platform/plugins/private/rollup/public/application.tsx index b225f419aaf83..f6f554790c47c 100644 --- a/x-pack/platform/plugins/private/rollup/public/application.tsx +++ b/x-pack/platform/plugins/private/rollup/public/application.tsx @@ -30,7 +30,6 @@ const AppWithExecutionContext = ({ history: ManagementAppMountParams['history']; executionContext: ExecutionContextStart; }) => { - // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', page: 'rollup', diff --git a/x-pack/platform/plugins/shared/aiops/public/hooks/use_data.ts b/x-pack/platform/plugins/shared/aiops/public/hooks/use_data.ts index ce72f9b6e8085..9d54dfaac1eaf 100644 --- a/x-pack/platform/plugins/shared/aiops/public/hooks/use_data.ts +++ b/x-pack/platform/plugins/shared/aiops/public/hooks/use_data.ts @@ -41,7 +41,6 @@ export const useData = ( ) => { const { executionContext, uiSettings } = useAiopsAppContext(); - // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: AIOPS_PLUGIN_ID, type: 'application', diff --git a/x-pack/platform/plugins/shared/ml/public/application/routing/use_active_route.tsx b/x-pack/platform/plugins/shared/ml/public/application/routing/use_active_route.tsx index 738edfd2691b2..5827cc036ddf4 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/routing/use_active_route.tsx +++ b/x-pack/platform/plugins/shared/ml/public/application/routing/use_active_route.tsx @@ -98,7 +98,6 @@ export const useActiveRoute = (routesList: MlRoute[]): MlRoute => { [activeRoute, overlays, pathname, startServices] ); - // TODO: Remove this comment after testing useExecutionContext(executionContext, { name: PLUGIN_ID, type: 'application', diff --git a/x-pack/plugins/lens/public/app_plugin/app.tsx b/x-pack/plugins/lens/public/app_plugin/app.tsx index ab6f2fbbbfaa4..b8903bde1af0f 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.tsx @@ -165,7 +165,6 @@ export function App({ setIndicateNoData(true); }, [setIndicateNoData]); - // TODO: Remove this comment after testing useExecutionContext(executionContext, { type: 'application', id: savedObjectId || 'new', // TODO: this doesn't consider when lens is saved by value diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts b/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts index 967212ad9459c..84badfae5413c 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/use_update_execution_context.ts @@ -16,7 +16,6 @@ export const useUpdateExecutionContext = () => { useEffect(() => { // setImmediate is required to ensure that EBT telemetry for the previous page is shipped before the new page is updated setImmediate(() => { - // TODO: Remove this comment after testing executionContext.set({ page: pathname }); }); }, [pathname, executionContext]); diff --git a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx index 54b8b4044e64e..4bfd755c42543 100644 --- a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx @@ -28,7 +28,7 @@ import { HideableReactQueryDevTools } from './hideable_react_query_dev_tools'; function App() { return ( <> - + {Object.keys(routes).map((key) => { const path = key as keyof typeof routes; const { handler, exact } = routes[path]; From 79586d6f6703edf55a246234086510ef7e0bef78 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 12:31:05 +0100 Subject: [PATCH 13/18] Make executionContext dep optional --- packages/react/kibana_context/root/root_provider.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/kibana_context/root/root_provider.tsx b/packages/react/kibana_context/root/root_provider.tsx index 77771f39ccf53..438798122ab5f 100644 --- a/packages/react/kibana_context/root/root_provider.tsx +++ b/packages/react/kibana_context/root/root_provider.tsx @@ -25,10 +25,10 @@ import { KibanaEuiProvider, type KibanaEuiProviderProps } from './eui_provider'; export interface KibanaRootContextProviderProps extends KibanaEuiProviderProps { /** The `I18nStart` API from `CoreStart`. */ i18n: I18nStart; - /** The `ExecutionContextStart` API from `CoreStart`. */ - executionContext: ExecutionContextStart; /** The `AnalyticsServiceStart` API from `CoreStart`. */ analytics?: Pick; + /** The `ExecutionContextStart` API from `CoreStart`. */ + executionContext?: ExecutionContextStart; } /** From b22b5b80ad44b519125f4946412204fcf8d0edfe Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 14:59:02 +0100 Subject: [PATCH 14/18] Fix test --- .../impl/__snapshots__/route.test.tsx.snap | 2 ++ packages/shared-ux/router/impl/route.test.tsx | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/shared-ux/router/impl/__snapshots__/route.test.tsx.snap b/packages/shared-ux/router/impl/__snapshots__/route.test.tsx.snap index 418aa60b7c1f4..b7ef595289233 100644 --- a/packages/shared-ux/router/impl/__snapshots__/route.test.tsx.snap +++ b/packages/shared-ux/router/impl/__snapshots__/route.test.tsx.snap @@ -33,3 +33,5 @@ exports[`Route renders 1`] = ` `; + +exports[`Route renders with enableExecutionContextTracking as false 1`] = ``; diff --git a/packages/shared-ux/router/impl/route.test.tsx b/packages/shared-ux/router/impl/route.test.tsx index 96bb6130387af..9d21690cdcf4f 100644 --- a/packages/shared-ux/router/impl/route.test.tsx +++ b/packages/shared-ux/router/impl/route.test.tsx @@ -9,15 +9,34 @@ import React, { Component, FC } from 'react'; import { shallow } from 'enzyme'; +import { useSharedUXRoutesContext } from './routes_context'; import { Route } from './route'; import { createMemoryHistory } from 'history'; +jest.mock('./routes_context', () => ({ + useSharedUXRoutesContext: jest.fn().mockImplementation(() => ({ + enableExecutionContextTracking: true, + })), +})); + describe('Route', () => { + beforeEach(() => { + jest.restoreAllMocks(); + }); + test('renders', () => { const example = shallow(); expect(example).toMatchSnapshot(); }); + test('renders with enableExecutionContextTracking as false', () => { + (useSharedUXRoutesContext as jest.Mock).mockImplementationOnce(() => ({ + enableExecutionContextTracking: false, + })); + const example = shallow(); + expect(example).toMatchSnapshot(); + }); + test('location renders as expected', () => { // create a history const historyLocation = createMemoryHistory(); From e23b5610bb557b3dd6559a2355323dd666c3b16e Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 17:06:13 +0100 Subject: [PATCH 15/18] Enable execution context tracking for observability --- .../plugins/observability/public/application/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx index 4bfd755c42543..54b8b4044e64e 100644 --- a/x-pack/solutions/observability/plugins/observability/public/application/index.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/application/index.tsx @@ -28,7 +28,7 @@ import { HideableReactQueryDevTools } from './hideable_react_query_dev_tools'; function App() { return ( <> - + {Object.keys(routes).map((key) => { const path = key as keyof typeof routes; const { handler, exact } = routes[path]; From 9b3532cc7b0ff8664e7595cc130f15eebe94dee7 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 17 Dec 2024 17:25:28 +0100 Subject: [PATCH 16/18] Fix comment --- packages/shared-ux/router/impl/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared-ux/router/impl/types.ts b/packages/shared-ux/router/impl/types.ts index 2dd2fa2d92067..067677d152cae 100644 --- a/packages/shared-ux/router/impl/types.ts +++ b/packages/shared-ux/router/impl/types.ts @@ -36,8 +36,8 @@ export declare interface SharedUXExecutionContext { export declare interface SharedUXRoutesContextType { /** - * This flag is used to disable the default execution context tracking for a specific router. - * Disable this flag in case you have a custom implementation for execution context tracking. + * This flag is used to enable the default execution context tracking for a specific router. + * Enable this flag in case you don't have a custom implementation for execution context tracking. * */ readonly enableExecutionContextTracking?: boolean; } From c56ab90169db20ce341fd6bf9f12442e74a6c3b3 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Wed, 18 Dec 2024 09:49:05 +0100 Subject: [PATCH 17/18] Rename SharedUXContext to SharedUXRouterContext --- packages/react/kibana_context/root/root_provider.tsx | 6 +++--- packages/shared-ux/router/impl/index.ts | 2 +- packages/shared-ux/router/impl/services.ts | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react/kibana_context/root/root_provider.tsx b/packages/react/kibana_context/root/root_provider.tsx index 438798122ab5f..be8ddfa3f95ae 100644 --- a/packages/react/kibana_context/root/root_provider.tsx +++ b/packages/react/kibana_context/root/root_provider.tsx @@ -12,7 +12,7 @@ import React, { FC, PropsWithChildren } from 'react'; import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; import type { I18nStart } from '@kbn/core-i18n-browser'; import type { ExecutionContextStart } from '@kbn/core-execution-context-browser'; -import { SharedUXContext } from '@kbn/shared-ux-router'; +import { SharedUXRouterContext } from '@kbn/shared-ux-router'; // @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types import { useIsNestedEuiProvider } from '@elastic/eui/lib/components/provider/nested'; @@ -53,9 +53,9 @@ export const KibanaRootContextProvider: FC { const hasEuiProvider = useIsNestedEuiProvider(); const rootContextProvider = ( - + {children} - + ); if (hasEuiProvider) { diff --git a/packages/shared-ux/router/impl/index.ts b/packages/shared-ux/router/impl/index.ts index 63d8916624091..253d42beaa501 100644 --- a/packages/shared-ux/router/impl/index.ts +++ b/packages/shared-ux/router/impl/index.ts @@ -11,4 +11,4 @@ export { Route } from './route'; export { HashRouter, BrowserRouter, MemoryRouter, Router } from './router'; export { Routes } from './routes'; -export { SharedUXContext } from './services'; +export { SharedUXRouterContext } from './services'; diff --git a/packages/shared-ux/router/impl/services.ts b/packages/shared-ux/router/impl/services.ts index 825d4485802f8..7cea72f03bd82 100644 --- a/packages/shared-ux/router/impl/services.ts +++ b/packages/shared-ux/router/impl/services.ts @@ -63,12 +63,14 @@ const defaultContextValue = { services: {}, }; -export const SharedUXContext = +export const SharedUXRouterContext = createContext>(defaultContextValue); export const useKibanaSharedUX = (): SharedUXRouterContextValue< KibanaServices & Extra > => useContext( - SharedUXContext as unknown as React.Context> + SharedUXRouterContext as unknown as React.Context< + SharedUXRouterContextValue + > ); From 53a7e9a096159c80d146b4dda441edc79d4b49b9 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Wed, 18 Dec 2024 11:23:22 +0100 Subject: [PATCH 18/18] Throw error if executionContext is undefined --- packages/shared-ux/router/impl/route.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/shared-ux/router/impl/route.tsx b/packages/shared-ux/router/impl/route.tsx index 1ab02ef10e12d..5041f872b71b1 100644 --- a/packages/shared-ux/router/impl/route.tsx +++ b/packages/shared-ux/router/impl/route.tsx @@ -77,6 +77,12 @@ export const MatchPropagator = () => { const { executionContext } = useKibanaSharedUX().services; const match = useRouteMatch(); + if (!executionContext && process.env.NODE_ENV !== 'production') { + throw new Error( + 'Default execution context tracking is enabled but the executionContext service is not available' + ); + } + useSharedUXExecutionContext(executionContext, { type: 'application', page: match.path,