diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index eb08ada7da2c4..ae55ea6b37108 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1095,6 +1095,7 @@ x-pack/test_serverless/api_integration/test_suites/common/platform_security @ela src/plugins/discover/public/context_awareness/profile_providers/security @elastic/kibana-data-discovery @elastic/security-threat-hunting-investigations # Platform Docs +/x-pack/test/functional/services/sample_data @elastic/platform-docs /x-pack/test_serverless/functional/test_suites/security/screenshot_creation/index.ts @elastic/platform-docs /x-pack/test_serverless/functional/test_suites/security/config.screenshots.ts @elastic/platform-docs /x-pack/test/screenshot_creation @elastic/platform-docs @@ -1202,6 +1203,10 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai ## This should allow the infra team to work without dependencies on the @elastic/obs-ux-logs-team, which will maintain ownership of the Logs UI code only. ## infra/{common,docs,public,server}/{sub-folders}/ -> @elastic/obs-ux-infra_services-team +# obs-ux-infra_services-team +/x-pack/test/functional/page_objects/asset_details.ts @elastic/obs-ux-infra_services-team # Assigned per https://github.com/elastic/kibana/pull/200157/files/c83fae62151fe634342c498aca69b686b739fe45#r1842202022 +/x-pack/test/functional/page_objects/infra_* @elastic/obs-ux-infra_services-team +/x-pack/test/functional/es_archives/infra @elastic/obs-ux-infra_services-team /test/common/plugins/otel_metrics @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/common @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/docs @elastic/obs-ux-infra_services-team @@ -1223,10 +1228,10 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/plugins/observability_solution/infra/server/services @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/server/usage @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/server/utils @elastic/obs-ux-infra_services-team -/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra @elastic/obs-ux-logs-team -/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm @elastic/obs-ux-logs-team +/x-pack/test/api_integration/services/infraops_source_configuration.ts @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team # Assigned per https://github.com/elastic/kibana/pull/34916 ## Logs UI code exceptions -> @elastic/obs-ux-logs-team +/x-pack/test/upgrade/apps/logs @elastic/obs-ux-logs-team /x-pack/test_serverless/functional/page_objects/svl_oblt_onboarding_stream_log_file.ts @elastic/obs-ux-logs-team /x-pack/test_serverless/functional/page_objects/svl_oblt_onboarding_page.ts @elastic/obs-ux-logs-team /x-pack/plugins/observability_solution/infra/common/http_api/log_alerts @elastic/obs-ux-logs-team @@ -1248,12 +1253,20 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/plugins/observability_solution/infra/server/routes/log_alerts @elastic/obs-ux-logs-team /x-pack/plugins/observability_solution/infra/server/routes/log_analysis @elastic/obs-ux-logs-team /x-pack/plugins/observability_solution/infra/server/services/rules @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team +/x-pack/test/common/utils/synthtrace @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team # Assigned per https://github.com/elastic/kibana/blob/main/packages/kbn-apm-synthtrace/kibana.jsonc#L5 + # Infra Monitoring tests /x-pack/test/api_integration/apis/infra @elastic/obs-ux-infra_services-team /x-pack/test/functional/apps/infra @elastic/obs-ux-infra_services-team /x-pack/test/functional/apps/infra/logs @elastic/obs-ux-logs-team # Observability UX management team +/x-pack/test/api_integration/services/data_view_api.ts @elastic/obs-ux-management-team +/x-pack/test/api_integration/services/slo.ts @elastic/obs-ux-management-team +/x-pack/test/functional/services/slo @elastic/obs-ux-management-team +/x-pack/test/functional/apps/slo @elastic/obs-ux-management-team +/x-pack/test/observability_api_integration @elastic/obs-ux-management-team # Assigned per https://github.com/elastic/kibana/pull/182243 +/x-pack/test/functional/services/observability @elastic/obs-ux-management-team /x-pack/test/api_integration/apis/slos @elastic/obs-ux-management-team /x-pack/test/accessibility/apps/group1/uptime.ts @elastic/obs-ux-management-team /x-pack/test/accessibility/apps/group3/observability.ts @elastic/obs-ux-management-team @@ -1264,12 +1277,15 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test_serverless/**/test_suites/observability/custom_threshold_rule/ @elastic/obs-ux-management-team /x-pack/test_serverless/**/test_suites/observability/slos/ @elastic/obs-ux-management-team /x-pack/test_serverless/api_integration/test_suites/observability/es_query_rule @elastic/obs-ux-management-team -/x-pack/test/api_integration/deployment_agnostic/apis/observability/alerting @elastic/obs-ux-management-team +/x-pack/test/api_integration/deployment_agnostic/apis/observability/alerting/burn_rate_rule @elastic/obs-ux-management-team /x-pack/test/api_integration/deployment_agnostic/services/alerting_api @elastic/obs-ux-management-team /x-pack/test/api_integration/deployment_agnostic/services/slo_api @elastic/obs-ux-management-team /x-pack/test_serverless/**/test_suites/observability/infra/ @elastic/obs-ux-infra_services-team # Elastic Stack Monitoring +/x-pack/test/monitoring_api_integration @elastic/stack-monitoring +/x-pack/test/functional/page_objects/monitoring_page.ts @elastic/stack-monitoring +/x-pack/test/functional/es_archives/monitoring @elastic/stack-monitoring /x-pack/test/functional/services/monitoring @elastic/stack-monitoring /x-pack/test/functional/apps/monitoring @elastic/stack-monitoring /x-pack/test/api_integration/apis/monitoring @elastic/stack-monitoring @@ -1289,7 +1305,10 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test_serverless/**/test_suites/**/fleet/ @elastic/fleet # APM -/x-pack/test/functional/apps/apm/ @elastic/obs-ux-infra_services-team +/x-pack/test/stack_functional_integration/apps/apm @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team +/x-pack/test/common/services/apm_synthtrace_kibana_client.ts @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team +/test/api_integration/apis/ui_metric/*.ts @elastic/obs-ux-infra_services-team +/x-pack/test/functional/apps/apm/ @elastic/obs-ux-infra_services-team /x-pack/test/apm_api_integration/ @elastic/obs-ux-infra_services-team /src/apm.js @elastic/kibana-core @vigneshshanmugam /packages/kbn-utility-types/src/dot.ts @dgieselaar @@ -1299,6 +1318,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai #CC# /x-pack/plugins/observability_solution/observability/ @elastic/apm-ui # Uptime +/x-pack/test/functional/page_objects/uptime_page.ts @elastic/obs-ux-management-team /x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/uptime/ @elastic/obs-ux-management-team /x-pack/test/functional/apps/uptime @elastic/obs-ux-management-team /x-pack/test/functional/es_archives/uptime @elastic/obs-ux-management-team @@ -1310,6 +1330,16 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test_serverless/api_integration/test_suites/observability/synthetics @elastic/obs-ux-management-team # obs-ux-logs-team +/x-pack/test_serverless/functional/test_suites/observability/config.* @elastic/obs-ux-logs-team +/x-pack/test_serverless/functional/test_suites/observability/landing_page.ts @elastic/obs-ux-logs-team +/x-pack/test_serverless/functional/test_suites/observability/navigation.ts @elastic/obs-ux-logs-team +/x-pack/test/functional/page_objects/dataset_quality.ts @elastic/obs-ux-logs-team +/x-pack/test_serverless/functional/test_suites/observability/index* @elastic/obs-ux-logs-team +/x-pack/test_serverless/functional/test_suites/observability/cypress @elastic/obs-ux-logs-team +/x-pack/test/functional/services/infra_source_configuration_form.ts @elastic/obs-ux-logs-team +/x-pack/test/functional/services/logs_ui @elastic/obs-ux-logs-team +/x-pack/test/functional/page_objects/observability_logs_explorer.ts @elastic/obs-ux-logs-team +/test/functional/services/selectable.ts @elastic/obs-ux-logs-team /x-pack/test/observability_onboarding_api_integration @elastic/obs-ux-logs-team /x-pack/test_serverless/api_integration/test_suites/observability/index.feature_flags.ts @elastic/obs-ux-logs-team /x-pack/test/api_integration/apis/logs_ui @elastic/obs-ux-logs-team @@ -1319,11 +1349,16 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer @elastic/obs-ux-logs-team /x-pack/test/functional/apps/dataset_quality @elastic/obs-ux-logs-team /x-pack/test_serverless/functional/test_suites/observability/dataset_quality @elastic/obs-ux-logs-team -/x-pack/test_serverless/functional/test_suites/observability/ @elastic/obs-ux-logs-team /x-pack/test_serverless/functional/test_suites/observability/discover @elastic/obs-ux-logs-team @elastic/kibana-data-discovery /src/plugins/unified_doc_viewer/public/components/doc_viewer_logs_overview @elastic/obs-ux-logs-team /x-pack/test/api_integration/apis/logs_shared @elastic/obs-ux-logs-team +# Observability-ui +/x-pack/test_serverless/api_integration/test_suites/observability/index.ts @elastic/observability-ui +/x-pack/test/functional_solution_sidenav/tests/observability_sidenav.ts @elastic/observability-ui +/x-pack/test/functional/page_objects/observability_page.ts @elastic/observability-ui +/x-pack/test_serverless/**/test_suites/observability/config.ts @elastic/observability-ui + # Observability onboarding tour /x-pack/plugins/observability_solution/observability_shared/public/components/tour @elastic/appex-sharedux /x-pack/test/functional/apps/infra/tour.ts @elastic/appex-sharedux @@ -1350,8 +1385,11 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai #CC# /src/plugins/kibana_react/public/code_editor/ @elastic/kibana-presentation # Machine Learning +/x-pack/test/stack_functional_integration/apps/ml @elastic/ml-ui +/x-pack/test/functional/fixtures/kbn_archiver/ml @elastic/ml-ui /x-pack/test/api_integration/apis/file_upload @elastic/ml-ui /x-pack/test/accessibility/apps/group2/ml.ts @elastic/ml-ui +/x-pack/test/accessibility/apps/group2/ml_* @elastic/ml-ui /x-pack/test/accessibility/apps/group3/ml_embeddables_in_dashboard.ts @elastic/ml-ui /x-pack/test/api_integration/apis/ml/ @elastic/ml-ui /x-pack/test/api_integration_basic/apis/ml/ @elastic/ml-ui @@ -1359,6 +1397,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test/functional/es_archives/ml/ @elastic/ml-ui /x-pack/test/functional/services/ml/ @elastic/ml-ui /x-pack/test/functional_basic/apps/ml/ @elastic/ml-ui +/x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/config.ts @elastic/ml-ui /x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/ml/ @elastic/ml-ui /x-pack/test/alerting_api_integration/spaces_only/tests/alerting/ml_rule_types/ @elastic/ml-ui /x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/ @elastic/ml-ui @@ -1369,7 +1408,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test/api_integration/services/ml.ts @elastic/ml-ui # Additional plugins and packages maintained by the ML team. -/test/examples/response_stream @elastic/ml-ui +/test/examples/response_stream/*.ts @elastic/ml-ui /x-pack/test/accessibility/apps/group2/transform.ts @elastic/ml-ui /x-pack/test/api_integration/apis/aiops/ @elastic/ml-ui /x-pack/test/api_integration/apis/transform/ @elastic/ml-ui @@ -1380,6 +1419,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/test/functional/apps/aiops @elastic/ml-ui /x-pack/test/functional/apps/transform/ @elastic/ml-ui /x-pack/test/functional/services/transform/ @elastic/ml-ui +/x-pack/test/functional/services/aiops @elastic/ml-ui /x-pack/test/functional_basic/apps/transform/ @elastic/ml-ui # Maps @@ -1392,6 +1432,9 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai #CC# /x-pack/plugins/file_upload @elastic/kibana-gis # Operations +/test/package @elastic/kibana-operations +/test/package/roles @elastic/kibana-operations +/test/common/fixtures/plugins/coverage/kibana.json @elastic/kibana-operations /src/dev/license_checker/config.ts @elastic/kibana-operations /src/dev/ @elastic/kibana-operations /src/setup_node_env/ @elastic/kibana-operations diff --git a/packages/core/base/core-base-common/BUILD.bazel b/packages/core/base/core-base-common/BUILD.bazel new file mode 100644 index 0000000000000..30c3b1ae616f4 --- /dev/null +++ b/packages/core/base/core-base-common/BUILD.bazel @@ -0,0 +1,35 @@ +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 = [ + "@npm//react", + "@npm//tslib", +] + +js_library( + name = "core-base-common", + package_name = "@kbn/core-base-common", + srcs = ["package.json"] + SRCS, + deps = DEPS, + visibility = ["//visibility:public"], +) diff --git a/packages/core/injected-metadata/core-injected-metadata-browser-mocks/src/injected_metadata_service.mock.ts b/packages/core/injected-metadata/core-injected-metadata-browser-mocks/src/injected_metadata_service.mock.ts index 804134cabd4b9..68fa84022ce34 100644 --- a/packages/core/injected-metadata/core-injected-metadata-browser-mocks/src/injected_metadata_service.mock.ts +++ b/packages/core/injected-metadata/core-injected-metadata-browser-mocks/src/injected_metadata_service.mock.ts @@ -57,6 +57,7 @@ const createSetupContractMock = () => { setupContract.getPlugins.mockReturnValue([]); setupContract.getTheme.mockReturnValue({ darkMode: false, + name: 'amsterdam', version: 'v8', stylesheetPaths: { default: ['light-1.css'], diff --git a/packages/core/injected-metadata/core-injected-metadata-common-internal/src/types.ts b/packages/core/injected-metadata/core-injected-metadata-common-internal/src/types.ts index 1ee75dbfc0d5d..e988420720900 100644 --- a/packages/core/injected-metadata/core-injected-metadata-common-internal/src/types.ts +++ b/packages/core/injected-metadata/core-injected-metadata-common-internal/src/types.ts @@ -41,6 +41,7 @@ export interface InjectedMetadataExternalUrlPolicy { /** @internal */ export interface InjectedMetadataTheme { darkMode: DarkModeValue; + name: string; version: ThemeVersion; stylesheetPaths: { default: string[]; diff --git a/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap b/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap index c858b6a8470d2..8b1dc7ef53e15 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap +++ b/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap @@ -68,6 +68,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -149,6 +150,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -234,6 +236,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -315,6 +318,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -396,6 +400,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -481,6 +486,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -562,6 +568,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -643,6 +650,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -724,6 +732,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -814,6 +823,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -895,6 +905,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -985,6 +996,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1071,6 +1083,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1152,6 +1165,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1242,6 +1256,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1328,6 +1343,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1414,6 +1430,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", @@ -1502,6 +1519,7 @@ Object { "serverBasePath": "/mock-server-basepath", "theme": Object { "darkMode": "theme:darkMode", + "name": "theme:name", "stylesheetPaths": Object { "dark": Array [ "/style-1.css", diff --git a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts index 597e4159e4cc7..25d7e241325f3 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts @@ -34,6 +34,18 @@ const createPackageInfo = (parts: Partial = {}): PackageInfo => ({ ...parts, }); +const getClientGetMockImplementation = + ({ darkMode, name }: { darkMode?: boolean; name?: string } = {}) => + (key: string) => { + switch (key) { + case 'theme:darkMode': + return Promise.resolve(darkMode ?? false); + case 'theme:name': + return Promise.resolve(name ?? 'amsterdam'); + } + return Promise.resolve(); + }; + const createUiPlugins = (): UiPlugins => ({ public: new Map(), internal: new Map(), @@ -59,6 +71,7 @@ describe('bootstrapRenderer', () => { getPluginsBundlePathsMock.mockReturnValue(new Map()); renderTemplateMock.mockReturnValue('__rendered__'); getJsDependencyPathsMock.mockReturnValue([]); + uiSettingsClient.get.mockImplementation(getClientGetMockImplementation()); renderer = bootstrapRendererFactory({ auth, @@ -91,13 +104,17 @@ describe('bootstrapRenderer', () => { uiSettingsClient, }); - expect(uiSettingsClient.get).toHaveBeenCalledTimes(1); + expect(uiSettingsClient.get).toHaveBeenCalledTimes(2); expect(uiSettingsClient.get).toHaveBeenCalledWith('theme:darkMode'); + expect(uiSettingsClient.get).toHaveBeenCalledWith('theme:name'); }); it('calls getThemeTag with the values from the UiSettingsClient (true/dark) when the UserSettingsService is not provided', async () => { - uiSettingsClient.get.mockResolvedValue(true); - + uiSettingsClient.get.mockImplementation( + getClientGetMockImplementation({ + darkMode: true, + }) + ); const request = httpServerMock.createKibanaRequest(); await renderer({ @@ -107,13 +124,13 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: true, }); }); it('calls getThemeTag with the values from the UiSettingsClient (false/light) when the UserSettingsService is not provided', async () => { - uiSettingsClient.get.mockResolvedValue(false); + uiSettingsClient.get.mockImplementation(getClientGetMockImplementation({})); const request = httpServerMock.createKibanaRequest(); @@ -124,7 +141,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: false, }); }); @@ -150,7 +167,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: true, }); }); @@ -166,7 +183,6 @@ describe('bootstrapRenderer', () => { userSettingsService, }); - uiSettingsClient.get.mockResolvedValue(true); const request = httpServerMock.createKibanaRequest(); await renderer({ @@ -176,7 +192,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: false, }); }); @@ -192,7 +208,6 @@ describe('bootstrapRenderer', () => { userSettingsService, }); - uiSettingsClient.get.mockResolvedValue(false); const request = httpServerMock.createKibanaRequest(); await renderer({ @@ -202,7 +217,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: false, }); }); @@ -218,7 +233,11 @@ describe('bootstrapRenderer', () => { userSettingsService, }); - uiSettingsClient.get.mockResolvedValue(true); + uiSettingsClient.get.mockImplementation( + getClientGetMockImplementation({ + darkMode: true, + }) + ); const request = httpServerMock.createKibanaRequest(); await renderer({ @@ -228,7 +247,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: true, }); }); @@ -250,12 +269,17 @@ describe('bootstrapRenderer', () => { uiSettingsClient, }); - expect(uiSettingsClient.get).toHaveBeenCalledTimes(1); + expect(uiSettingsClient.get).toHaveBeenCalledTimes(2); expect(uiSettingsClient.get).toHaveBeenCalledWith('theme:darkMode'); + expect(uiSettingsClient.get).toHaveBeenCalledWith('theme:name'); }); it('calls getThemeTag with the correct parameters', async () => { - uiSettingsClient.get.mockResolvedValue(true); + uiSettingsClient.get.mockImplementation( + getClientGetMockImplementation({ + darkMode: true, + }) + ); const request = httpServerMock.createKibanaRequest(); @@ -266,7 +290,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: true, }); }); @@ -283,7 +307,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'system', darkMode: false, }); }); @@ -318,7 +342,7 @@ describe('bootstrapRenderer', () => { expect(getThemeTagMock).toHaveBeenCalledTimes(1); expect(getThemeTagMock).toHaveBeenCalledWith({ - themeVersion: 'v8', + name: 'v8', darkMode: false, }); }); diff --git a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.ts index 8aa0d2a6c0387..5b8c267532d0b 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.ts @@ -9,7 +9,6 @@ import { createHash } from 'crypto'; import { PackageInfo } from '@kbn/config'; -import { ThemeVersion } from '@kbn/ui-shared-deps-npm'; import type { KibanaRequest, HttpAuth } from '@kbn/core-http-server'; import { type DarkModeValue, parseDarkModeValue } from '@kbn/core-ui-settings-common'; import type { IUiSettingsClient } from '@kbn/core-ui-settings-server'; @@ -59,7 +58,7 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({ return async function bootstrapRenderer({ uiSettingsClient, request, isAnonymousPage = false }) { let darkMode: DarkModeValue = false; - const themeVersion: ThemeVersion = 'v8'; + let themeName: string = 'amsterdam'; try { const authenticated = isAuthenticated(request); @@ -72,6 +71,8 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({ } else { darkMode = parseDarkModeValue(await uiSettingsClient.get('theme:darkMode')); } + + themeName = await uiSettingsClient.get('theme:name'); } } catch (e) { // just use the default values in case of connectivity issues with ES @@ -83,7 +84,7 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({ } const themeTag = getThemeTag({ - themeVersion, + name: !themeName || themeName === 'amsterdam' ? 'v8' : themeName, darkMode, }); const bundlesHref = getBundlesHref(baseHref); diff --git a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.test.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.test.ts index 0f9839e8cda89..216e87269818b 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.test.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.test.ts @@ -10,18 +10,18 @@ import { getThemeTag } from './get_theme_tag'; describe('getThemeTag', () => { - it('returns the correct value for version:v8 and darkMode:false', () => { + it('returns the correct value for name:v8 and darkMode:false', () => { expect( getThemeTag({ - themeVersion: 'v8', + name: 'v8', darkMode: false, }) ).toEqual('v8light'); }); - it('returns the correct value for version:v8 and darkMode:true', () => { + it('returns the correct value for name:v8 and darkMode:true', () => { expect( getThemeTag({ - themeVersion: 'v8', + name: 'v8', darkMode: true, }) ).toEqual('v8dark'); diff --git a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.ts index 97f5c17ef240b..f89bd41404633 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/get_theme_tag.ts @@ -7,18 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { ThemeVersion } from '@kbn/ui-shared-deps-npm'; - /** * Computes the themeTag that will be used on the client-side as `__kbnThemeTag__` * @see `packages/kbn-ui-shared-deps-src/theme.ts` */ -export const getThemeTag = ({ - themeVersion, - darkMode, -}: { - themeVersion: ThemeVersion; - darkMode: boolean; -}) => { - return `${themeVersion}${darkMode ? 'dark' : 'light'}`; +export const getThemeTag = ({ name, darkMode }: { name: string; darkMode: boolean }) => { + return `${name}${darkMode ? 'dark' : 'light'}`; }; diff --git a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx index ace0399f242af..a92c3dac485b5 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx +++ b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx @@ -22,6 +22,7 @@ import type { CustomBranding } from '@kbn/core-custom-branding-common'; import { type DarkModeValue, parseDarkModeValue, + parseThemeNameValue, type UiSettingsParams, type UserProvidedValues, } from '@kbn/core-ui-settings-common'; @@ -211,6 +212,8 @@ export class RenderingService { darkMode = getSettingValue('theme:darkMode', settings, parseDarkModeValue); } + const themeName = getSettingValue('theme:name', settings, parseThemeNameValue); + const themeStylesheetPaths = (mode: boolean) => getThemeStylesheetPaths({ darkMode: mode, @@ -274,6 +277,7 @@ export class RenderingService { }, theme: { darkMode, + name: themeName, version: themeVersion, stylesheetPaths: { default: themeStylesheetPaths(false), diff --git a/packages/core/theme/core-theme-browser-internal/src/core_theme_provider.test.tsx b/packages/core/theme/core-theme-browser-internal/src/core_theme_provider.test.tsx index 3f4aebe797172..a3e4516b07510 100644 --- a/packages/core/theme/core-theme-browser-internal/src/core_theme_provider.test.tsx +++ b/packages/core/theme/core-theme-browser-internal/src/core_theme_provider.test.tsx @@ -50,7 +50,7 @@ describe('CoreThemeProvider', () => { }; it('exposes the EUI theme provider', async () => { - const coreTheme: CoreTheme = { darkMode: true }; + const coreTheme: CoreTheme = { darkMode: true, name: 'amsterdam' }; const wrapper = mountWithIntl( @@ -64,7 +64,7 @@ describe('CoreThemeProvider', () => { }); it('propagates changes of the coreTheme observable', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const wrapper = mountWithIntl( @@ -77,7 +77,7 @@ describe('CoreThemeProvider', () => { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - coreTheme$.next({ darkMode: false }); + coreTheme$.next({ darkMode: false, name: 'amsterdam' }); }); await refresh(wrapper); diff --git a/packages/core/theme/core-theme-browser-internal/src/theme_service.test.ts b/packages/core/theme/core-theme-browser-internal/src/theme_service.test.ts index 45c90d90d522a..575d98fe40c8d 100644 --- a/packages/core/theme/core-theme-browser-internal/src/theme_service.test.ts +++ b/packages/core/theme/core-theme-browser-internal/src/theme_service.test.ts @@ -45,6 +45,7 @@ describe('ThemeService', () => { beforeEach(() => { injectedMetadata.getTheme.mockReturnValue({ version: 'v8', + name: 'amsterdam', darkMode: false, stylesheetPaths: { dark: ['dark-1.css'], @@ -58,6 +59,7 @@ describe('ThemeService', () => { const theme = await firstValueFrom(theme$); expect(theme).toEqual({ darkMode: false, + name: 'amsterdam', }); }); @@ -88,6 +90,7 @@ describe('ThemeService', () => { beforeEach(() => { injectedMetadata.getTheme.mockReturnValue({ version: 'v8', + name: 'amsterdam', darkMode: true, stylesheetPaths: { dark: ['dark-1.css'], @@ -101,6 +104,7 @@ describe('ThemeService', () => { const theme = await firstValueFrom(theme$); expect(theme).toEqual({ darkMode: true, + name: 'amsterdam', }); }); @@ -131,6 +135,7 @@ describe('ThemeService', () => { beforeEach(() => { injectedMetadata.getTheme.mockReturnValue({ version: 'v8', + name: 'amsterdam', darkMode: 'system', stylesheetPaths: { dark: ['dark-1.css'], @@ -150,6 +155,7 @@ describe('ThemeService', () => { expect(theme).toEqual({ darkMode: false, + name: 'amsterdam', }); expect(window.__kbnThemeTag__).toEqual('v8light'); @@ -177,6 +183,7 @@ describe('ThemeService', () => { expect(theme).toEqual({ darkMode: false, + name: 'amsterdam', }); expect(window.__kbnThemeTag__).toEqual('v8light'); @@ -196,6 +203,7 @@ describe('ThemeService', () => { expect(theme).toEqual({ darkMode: true, + name: 'amsterdam', }); expect(window.__kbnThemeTag__).toEqual('v8dark'); @@ -244,6 +252,7 @@ describe('ThemeService', () => { it('exposes a `theme$` observable with the values provided by the injected metadata', async () => { injectedMetadata.getTheme.mockReturnValue({ version: 'v8', + name: 'amsterdam', darkMode: true, stylesheetPaths: { dark: [], @@ -255,6 +264,7 @@ describe('ThemeService', () => { const theme = await firstValueFrom(theme$); expect(theme).toEqual({ darkMode: true, + name: 'amsterdam', }); }); }); diff --git a/packages/core/theme/core-theme-browser-internal/src/theme_service.ts b/packages/core/theme/core-theme-browser-internal/src/theme_service.ts index 7bc51c9a0c34a..e79a19550bb8d 100644 --- a/packages/core/theme/core-theme-browser-internal/src/theme_service.ts +++ b/packages/core/theme/core-theme-browser-internal/src/theme_service.ts @@ -28,16 +28,21 @@ export class ThemeService { public setup({ injectedMetadata }: ThemeServiceSetupDeps): ThemeServiceSetup { const themeMetadata = injectedMetadata.getTheme(); + this.themeMetadata = themeMetadata; - let theme: CoreTheme; + let darkMode: boolean; if (themeMetadata.darkMode === 'system' && browsersSupportsSystemTheme()) { - theme = { darkMode: systemThemeIsDark() }; + darkMode = systemThemeIsDark(); } else { - const darkMode = themeMetadata.darkMode === 'system' ? false : themeMetadata.darkMode; - theme = { darkMode }; + darkMode = themeMetadata.darkMode === 'system' ? false : themeMetadata.darkMode; } + const theme: CoreTheme = { + darkMode, + name: themeMetadata.name, + }; + this.applyTheme(theme); this.contract = { @@ -73,11 +78,13 @@ export class ThemeService { }); _setDarkMode(darkMode); - updateKbnThemeTag(darkMode); + updateKbnThemeTag(theme); } } -const updateKbnThemeTag = (darkMode: boolean) => { +const updateKbnThemeTag = (theme: CoreTheme) => { + const name = theme.name === 'amsterdam' ? 'v8' : theme.name; + const globals: any = typeof window === 'undefined' ? {} : window; - globals.__kbnThemeTag__ = darkMode ? 'v8dark' : 'v8light'; + globals.__kbnThemeTag__ = `${name}${theme.darkMode ? 'dark' : 'light'}`; }; diff --git a/packages/core/theme/core-theme-browser-mocks/src/theme_service.mock.ts b/packages/core/theme/core-theme-browser-mocks/src/theme_service.mock.ts index beee2320d7cca..e3d2b66645794 100644 --- a/packages/core/theme/core-theme-browser-mocks/src/theme_service.mock.ts +++ b/packages/core/theme/core-theme-browser-mocks/src/theme_service.mock.ts @@ -14,6 +14,7 @@ import type { ThemeService } from '@kbn/core-theme-browser-internal'; const mockTheme: CoreTheme = { darkMode: false, + name: 'amsterdam', }; const createThemeMock = (): CoreTheme => { diff --git a/packages/core/theme/core-theme-browser/src/types.ts b/packages/core/theme/core-theme-browser/src/types.ts index 161758ec362f3..365cde9f814ac 100644 --- a/packages/core/theme/core-theme-browser/src/types.ts +++ b/packages/core/theme/core-theme-browser/src/types.ts @@ -17,6 +17,10 @@ import { Observable } from 'rxjs'; export interface CoreTheme { /** is dark mode enabled or not */ readonly darkMode: boolean; + /** + * Name of the active theme + */ + readonly name: string; } /** diff --git a/packages/core/ui-settings/core-ui-settings-common/index.ts b/packages/core/ui-settings/core-ui-settings-common/index.ts index b7adb288008df..d290b9065c546 100644 --- a/packages/core/ui-settings/core-ui-settings-common/index.ts +++ b/packages/core/ui-settings/core-ui-settings-common/index.ts @@ -17,5 +17,18 @@ export type { GetUiSettingsContext, } from './src/ui_settings'; export { type DarkModeValue, parseDarkModeValue } from './src/dark_mode'; +export { + DEFAULT_THEME_TAGS, + SUPPORTED_THEME_TAGS, + DEFAULT_THEME_NAME, + SUPPORTED_THEME_NAMES, + FALLBACK_THEME_TAG, + parseThemeTags, + hasNonDefaultThemeTags, + parseThemeNameValue, + type ThemeName, + type ThemeTag, + type ThemeTags, +} from './src/theme'; export { TIMEZONE_OPTIONS } from './src/timezones'; diff --git a/packages/core/ui-settings/core-ui-settings-common/src/theme.ts b/packages/core/ui-settings/core-ui-settings-common/src/theme.ts new file mode 100644 index 0000000000000..7bf9cbfe9486a --- /dev/null +++ b/packages/core/ui-settings/core-ui-settings-common/src/theme.ts @@ -0,0 +1,97 @@ +/* + * 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". + */ + +export const DEFAULT_THEME_NAME = 'amsterdam'; +export const SUPPORTED_THEME_NAMES = ['amsterdam', 'borealis']; + +export type ThemeName = (typeof SUPPORTED_THEME_NAMES)[number]; + +/** + * Theme tags of the Amsterdam theme + */ +export const ThemeAmsterdamTags = ['v8light', 'v8dark'] as const; + +/** + * Theme tags of the experimental Borealis theme + */ +export const ThemeBorealisTags = ['borealislight', 'borealisdark'] as const; + +/** + * An array of all theme tags supported by Kibana. Note that this list doesn't + * reflect what theme tags are available in a Kibana build. + */ +export const SUPPORTED_THEME_TAGS = [...ThemeAmsterdamTags, ...ThemeBorealisTags] as const; + +export type ThemeTag = (typeof SUPPORTED_THEME_TAGS)[number]; +export type ThemeTags = readonly ThemeTag[]; + +/** + * An array of theme tags available in Kibana by default when not customized + * using KBN_OPTIMIZER_THEMES environment variable. + */ +export const DEFAULT_THEME_TAGS: ThemeTags = ThemeAmsterdamTags; + +export const FALLBACK_THEME_TAG: ThemeTag = 'v8light'; + +const isValidTag = (tag: unknown) => + SUPPORTED_THEME_TAGS.includes(tag as (typeof SUPPORTED_THEME_TAGS)[number]); + +export function parseThemeTags(input?: unknown): ThemeTags { + if (!input) { + return DEFAULT_THEME_TAGS; + } + + if (input === '*') { + // TODO: Replace with SUPPORTED_THEME_TAGS when Borealis is in public beta + return DEFAULT_THEME_TAGS; + } + + let rawTags: string[]; + if (typeof input === 'string') { + rawTags = input.split(',').map((tag) => tag.trim()); + } else if (Array.isArray(input)) { + rawTags = input; + } else { + throw new Error('Invalid theme tags, must be an array of strings'); + } + + if (!rawTags.length) { + throw new Error( + `Invalid theme tags, you must specify at least one of [${SUPPORTED_THEME_TAGS.join(', ')}]` + ); + } + + const invalidTags = rawTags.filter((t) => !isValidTag(t)); + if (invalidTags.length) { + throw new Error( + `Invalid theme tags [${invalidTags.join(', ')}], options: [${SUPPORTED_THEME_TAGS.join( + ', ' + )}]` + ); + } + + return rawTags as ThemeTags; +} + +export const hasNonDefaultThemeTags = (tags: ThemeTags) => + tags.length !== DEFAULT_THEME_TAGS.length || + tags.some((tag) => !DEFAULT_THEME_TAGS.includes(tag as (typeof DEFAULT_THEME_TAGS)[number])); + +export const parseThemeNameValue = (value: unknown): ThemeName => { + if (typeof value !== 'string') { + return DEFAULT_THEME_NAME; + } + + const themeName = value.toLowerCase(); + if (SUPPORTED_THEME_NAMES.includes(themeName.toLowerCase() as ThemeName)) { + return themeName as ThemeName; + } + + return DEFAULT_THEME_NAME; +}; diff --git a/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/index.ts b/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/index.ts index f74977af04b8b..093b4eef9a6de 100644 --- a/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/index.ts +++ b/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/index.ts @@ -18,6 +18,7 @@ import { getAnnouncementsSettings } from './announcements'; interface GetCoreSettingsOptions { isDist?: boolean; + isThemeSwitcherEnabled?: boolean; } export const getCoreSettings = ( diff --git a/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/theme.ts b/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/theme.ts index 5701694f97abc..36324f951952e 100644 --- a/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/theme.ts +++ b/packages/core/ui-settings/core-ui-settings-server-internal/src/settings/theme.ts @@ -10,15 +10,11 @@ import { schema } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; import type { ThemeVersion } from '@kbn/ui-shared-deps-npm'; -import type { UiSettingsParams } from '@kbn/core-ui-settings-common'; - -function parseThemeTags() { - if (!process.env.KBN_OPTIMIZER_THEMES || process.env.KBN_OPTIMIZER_THEMES === '*') { - return ['v8light', 'v8dark']; - } - - return process.env.KBN_OPTIMIZER_THEMES.split(',').map((t) => t.trim()); -} +import { + type UiSettingsParams, + parseThemeTags, + SUPPORTED_THEME_NAMES, +} from '@kbn/core-ui-settings-common'; function getThemeInfo(options: GetThemeSettingsOptions) { if (options?.isDist ?? true) { @@ -27,7 +23,7 @@ function getThemeInfo(options: GetThemeSettingsOptions) { }; } - const themeTags = parseThemeTags(); + const themeTags = parseThemeTags(process.env.KBN_OPTIMIZER_THEMES); return { defaultDarkMode: themeTags[0].endsWith('dark'), }; @@ -35,6 +31,7 @@ function getThemeInfo(options: GetThemeSettingsOptions) { interface GetThemeSettingsOptions { isDist?: boolean; + isThemeSwitcherEnabled?: boolean; } export const getThemeSettings = ( @@ -89,5 +86,34 @@ export const getThemeSettings = ( readonly: true, schema: schema.literal('v8'), }, + /** + * Theme name is the (upcoming) replacement for theme versions. + */ + 'theme:name': { + name: i18n.translate('core.ui_settings.params.themeName', { + defaultMessage: 'Theme', + }), + type: 'select', + options: SUPPORTED_THEME_NAMES, + optionLabels: { + amsterdam: i18n.translate('core.ui_settings.params.themeName.options.amsterdam', { + defaultMessage: 'Amsterdam', + }), + borealis: i18n.translate('core.ui_settings.params.themeName.options.borealis', { + defaultMessage: 'Borealis', + }), + }, + value: 'amsterdam', + readonly: Object.hasOwn(options, 'isThemeSwitcherEnabled') + ? !options.isThemeSwitcherEnabled + : true, + requiresPageReload: true, + schema: schema.oneOf([ + schema.literal('amsterdam'), + schema.literal('borealis'), + // Allow experimental themes + schema.string(), + ]), + }, }; }; diff --git a/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_config.ts b/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_config.ts index 6563ffff78949..04b7ff6b0f558 100644 --- a/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_config.ts +++ b/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_config.ts @@ -19,6 +19,11 @@ const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) => const configSchema = schema.object({ overrides: schema.object({}, { unknowns: 'allow' }), publicApiEnabled: offeringBasedSchema({ serverless: schema.boolean({ defaultValue: false }) }), + experimental: schema.maybe( + schema.object({ + themeSwitcherEnabled: schema.maybe(schema.boolean({ defaultValue: false })), + }) + ), }); export type UiSettingsConfigType = TypeOf; diff --git a/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_service.ts b/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_service.ts index 958391b5fc725..70c880c85594f 100644 --- a/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_service.ts +++ b/packages/core/ui-settings/core-ui-settings-server-internal/src/ui_settings_service.ts @@ -68,10 +68,15 @@ export class UiSettingsService public async preboot(): Promise { this.log.debug('Prebooting ui settings service'); - const { overrides } = await firstValueFrom(this.config$); + const { overrides, experimental } = await firstValueFrom(this.config$); this.overrides = overrides; - this.register(getCoreSettings({ isDist: this.isDist })); + this.register( + getCoreSettings({ + isDist: this.isDist, + isThemeSwitcherEnabled: experimental?.themeSwitcherEnabled, + }) + ); return { createDefaultsClient: () => diff --git a/packages/kbn-lens-embeddable-utils/attribute_builder/utils.ts b/packages/kbn-lens-embeddable-utils/attribute_builder/utils.ts index 6418023586084..9c6ea500c97c7 100644 --- a/packages/kbn-lens-embeddable-utils/attribute_builder/utils.ts +++ b/packages/kbn-lens-embeddable-utils/attribute_builder/utils.ts @@ -28,7 +28,7 @@ export type DateHistogramColumnParams = DateHistogramIndexPatternColumn['params' export type TopValuesColumnParams = Pick< TermsIndexPatternColumn['params'], - 'size' | 'orderDirection' | 'orderBy' | 'secondaryFields' | 'accuracyMode' + 'size' | 'orderDirection' | 'orderBy' | 'secondaryFields' | 'accuracyMode' | 'orderAgg' >; export const getHistogramColumn = ({ diff --git a/packages/kbn-management/settings/setting_ids/index.ts b/packages/kbn-management/settings/setting_ids/index.ts index bc0f7206a2835..9a7c95917878a 100644 --- a/packages/kbn-management/settings/setting_ids/index.ts +++ b/packages/kbn-management/settings/setting_ids/index.ts @@ -45,6 +45,7 @@ export const SHORT_DOTS_ENABLE_ID = 'shortDots:enable'; export const SORT_OPTIONS_ID = 'sort:options'; export const STATE_STORE_IN_SESSION_STORAGE_ID = 'state:storeInSessionStorage'; export const THEME_DARK_MODE_ID = 'theme:darkMode'; +export const THEME_NAME_ID = 'theme:name'; export const TIMEPICKER_QUICK_RANGES_ID = 'timepicker:quickRanges'; export const TIMEPICKER_REFRESH_INTERVAL_DEFAULTS_ID = 'timepicker:refreshIntervalDefaults'; export const TIMEPICKER_TIME_DEFAULTS_ID = 'timepicker:timeDefaults'; diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 8e1cd3e8fb7a1..58424700d9bf6 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -2,7 +2,7 @@ pageLoadAssetSize: actions: 20000 advancedSettings: 27596 aiAssistantManagementSelection: 19146 - aiops: 16526 + aiops: 16600 alerting: 106936 apm: 64385 banners: 17946 diff --git a/packages/kbn-optimizer/src/common/index.ts b/packages/kbn-optimizer/src/common/index.ts index 112e677c9d713..543991a92065d 100644 --- a/packages/kbn-optimizer/src/common/index.ts +++ b/packages/kbn-optimizer/src/common/index.ts @@ -18,7 +18,6 @@ export * from './rxjs_helpers'; export * from './array_helpers'; export * from './event_stream_helpers'; export * from './parse_path'; -export * from './theme_tags'; export * from './obj_helpers'; export * from './hashes'; export * from './dll_manifest'; diff --git a/packages/kbn-optimizer/src/common/theme_tags.test.ts b/packages/kbn-optimizer/src/common/theme_tags.test.ts deleted file mode 100644 index edf58797587f6..0000000000000 --- a/packages/kbn-optimizer/src/common/theme_tags.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", 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 { parseThemeTags } from './theme_tags'; - -it('returns default tags when passed undefined', () => { - expect(parseThemeTags()).toMatchInlineSnapshot(` - Array [ - "v8dark", - "v8light", - ] - `); -}); - -it('returns all tags when passed *', () => { - expect(parseThemeTags('*')).toMatchInlineSnapshot(` - Array [ - "v8dark", - "v8light", - ] - `); -}); - -it('returns specific tag when passed a single value', () => { - expect(parseThemeTags('v8light')).toMatchInlineSnapshot(` - Array [ - "v8light", - ] - `); -}); - -it('returns specific tags when passed a comma separated list', () => { - expect(parseThemeTags('v8light,v8dark')).toMatchInlineSnapshot(` - Array [ - "v8dark", - "v8light", - ] - `); -}); - -it('returns specific tags when passed an array', () => { - expect(parseThemeTags(['v8light', 'v8dark'])).toMatchInlineSnapshot(` - Array [ - "v8dark", - "v8light", - ] - `); -}); - -it('throws when an invalid tag is in the array', () => { - expect(() => parseThemeTags(['v8light', 'v7light'])).toThrowErrorMatchingInlineSnapshot( - `"Invalid theme tags [v7light], options: [v8dark, v8light]"` - ); -}); - -it('throws when an invalid tags in comma separated list', () => { - expect(() => parseThemeTags('v8light ,v7light')).toThrowErrorMatchingInlineSnapshot( - `"Invalid theme tags [v7light], options: [v8dark, v8light]"` - ); -}); - -it('returns tags in alphabetical order', () => { - const tags = parseThemeTags(['v8dark', 'v8light']); - expect(tags).toEqual(tags.slice().sort((a, b) => a.localeCompare(b))); -}); - -it('returns an immutable array', () => { - expect(() => { - const tags = parseThemeTags('v8light'); - // @ts-expect-error - tags.push('foo'); - }).toThrowErrorMatchingInlineSnapshot(`"Cannot add property 1, object is not extensible"`); -}); diff --git a/packages/kbn-optimizer/src/common/theme_tags.ts b/packages/kbn-optimizer/src/common/theme_tags.ts deleted file mode 100644 index fc126d55a4330..0000000000000 --- a/packages/kbn-optimizer/src/common/theme_tags.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", 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 { ascending } from './array_helpers'; - -const tags = (...themeTags: string[]) => - Object.freeze(themeTags.sort(ascending((tag) => tag)) as ThemeTag[]); - -const validTag = (tag: any): tag is ThemeTag => ALL_THEMES.includes(tag); -const isArrayOfStrings = (input: unknown): input is string[] => - Array.isArray(input) && input.every((v) => typeof v === 'string'); - -export type ThemeTags = readonly ThemeTag[]; -export type ThemeTag = 'v8light' | 'v8dark'; -export const DEFAULT_THEMES = tags('v8light', 'v8dark'); -export const ALL_THEMES = tags('v8light', 'v8dark'); - -export function parseThemeTags(input?: any): ThemeTags { - if (!input) { - return DEFAULT_THEMES; - } - - if (input === '*') { - return ALL_THEMES; - } - - if (typeof input === 'string') { - input = input.split(',').map((tag) => tag.trim()); - } - - if (!isArrayOfStrings(input)) { - throw new Error(`Invalid theme tags, must be an array of strings`); - } - - if (!input.length) { - throw new Error( - `Invalid theme tags, you must specify at least one of [${ALL_THEMES.join(', ')}]` - ); - } - - const invalidTags = input.filter((t) => !validTag(t)); - if (invalidTags.length) { - throw new Error( - `Invalid theme tags [${invalidTags.join(', ')}], options: [${ALL_THEMES.join(', ')}]` - ); - } - - return tags(...input); -} diff --git a/packages/kbn-optimizer/src/common/worker_config.ts b/packages/kbn-optimizer/src/common/worker_config.ts index 8881d2354740b..6a61c3a99af07 100644 --- a/packages/kbn-optimizer/src/common/worker_config.ts +++ b/packages/kbn-optimizer/src/common/worker_config.ts @@ -9,8 +9,8 @@ import Path from 'path'; +import { ThemeTags, parseThemeTags } from '@kbn/core-ui-settings-common'; import { UnknownVals } from './ts_helpers'; -import { ThemeTags, parseThemeTags } from './theme_tags'; export interface WorkerConfig { readonly repoRoot: string; diff --git a/packages/kbn-optimizer/src/log_optimizer_state.ts b/packages/kbn-optimizer/src/log_optimizer_state.ts index 3173ef2a05980..2bb810f45d240 100644 --- a/packages/kbn-optimizer/src/log_optimizer_state.ts +++ b/packages/kbn-optimizer/src/log_optimizer_state.ts @@ -10,11 +10,12 @@ import { inspect } from 'util'; import { ToolingLog } from '@kbn/tooling-log'; +import { hasNonDefaultThemeTags } from '@kbn/core-ui-settings-common'; import { tap } from 'rxjs'; import { OptimizerConfig } from './optimizer'; import { OptimizerUpdate$ } from './run_optimizer'; -import { CompilerMsg, pipeClosure, ALL_THEMES } from './common'; +import { CompilerMsg, pipeClosure } from './common'; export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) { return pipeClosure((update$: OptimizerUpdate$) => { @@ -80,9 +81,9 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) { ); } - if (config.themeTags.length !== ALL_THEMES.length) { + if (hasNonDefaultThemeTags(config.themeTags)) { log.warning( - `only building [${config.themeTags}] themes, customize with the KBN_OPTIMIZER_THEMES environment variable` + `running with non-default [${config.themeTags}] set of themes, customize with the KBN_OPTIMIZER_THEMES environment variable` ); } } diff --git a/packages/kbn-optimizer/src/optimizer/optimizer_cache_key.test.ts b/packages/kbn-optimizer/src/optimizer/optimizer_cache_key.test.ts index 6d520836ac4b2..f08849005e971 100644 --- a/packages/kbn-optimizer/src/optimizer/optimizer_cache_key.test.ts +++ b/packages/kbn-optimizer/src/optimizer/optimizer_cache_key.test.ts @@ -90,8 +90,8 @@ describe('getOptimizerCacheKey()', () => { "optimizerCacheKey": "♻", "repoRoot": , "themeTags": Array [ - "v8dark", "v8light", + "v8dark", ], }, } diff --git a/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts b/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts index a3329dcc3d57f..5fd2318953a8c 100644 --- a/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts +++ b/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts @@ -8,10 +8,10 @@ */ jest.mock('@kbn/repo-packages'); +jest.mock('@kbn/core-ui-settings-common'); jest.mock('./assign_bundles_to_workers'); jest.mock('./kibana_platform_plugins'); jest.mock('./get_plugin_bundles'); -jest.mock('../common/theme_tags'); jest.mock('./filter_by_id'); jest.mock('./focus_bundles'); jest.mock('../limits'); @@ -29,7 +29,7 @@ import { REPO_ROOT } from '@kbn/repo-info'; import { createAbsolutePathSerializer } from '@kbn/jest-serializers'; import { OptimizerConfig, ParsedOptions } from './optimizer_config'; -import { parseThemeTags } from '../common'; +import { parseThemeTags } from '@kbn/core-ui-settings-common'; expect.addSnapshotSerializer(createAbsolutePathSerializer()); diff --git a/packages/kbn-optimizer/src/optimizer/optimizer_config.ts b/packages/kbn-optimizer/src/optimizer/optimizer_config.ts index b09650c0708da..1b04a6fbd25a3 100644 --- a/packages/kbn-optimizer/src/optimizer/optimizer_config.ts +++ b/packages/kbn-optimizer/src/optimizer/optimizer_config.ts @@ -10,16 +10,9 @@ import Path from 'path'; import Os from 'os'; import { getPackages, getPluginPackagesFilter, type PluginSelector } from '@kbn/repo-packages'; +import { ThemeTag, ThemeTags, parseThemeTags } from '@kbn/core-ui-settings-common'; -import { - Bundle, - WorkerConfig, - CacheableWorkerConfig, - ThemeTag, - ThemeTags, - parseThemeTags, - omit, -} from '../common'; +import { Bundle, WorkerConfig, CacheableWorkerConfig, omit } from '../common'; import { toKibanaPlatformPlugin, KibanaPlatformPlugin } from './kibana_platform_plugins'; import { getPluginBundles } from './get_plugin_bundles'; diff --git a/packages/kbn-optimizer/src/worker/theme_loader.ts b/packages/kbn-optimizer/src/worker/theme_loader.ts index 92a728f17f5cb..3bce12d94e974 100644 --- a/packages/kbn-optimizer/src/worker/theme_loader.ts +++ b/packages/kbn-optimizer/src/worker/theme_loader.ts @@ -9,12 +9,11 @@ import { stringifyRequest, getOptions } from 'loader-utils'; import webpack from 'webpack'; -import { parseThemeTags, ALL_THEMES, ThemeTag } from '../common'; - -const getVersion = (tag: ThemeTag) => 8; -const getIsDark = (tag: ThemeTag) => tag.includes('dark'); -const compare = (a: ThemeTag, b: ThemeTag) => - (getVersion(a) === getVersion(b) ? 1 : 0) + (getIsDark(a) === getIsDark(b) ? 1 : 0); +import { + FALLBACK_THEME_TAG, + parseThemeTags, + hasNonDefaultThemeTags, +} from '@kbn/core-ui-settings-common'; // eslint-disable-next-line import/no-default-export export default function (this: webpack.loader.LoaderContext) { @@ -23,27 +22,34 @@ export default function (this: webpack.loader.LoaderContext) { const options = getOptions(this); const bundleId = options.bundleId as string; const themeTags = parseThemeTags(options.themeTags); - - const cases = ALL_THEMES.map((tag) => { - if (themeTags.includes(tag)) { - return ` - case '${tag}': - return require(${stringifyRequest(this, `${this.resourcePath}?${tag}`)});`; - } - - const fallback = themeTags - .slice() - .sort((a, b) => compare(b, tag) - compare(a, tag)) - .shift()!; - - const message = `SASS files in [${bundleId}] were not built for theme [${tag}]. Styles were compiled using the [${fallback}] theme instead to keep Kibana somewhat usable. Please adjust the advanced settings to make use of [${themeTags}] or make sure the KBN_OPTIMIZER_THEMES environment variable includes [${tag}] in a comma separated list of themes you want to compile. You can also set it to "*" to build all themes.`; - return ` - case '${tag}': - console.error(new Error(${JSON.stringify(message)})); - return require(${stringifyRequest(this, `${this.resourcePath}?${fallback}`)})`; - }).join('\n'); + const isFallbackNeeded = hasNonDefaultThemeTags(themeTags); + + /** + * The following piece of code generates a `switch` statement that gets injected into the output + * bundle for all `.scss` file imports. The generated `switch` contains: + * - a `case` clause for each of the bundled theme tags, + * - an optional `default` clause for the theme fallback logic, included when some of the default + * Kibana theme tags are omitted and the fallback logic might be needed. The fallback logic + * should never have to run and is added as an extra precaution layer. + */ + + let defaultClause = ''; + if (isFallbackNeeded) { + defaultClause = ` + default: + console.error(new Error("SASS files in [${bundleId}] were not built for theme [" + window.__kbnThemeTag__ + "]. Styles were compiled using the [${FALLBACK_THEME_TAG}] theme instead to keep Kibana somewhat usable. Please adjust the advanced settings to make use of [${themeTags}] or make sure the KBN_OPTIMIZER_THEMES environment variable includes [" + window.__kbnThemeTag__ + "] in a comma-separated list of themes you want to compile. You can also set it to \'*\' to build all themes.")); + return require(${stringifyRequest(this, `${this.resourcePath}?${FALLBACK_THEME_TAG}`)});`; + } return ` -switch (window.__kbnThemeTag__) {${cases} +switch (window.__kbnThemeTag__) { +${themeTags + .map( + (tag) => ` + case '${tag}': + return require(${stringifyRequest(this, `${this.resourcePath}?${tag}`)});` + ) + .join('\n')} + ${defaultClause} }`; } diff --git a/packages/kbn-optimizer/tsconfig.json b/packages/kbn-optimizer/tsconfig.json index f8cb993537be7..d6e79f66a561a 100644 --- a/packages/kbn-optimizer/tsconfig.json +++ b/packages/kbn-optimizer/tsconfig.json @@ -18,6 +18,7 @@ "kbn_references": [ "@kbn/config-schema", "@kbn/dev-utils", + "@kbn/core-ui-settings-common", "@kbn/optimizer-webpack-helpers", "@kbn/std", "@kbn/ui-shared-deps-npm", diff --git a/packages/kbn-react-hooks/README.md b/packages/kbn-react-hooks/README.md index 792df6534c8d8..6eba8db3641d6 100644 --- a/packages/kbn-react-hooks/README.md +++ b/packages/kbn-react-hooks/README.md @@ -4,7 +4,7 @@ A utility package, `@kbn/react-hooks`, provides custom react hooks for simple ab ## Custom Hooks -### [useBoolean](./src/useBoolean) +### [useBoolean](./src/use_boolean/use_boolean.ts) Simplify handling boolean value with predefined handlers. @@ -25,4 +25,20 @@ function App() { ); } -``` \ No newline at end of file +``` + +### [useErrorTextStyle](./src/use_error_text_style/use_error_text_style.ts) + +Returns styles used for styling error text. + +```tsx +function App() { + const errorTextStyle = useErrorTextStyle(); + + return ( +
+ Error message +
+ ); +} +``` diff --git a/packages/kbn-react-hooks/index.ts b/packages/kbn-react-hooks/index.ts index 51c15bd0f10d2..0c8550091ef5a 100644 --- a/packages/kbn-react-hooks/index.ts +++ b/packages/kbn-react-hooks/index.ts @@ -8,4 +8,5 @@ */ export { useBoolean } from './src/use_boolean'; +export { useErrorTextStyle } from './src/use_error_text_style'; export type { UseBooleanHandlers, UseBooleanResult } from './src/use_boolean'; diff --git a/packages/kbn-react-hooks/src/use_error_text_style/index.ts b/packages/kbn-react-hooks/src/use_error_text_style/index.ts new file mode 100644 index 0000000000000..3cbc69f2b988d --- /dev/null +++ b/packages/kbn-react-hooks/src/use_error_text_style/index.ts @@ -0,0 +1,10 @@ +/* + * 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". + */ + +export * from './use_error_text_style'; diff --git a/packages/kbn-react-hooks/src/use_error_text_style/use_error_text_style.ts b/packages/kbn-react-hooks/src/use_error_text_style/use_error_text_style.ts new file mode 100644 index 0000000000000..cb21a95c6ae71 --- /dev/null +++ b/packages/kbn-react-hooks/src/use_error_text_style/use_error_text_style.ts @@ -0,0 +1,21 @@ +/* + * 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 { css } from '@emotion/react'; +import { useEuiTheme } from '@elastic/eui'; + +export const useErrorTextStyle = () => { + const { euiTheme } = useEuiTheme(); + const errorTextStyle = css` + font-family: ${euiTheme.font.familyCode}; + white-space: break-spaces; + `; + + return errorTextStyle; +}; diff --git a/packages/kbn-storybook/src/lib/decorators.tsx b/packages/kbn-storybook/src/lib/decorators.tsx index d6b3c6abf2f40..270da371172eb 100644 --- a/packages/kbn-storybook/src/lib/decorators.tsx +++ b/packages/kbn-storybook/src/lib/decorators.tsx @@ -21,7 +21,7 @@ import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; import { KibanaRootContextProvider } from '@kbn/react-kibana-context-root'; import { i18n } from '@kbn/i18n'; -const theme$ = new BehaviorSubject({ darkMode: false }); +const theme$ = new BehaviorSubject({ darkMode: false, name: 'amsterdam' }); const i18nStart: I18nStart = { Context: ({ children }) => {children}, @@ -43,7 +43,7 @@ const KibanaContextDecorator: DecoratorFn = (storyFn, { globals }) => { const colorMode = globals.euiTheme === 'v8.dark' ? 'dark' : 'light'; useEffect(() => { - theme$.next({ darkMode: colorMode === 'dark' }); + theme$.next({ darkMode: colorMode === 'dark', name: 'amsterdam' }); }, [colorMode]); return ( diff --git a/packages/kbn-ui-shared-deps-src/BUILD.bazel b/packages/kbn-ui-shared-deps-src/BUILD.bazel index d2e67ccd14ac6..b0d7bb65843d9 100644 --- a/packages/kbn-ui-shared-deps-src/BUILD.bazel +++ b/packages/kbn-ui-shared-deps-src/BUILD.bazel @@ -39,6 +39,7 @@ webpack_cli( "//packages/shared-ux/error_boundary", "//packages/kbn-rison", "//packages/shared-ux/code_editor/impl:code_editor", + "//packages/react/kibana_context/theme", ], output_dir = True, args = [ diff --git a/packages/kbn-ui-shared-deps-src/src/definitions.js b/packages/kbn-ui-shared-deps-src/src/definitions.js index f56baf1731ac9..2c391dd18d1bc 100644 --- a/packages/kbn-ui-shared-deps-src/src/definitions.js +++ b/packages/kbn-ui-shared-deps-src/src/definitions.js @@ -105,6 +105,7 @@ const externals = { '@kbn/esql-ast': '__kbnSharedDeps__.KbnEsqlAst', '@kbn/ebt-tools': '__kbnSharedDeps__.KbnEbtTools', '@elastic/apm-rum-core': '__kbnSharedDeps__.ElasticApmRumCore', + '@kbn/react-kibana-context-theme': '__kbnSharedDeps__.KbnReactKibanaContextTheme', }; module.exports = { distDir, jsFilename, cssDistFilename, externals }; diff --git a/packages/kbn-ui-shared-deps-src/src/entry.js b/packages/kbn-ui-shared-deps-src/src/entry.js index f87c2e7d75ead..25432fcfe399e 100644 --- a/packages/kbn-ui-shared-deps-src/src/entry.js +++ b/packages/kbn-ui-shared-deps-src/src/entry.js @@ -78,3 +78,4 @@ export const KbnCodeEditor = require('@kbn/code-editor'); export const KbnEsqlAst = require('@kbn/esql-ast'); export const KbnEbtTools = require('@kbn/ebt-tools'); export const ElasticApmRumCore = require('@elastic/apm-rum-core'); +export const KbnReactKibanaContextTheme = require('@kbn/react-kibana-context-theme'); diff --git a/packages/kbn-ui-theme/src/theme.ts b/packages/kbn-ui-theme/src/theme.ts index 0d8f7fb789c2a..3718c7dfb9d64 100644 --- a/packages/kbn-ui-theme/src/theme.ts +++ b/packages/kbn-ui-theme/src/theme.ts @@ -7,6 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +// TODO(tkajtoch): Add support for multiple themes + /* eslint-disable-next-line @kbn/eslint/module_migration */ import { default as v8Light } from '@elastic/eui/dist/eui_theme_light.json'; /* eslint-disable-next-line @kbn/eslint/module_migration */ diff --git a/packages/kbn-unified-data-table/__mocks__/services.ts b/packages/kbn-unified-data-table/__mocks__/services.ts index c4bafef861afb..8a3f9568ba5e9 100644 --- a/packages/kbn-unified-data-table/__mocks__/services.ts +++ b/packages/kbn-unified-data-table/__mocks__/services.ts @@ -43,7 +43,7 @@ export function createServicesMock() { ...uiSettingsMock, }; - const theme = themeServiceMock.createSetupContract({ darkMode: false }); + const theme = themeServiceMock.createSetupContract({ darkMode: false, name: 'amsterdam' }); corePluginMock.theme = theme; const dataPlugin = dataPluginMock.createStartContract(); diff --git a/packages/react/kibana_context/common/BUILD.bazel b/packages/react/kibana_context/common/BUILD.bazel new file mode 100644 index 0000000000000..43f20a833d07f --- /dev/null +++ b/packages/react/kibana_context/common/BUILD.bazel @@ -0,0 +1,36 @@ +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 = [ + "@npm//react", + "@npm//tslib", + "@npm//@elastic/eui", +] + +js_library( + name = "common", + package_name = "@kbn/react-kibana-context-common", + srcs = ["package.json"] + SRCS, + deps = DEPS, + visibility = ["//visibility:public"], +) diff --git a/packages/react/kibana_context/common/color_mode.test.ts b/packages/react/kibana_context/common/color_mode.test.ts index 2062f628b54ae..8fcd75f49d45a 100644 --- a/packages/react/kibana_context/common/color_mode.test.ts +++ b/packages/react/kibana_context/common/color_mode.test.ts @@ -11,10 +11,10 @@ import { getColorMode } from './color_mode'; describe('getColorMode', () => { it('returns the correct `colorMode` when `darkMode` is enabled', () => { - expect(getColorMode({ darkMode: true })).toEqual('DARK'); + expect(getColorMode({ name: 'amsterdam', darkMode: true })).toEqual('DARK'); }); it('returns the correct `colorMode` when `darkMode` is disabled', () => { - expect(getColorMode({ darkMode: false })).toEqual('LIGHT'); + expect(getColorMode({ name: 'amsterdam', darkMode: false })).toEqual('LIGHT'); }); }); diff --git a/packages/react/kibana_context/common/index.ts b/packages/react/kibana_context/common/index.ts index 77edac36e7912..541e804b788c7 100644 --- a/packages/react/kibana_context/common/index.ts +++ b/packages/react/kibana_context/common/index.ts @@ -8,6 +8,7 @@ */ export { getColorMode } from './color_mode'; +export { getThemeConfigByName, DEFAULT_THEME_CONFIG, type ThemeConfig } from './theme'; export type { KibanaTheme, ThemeServiceStart } from './types'; import type { KibanaTheme } from './types'; @@ -18,4 +19,5 @@ import type { KibanaTheme } from './types'; */ export const defaultTheme: KibanaTheme = { darkMode: false, + name: 'amsterdam', }; diff --git a/packages/react/kibana_context/common/kibana.jsonc b/packages/react/kibana_context/common/kibana.jsonc index 90fde56f05df6..b52bc6a40d0cc 100644 --- a/packages/react/kibana_context/common/kibana.jsonc +++ b/packages/react/kibana_context/common/kibana.jsonc @@ -1,5 +1,5 @@ { - "type": "shared-browser", + "type": "shared-common", "id": "@kbn/react-kibana-context-common", "owner": "@elastic/appex-sharedux" } diff --git a/packages/react/kibana_context/common/theme.ts b/packages/react/kibana_context/common/theme.ts new file mode 100644 index 0000000000000..45c89172cf187 --- /dev/null +++ b/packages/react/kibana_context/common/theme.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", 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 { EuiThemeSystem, EuiThemeAmsterdam } from '@elastic/eui'; + +export interface ThemeConfig { + euiTheme: EuiThemeSystem; +} + +const THEMES: Record = { + amsterdam: { + euiTheme: EuiThemeAmsterdam, + }, +}; + +export const getThemeConfigByName = (name: string): ThemeConfig | null => { + return THEMES[name as keyof typeof THEMES] || null; +}; + +export const DEFAULT_THEME_CONFIG = THEMES.amsterdam; diff --git a/packages/react/kibana_context/common/types.ts b/packages/react/kibana_context/common/types.ts index 2118c797d8be6..05e7ab7a0c7d5 100644 --- a/packages/react/kibana_context/common/types.ts +++ b/packages/react/kibana_context/common/types.ts @@ -20,6 +20,10 @@ import { Observable } from 'rxjs'; export interface KibanaTheme { /** is dark mode enabled or not */ readonly darkMode: boolean; + /** + * Name of the active theme + */ + readonly name: string; } // To avoid a circular dependency with the deprecation of `CoreThemeProvider`, diff --git a/packages/react/kibana_context/root/BUILD.bazel b/packages/react/kibana_context/root/BUILD.bazel new file mode 100644 index 0000000000000..1c47c25bc20a9 --- /dev/null +++ b/packages/react/kibana_context/root/BUILD.bazel @@ -0,0 +1,37 @@ +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 = [ + "@npm//react", + "@npm//tslib", + "@npm//@elastic/eui", + "//packages/core/base/core-base-common", +] + +js_library( + name = "root", + package_name = "@kbn/react-kibana-context-root", + srcs = ["package.json"] + SRCS, + deps = DEPS, + visibility = ["//visibility:public"], +) diff --git a/packages/react/kibana_context/root/eui_provider.test.tsx b/packages/react/kibana_context/root/eui_provider.test.tsx index 069954b09fc60..d7486be2d4798 100644 --- a/packages/react/kibana_context/root/eui_provider.test.tsx +++ b/packages/react/kibana_context/root/eui_provider.test.tsx @@ -54,7 +54,7 @@ describe('KibanaEuiProvider', () => { }; it('exposes the EUI theme provider', async () => { - const coreTheme: KibanaTheme = { darkMode: true }; + const coreTheme: KibanaTheme = { darkMode: true, name: 'amsterdam' }; const wrapper = mountWithIntl( @@ -70,7 +70,7 @@ describe('KibanaEuiProvider', () => { }); it('propagates changes of the coreTheme observable', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const wrapper = mountWithIntl( @@ -83,7 +83,7 @@ describe('KibanaEuiProvider', () => { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - coreTheme$.next({ darkMode: false }); + coreTheme$.next({ darkMode: false, name: 'amsterdam' }); }); await refresh(wrapper); diff --git a/packages/react/kibana_context/root/eui_provider.tsx b/packages/react/kibana_context/root/eui_provider.tsx index 74b2f6d8605ab..1e4e45c9f36f1 100644 --- a/packages/react/kibana_context/root/eui_provider.tsx +++ b/packages/react/kibana_context/root/eui_provider.tsx @@ -13,7 +13,12 @@ import createCache from '@emotion/cache'; import { EuiProvider, EuiProviderProps, euiStylisPrefixer } from '@elastic/eui'; import { EUI_STYLES_GLOBAL, EUI_STYLES_UTILS } from '@kbn/core-base-common'; -import { getColorMode, defaultTheme } from '@kbn/react-kibana-context-common'; +import { + getColorMode, + defaultTheme, + getThemeConfigByName, + DEFAULT_THEME_CONFIG, +} from '@kbn/react-kibana-context-common'; import { ThemeServiceStart } from '@kbn/react-kibana-context-common'; /** @@ -64,8 +69,13 @@ export const KibanaEuiProvider: FC> = modify, children, }) => { - const theme = useObservable(theme$, defaultTheme); - const themeColorMode = useMemo(() => getColorMode(theme), [theme]); + const kibanaTheme = useObservable(theme$, defaultTheme); + const themeColorMode = useMemo(() => getColorMode(kibanaTheme), [kibanaTheme]); + + const theme = useMemo(() => { + const config = getThemeConfigByName(kibanaTheme.name) || DEFAULT_THEME_CONFIG; + return config.euiTheme; + }, [kibanaTheme.name]); // In some cases-- like in Storybook or testing-- we want to explicitly override the // colorMode provided by the `theme`. @@ -76,7 +86,9 @@ export const KibanaEuiProvider: FC> = const globalStyles = globalStylesProp === false ? false : undefined; return ( - + {children} ); diff --git a/packages/react/kibana_context/root/kibana.jsonc b/packages/react/kibana_context/root/kibana.jsonc index 80a029c6ed487..740d92da927c9 100644 --- a/packages/react/kibana_context/root/kibana.jsonc +++ b/packages/react/kibana_context/root/kibana.jsonc @@ -1,5 +1,5 @@ { - "type": "shared-browser", + "type": "shared-common", "id": "@kbn/react-kibana-context-root", "owner": "@elastic/appex-sharedux" } diff --git a/packages/react/kibana_context/root/root_provider.test.tsx b/packages/react/kibana_context/root/root_provider.test.tsx index df4bdf14c5c22..919adb09581d5 100644 --- a/packages/react/kibana_context/root/root_provider.test.tsx +++ b/packages/react/kibana_context/root/root_provider.test.tsx @@ -58,7 +58,7 @@ describe('KibanaRootContextProvider', () => { }; it('exposes the EUI theme provider', async () => { - const coreTheme: KibanaTheme = { darkMode: true }; + const coreTheme: KibanaTheme = { darkMode: true, name: 'amsterdam' }; const wrapper = mountWithIntl( { }); it('propagates changes of the coreTheme observable', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const wrapper = mountWithIntl( { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - coreTheme$.next({ darkMode: false }); + coreTheme$.next({ darkMode: false, name: 'amsterdam' }); }); await refresh(wrapper); diff --git a/packages/react/kibana_context/theme/BUILD.bazel b/packages/react/kibana_context/theme/BUILD.bazel new file mode 100644 index 0000000000000..504477ad7a0ed --- /dev/null +++ b/packages/react/kibana_context/theme/BUILD.bazel @@ -0,0 +1,38 @@ +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/**", + ], +) + +BUNDLER_DEPS = [ + "@npm//react", + "@npm//tslib", + "@npm//react-use", + "//packages/react/kibana_context/common", + "//packages/react/kibana_context/root", +] + +js_library( + name = "theme", + package_name = "@kbn/react-kibana-context-theme", + srcs = ["package.json"] + SRCS, + deps = BUNDLER_DEPS, + visibility = ["//visibility:public"], +) diff --git a/packages/react/kibana_context/theme/kibana.jsonc b/packages/react/kibana_context/theme/kibana.jsonc index b3f8ba25cc5d3..56ae8b57a6682 100644 --- a/packages/react/kibana_context/theme/kibana.jsonc +++ b/packages/react/kibana_context/theme/kibana.jsonc @@ -1,5 +1,5 @@ { - "type": "shared-browser", + "type": "shared-common", "id": "@kbn/react-kibana-context-theme", "owner": "@elastic/appex-sharedux" } diff --git a/packages/react/kibana_context/theme/theme_provider.test.tsx b/packages/react/kibana_context/theme/theme_provider.test.tsx index a20af098d857d..9889da9a689a3 100644 --- a/packages/react/kibana_context/theme/theme_provider.test.tsx +++ b/packages/react/kibana_context/theme/theme_provider.test.tsx @@ -52,7 +52,7 @@ describe('KibanaThemeProvider', () => { }; it('exposes the EUI theme provider', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const wrapper = mountWithIntl( @@ -66,7 +66,10 @@ describe('KibanaThemeProvider', () => { }); it('propagates changes of the coreTheme observable', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ + darkMode: true, + name: 'amsterdam', + }); const wrapper = mountWithIntl( @@ -79,7 +82,7 @@ describe('KibanaThemeProvider', () => { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - coreTheme$.next({ darkMode: false }); + coreTheme$.next({ darkMode: false, name: 'amsterdam' }); }); await refresh(wrapper); diff --git a/packages/react/kibana_mount/to_mount_point.test.tsx b/packages/react/kibana_mount/to_mount_point.test.tsx index 2232551877750..50a49263e2532 100644 --- a/packages/react/kibana_mount/to_mount_point.test.tsx +++ b/packages/react/kibana_mount/to_mount_point.test.tsx @@ -41,7 +41,7 @@ describe('toMountPoint', () => { }; it('exposes the euiTheme when `theme$` is provided', async () => { - const theme = { theme$: of({ darkMode: true }) }; + const theme = { theme$: of({ darkMode: true, name: 'amsterdam' }) }; const mount = toMountPoint(, { theme, i18n, analytics }); const targetEl = document.createElement('div'); @@ -53,7 +53,7 @@ describe('toMountPoint', () => { }); it('propagates changes of the theme$ observable', async () => { - const theme$ = new BehaviorSubject({ darkMode: true }); + const theme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const mount = toMountPoint(, { theme: { theme$ }, i18n, analytics }); @@ -65,7 +65,7 @@ describe('toMountPoint', () => { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - theme$.next({ darkMode: false }); + theme$.next({ darkMode: false, name: 'amsterdam' }); }); await flushPromises(); diff --git a/src/plugins/chart_expressions/expression_partition_vis/public/__mocks__/theme.ts b/src/plugins/chart_expressions/expression_partition_vis/public/__mocks__/theme.ts index d91f31e243783..01c40ecc53d2d 100644 --- a/src/plugins/chart_expressions/expression_partition_vis/public/__mocks__/theme.ts +++ b/src/plugins/chart_expressions/expression_partition_vis/public/__mocks__/theme.ts @@ -11,6 +11,6 @@ import { themeServiceMock } from '@kbn/core/public/mocks'; import { ThemeService } from '@kbn/charts-plugin/public/services'; const theme = new ThemeService(); -theme.init(themeServiceMock.createSetupContract({ darkMode: false })); +theme.init(themeServiceMock.createSetupContract({ darkMode: false, name: 'amsterdam' })); export { theme }; diff --git a/src/plugins/charts/public/services/theme/theme.test.tsx b/src/plugins/charts/public/services/theme/theme.test.tsx index ef8594e200dca..ef77405edf27e 100644 --- a/src/plugins/charts/public/services/theme/theme.test.tsx +++ b/src/plugins/charts/public/services/theme/theme.test.tsx @@ -19,7 +19,7 @@ import { ThemeService } from './theme'; import { coreMock } from '@kbn/core/public/mocks'; const createTheme$Mock = (mode: boolean) => { - return from([{ darkMode: mode }]); + return from([{ darkMode: mode, name: 'amsterdam' }]); }; const { theme: setUpMockTheme } = coreMock.createSetup(); @@ -37,6 +37,7 @@ describe('ThemeService', () => { expect(await themeService.darkModeEnabled$.pipe(take(1)).toPromise()).toStrictEqual({ darkMode: false, + name: 'amsterdam', }); }); @@ -47,6 +48,7 @@ describe('ThemeService', () => { expect(await themeService.darkModeEnabled$.pipe(take(1)).toPromise()).toStrictEqual({ darkMode: true, + name: 'amsterdam', }); }); }); diff --git a/src/plugins/controls/public/control_group/components/control_error.tsx b/src/plugins/controls/public/control_group/components/control_error.tsx index 2ef6b06faeedd..80d33d8225b3b 100644 --- a/src/plugins/controls/public/control_group/components/control_error.tsx +++ b/src/plugins/controls/public/control_group/components/control_error.tsx @@ -12,12 +12,14 @@ import React, { useState } from 'react'; import { EuiButtonEmpty, EuiPopover } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { Markdown } from '@kbn/shared-ux-markdown'; +import { useErrorTextStyle } from '@kbn/react-hooks'; interface ControlErrorProps { error: Error | string; } export const ControlError = ({ error }: ControlErrorProps) => { + const errorTextStyle = useErrorTextStyle(); const [isPopoverOpen, setPopoverOpen] = useState(false); const errorMessage = error instanceof Error ? error.message : error; @@ -47,7 +49,7 @@ export const ControlError = ({ error }: ControlErrorProps) => { className="controlPanel errorEmbeddableCompact__popover" closePopover={() => setPopoverOpen(false)} > - + {errorMessage} diff --git a/src/plugins/controls/tsconfig.json b/src/plugins/controls/tsconfig.json index 41ab33dc18969..7759a0fdc7935 100644 --- a/src/plugins/controls/tsconfig.json +++ b/src/plugins/controls/tsconfig.json @@ -39,6 +39,7 @@ "@kbn/presentation-panel-plugin", "@kbn/shared-ux-utility", "@kbn/std", + "@kbn/react-hooks", ], "exclude": ["target/**/*"] } diff --git a/src/plugins/discover/public/__mocks__/services.ts b/src/plugins/discover/public/__mocks__/services.ts index f00d105444630..b00b5a95b3958 100644 --- a/src/plugins/discover/public/__mocks__/services.ts +++ b/src/plugins/discover/public/__mocks__/services.ts @@ -143,7 +143,7 @@ export function createDiscoverServicesMock(): DiscoverServices { }; const { profilesManagerMock } = createContextAwarenessMocks(); - const theme = themeServiceMock.createSetupContract({ darkMode: false }); + const theme = themeServiceMock.createSetupContract({ darkMode: false, name: 'amsterdam' }); corePluginMock.theme = theme; corePluginMock.chrome.getActiveSolutionNavId$.mockReturnValue(new BehaviorSubject(null)); diff --git a/src/plugins/guided_onboarding/public/components/guide_panel.test.tsx b/src/plugins/guided_onboarding/public/components/guide_panel.test.tsx index 0de8d47398e51..1732ff51bf87d 100644 --- a/src/plugins/guided_onboarding/public/components/guide_panel.test.tsx +++ b/src/plugins/guided_onboarding/public/components/guide_panel.test.tsx @@ -58,7 +58,7 @@ const setupComponentWithPluginStateMock = async ( }; const setupGuidePanelComponent = async (api: GuidedOnboardingApi) => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); let testBed: TestBed; const GuidePanelComponent = () => ( (undefined); const [guideConfig, setGuideConfig] = useState(undefined); const [isLoading, setIsLoading] = useState(false); - const { darkMode: isDarkTheme } = useObservable(theme$, { darkMode: false }); + const { darkMode: isDarkTheme } = useObservable(theme$, { darkMode: false, name: 'amsterdam' }); const styles = getGuidePanelStyles({ euiThemeContext, isDarkTheme }); diff --git a/src/plugins/kibana_overview/public/components/overview/overview.tsx b/src/plugins/kibana_overview/public/components/overview/overview.tsx index ef7820391273b..4d21adeecd377 100644 --- a/src/plugins/kibana_overview/public/components/overview/overview.tsx +++ b/src/plugins/kibana_overview/public/components/overview/overview.tsx @@ -73,7 +73,7 @@ export const Overview: FC = ({ newsFetchResult, solutions, features }) => theme, } = services; const addBasePath = http.basePath.prepend; - const currentTheme = useObservable(theme.theme$, { darkMode: false }); + const currentTheme = useObservable(theme.theme$, { darkMode: false, name: 'amsterdam' }); // Home does not have a locator implemented, so hard-code it here. const addDataHref = addBasePath('/app/integrations/browse'); diff --git a/src/plugins/kibana_react/public/dark_mode/use_dark_mode.test.tsx b/src/plugins/kibana_react/public/dark_mode/use_dark_mode.test.tsx index 4c3e1d91b91b5..95b56ac659603 100644 --- a/src/plugins/kibana_react/public/dark_mode/use_dark_mode.test.tsx +++ b/src/plugins/kibana_react/public/dark_mode/use_dark_mode.test.tsx @@ -37,7 +37,7 @@ describe('useDarkMode', () => { const mock = (): [KibanaServices, BehaviorSubject] => { const core = coreMock.createStart(); - const subject = new BehaviorSubject({ darkMode: false }); + const subject = new BehaviorSubject({ darkMode: false, name: 'amsterdam' }); core.theme.theme$ = subject.asObservable(); return [core, subject]; @@ -73,7 +73,7 @@ describe('useDarkMode', () => { expect(div!.textContent).toBe('false'); act(() => { - subject.next({ darkMode: true }); + subject.next({ darkMode: true, name: 'amsterdam' }); }); div = container!.querySelector('div'); diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index e3374219b6553..c4202cf6f92e2 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -272,6 +272,10 @@ export const stackManagementSchema: MakeSchemaFrom = { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, }, + 'theme:name': { + type: 'keyword', + _meta: { description: 'Non-default value of setting.' }, + }, 'state:storeInSessionStorage': { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts index b49647c3d4791..e4b10f038a75a 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts @@ -108,6 +108,7 @@ export interface UsageStats { 'timepicker:quickRanges': string; 'theme:version': string; 'theme:darkMode': boolean; + 'theme:name': string; 'state:storeInSessionStorage': boolean; 'savedObjects:perPage': number; 'search:queryLanguage': string; diff --git a/src/plugins/kibana_utils/public/theme/kibana_theme_provider.test.tsx b/src/plugins/kibana_utils/public/theme/kibana_theme_provider.test.tsx index 27aefe1d43488..93511354b19ad 100644 --- a/src/plugins/kibana_utils/public/theme/kibana_theme_provider.test.tsx +++ b/src/plugins/kibana_utils/public/theme/kibana_theme_provider.test.tsx @@ -52,7 +52,7 @@ describe('KibanaThemeProvider', () => { }; it('exposes the EUI theme provider', async () => { - const coreTheme: CoreTheme = { darkMode: true }; + const coreTheme: CoreTheme = { darkMode: true, name: 'amsterdam' }; const wrapper = mountWithIntl( @@ -66,7 +66,7 @@ describe('KibanaThemeProvider', () => { }); it('propagates changes of the coreTheme observable', async () => { - const coreTheme$ = new BehaviorSubject({ darkMode: true }); + const coreTheme$ = new BehaviorSubject({ darkMode: true, name: 'amsterdam' }); const wrapper = mountWithIntl( @@ -79,7 +79,7 @@ describe('KibanaThemeProvider', () => { expect(euiTheme!.colorMode).toEqual('DARK'); await act(async () => { - coreTheme$.next({ darkMode: false }); + coreTheme$.next({ darkMode: false, name: 'amsterdam' }); }); await refresh(wrapper); diff --git a/src/plugins/presentation_panel/public/panel_component/presentation_panel_error.tsx b/src/plugins/presentation_panel/public/panel_component/presentation_panel_error.tsx index 5e6ac14d14328..4973e2599ddad 100644 --- a/src/plugins/presentation_panel/public/panel_component/presentation_panel_error.tsx +++ b/src/plugins/presentation_panel/public/panel_component/presentation_panel_error.tsx @@ -16,6 +16,7 @@ import { renderSearchError } from '@kbn/search-errors'; import { Markdown } from '@kbn/shared-ux-markdown'; import { Subscription } from 'rxjs'; import { i18n } from '@kbn/i18n'; +import { useErrorTextStyle } from '@kbn/react-hooks'; import { editPanelAction } from '../panel_actions/panel_actions'; import { getErrorCallToAction } from './presentation_panel_strings'; import { DefaultPresentationPanelApi } from './types'; @@ -27,6 +28,8 @@ export const PresentationPanelError = ({ error: ErrorLike; api?: DefaultPresentationPanelApi; }) => { + const errorTextStyle = useErrorTextStyle(); + const [isEditable, setIsEditable] = useState(false); const handleErrorClick = useMemo( () => (isEditable ? () => editPanelAction?.execute({ embeddable: api }) : undefined), @@ -82,7 +85,7 @@ export const PresentationPanelError = ({ + {error.message?.length ? error.message diff --git a/src/plugins/presentation_panel/tsconfig.json b/src/plugins/presentation_panel/tsconfig.json index 9b867c0ada43c..255e4fd4eccde 100644 --- a/src/plugins/presentation_panel/tsconfig.json +++ b/src/plugins/presentation_panel/tsconfig.json @@ -28,7 +28,8 @@ "@kbn/data-views-plugin", "@kbn/panel-loader", "@kbn/search-errors", - "@kbn/shared-ux-markdown" + "@kbn/shared-ux-markdown", + "@kbn/react-hooks" ], "exclude": ["target/**/*"] } diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index 6a43177492548..78f8b4f2f7b38 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -10272,6 +10272,12 @@ "description": "Non-default value of setting." } }, + "theme:name": { + "type": "keyword", + "_meta": { + "description": "Non-default value of setting." + } + }, "state:storeInSessionStorage": { "type": "boolean", "_meta": { diff --git a/src/plugins/visualizations/public/embeddable/visualize_embeddable.tsx b/src/plugins/visualizations/public/embeddable/visualize_embeddable.tsx index 52c76a426dc14..7b48521265d6f 100644 --- a/src/plugins/visualizations/public/embeddable/visualize_embeddable.tsx +++ b/src/plugins/visualizations/public/embeddable/visualize_embeddable.tsx @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { EuiEmptyPrompt, EuiFlexGroup, EuiLoadingChart } from '@elastic/eui'; +import { EuiEmptyPrompt, EuiFlexGroup, EuiLoadingChart, EuiText } from '@elastic/eui'; import { isChartSizeEvent } from '@kbn/chart-expressions-common'; import { APPLY_FILTER_TRIGGER } from '@kbn/data-plugin/public'; import type { DataView } from '@kbn/data-views-plugin/public'; @@ -38,6 +38,7 @@ import { apiPublishesSearchSession } from '@kbn/presentation-publishing/interfac import { get, isEmpty, isEqual, isNil, omitBy } from 'lodash'; import React, { useEffect, useRef } from 'react'; import { BehaviorSubject, switchMap } from 'rxjs'; +import { useErrorTextStyle } from '@kbn/react-hooks'; import { VISUALIZE_APP_NAME, VISUALIZE_EMBEDDABLE_TYPE } from '../../common/constants'; import { VIS_EVENT_TO_TRIGGER } from './events'; import { getInspector, getUiActions, getUsageCollection } from '../services'; @@ -454,6 +455,7 @@ export const getVisualizeEmbeddableFactory: (deps: { const hasRendered = useStateFromPublishingSubject(hasRendered$); const domNode = useRef(null); const { error, isLoading } = useExpressionRenderer(domNode, expressionParams); + const errorTextStyle = useErrorTextStyle(); useEffect(() => { return () => { @@ -495,9 +497,9 @@ export const getVisualizeEmbeddableFactory: (deps: { } body={ -

+ {error.name}: {error.message} -

+
} /> )} diff --git a/src/plugins/visualizations/tsconfig.json b/src/plugins/visualizations/tsconfig.json index 06d3931fe8e08..51deaf4139aa2 100644 --- a/src/plugins/visualizations/tsconfig.json +++ b/src/plugins/visualizations/tsconfig.json @@ -72,7 +72,8 @@ "@kbn/presentation-containers", "@kbn/search-response-warnings", "@kbn/embeddable-enhanced-plugin", - "@kbn/content-management-utils" + "@kbn/content-management-utils", + "@kbn/react-hooks" ], "exclude": ["target/**/*"] } diff --git a/test/functional/apps/console/_text_input.ts b/test/functional/apps/console/_text_input.ts index c2580d2dbb067..0e286434fa8d1 100644 --- a/test/functional/apps/console/_text_input.ts +++ b/test/functional/apps/console/_text_input.ts @@ -32,7 +32,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { describe('with a data URI in the load_from query', () => { it('loads the data from the URI', async () => { await PageObjects.common.navigateToApp('console', { - hash: '#/console?load_from=data:text/plain,BYUwNmD2Q', + hash: '#/console/shell?load_from=data:text/plain,BYUwNmD2Q', }); await retry.try(async () => { @@ -44,7 +44,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { describe('with invalid data', () => { it('shows a toast error', async () => { await PageObjects.common.navigateToApp('console', { - hash: '#/console?load_from=data:text/plain,BYUwNmD2', + hash: '#/console/shell?load_from=data:text/plain,BYUwNmD2', }); await retry.try(async () => { diff --git a/x-pack/plugins/fleet/.storybook/context/index.tsx b/x-pack/plugins/fleet/.storybook/context/index.tsx index 67ed1c8aa6845..373dbc838835f 100644 --- a/x-pack/plugins/fleet/.storybook/context/index.tsx +++ b/x-pack/plugins/fleet/.storybook/context/index.tsx @@ -99,7 +99,7 @@ export const StorybookContext: React.FC<{ settings: getSettings(), theme: { theme$: EMPTY, - getTheme: () => ({ darkMode: false }), + getTheme: () => ({ darkMode: false, name: 'amsterdam' }), }, security: {} as unknown as SecurityServiceStart, userProfile: {} as unknown as UserProfileServiceStart, diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx index 6c4a94d77a871..b32d7456bd2b5 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx @@ -488,7 +488,10 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ } }, [suggestionForDraggedField, dispatchLens]); - const IS_DARK_THEME: boolean = useObservable(core.theme.theme$, { darkMode: false }).darkMode; + const IS_DARK_THEME: boolean = useObservable(core.theme.theme$, { + darkMode: false, + name: 'amsterdam', + }).darkMode; const renderDragDropPrompt = () => { if (chartSizeSpec) { diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx index ec672d20f55da..0633c13b8097a 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx @@ -80,7 +80,10 @@ export const DatatableComponent = (props: DatatableRenderProps) => { const dataGridRef = useRef(null); const isInteractive = props.interactive; - const isDarkMode = useObservable(props.theme.theme$, { darkMode: false }).darkMode; + const isDarkMode = useObservable(props.theme.theme$, { + darkMode: false, + name: 'amsterdam', + }).darkMode; const [columnConfig, setColumnConfig] = useState({ columns: props.args.columns, diff --git a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx index 55dea2be2e370..efe5a39458eed 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx @@ -465,7 +465,10 @@ export const getDatatableVisualization = ({ }; }, DimensionEditorComponent(props) { - const isDarkMode = useObservable(kibanaTheme.theme$, { darkMode: false }).darkMode; + const isDarkMode = useObservable(kibanaTheme.theme$, { + darkMode: false, + name: 'amsterdam', + }).darkMode; return ( diff --git a/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts index 60a7aed1c9274..b848e0c44922e 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts @@ -668,7 +668,7 @@ describe('suggestions', () => { ).toContainEqual( expect.objectContaining({ state: { - shape: PieChartTypes.DONUT, + shape: PieChartTypes.PIE, palette, layers: [ { diff --git a/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts b/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts index 0e66291c068da..4654ce73d8157 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts @@ -39,20 +39,18 @@ function shouldReject({ table, keptLayerIds, state }: SuggestionRequest = { title: i18n.translate('xpack.lens.pie.suggestionLabel', { defaultMessage: '{chartName}', diff --git a/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx b/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx index 661921caaa1ef..8d44fec4e96e4 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx @@ -494,7 +494,10 @@ export const getPieVisualization = ({ }; }, DimensionEditorComponent(props) { - const isDarkMode = useObservable(kibanaTheme.theme$, { darkMode: false }).darkMode; + const isDarkMode = useObservable(kibanaTheme.theme$, { + darkMode: false, + name: 'amsterdam', + }).darkMode; return ; }, DimensionEditorDataExtraComponent(props) { diff --git a/x-pack/plugins/lens/public/visualizations/tagcloud/tagcloud_visualization.tsx b/x-pack/plugins/lens/public/visualizations/tagcloud/tagcloud_visualization.tsx index 8d962ef076093..b457926fe373d 100644 --- a/x-pack/plugins/lens/public/visualizations/tagcloud/tagcloud_visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/tagcloud/tagcloud_visualization.tsx @@ -294,7 +294,10 @@ export const getTagcloudVisualization = ({ }, DimensionEditorComponent(props) { - const isDarkMode: boolean = useObservable(kibanaTheme.theme$, { darkMode: false }).darkMode; + const isDarkMode: boolean = useObservable(kibanaTheme.theme$, { + darkMode: false, + name: 'amsterdam', + }).darkMode; if (props.groupId === TAG_GROUP_ID) { return ( l.layerId === props.layerId)!; const dimensionEditor = isReferenceLayer(layer) ? ( diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/legend_details.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/legend_details.tsx index 3f9e5c8f11627..37257746006cd 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/legend_details.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/legend_details.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { Adapters } from '@kbn/inspector-plugin/common/adapters'; import { EuiCallOut, EuiSpacer } from '@elastic/eui'; +import { useErrorTextStyle } from '@kbn/react-hooks'; import type { ILayer } from '../../../../../classes/layers/layer'; interface Props { @@ -16,13 +17,15 @@ interface Props { } export function LegendDetails({ inspectorAdapters, layer }: Props) { + const errorTextStyle = useErrorTextStyle(); + const errors = layer.getErrors(inspectorAdapters); if (errors.length) { return ( <> {errors.map(({ title, body }, index) => (
- + {body} @@ -37,7 +40,7 @@ export function LegendDetails({ inspectorAdapters, layer }: Props) { <> {warnings.map(({ title, body }, index) => (
- + {body} diff --git a/x-pack/plugins/maps/tsconfig.json b/x-pack/plugins/maps/tsconfig.json index dfee193ed0a25..e82e35b5ccbfd 100644 --- a/x-pack/plugins/maps/tsconfig.json +++ b/x-pack/plugins/maps/tsconfig.json @@ -90,7 +90,8 @@ "@kbn/react-kibana-context-render", "@kbn/embeddable-enhanced-plugin", "@kbn/presentation-containers", - "@kbn/field-utils" + "@kbn/field-utils", + "@kbn/react-hooks" ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/observability_solution/infra/public/components/shared/templates/infra_page_template.tsx b/x-pack/plugins/observability_solution/infra/public/components/shared/templates/infra_page_template.tsx index b7318c736843a..61130564a2753 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/shared/templates/infra_page_template.tsx +++ b/x-pack/plugins/observability_solution/infra/public/components/shared/templates/infra_page_template.tsx @@ -98,12 +98,12 @@ export const InfraPageTemplate = ({ }); }, [hasData, setScreenContext, source]); - if (!isSourceLoading && !remoteClustersExist) { - return ; + if (sourceError) { + return ; } - if (sourceError) { - ; + if (!isSourceLoading && !remoteClustersExist) { + return ; } if (dataViewLoadError) { diff --git a/x-pack/plugins/observability_solution/infra/public/hooks/use_is_dark_mode.ts b/x-pack/plugins/observability_solution/infra/public/hooks/use_is_dark_mode.ts index e618e02b1b51e..93260405cce59 100644 --- a/x-pack/plugins/observability_solution/infra/public/hooks/use_is_dark_mode.ts +++ b/x-pack/plugins/observability_solution/infra/public/hooks/use_is_dark_mode.ts @@ -10,7 +10,7 @@ import useObservable from 'react-use/lib/useObservable'; import { of } from 'rxjs'; import { useKibanaContextForPlugin } from './use_kibana'; -const themeDefault: CoreTheme = { darkMode: false }; +const themeDefault: CoreTheme = { darkMode: false, name: 'amsterdam' }; export const useIsDarkMode = () => { const { services } = useKibanaContextForPlugin(); diff --git a/x-pack/plugins/observability_solution/infra/public/test_utils/use_global_storybook_theme.tsx b/x-pack/plugins/observability_solution/infra/public/test_utils/use_global_storybook_theme.tsx index dd0f97038740a..482602c87fd06 100644 --- a/x-pack/plugins/observability_solution/infra/public/test_utils/use_global_storybook_theme.tsx +++ b/x-pack/plugins/observability_solution/infra/public/test_utils/use_global_storybook_theme.tsx @@ -53,8 +53,8 @@ export const decorateWithGlobalStorybookThemeProviders: DecoratorFn = ( const euiThemeFromId = (themeId: string): CoreTheme => { switch (themeId) { case 'v8.dark': - return { darkMode: true }; + return { darkMode: true, name: 'amsterdam' }; default: - return { darkMode: false }; + return { darkMode: false, name: 'amsterdam' }; } }; diff --git a/x-pack/plugins/observability_solution/logs_shared/public/test_utils/use_global_storybook_theme.tsx b/x-pack/plugins/observability_solution/logs_shared/public/test_utils/use_global_storybook_theme.tsx index dd0f97038740a..482602c87fd06 100644 --- a/x-pack/plugins/observability_solution/logs_shared/public/test_utils/use_global_storybook_theme.tsx +++ b/x-pack/plugins/observability_solution/logs_shared/public/test_utils/use_global_storybook_theme.tsx @@ -53,8 +53,8 @@ export const decorateWithGlobalStorybookThemeProviders: DecoratorFn = ( const euiThemeFromId = (themeId: string): CoreTheme => { switch (themeId) { case 'v8.dark': - return { darkMode: true }; + return { darkMode: true, name: 'amsterdam' }; default: - return { darkMode: false }; + return { darkMode: false, name: 'amsterdam' }; } }; diff --git a/x-pack/plugins/observability_solution/metrics_data_access/public/test_utils/use_global_storybook_theme.tsx b/x-pack/plugins/observability_solution/metrics_data_access/public/test_utils/use_global_storybook_theme.tsx index 7ed147138cce3..536cebb21a511 100644 --- a/x-pack/plugins/observability_solution/metrics_data_access/public/test_utils/use_global_storybook_theme.tsx +++ b/x-pack/plugins/observability_solution/metrics_data_access/public/test_utils/use_global_storybook_theme.tsx @@ -52,8 +52,8 @@ export const decorateWithGlobalStorybookThemeProviders: DecoratorFn = ( const euiThemeFromId = (themeId: string): CoreTheme => { switch (themeId) { case 'v8.dark': - return { darkMode: true }; + return { darkMode: true, name: 'amsterdam' }; default: - return { darkMode: false }; + return { darkMode: false, name: 'amsterdam' }; } }; diff --git a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.test.ts b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.test.ts index 044b57c64da28..a4825c11f85cd 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.test.ts +++ b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.test.ts @@ -17,7 +17,11 @@ const useCases = [ filter: '', name: '', }, - 'sum(system.cpu.user.pct)', + { + operation: 'sum', + operationWithField: 'sum(system.cpu.user.pct)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -26,7 +30,11 @@ const useCases = [ filter: '', name: '', }, - 'max(system.cpu.user.pct)', + { + operation: 'max', + operationWithField: 'max(system.cpu.user.pct)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -35,7 +43,11 @@ const useCases = [ filter: '', name: '', }, - 'min(system.cpu.user.pct)', + { + operation: 'min', + operationWithField: 'min(system.cpu.user.pct)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -44,16 +56,24 @@ const useCases = [ filter: '', name: '', }, - 'average(system.cpu.user.pct)', + { + operation: 'average', + operationWithField: 'average(system.cpu.user.pct)', + sourceField: 'system.cpu.user.pct', + }, ], [ { aggType: Aggregators.COUNT, - field: 'system.cpu.user.pct', - filter: '', + field: '', + filter: 'system.cpu.user.pct: *', name: '', }, - 'count(___records___)', + { + operation: 'count', + operationWithField: `count(kql='system.cpu.user.pct: *')`, + sourceField: '', + }, ], [ { @@ -62,7 +82,11 @@ const useCases = [ filter: '', name: '', }, - 'unique_count(system.cpu.user.pct)', + { + operation: 'unique_count', + operationWithField: 'unique_count(system.cpu.user.pct)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -71,7 +95,11 @@ const useCases = [ filter: '', name: '', }, - 'percentile(system.cpu.user.pct, percentile=95)', + { + operation: 'percentile', + operationWithField: 'percentile(system.cpu.user.pct, percentile=95)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -80,7 +108,11 @@ const useCases = [ filter: '', name: '', }, - 'percentile(system.cpu.user.pct, percentile=99)', + { + operation: 'percentile', + operationWithField: 'percentile(system.cpu.user.pct, percentile=99)', + sourceField: 'system.cpu.user.pct', + }, ], [ { @@ -89,7 +121,11 @@ const useCases = [ filter: '', name: '', }, - `counter_rate(max(system.network.in.bytes), kql='')`, + { + operation: 'counter_rate', + operationWithField: `counter_rate(max(system.network.in.bytes), kql='')`, + sourceField: 'system.network.in.bytes', + }, ], [ { @@ -98,7 +134,11 @@ const useCases = [ filter: 'host.name : "foo"', name: '', }, - `counter_rate(max(system.network.in.bytes), kql='host.name : foo')`, + { + operation: 'counter_rate', + operationWithField: `counter_rate(max(system.network.in.bytes), kql='host.name : foo')`, + sourceField: 'system.network.in.bytes', + }, ], ]; diff --git a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.ts b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.ts index a487f4899ad06..9eb52af738ea9 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.ts +++ b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/helpers.ts @@ -8,14 +8,24 @@ import { Aggregators } from '../../../common/custom_threshold_rule/types'; import { GenericMetric } from './rule_condition_chart'; -export const getLensOperationFromRuleMetric = (metric: GenericMetric): string => { +export interface LensOperation { + operation: string; + operationWithField: string; + sourceField: string; +} + +export const getLensOperationFromRuleMetric = (metric: GenericMetric): LensOperation => { const { aggType, field, filter } = metric; let operation: string = aggType; const operationArgs: string[] = []; const aggFilter = JSON.stringify(filter || '').replace(/"|\\/g, ''); if (aggType === Aggregators.RATE) { - return `counter_rate(max(${field}), kql='${aggFilter}')`; + return { + operation: 'counter_rate', + operationWithField: `counter_rate(max(${field}), kql='${aggFilter}')`, + sourceField: field || '', + }; } if (aggType === Aggregators.AVERAGE) operation = 'average'; @@ -23,14 +33,10 @@ export const getLensOperationFromRuleMetric = (metric: GenericMetric): string => if (aggType === Aggregators.P95 || aggType === Aggregators.P99) operation = 'percentile'; if (aggType === Aggregators.COUNT) operation = 'count'; - let sourceField = field; - - if (aggType === Aggregators.COUNT) { - sourceField = '___records___'; + if (field) { + operationArgs.push(field); } - operationArgs.push(sourceField || ''); - if (aggType === Aggregators.P95) { operationArgs.push('percentile=95'); } @@ -41,7 +47,11 @@ export const getLensOperationFromRuleMetric = (metric: GenericMetric): string => if (aggFilter) operationArgs.push(`kql='${aggFilter}'`); - return operation + '(' + operationArgs.join(', ') + ')'; + return { + operation, + operationWithField: `${operation}(${operationArgs.join(', ')})`, + sourceField: field || '', + }; }; export const getBufferThreshold = (threshold?: number): string => diff --git a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.test.ts b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.test.ts index a957c58167403..647791cab5b8d 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.test.ts +++ b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.test.ts @@ -17,7 +17,11 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -28,7 +32,11 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - 'ABC-abc': 'average(system.cpu.system.pct)', + 'ABC-abc': { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, }, }); expect(parser.parse()).toEqual('100*average(system.cpu.system.pct)'); @@ -38,8 +46,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -52,9 +68,21 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', - C: 'average(system.cpu.cores)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, + C: { + operationWithField: 'average(system.cpu.cores)', + operation: 'average', + sourceField: 'system.cpu.cores', + }, }, }); // ✅ checked with Lens Formula editor @@ -67,7 +95,11 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -79,8 +111,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -93,8 +133,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -107,8 +155,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -121,8 +177,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -135,8 +199,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -149,8 +221,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -163,8 +243,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -178,8 +266,16 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - aa: 'average(system.cpu.system.pct)', - baa: 'average(system.cpu.user.pct)', + aa: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + baa: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, }, }); expect(parser.parse()).toEqual( @@ -193,12 +289,36 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', - C: 'average(system.cpu.total.pct)', - D: 'average(system.cpu.cores)', - E: 'count()', - F: 'sum(system.cpu.total.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, + C: { + operationWithField: 'average(system.cpu.total.pct)', + operation: 'average', + sourceField: 'system.cpu.total.pct', + }, + D: { + operationWithField: 'average(system.cpu.cores)', + operation: 'average', + sourceField: 'system.cpu.cores', + }, + E: { + operationWithField: 'count()', + operation: 'count', + sourceField: '', + }, + F: { + operationWithField: 'sum(system.cpu.total.pct)', + operation: 'sum', + sourceField: 'system.cpu.total.pct', + }, }, }); // ✅ checked with Lens Formula editor @@ -213,12 +333,36 @@ describe('PainlessTinyMathParser', () => { const parser = new PainlessTinyMathParser({ equation, aggMap: { - A: 'average(system.cpu.system.pct)', - B: 'average(system.cpu.user.pct)', - C: 'average(system.cpu.total.pct)', - D: 'average(system.cpu.cores)', - E: 'count()', - F: 'sum(system.cpu.total.pct)', + A: { + operationWithField: 'average(system.cpu.system.pct)', + operation: 'average', + sourceField: 'system.cpu.system.pct', + }, + B: { + operationWithField: 'average(system.cpu.user.pct)', + operation: 'average', + sourceField: 'system.cpu.user.pct', + }, + C: { + operationWithField: 'average(system.cpu.total.pct)', + operation: 'average', + sourceField: 'system.cpu.total.pct', + }, + D: { + operationWithField: 'average(system.cpu.cores)', + operation: 'average', + sourceField: 'system.cpu.cores', + }, + E: { + operationWithField: 'count()', + operation: 'count', + sourceField: '', + }, + F: { + operationWithField: 'sum(system.cpu.total.pct)', + operation: 'sum', + sourceField: 'system.cpu.total.pct', + }, }, }); // ✅ checked with Lens Formula editor diff --git a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.ts b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.ts index 25ec15d3a808b..8c09ba029c579 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.ts +++ b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/painless_tinymath_parser.ts @@ -5,6 +5,8 @@ * 2.0. */ +import { LensOperation } from './helpers'; + // This is a parser of a subset operations/expression/statement of Painless A-Z, +, -, /, *, (, ), ?, !, &, :, |, >, <, = to be used in Lens formula editor that uses TinyMath // The goal is to parse painless expressions to a format that can be used in Lens formula editor // The parser will also replace the characters A-Z with the values from aggMap @@ -13,7 +15,7 @@ // This parser is using a simple recursive function to parse the expression and replace the characters with the values from aggMap export interface AggMap { - [key: string]: string; + [key: string]: LensOperation; } interface PainlessTinyMathParserProps { equation: string; @@ -81,7 +83,10 @@ export class PainlessTinyMathParser { .sort() .reverse() .forEach((metricName) => { - parsedInputString = parsedInputString.replaceAll(metricName, aggMap[metricName]); + parsedInputString = parsedInputString.replaceAll( + metricName, + aggMap[metricName].operationWithField + ); }); return parsedInputString; diff --git a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/rule_condition_chart.tsx b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/rule_condition_chart.tsx index 4567d7c37b10b..2a9fa2c295274 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/rule_condition_chart.tsx +++ b/x-pack/plugins/observability_solution/observability/public/components/rule_condition_chart/rule_condition_chart.tsx @@ -8,7 +8,7 @@ import React, { useState, useEffect } from 'react'; import { EuiEmptyPrompt, useEuiTheme } from '@elastic/eui'; import { Query, Filter } from '@kbn/es-query'; -import { FillStyle, SeriesType } from '@kbn/lens-plugin/public'; +import { FillStyle, SeriesType, TermsIndexPatternColumn } from '@kbn/lens-plugin/public'; import { DataView } from '@kbn/data-views-plugin/common'; import { FormattedMessage } from '@kbn/i18n-react'; import useAsync from 'react-use/lib/useAsync'; @@ -82,6 +82,10 @@ export interface RuleConditionChartProps { additionalFilters?: Filter[]; } +export type TopValuesOrderParams = + | Pick + | undefined; + const defaultQuery: Query = { language: 'kuery', query: '', @@ -299,10 +303,10 @@ export function RuleConditionChart({ return; } const aggMapFromMetrics = metrics.reduce((acc, metric) => { - const operationField = getLensOperationFromRuleMetric(metric); + const { operation, operationWithField, sourceField } = getLensOperationFromRuleMetric(metric); return { ...acc, - [metric.name]: operationField, + [metric.name]: { operation, operationWithField, sourceField }, }; }, {} as AggMap); @@ -354,6 +358,26 @@ export function RuleConditionChart({ seriesType: seriesType ? seriesType : 'bar', }; + const firstMetricAggMap = aggMap && metrics.length > 0 ? aggMap[metrics[0].name] : undefined; + const convertToMaxOperation = ['counter_rate', 'last_value', 'percentile']; + + const orderParams: TopValuesOrderParams = firstMetricAggMap + ? { + orderDirection: 'desc', + orderBy: { type: 'custom' }, + orderAgg: { + label: firstMetricAggMap.operationWithField, + dataType: 'number', + operationType: convertToMaxOperation.includes(firstMetricAggMap.operation) + ? 'max' + : firstMetricAggMap.operation, + sourceField: firstMetricAggMap.sourceField, + isBucketed: false, + scale: 'ratio', + }, + } + : undefined; + if (groupBy && groupBy?.length) { xYDataLayerOptions.breakdown = { type: 'top_values', @@ -362,6 +386,7 @@ export function RuleConditionChart({ size: 3, secondaryFields: (groupBy as string[]).slice(1), accuracyMode: false, + ...orderParams, }, }; } @@ -425,6 +450,7 @@ export function RuleConditionChart({ timeUnit, seriesType, warningThresholdReferenceLine, + aggMap, ]); if ( diff --git a/x-pack/plugins/observability_solution/observability/public/test_utils/use_global_storybook_theme.tsx b/x-pack/plugins/observability_solution/observability/public/test_utils/use_global_storybook_theme.tsx index ea94e2edb6f8b..86e67681ab7af 100644 --- a/x-pack/plugins/observability_solution/observability/public/test_utils/use_global_storybook_theme.tsx +++ b/x-pack/plugins/observability_solution/observability/public/test_utils/use_global_storybook_theme.tsx @@ -55,8 +55,8 @@ export const decorateWithGlobalStorybookThemeProviders: DecoratorFn = ( const euiThemeFromId = (themeId: string): CoreTheme => { switch (themeId) { case 'v8.dark': - return { darkMode: true }; + return { darkMode: true, name: 'amsterdam' }; default: - return { darkMode: false }; + return { darkMode: false, name: 'amsterdam' }; } }; diff --git a/x-pack/plugins/observability_solution/observability/public/utils/kibana_react.storybook_decorator.tsx b/x-pack/plugins/observability_solution/observability/public/utils/kibana_react.storybook_decorator.tsx index 593c2eafa920e..09740a5be71af 100644 --- a/x-pack/plugins/observability_solution/observability/public/utils/kibana_react.storybook_decorator.tsx +++ b/x-pack/plugins/observability_solution/observability/public/utils/kibana_react.storybook_decorator.tsx @@ -36,6 +36,7 @@ export function KibanaReactStorybookDecorator(Story: ComponentType) { const mockTheme: CoreTheme = { darkMode: false, + name: 'amsterdam', }; const createTheme$Mock = () => { diff --git a/x-pack/plugins/observability_solution/slo/public/utils/kibana_react.storybook_decorator.tsx b/x-pack/plugins/observability_solution/slo/public/utils/kibana_react.storybook_decorator.tsx index 8b6e951f9c97c..92a9f0b03a35a 100644 --- a/x-pack/plugins/observability_solution/slo/public/utils/kibana_react.storybook_decorator.tsx +++ b/x-pack/plugins/observability_solution/slo/public/utils/kibana_react.storybook_decorator.tsx @@ -27,6 +27,7 @@ export function KibanaReactStorybookDecorator(Story: ComponentType) { const mockTheme: CoreTheme = { darkMode: false, + name: 'amsterdam', }; const createTheme$Mock = () => { diff --git a/x-pack/plugins/security/public/account_management/user_profile/user_profile.test.tsx b/x-pack/plugins/security/public/account_management/user_profile/user_profile.test.tsx index 01d6fc95afcc1..e78ed371468fc 100644 --- a/x-pack/plugins/security/public/account_management/user_profile/user_profile.test.tsx +++ b/x-pack/plugins/security/public/account_management/user_profile/user_profile.test.tsx @@ -318,7 +318,7 @@ describe('useUserProfileForm', () => { const data: UserProfileData = {}; const nonCloudUser = mockAuthenticatedUser({ elastic_cloud_user: false }); - coreStart.theme.getTheme.mockReturnValue({ darkMode: true }); + coreStart.theme.getTheme.mockReturnValue({ darkMode: true, name: 'amsterdam' }); coreStart.settings.client.isOverridden.mockReturnValue(true); const testWrapper = mount( @@ -354,7 +354,7 @@ describe('useUserProfileForm', () => { const data: UserProfileData = {}; const nonCloudUser = mockAuthenticatedUser({ elastic_cloud_user: false }); - coreStart.theme.getTheme.mockReturnValue({ darkMode: false }); + coreStart.theme.getTheme.mockReturnValue({ darkMode: false, name: 'amsterdam' }); coreStart.settings.client.isOverridden.mockReturnValue(true); const testWrapper = mount( diff --git a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/droppable_wrapper.tsx b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/droppable_wrapper.tsx index 586165893408c..d14a651a027a9 100644 --- a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/droppable_wrapper.tsx +++ b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/droppable_wrapper.tsx @@ -15,7 +15,6 @@ interface Props { children?: React.ReactNode; droppableId: string; height?: string; - isDropDisabled?: boolean; type?: string; render?: ({ isDraggingOver }: { isDraggingOver: boolean }) => React.ReactNode; renderClone?: DraggableChildrenFn; @@ -90,15 +89,7 @@ const ReactDndDropTarget = styled.div<{ isDraggingOver: boolean; height: string ReactDndDropTarget.displayName = 'ReactDndDropTarget'; export const DroppableWrapper = React.memo( - ({ - children = null, - droppableId, - height = '100%', - isDropDisabled = false, - type, - render = null, - renderClone, - }) => { + ({ children = null, droppableId, height = '100%', type, render = null, renderClone }) => { const DroppableContent = useCallback( (provided, snapshot) => ( ( return ( { const anchor = '2020-03-01T17:59:46.349Z'; const unix = moment(anchor).valueOf(); let createTimeline: CreateTimeline; - let updateTimelineIsLoading: UpdateTimelineLoading; let searchStrategyClient: jest.Mocked; let clock: sinon.SinonFakeTimers; let mockKibanaServices: jest.Mock; @@ -270,7 +269,6 @@ describe('alert actions', () => { mockGetExceptionFilter = jest.fn().mockResolvedValue(undefined); createTimeline = jest.fn() as jest.Mocked; - updateTimelineIsLoading = jest.fn() as jest.Mocked; mockKibanaServices = KibanaServices.get as jest.Mock; fetchMock = jest.fn(); @@ -296,28 +294,10 @@ describe('alert actions', () => { describe('sendAlertToTimelineAction', () => { describe('timeline id is NOT empty string and apollo client exists', () => { - test('it invokes updateTimelineIsLoading to set to true', async () => { - await sendAlertToTimelineAction({ - createTimeline, - ecsData: mockEcsDataWithAlert, - updateTimelineIsLoading, - searchStrategyClient, - getExceptionFilter: mockGetExceptionFilter, - }); - - expect(mockGetExceptionFilter).not.toHaveBeenCalled(); - expect(updateTimelineIsLoading).toHaveBeenCalledTimes(1); - expect(updateTimelineIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - }); - test('it invokes createTimeline with designated timeline template if "timelineTemplate" exists', async () => { await sendAlertToTimelineAction({ createTimeline, ecsData: mockEcsDataWithAlert, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -407,7 +387,6 @@ describe('alert actions', () => { indexNames: [], isFavorite: false, isLive: false, - isLoading: false, isSaving: false, isSelectAllChecked: false, itemsPerPage: 25, @@ -477,7 +456,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: mockEcsDataWithAlert, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -496,7 +474,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: mockEcsDataWithAlert, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -505,14 +482,6 @@ describe('alert actions', () => { delete defaultTimelinePropsWithoutNote.ruleNote; delete defaultTimelinePropsWithoutNote.ruleAuthor; - expect(updateTimelineIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - expect(updateTimelineIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: false, - }); expect(mockGetExceptionFilter).not.toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith({ @@ -544,7 +513,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMock, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -552,7 +520,6 @@ describe('alert actions', () => { const expectedTimelineProps = structuredClone(defaultTimelineProps); expectedTimelineProps.timeline.excludedRowRendererIds = []; - expect(updateTimelineIsLoading).not.toHaveBeenCalled(); expect(mockGetExceptionFilter).not.toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps); @@ -574,7 +541,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMock, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -582,7 +548,6 @@ describe('alert actions', () => { const expectedTimelineProps = structuredClone(defaultTimelineProps); expectedTimelineProps.timeline.excludedRowRendererIds = []; - expect(updateTimelineIsLoading).not.toHaveBeenCalled(); expect(mockGetExceptionFilter).not.toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps); @@ -608,12 +573,10 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMock, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); - expect(updateTimelineIsLoading).not.toHaveBeenCalled(); expect(mockGetExceptionFilter).not.toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith({ @@ -655,12 +618,10 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMock, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); - expect(updateTimelineIsLoading).not.toHaveBeenCalled(); expect(mockGetExceptionFilter).not.toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps); @@ -732,7 +693,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMockWithNoTemplateTimeline, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -740,7 +700,6 @@ describe('alert actions', () => { const expectedFrom = '2021-01-10T21:11:45.839Z'; const expectedTo = '2021-01-10T21:12:45.839Z'; - expect(updateTimelineIsLoading).not.toHaveBeenCalled(); expect(mockGetExceptionFilter).toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith({ @@ -861,7 +820,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMockWithNoTemplateTimelineAndNoFilters, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -886,7 +844,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMockWithTemplateTimeline, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -894,7 +851,6 @@ describe('alert actions', () => { const expectedFrom = '2021-01-10T21:11:45.839Z'; const expectedTo = '2021-01-10T21:12:45.839Z'; - expect(updateTimelineIsLoading).toHaveBeenCalled(); expect(mockGetExceptionFilter).toHaveBeenCalled(); expect(createTimeline).toHaveBeenCalledTimes(1); expect(createTimeline).toHaveBeenCalledWith({ @@ -1046,7 +1002,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMockWithNoTemplateTimeline, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); @@ -1141,7 +1096,6 @@ describe('alert actions', () => { await sendAlertToTimelineAction({ createTimeline, ecsData: ecsDataMockWithNoTemplateTimeline, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter: mockGetExceptionFilter, }); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx index a2dfef2c43e9f..3a3e0d0255531 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx @@ -936,7 +936,6 @@ export const sendBulkEventsToTimelineAction = async ( export const sendAlertToTimelineAction = async ({ createTimeline, ecsData: ecs, - updateTimelineIsLoading, searchStrategyClient, getExceptionFilter, }: SendAlertToTimelineActionProps) => { @@ -962,7 +961,6 @@ export const sendAlertToTimelineAction = async ({ // For now we do not want to populate the template timeline if we have alertIds if (!isEmpty(timelineId)) { try { - updateTimelineIsLoading({ id: TimelineId.active, isLoading: true }); const [responseTimeline, eventDataResp] = await Promise.all([ getTimelineTemplate(timelineId), lastValueFrom( @@ -1092,7 +1090,6 @@ export const sendAlertToTimelineAction = async ({ } catch (error) { /* eslint-disable-next-line no-console */ console.error(error); - updateTimelineIsLoading({ id: TimelineId.active, isLoading: false }); return createTimeline({ from, notes: null, diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_bulk_to_timeline.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_bulk_to_timeline.tsx index 0086f40ffa44b..e402dfe2488fa 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_bulk_to_timeline.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_bulk_to_timeline.tsx @@ -23,7 +23,6 @@ import { useTimelineEventsHandler } from '../../../../timelines/containers'; import { eventsViewerSelector } from '../../../../common/components/events_viewer/selectors'; import type { State } from '../../../../common/store/types'; import { useUpdateTimeline } from '../../../../timelines/components/open_timeline/use_update_timeline'; -import { timelineActions } from '../../../../timelines/store'; import { useCreateTimeline } from '../../../../timelines/hooks/use_create_timeline'; import { INVESTIGATE_BULK_IN_TIMELINE } from '../translations'; import { TimelineId } from '../../../../../common/types/timeline'; @@ -141,18 +140,11 @@ export const useAddBulkToTimelineAction = ({ timelineType: TimelineTypeEnum.default, }); - const updateTimelineIsLoading = useCallback( - (payload: Parameters[0]) => - dispatch(timelineActions.updateIsLoading(payload)), - [dispatch] - ); - const updateTimeline = useUpdateTimeline(); const createTimeline = useCallback( async ({ timeline, ruleNote, timeline: { filters: eventIdFilters } }: CreateTimelineProps) => { await clearActiveTimeline(); - updateTimelineIsLoading({ id: TimelineId.active, isLoading: false }); updateTimeline({ duplicate: true, from, @@ -168,7 +160,7 @@ export const useAddBulkToTimelineAction = ({ ruleNote, }); }, - [updateTimeline, updateTimelineIsLoading, clearActiveTimeline, from, to] + [updateTimeline, clearActiveTimeline, from, to] ); const sendBulkEventsToTimelineHandler = useCallback( diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_investigate_in_timeline.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_investigate_in_timeline.tsx index d7df06616f221..3b36452f9315d 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_investigate_in_timeline.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_investigate_in_timeline.tsx @@ -5,7 +5,6 @@ * 2.0. */ import { useCallback, useMemo } from 'react'; -import { useDispatch } from 'react-redux'; import { i18n } from '@kbn/i18n'; import { ALERT_RULE_EXCEPTIONS_LIST, ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; @@ -23,7 +22,6 @@ import { createHistoryEntry } from '../../../../common/utils/global_query_string import { useKibana } from '../../../../common/lib/kibana'; import { TimelineId } from '../../../../../common/types/timeline'; import { TimelineTypeEnum } from '../../../../../common/api/timeline'; -import { timelineActions } from '../../../../timelines/store'; import { sendAlertToTimelineAction } from '../actions'; import { useUpdateTimeline } from '../../../../timelines/components/open_timeline/use_update_timeline'; import { useCreateTimeline } from '../../../../timelines/hooks/use_create_timeline'; @@ -98,7 +96,6 @@ export const useInvestigateInTimeline = ({ const { data: { search: searchStrategyClient }, } = useKibana().services; - const dispatch = useDispatch(); const { startTransaction } = useStartTransaction(); const { services } = useKibana(); @@ -133,12 +130,6 @@ export const useInvestigateInTimeline = ({ [addError, getExceptionFilterFromIds] ); - const updateTimelineIsLoading = useCallback( - (payload: Parameters[0]) => - dispatch(timelineActions.updateIsLoading(payload)), - [dispatch] - ); - const clearActiveTimeline = useCreateTimeline({ timelineId: TimelineId.active, timelineType: TimelineTypeEnum.default, @@ -153,7 +144,6 @@ export const useInvestigateInTimeline = ({ !newColumns || isEmpty(newColumns) ? defaultUdtHeaders : newColumns; await clearActiveTimeline(); - updateTimelineIsLoading({ id: TimelineId.active, isLoading: false }); updateTimeline({ duplicate: true, from: fromTimeline, @@ -173,12 +163,11 @@ export const useInvestigateInTimeline = ({ ruleNote, }); }, - [updateTimeline, updateTimelineIsLoading, clearActiveTimeline] + [updateTimeline, clearActiveTimeline] ); const investigateInTimelineAlertClick = useCallback(async () => { createHistoryEntry(); - startTransaction({ name: ALERTS_ACTIONS.INVESTIGATE_IN_TIMELINE }); if (onInvestigateInTimelineAlertClick) { onInvestigateInTimelineAlertClick(); @@ -188,7 +177,6 @@ export const useInvestigateInTimeline = ({ createTimeline, ecsData: ecsRowData, searchStrategyClient, - updateTimelineIsLoading, getExceptionFilter, }); } @@ -198,7 +186,6 @@ export const useInvestigateInTimeline = ({ ecsRowData, onInvestigateInTimelineAlertClick, searchStrategyClient, - updateTimelineIsLoading, getExceptionFilter, ]); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/types.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_table/types.ts index 167601871ae2a..53deaf4145310 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/types.ts +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/types.ts @@ -55,13 +55,10 @@ export interface UpdateAlertStatusActionProps { export interface SendAlertToTimelineActionProps { createTimeline: CreateTimeline; ecsData: Ecs | Ecs[]; - updateTimelineIsLoading: UpdateTimelineLoading; searchStrategyClient: ISearchStart; getExceptionFilter: GetExceptionFilter; } -export type UpdateTimelineLoading = ({ id, isLoading }: { id: string; isLoading: boolean }) => void; - export interface CreateTimelineProps { from: string; timeline: TimelineModel; diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_rule_from_timeline.test.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_rule_from_timeline.test.ts index ce653c82d7831..57a0aa43cdde6 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_rule_from_timeline.test.ts +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_rule_from_timeline.test.ts @@ -121,7 +121,6 @@ describe('useRuleFromTimeline', () => { expect(result.current.loading).toEqual(true); await waitForNextUpdate(); expect(setRuleQuery).toHaveBeenCalled(); - expect(mockDispatch).toHaveBeenCalledTimes(2); }); }); @@ -153,16 +152,8 @@ describe('useRuleFromTimeline', () => { await waitForNextUpdate(); expect(setRuleQuery).toHaveBeenCalled(); - expect(mockDispatch).toHaveBeenCalledTimes(4); + expect(mockDispatch).toHaveBeenCalledTimes(2); expect(mockDispatch).toHaveBeenNthCalledWith(1, { - type: 'x-pack/security_solution/local/timeline/UPDATE_LOADING', - payload: { - id: 'timeline-1', - isLoading: true, - }, - }); - - expect(mockDispatch).toHaveBeenNthCalledWith(2, { type: 'x-pack/security_solution/local/sourcerer/SET_SELECTED_DATA_VIEW', payload: { id: 'timeline', @@ -170,13 +161,6 @@ describe('useRuleFromTimeline', () => { selectedPatterns: selectedTimeline.data.timeline.indexNames, }, }); - expect(mockDispatch).toHaveBeenNthCalledWith(3, { - type: 'x-pack/security_solution/local/timeline/UPDATE_LOADING', - payload: { - id: 'timeline-1', - isLoading: false, - }, - }); }); it('when from timeline data view id === selected data view id and browser fields is not empty, set rule data to match from timeline query', async () => { @@ -347,7 +331,7 @@ describe('useRuleFromTimeline', () => { const { waitForNextUpdate } = renderHook(() => useRuleFromTimeline(setRuleQuery)); await waitForNextUpdate(); expect(setRuleQuery).toHaveBeenCalled(); - expect(mockDispatch).toHaveBeenNthCalledWith(4, { + expect(mockDispatch).toHaveBeenNthCalledWith(2, { type: 'x-pack/security_solution/local/sourcerer/SET_SELECTED_DATA_VIEW', payload: { id: 'timeline', diff --git a/x-pack/plugins/security_solution/public/threat_intelligence/use_investigate_in_timeline.ts b/x-pack/plugins/security_solution/public/threat_intelligence/use_investigate_in_timeline.ts index 85ced6d6e153d..f840e65497cc4 100644 --- a/x-pack/plugins/security_solution/public/threat_intelligence/use_investigate_in_timeline.ts +++ b/x-pack/plugins/security_solution/public/threat_intelligence/use_investigate_in_timeline.ts @@ -6,14 +6,12 @@ */ import { useCallback } from 'react'; -import { useDispatch } from 'react-redux'; import { timelineDefaults } from '../timelines/store/defaults'; import { APP_UI_ID } from '../../common/constants'; import type { DataProvider } from '../../common/types'; import { TimelineId } from '../../common/types/timeline'; import { TimelineTypeEnum } from '../../common/api/timeline'; import { useStartTransaction } from '../common/lib/apm/use_start_transaction'; -import { timelineActions } from '../timelines/store'; import { useCreateTimeline } from '../timelines/hooks/use_create_timeline'; import type { CreateTimelineProps } from '../detections/components/alerts_table/types'; import { useUpdateTimeline } from '../timelines/components/open_timeline/use_update_timeline'; @@ -46,15 +44,8 @@ export const useInvestigateInTimeline = ({ from, to, }: UseInvestigateInTimelineActionProps) => { - const dispatch = useDispatch(); const { startTransaction } = useStartTransaction(); - const updateTimelineIsLoading = useCallback( - (payload: Parameters[0]) => - dispatch(timelineActions.updateIsLoading(payload)), - [dispatch] - ); - const clearActiveTimeline = useCreateTimeline({ timelineId: TimelineId.active, timelineType: TimelineTypeEnum.default, @@ -65,7 +56,6 @@ export const useInvestigateInTimeline = ({ const createTimeline = useCallback( async ({ from: fromTimeline, timeline, to: toTimeline, ruleNote }: CreateTimelineProps) => { await clearActiveTimeline(); - updateTimelineIsLoading({ id: TimelineId.active, isLoading: false }); updateTimeline({ duplicate: true, from: fromTimeline, @@ -80,7 +70,7 @@ export const useInvestigateInTimeline = ({ ruleNote, }); }, - [updateTimeline, updateTimelineIsLoading, clearActiveTimeline] + [updateTimeline, clearActiveTimeline] ); const investigateInTimelineClick = useCallback(async () => { diff --git a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts index 917f1d1bc29db..525d8bba3d909 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts @@ -11,7 +11,6 @@ import { waitFor } from '@testing-library/react'; import { mockTimelineResults, mockGetOneTimelineResult } from '../../../common/mock'; import { timelineDefaults } from '../../store/defaults'; -import { updateIsLoading as dispatchUpdateIsLoading } from '../../store/actions'; import type { QueryTimelineById } from './helpers'; import { defaultTimelineToTimelineModel, @@ -646,13 +645,6 @@ describe('helpers', () => { jest.clearAllMocks(); }); - test('dispatch updateIsLoading to true', () => { - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - }); - test('get timeline by Id', () => { expect(resolveTimeline).toHaveBeenCalled(); }); @@ -671,13 +663,6 @@ describe('helpers', () => { ...timeline, }); }); - - test('dispatch updateIsLoading to false', () => { - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: false, - }); - }); }); describe('update a timeline', () => { @@ -706,11 +691,6 @@ describe('helpers', () => { await queryTimelineById(args); }); - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - // expect(resolveTimeline).toHaveBeenCalled(); const { timeline } = formatTimelineResponseToModel( omitTypenameInTimeline(getOr({}, 'data.timeline', selectedTimeline)), @@ -741,11 +721,6 @@ describe('helpers', () => { }, }); }); - - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: false, - }); }); test('should update timeline correctly when timeline is untitled', async () => { @@ -764,11 +739,6 @@ describe('helpers', () => { queryTimelineById(newArgs); }); - expect(dispatchUpdateIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - expect(mockUpdateTimeline).toHaveBeenNthCalledWith( 1, expect.objectContaining({ @@ -778,10 +748,6 @@ describe('helpers', () => { }), }) ); - expect(dispatchUpdateIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: false, - }); }); test('should update timeline correctly when timeline is already saved and onOpenTimeline is not provided', async () => { @@ -791,11 +757,6 @@ describe('helpers', () => { queryTimelineById(args); }); - expect(dispatchUpdateIsLoading).toHaveBeenCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - await waitFor(() => { expect(mockUpdateTimeline).toHaveBeenNthCalledWith( 1, @@ -860,13 +821,6 @@ describe('helpers', () => { jest.clearAllMocks(); }); - test('dispatch updateIsLoading to true', () => { - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: true, - }); - }); - test('get timeline by Id', () => { expect(resolveTimeline).toHaveBeenCalled(); }); @@ -885,13 +839,6 @@ describe('helpers', () => { }, }); }); - - test('dispatch updateIsLoading to false', () => { - expect(dispatchUpdateIsLoading).toBeCalledWith({ - id: TimelineId.active, - isLoading: false, - }); - }); }); }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts index e9c1d85b9049e..d3ca6c4654ff3 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts @@ -9,8 +9,6 @@ import { set } from '@kbn/safer-lodash-set/fp'; import { getOr } from 'lodash/fp'; import { v4 as uuidv4 } from 'uuid'; import deepMerge from 'deepmerge'; -import { useDispatch } from 'react-redux'; -import { useCallback } from 'react'; import { useDiscoverInTimelineContext } from '../../../common/components/discover_in_timeline/use_discover_in_timeline_context'; import type { ColumnHeaderOptions } from '../../../../common/types/timeline'; import type { @@ -49,7 +47,6 @@ import { DEFAULT_TO_MOMENT, } from '../../../common/utils/default_date_settings'; import { resolveTimeline } from '../../containers/api'; -import { timelineActions } from '../../store'; export const OPEN_TIMELINE_CLASS_NAME = 'open-timeline'; @@ -314,13 +311,6 @@ export interface QueryTimelineById { export const useQueryTimelineById = () => { const { resetDiscoverAppState } = useDiscoverInTimelineContext(); const updateTimeline = useUpdateTimeline(); - const dispatch = useDispatch(); - - const updateIsLoading = useCallback( - (status: { id: string; isLoading: boolean }) => - dispatch(timelineActions.updateIsLoading(status)), - [dispatch] - ); return ({ activeTimelineTab = TimelineTabs.query, @@ -333,7 +323,6 @@ export const useQueryTimelineById = () => { openTimeline = true, savedSearchId, }: QueryTimelineById) => { - updateIsLoading({ id: TimelineId.active, isLoading: true }); if (timelineId == null) { updateTimeline({ id: TimelineId.active, @@ -356,7 +345,6 @@ export const useQueryTimelineById = () => { }, }); resetDiscoverAppState(); - updateIsLoading({ id: TimelineId.active, isLoading: false }); } else { return Promise.resolve(resolveTimeline(timelineId)) .then((result) => { @@ -409,9 +397,6 @@ export const useQueryTimelineById = () => { if (onError != null) { onError(error, timelineId); } - }) - .finally(() => { - updateIsLoading({ id: TimelineId.active, isLoading: false }); }); } }; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/index.tsx index bcdf750d114f0..7a90b5254e445 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/index.tsx @@ -109,9 +109,6 @@ export const DataProviders = React.memo(({ timelineId }) => { const { browserFields } = useSourcererDataView(SourcererScopeName.timeline); const getTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []); - const isLoading = useDeepEqualSelector( - (state) => (getTimeline(state, timelineId) ?? timelineDefaults).isLoading - ); const dataProviders = useDeepEqualSelector( (state) => (getTimeline(state, timelineId) ?? timelineDefaults).dataProviders ); @@ -167,7 +164,7 @@ export const DataProviders = React.memo(({ timelineId }) => { dataProviders={dataProviders} /> ) : ( - + )} diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_actions.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_actions.tsx index a5bef9b83551b..39d765fdd1f61 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_actions.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_actions.tsx @@ -44,7 +44,6 @@ interface OwnProps { kqlQuery: string; // eslint-disable-line react/no-unused-prop-types isEnabled: boolean; isExcluded: boolean; - isLoading: boolean; isOpen: boolean; onDataProviderEdited?: OnDataProviderEdited; operator: QueryOperator; @@ -77,7 +76,6 @@ interface GetProviderActionsProps { field: string; isEnabled: boolean; isExcluded: boolean; - isLoading: boolean; onDataProviderEdited?: OnDataProviderEdited; onFilterForFieldPresent: () => void; operator: QueryOperator; @@ -98,7 +96,6 @@ export const getProviderActions = ({ field, isEnabled, isExcluded, - isLoading, operator, onDataProviderEdited, onFilterForFieldPresent, @@ -116,28 +113,24 @@ export const getProviderActions = ({ items: [ { className: EDIT_CLASS_NAME, - disabled: isLoading, icon: 'pencil', name: i18n.EDIT_MENU_ITEM, panel: 1, }, { className: EXCLUDE_CLASS_NAME, - disabled: isLoading, icon: `${isExcluded ? 'plusInCircle' : 'minusInCircle'}`, name: isExcluded ? i18n.INCLUDE_DATA_PROVIDER : i18n.EXCLUDE_DATA_PROVIDER, onClick: toggleExcluded, }, { className: ENABLE_CLASS_NAME, - disabled: isLoading, icon: `${isEnabled ? 'eyeClosed' : 'eye'}`, name: isEnabled ? i18n.TEMPORARILY_DISABLE_DATA_PROVIDER : i18n.RE_ENABLE_DATA_PROVIDER, onClick: toggleEnabled, }, { className: FILTER_FOR_FIELD_PRESENT_CLASS_NAME, - disabled: isLoading, icon: 'logstashFilter', name: i18n.FILTER_FOR_FIELD_PRESENT, onClick: onFilterForFieldPresent, @@ -145,7 +138,7 @@ export const getProviderActions = ({ timelineType === TimelineTypeEnum.template ? { className: CONVERT_TO_FIELD_CLASS_NAME, - disabled: isLoading || operator === IS_ONE_OF_OPERATOR, + disabled: operator === IS_ONE_OF_OPERATOR, icon: 'visText', name: type === DataProviderTypeEnum.template @@ -156,7 +149,6 @@ export const getProviderActions = ({ : { name: null }, { className: DELETE_CLASS_NAME, - disabled: isLoading, icon: 'trash', name: i18n.DELETE_DATA_PROVIDER, onClick: deleteItem, @@ -196,7 +188,6 @@ export class ProviderItemActions extends React.PureComponent { field, isEnabled, isExcluded, - isLoading, isOpen, operator, providerId, @@ -216,7 +207,6 @@ export class ProviderItemActions extends React.PureComponent { field, isEnabled, isExcluded, - isLoading, onDataProviderEdited: this.onDataProviderEdited, onFilterForFieldPresent: this.onFilterForFieldPresent, operator, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_badge.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_badge.tsx index 5f6f567bf32c7..53d43689a2706 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_badge.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/provider_item_badge.tsx @@ -5,7 +5,6 @@ * 2.0. */ -import { noop } from 'lodash/fp'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useDispatch } from 'react-redux'; @@ -15,10 +14,7 @@ import { TimelineTypeEnum, } from '../../../../../common/api/timeline'; import type { BrowserFields } from '../../../../common/containers/source'; -import { - useDeepEqualSelector, - useShallowEqualSelector, -} from '../../../../common/hooks/use_selector'; +import { useShallowEqualSelector } from '../../../../common/hooks/use_selector'; import { timelineSelectors } from '../../../store'; import type { PrimitiveOrArrayOfPrimitives } from '../../../../common/lib/kuery'; @@ -27,7 +23,6 @@ import { ProviderBadge } from './provider_badge'; import { ProviderItemActions } from './provider_item_actions'; import type { DataProvidersAnd, QueryOperator } from './data_provider'; import { dragAndDropActions } from '../../../../common/store/drag_and_drop'; -import { timelineDefaults } from '../../../store/defaults'; interface ProviderItemBadgeProps { andProviderId?: string; @@ -86,10 +81,6 @@ export const ProviderItemBadge = React.memo( return getTimeline(state, timelineId)?.timelineType ?? TimelineTypeEnum.default; }); - const { isLoading } = useDeepEqualSelector( - (state) => getTimeline(state, timelineId ?? '') ?? timelineDefaults - ); - const togglePopover = useCallback(() => { setIsPopoverOpen(!isPopoverOpen); }, [isPopoverOpen, setIsPopoverOpen]); @@ -142,7 +133,7 @@ export const ProviderItemBadge = React.memo( const button = useMemo( () => ( ( field, isEnabled, isExcluded, - isLoading, kqlQuery, onToggleTypeProvider, operator, @@ -186,7 +176,6 @@ export const ProviderItemBadge = React.memo( kqlQuery={kqlQuery} isEnabled={isEnabled} isExcluded={isExcluded} - isLoading={isLoading} isOpen={isPopoverOpen} onDataProviderEdited={onDataProviderEdited} operator={operator} diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx index d6492c0d864b0..dbb073ddecc80 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx @@ -32,7 +32,7 @@ describe('Providers', () => { beforeEach(() => { jest.clearAllMocks(); - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: false }); + (useDeepEqualSelector as jest.Mock).mockReturnValue({}); }); describe('rendering', () => { @@ -88,28 +88,6 @@ describe('Providers', () => { expect(mockOnDataProviderRemoved.mock.calls[0][0].providerId).toEqual('id-Provider 1'); }); - test('while loading data, it does NOT invoke the onDataProviderRemoved callback when the close button is clicked', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const wrapper = mount( - - - - - - ); - - wrapper - .find('[data-test-subj="providerBadge"] [data-euiicon-type]') - .first() - .simulate('click'); - - expect(mockOnDataProviderRemoved).not.toBeCalled(); - }); - test('it invokes the onDataProviderRemoved callback when you click on the option "Delete" in the provider menu', () => { const wrapper = mount( @@ -132,31 +110,6 @@ describe('Providers', () => { .simulate('click'); expect(mockOnDataProviderRemoved.mock.calls[0][0].providerId).toEqual('id-Provider 1'); }); - - test('while loading data, it does NOT invoke the onDataProviderRemoved callback when you click on the option "Delete" in the provider menu', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const wrapper = mount( - - - - - - ); - wrapper.find('button[data-test-subj="providerBadge"]').first().simulate('click'); - - wrapper.update(); - - wrapper - .find(`[data-test-subj="providerActions"] .${DELETE_CLASS_NAME}`) - .first() - .simulate('click'); - - expect(mockOnDataProviderRemoved).not.toBeCalled(); - }); }); describe('#onToggleDataProviderEnabled', () => { @@ -191,35 +144,6 @@ describe('Providers', () => { providerId: 'id-Provider 1', }); }); - - test('while loading data, it does NOT invoke the onToggleDataProviderEnabled callback when you click on the option "Temporary disable" in the provider menu', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const mockOnToggleDataProviderEnabled = jest.spyOn( - timelineActions, - 'updateDataProviderEnabled' - ); - const wrapper = mount( - - - - - - ); - - wrapper.find('button[data-test-subj="providerBadge"]').first().simulate('click'); - wrapper.update(); - - wrapper - .find(`[data-test-subj="providerActions"] .${ENABLE_CLASS_NAME}`) - .first() - .simulate('click'); - - expect(mockOnToggleDataProviderEnabled).not.toBeCalled(); - }); }); describe('#onToggleDataProviderExcluded', () => { @@ -257,37 +181,6 @@ describe('Providers', () => { providerId: 'id-Provider 1', }); }); - - test('while loading data, it does NOT invoke the onToggleDataProviderExcluded callback when you click on the option "Exclude results" in the provider menu', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const mockOnToggleDataProviderExcluded = jest.spyOn( - timelineActions, - 'updateDataProviderExcluded' - ); - - const wrapper = mount( - - - - - - ); - - wrapper.find('button[data-test-subj="providerBadge"]').first().simulate('click'); - - wrapper.update(); - - wrapper - .find(`[data-test-subj="providerActions"] .${EXCLUDE_CLASS_NAME}`) - .first() - .simulate('click'); - - expect(mockOnToggleDataProviderExcluded).not.toBeCalled(); - }); }); describe('#ProviderWithAndProvider', () => { @@ -349,35 +242,6 @@ describe('Providers', () => { }); }); - test('while loading data, it does NOT invoke the onDataProviderRemoved callback when you click on the close button is clicked', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const dataProviders = mockDataProviders.slice(0, 1); - dataProviders[0].and = mockDataProviders.slice(1, 3); - - const wrapper = mount( - - - - - - ); - - wrapper - .find('[data-test-subj="providerBadge"]') - .at(4) - .find('[data-euiicon-type]') - .first() - .simulate('click'); - - wrapper.update(); - - expect(mockOnDataProviderRemoved).not.toBeCalled(); - }); - test('it invokes the onToggleDataProviderEnabled callback when you click on the option "Temporary disable" in the provider menu', () => { const dataProviders = mockDataProviders.slice(0, 1); dataProviders[0].and = mockDataProviders.slice(1, 3); @@ -420,44 +284,6 @@ describe('Providers', () => { }); }); - test('while loading data, it does NOT invoke the onToggleDataProviderEnabled callback when you click on the option "Temporary disable" in the provider menu', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const dataProviders = mockDataProviders.slice(0, 1); - dataProviders[0].and = mockDataProviders.slice(1, 3); - const mockOnToggleDataProviderEnabled = jest.spyOn( - timelineActions, - 'updateDataProviderEnabled' - ); - - const wrapper = mount( - - - - - - ); - - wrapper - .find('[data-test-subj="providerBadge"]') - .at(4) - .find('button') - .first() - .simulate('click'); - - wrapper.update(); - - wrapper - .find(`[data-test-subj="providerActions"] .${ENABLE_CLASS_NAME}`) - .first() - .simulate('click'); - - expect(mockOnToggleDataProviderEnabled).not.toBeCalled(); - }); - test('it invokes the onToggleDataProviderExcluded callback when you click on the option "Exclude results" in the provider menu', () => { const dataProviders = mockDataProviders.slice(0, 1); dataProviders[0].and = mockDataProviders.slice(1, 3); @@ -499,43 +325,5 @@ describe('Providers', () => { providerId: 'id-Provider 1', }); }); - - test('while loading data, it does NOT invoke the onToggleDataProviderExcluded callback when you click on the option "Exclude results" in the provider menu', () => { - (useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: true }); - const dataProviders = mockDataProviders.slice(0, 1); - dataProviders[0].and = mockDataProviders.slice(1, 3); - const mockOnToggleDataProviderExcluded = jest.spyOn( - timelineActions, - 'updateDataProviderExcluded' - ); - - const wrapper = mount( - - - - - - ); - - wrapper - .find('[data-test-subj="providerBadge"]') - .at(4) - .find('button') - .first() - .simulate('click'); - - wrapper.update(); - - wrapper - .find(`[data-test-subj="providerActions"] .${EXCLUDE_CLASS_NAME}`) - .first() - .simulate('click'); - - expect(mockOnToggleDataProviderExcluded).not.toBeCalled(); - }); }); }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/index.tsx index 05d15f076f569..e54bfc82399f9 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/index.tsx @@ -100,7 +100,6 @@ const StatefulTimelineComponent: React.FC = ({ 'sessionViewConfig', 'initialized', 'show', - 'isLoading', 'activeTab', ], getTimeline(state, timelineId) ?? timelineDefaults diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/eql/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/eql/index.tsx index 5c4a592d99a7d..22289d090ab39 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/eql/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/eql/index.tsx @@ -7,9 +7,9 @@ import { EuiFlexGroup } from '@elastic/eui'; import { isEmpty } from 'lodash/fp'; -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useMemo } from 'react'; import type { ConnectedProps } from 'react-redux'; -import { connect, useDispatch } from 'react-redux'; +import { connect } from 'react-redux'; import deepEqual from 'fast-deep-equal'; import { InPortal } from 'react-reverse-portal'; import type { EuiDataGridControlColumn } from '@elastic/eui'; @@ -25,7 +25,7 @@ import { } from '../../../../../flyout/document_details/shared/constants/panel_keys'; import { useDeepEqualSelector } from '../../../../../common/hooks/use_selector'; import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features'; -import { timelineActions, timelineSelectors } from '../../../../store'; +import { timelineSelectors } from '../../../../store'; import { useTimelineEvents } from '../../../../containers'; import { TimelineId, TimelineTabs } from '../../../../../../common/types/timeline'; import type { inputsModel, State } from '../../../../../common/store'; @@ -66,7 +66,6 @@ export const EqlTabContentComponent: React.FC = ({ eventIdToNoteIds, }) => { const { telemetry } = useKibana().services; - const dispatch = useDispatch(); const { query: eqlQuery = '', ...restEqlOption } = eqlOptions; const { portalNode: eqlEventsCountPortalNode } = useEqlEventsCountPortal(); const { setTimelineFullScreen, timelineFullScreen } = useTimelineFullScreen(); @@ -206,15 +205,6 @@ export const EqlTabContentComponent: React.FC = ({ [dataLoadingState] ); - useEffect(() => { - dispatch( - timelineActions.updateIsLoading({ - id: timelineId, - isLoading: isQueryLoading || loadingSourcerer, - }) - ); - }, [loadingSourcerer, timelineId, isQueryLoading, dispatch]); - const unifiedHeader = useMemo( () => ( diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/index.tsx index ec61c67a3954a..967253a34a71a 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/index.tsx @@ -280,15 +280,6 @@ export const QueryTabContentComponent: React.FC = ({ [dataLoadingState] ); - useEffect(() => { - dispatch( - timelineActions.updateIsLoading({ - id: timelineId, - isLoading: isQueryLoading || loadingSourcerer, - }) - ); - }, [loadingSourcerer, timelineId, isQueryLoading, dispatch]); - // NOTE: The timeline is blank after browser FORWARD navigation (after using back button to navigate to // the previous page from the timeline), yet we still see total count. This is because the timeline // is not getting refreshed when using browser navigation. diff --git a/x-pack/plugins/security_solution/public/timelines/store/actions.ts b/x-pack/plugins/security_solution/public/timelines/store/actions.ts index e65b7273b5de7..976d35c030651 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/actions.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/actions.ts @@ -191,11 +191,6 @@ export const updateEqlOptions = actionCreator<{ value: string | undefined; }>('UPDATE_EQL_OPTIONS_TIMELINE'); -export const updateIsLoading = actionCreator<{ - id: string; - isLoading: boolean; -}>('UPDATE_LOADING'); - export const setEventsLoading = actionCreator<{ id: string; eventIds: string[]; diff --git a/x-pack/plugins/security_solution/public/timelines/store/defaults.ts b/x-pack/plugins/security_solution/public/timelines/store/defaults.ts index e4fd97cd50534..5dbe2d1b9c1e8 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/defaults.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/defaults.ts @@ -64,7 +64,6 @@ export const timelineDefaults: SubsetTimelineModel & indexNames: [], isFavorite: false, isLive: false, - isLoading: false, isSaving: false, itemsPerPage: 25, itemsPerPageOptions: [10, 25, 50, 100], diff --git a/x-pack/plugins/security_solution/public/timelines/store/helpers.test.ts b/x-pack/plugins/security_solution/public/timelines/store/helpers.test.ts index b0067d6d0d9f4..328c62fb08e20 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/helpers.test.ts @@ -104,7 +104,6 @@ const basicTimeline: TimelineModel = { indexNames: [], isFavorite: false, isLive: false, - isLoading: false, isSaving: false, isSelectAllChecked: false, itemsPerPage: 25, diff --git a/x-pack/plugins/security_solution/public/timelines/store/helpers.ts b/x-pack/plugins/security_solution/public/timelines/store/helpers.ts index a9566c22a814a..6aa4262b26310 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/helpers.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/helpers.ts @@ -131,7 +131,6 @@ export const addTimelineToStore = ({ ...timelineById, [id]: { ...timeline, - isLoading: timelineById[id].isLoading, initialized: timeline.initialized ?? timelineById[id].initialized, resolveTimelineConfig, dateRange: @@ -180,7 +179,6 @@ export const addNewTimeline = ({ savedObjectId: null, version: null, isSaving: false, - isLoading: false, timelineType, ...templateTimelineInfo, }, diff --git a/x-pack/plugins/security_solution/public/timelines/store/middlewares/timeline_save.test.ts b/x-pack/plugins/security_solution/public/timelines/store/middlewares/timeline_save.test.ts index 3c8bcf4b55f58..c3d7a26d7b027 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/middlewares/timeline_save.test.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/middlewares/timeline_save.test.ts @@ -295,7 +295,6 @@ describe('Timeline save middleware', () => { isFavorite: false, isLive: false, isSelectAllChecked: false, - isLoading: false, isSaving: false, itemsPerPage: 25, itemsPerPageOptions: [10, 25, 50, 100], diff --git a/x-pack/plugins/security_solution/public/timelines/store/model.ts b/x-pack/plugins/security_solution/public/timelines/store/model.ts index 4061276204668..92c435f93cb43 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/model.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/model.ts @@ -129,7 +129,6 @@ export interface TimelineModel { selectedEventIds: Record; /** If selectAll checkbox in header is checked **/ isSelectAllChecked: boolean; - isLoading: boolean; selectAll: boolean; /* discover saved search Id */ savedSearchId: string | null; @@ -190,7 +189,6 @@ export type SubsetTimelineModel = Readonly< | 'show' | 'sort' | 'isSaving' - | 'isLoading' | 'savedObjectId' | 'version' | 'status' diff --git a/x-pack/plugins/security_solution/public/timelines/store/reducer.ts b/x-pack/plugins/security_solution/public/timelines/store/reducer.ts index ba93b512136c8..546e60e47d10b 100644 --- a/x-pack/plugins/security_solution/public/timelines/store/reducer.ts +++ b/x-pack/plugins/security_solution/public/timelines/store/reducer.ts @@ -45,7 +45,6 @@ import { removeColumn, upsertColumn, updateColumns, - updateIsLoading, updateSort, clearSelected, setSelected, @@ -409,16 +408,6 @@ export const timelineReducer = reducerWithInitialState(initialTimelineState) timelineById: state.timelineById, }), })) - .case(updateIsLoading, (state, { id, isLoading }) => ({ - ...state, - timelineById: { - ...state.timelineById, - [id]: { - ...state.timelineById[id], - isLoading, - }, - }, - })) .case(updateSort, (state, { id, sort }) => ({ ...state, timelineById: updateTableSort({ id, sort, timelineById: state.timelineById }), diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/inspect/modal.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/inspect/modal.test.tsx index 5d9d126f1940d..12b1162082bfc 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/inspect/modal.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/inspect/modal.test.tsx @@ -43,7 +43,7 @@ describe('Modal Inspect', () => { }; const renderModalInspectQuery = () => { - const theme = { theme$: of({ darkMode: false }) }; + const theme = { theme$: of({ darkMode: false, name: 'amsterdam' }) }; return render(, { wrapper: ({ children }) => ( {children} diff --git a/x-pack/test/api_integration/deployment_agnostic/README.md b/x-pack/test/api_integration/deployment_agnostic/README.md index b029d0d167002..3bc1c70dda1ab 100644 --- a/x-pack/test/api_integration/deployment_agnostic/README.md +++ b/x-pack/test/api_integration/deployment_agnostic/README.md @@ -108,7 +108,7 @@ Kibana provides both public and internal APIs, each requiring authentication wit Recommendations: - use `roleScopedSupertest` service to create supertest instance scoped to specific role and pre-defined request headers - `roleScopedSupertest.getSupertestWithRoleScope()` authenticate requests with API key by default -- pass `withCookieHeader: true` to use Cookie header for requests authentication +- pass `useCookieHeader: true` to use Cookie header for requests authentication - don't forget to invalidate API key using `destroy()` on supertest scoped instance in `after` hook Add test files to `x-pack/test//deployment_agnostic/apis/`: @@ -117,25 +117,36 @@ test example ```ts export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const roleScopedSupertest = getService('roleScopedSupertest'); - let supertestWithAdminScope: SupertestWithRoleScopeType; + let supertestViewerWithApiKey: SupertestWithRoleScopeType; + let supertestEditorWithCookieCredentials: SupertestWithRoleScopeType; - describe('compression', () => { + describe('test suite', () => { before(async () => { - supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + supertestViewerWithApiKey = await roleScopedSupertest.getSupertestWithRoleScope('viewer', { withInternalHeaders: true, withCustomHeaders: { 'accept-encoding': 'gzip' }, }); + supertestEditorWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope('editor', { + withInternalHeaders: true, + useCookieHeader: true, + }); }); after(async () => { // always invalidate API key for the scoped role in the end - await supertestWithAdminScope.destroy(); + await supertestViewerWithApiKey.destroy(); + // supertestEditorWithCookieCredentials.destroy() has no effect because Cookie session is cached per SAML role + // and valid for the whole FTR config run, no need to call it }); - describe('against an application page', () => { - it(`uses compression when there isn't a referer`, async () => { - const response = await supertestWithAdminScope.get('/app/kibana'); - expect(response.header).to.have.property('content-encoding', 'gzip'); - }); + it(`uses compression when there isn't a referer`, async () => { + const response = await supertestViewerWithApiKey.get('/app/kibana'); + expect(response.header).to.have.property('content-encoding', 'gzip'); }); + + it(`can run rule with Editor privileges`, async () => { + const response = await supertestEditorWithCookieCredentials + .post(`/internal/alerting/rule/${ruleId}/_run_soon`) + .expect(204); + }); }); } ``` diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts index 6fc519321f7bf..e3649eb1ed92c 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts @@ -29,10 +29,12 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./observability_overview')); loadTestFile(require.resolve('./latency')); loadTestFile(require.resolve('./infrastructure')); + loadTestFile(require.resolve('./service_maps')); loadTestFile(require.resolve('./inspect')); loadTestFile(require.resolve('./service_groups')); loadTestFile(require.resolve('./diagnostics')); loadTestFile(require.resolve('./service_nodes')); loadTestFile(require.resolve('./traces')); + loadTestFile(require.resolve('./span_links')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/index.ts new file mode 100644 index 0000000000000..97681cae7def9 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/index.ts @@ -0,0 +1,15 @@ +/* + * 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { + describe('service_maps', () => { + loadTestFile(require.resolve('./service_maps.spec.ts')); + loadTestFile(require.resolve('./service_maps_kuery_filter.spec.ts')); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps.spec.ts new file mode 100644 index 0000000000000..809c10b2f01e8 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps.spec.ts @@ -0,0 +1,156 @@ +/* + * 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 type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import expect from 'expect'; +import { serviceMap, timerange } from '@kbn/apm-synthtrace-client'; +import { Readable } from 'node:stream'; +import type { SupertestReturnType } from '../../../../../../apm_api_integration/common/apm_api_supertest'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +type DependencyResponse = SupertestReturnType<'GET /internal/apm/service-map/dependency'>; +type ServiceNodeResponse = + SupertestReturnType<'GET /internal/apm/service-map/service/{serviceName}'>; + +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); + + const start = new Date('2024-06-01T00:00:00.000Z').getTime(); + const end = new Date('2024-06-01T00:01:00.000Z').getTime(); + + describe('APM Service maps', () => { + describe('without data', () => { + it('returns an empty list', async () => { + const response = await apmApiClient.readUser({ + endpoint: `GET /internal/apm/service-map`, + params: { + query: { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }, + }, + }); + + expect(response.status).toBe(200); + expect(response.body.elements.length).toBe(0); + }); + + describe('/internal/apm/service-map/service/{serviceName} without data', () => { + let response: ServiceNodeResponse; + before(async () => { + response = await apmApiClient.readUser({ + endpoint: `GET /internal/apm/service-map/service/{serviceName}`, + params: { + path: { serviceName: 'opbeans-node' }, + query: { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }, + }, + }); + }); + + it('retuns status code 200', () => { + expect(response.status).toBe(200); + }); + + it('returns an object with nulls', async () => { + [ + response.body.currentPeriod?.failedTransactionsRate?.value, + response.body.currentPeriod?.memoryUsage?.value, + response.body.currentPeriod?.cpuUsage?.value, + response.body.currentPeriod?.transactionStats?.latency?.value, + response.body.currentPeriod?.transactionStats?.throughput?.value, + ].forEach((value) => { + expect(value).toEqual(null); + }); + }); + }); + + describe('/internal/apm/service-map/dependency', () => { + let response: DependencyResponse; + before(async () => { + response = await apmApiClient.readUser({ + endpoint: `GET /internal/apm/service-map/dependency`, + params: { + query: { + dependencyName: 'postgres', + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }, + }, + }); + }); + + it('retuns status code 200', () => { + expect(response.status).toBe(200); + }); + + it('returns undefined values', () => { + expect(response.body.currentPeriod).toEqual({ transactionStats: {} }); + }); + }); + }); + + describe('with synthtrace data', () => { + let synthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + synthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + + const events = timerange(start, end) + .interval('10s') + .rate(3) + .generator( + serviceMap({ + services: [ + { 'frontend-rum': 'rum-js' }, + { 'frontend-node': 'nodejs' }, + { advertService: 'java' }, + ], + definePaths([rum, node, adv]) { + return [ + [ + [rum, 'fetchAd'], + [node, 'GET /nodejs/adTag'], + [adv, 'APIRestController#getAd'], + ['elasticsearch', 'GET ad-*/_search'], + ], + ]; + }, + }) + ); + + return synthtraceEsClient.index(Readable.from(Array.from(events))); + }); + + after(async () => { + await synthtraceEsClient.clean(); + }); + + it('returns service map elements', async () => { + const response = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/service-map', + params: { + query: { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }, + }, + }); + + expect(response.status).toBe(200); + expect(response.body.elements.length).toBeGreaterThan(0); + }); + }); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps_kuery_filter.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps_kuery_filter.spec.ts new file mode 100644 index 0000000000000..9a14b3690a81b --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps_kuery_filter.spec.ts @@ -0,0 +1,137 @@ +/* + * 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 expect from '@kbn/expect'; +import { timerange, serviceMap } from '@kbn/apm-synthtrace-client'; +import { + APIClientRequestParamsOf, + APIReturnType, +} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; +import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; +import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); + + const start = new Date('2023-01-01T00:00:00.000Z').getTime(); + const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; + + async function callApi( + overrides?: RecursivePartial< + APIClientRequestParamsOf<'GET /internal/apm/service-map'>['params'] + > + ) { + return await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/service-map', + params: { + query: { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + kuery: '', + ...overrides?.query, + }, + }, + }); + } + + describe('service map kuery filter', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + + const events = timerange(start, end) + .interval('15m') + .rate(1) + .generator( + serviceMap({ + services: [ + { 'synthbeans-go': 'go' }, + { 'synthbeans-java': 'java' }, + { 'synthbeans-node': 'nodejs' }, + ], + definePaths([go, java, node]) { + return [ + [go, java], + [java, go, 'redis'], + [node, 'redis'], + { + path: [node, java, go, 'elasticsearch'], + transaction: (t) => t.defaults({ 'labels.name': 'node-java-go-es' }), + }, + [go, node, java], + ]; + }, + }) + ); + await apmSynthtraceEsClient.index(events); + }); + + after(() => apmSynthtraceEsClient.clean()); + + it('returns full service map when no kuery is defined', async () => { + const { status, body } = await callApi(); + + expect(status).to.be(200); + + const { nodes, edges } = partitionElements(body.elements); + + expect(getIds(nodes)).to.eql([ + '>elasticsearch', + '>redis', + 'synthbeans-go', + 'synthbeans-java', + 'synthbeans-node', + ]); + expect(getIds(edges)).to.eql([ + 'synthbeans-go~>elasticsearch', + 'synthbeans-go~>redis', + 'synthbeans-go~synthbeans-java', + 'synthbeans-go~synthbeans-node', + 'synthbeans-java~synthbeans-go', + 'synthbeans-node~>redis', + 'synthbeans-node~synthbeans-java', + ]); + }); + + it('returns only service nodes and connections filtered by given kuery', async () => { + const { status, body } = await callApi({ + query: { kuery: `labels.name: "node-java-go-es"` }, + }); + + expect(status).to.be(200); + + const { nodes, edges } = partitionElements(body.elements); + + expect(getIds(nodes)).to.eql([ + '>elasticsearch', + 'synthbeans-go', + 'synthbeans-java', + 'synthbeans-node', + ]); + expect(getIds(edges)).to.eql([ + 'synthbeans-go~>elasticsearch', + 'synthbeans-java~synthbeans-go', + 'synthbeans-node~synthbeans-java', + ]); + }); + }); +} + +type ConnectionElements = APIReturnType<'GET /internal/apm/service-map'>['elements']; + +function partitionElements(elements: ConnectionElements) { + const edges = elements.filter(({ data }) => 'source' in data && 'target' in data); + const nodes = elements.filter((element) => !edges.includes(element)); + return { edges, nodes }; +} + +function getIds(elements: ConnectionElements) { + return elements.map(({ data }) => data.id).sort(); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/agent.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/agent.spec.ts new file mode 100644 index 0000000000000..8d96b00867e80 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/agent.spec.ts @@ -0,0 +1,65 @@ +/* + * 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 expect from '@kbn/expect'; +import archives_metadata from '../../../../../../apm_api_integration/common/fixtures/es_archiver/archives_metadata'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; +import { ARCHIVER_ROUTES } from '../constants/archiver'; + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const esArchiver = getService('esArchiver'); + + const archiveName = '8.0.0'; + const { start, end } = archives_metadata[archiveName]; + + describe('Agent name', () => { + describe('when data is not loaded', () => { + it('handles the empty state', async () => { + const response = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services/{serviceName}/agent', + params: { + path: { serviceName: 'opbeans-node' }, + query: { + start, + end, + }, + }, + }); + + expect(response.status).to.be(200); + expect(response.body).to.eql({}); + }); + }); + + describe('when data is loaded', () => { + before(async () => { + await esArchiver.load(ARCHIVER_ROUTES[archiveName]); + }); + after(async () => { + await esArchiver.unload(ARCHIVER_ROUTES[archiveName]); + }); + + it('returns the agent name', async () => { + const response = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services/{serviceName}/agent', + params: { + path: { serviceName: 'opbeans-node' }, + query: { + start, + end, + }, + }, + }); + + expect(response.status).to.be(200); + + expect(response.body).to.eql({ agentName: 'nodejs', runtimeName: 'node' }); + }); + }); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/index.ts index 2beba223d9dc2..4993ec83c5eca 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/services/index.ts @@ -13,6 +13,7 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('./error_groups/error_groups_main_statistics.spec.ts')); loadTestFile(require.resolve('./service_details/service_details.spec.ts')); loadTestFile(require.resolve('./service_icons/service_icons.spec.ts')); + loadTestFile(require.resolve('./agent.spec.ts')); loadTestFile(require.resolve('./archive_services_detailed_statistics.spec.ts')); loadTestFile(require.resolve('./derived_annotations.spec.ts')); loadTestFile(require.resolve('./get_service_node_metadata.spec.ts')); diff --git a/x-pack/test/apm_api_integration/tests/span_links/data_generator.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/data_generator.ts similarity index 100% rename from x-pack/test/apm_api_integration/tests/span_links/data_generator.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/data_generator.ts diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/index.ts new file mode 100644 index 0000000000000..e7772daa131af --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/index.ts @@ -0,0 +1,14 @@ +/* + * 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { + describe('span_links', () => { + loadTestFile(require.resolve('./span_links.spec.ts')); + }); +} diff --git a/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/span_links.spec.ts similarity index 97% rename from x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/span_links.spec.ts index 871f44da4cdc1..5638d5d620d7b 100644 --- a/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/span_links/span_links.spec.ts @@ -7,23 +7,24 @@ import expect from '@kbn/expect'; import { ProcessorEvent } from '@kbn/observability-plugin/common'; import { Readable } from 'stream'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; import { generateSpanLinksData } from './data_generator'; -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; - // FLAKY: https://github.com/elastic/kibana/issues/177520 - registry.when('contains linked children', { config: 'basic', archives: [] }, () => { + describe('contains linked children', () => { let ids: ReturnType['ids']; + let apmSynthtraceEsClient: ApmSynthtraceEsClient; before(async () => { const spanLinksData = generateSpanLinksData(); + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); ids = spanLinksData.ids; diff --git a/x-pack/test/apm_api_integration/tests/service_maps/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/service_maps/service_maps.spec.ts index 83965595020da..ae7a08b0664c1 100644 --- a/x-pack/test/apm_api_integration/tests/service_maps/service_maps.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_maps/service_maps.spec.ts @@ -52,84 +52,6 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext) }); }); - registry.when('Service Map without data', { config: 'trial', archives: [] }, () => { - describe('/internal/apm/service-map without data', () => { - it('returns an empty list', async () => { - const response = await apmApiClient.readUser({ - endpoint: `GET /internal/apm/service-map`, - params: { - query: { - start: metadata.start, - end: metadata.end, - environment: 'ENVIRONMENT_ALL', - }, - }, - }); - - expect(response.status).to.be(200); - expect(response.body.elements.length).to.be(0); - }); - }); - - describe('/internal/apm/service-map/service/{serviceName} without data', () => { - let response: ServiceNodeResponse; - before(async () => { - response = await apmApiClient.readUser({ - endpoint: `GET /internal/apm/service-map/service/{serviceName}`, - params: { - path: { serviceName: 'opbeans-node' }, - query: { - start: metadata.start, - end: metadata.end, - environment: 'ENVIRONMENT_ALL', - }, - }, - }); - }); - - it('retuns status code 200', () => { - expect(response.status).to.be(200); - }); - - it('returns an object with nulls', async () => { - [ - response.body.currentPeriod?.failedTransactionsRate?.value, - response.body.currentPeriod?.memoryUsage?.value, - response.body.currentPeriod?.cpuUsage?.value, - response.body.currentPeriod?.transactionStats?.latency?.value, - response.body.currentPeriod?.transactionStats?.throughput?.value, - ].forEach((value) => { - expect(value).to.be.eql(null); - }); - }); - }); - - describe('/internal/apm/service-map/dependency', () => { - let response: DependencyResponse; - before(async () => { - response = await apmApiClient.readUser({ - endpoint: `GET /internal/apm/service-map/dependency`, - params: { - query: { - dependencyName: 'postgres', - start: metadata.start, - end: metadata.end, - environment: 'ENVIRONMENT_ALL', - }, - }, - }); - }); - - it('retuns status code 200', () => { - expect(response.status).to.be(200); - }); - - it('returns undefined values', () => { - expect(response.body.currentPeriod).to.eql({ transactionStats: {} }); - }); - }); - }); - registry.when('Service Map with data', { config: 'trial', archives: ['apm_8.0.0'] }, () => { describe('/internal/apm/service-map with data', () => { let response: ServiceMapResponse; diff --git a/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts b/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts deleted file mode 100644 index b87e0de70495e..0000000000000 --- a/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import expect from '@kbn/expect'; -import { timerange, serviceMap } from '@kbn/apm-synthtrace-client'; -import { - APIClientRequestParamsOf, - APIReturnType, -} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; -import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; - -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); - - const start = new Date('2023-01-01T00:00:00.000Z').getTime(); - const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; - - async function callApi( - overrides?: RecursivePartial< - APIClientRequestParamsOf<'GET /internal/apm/service-map'>['params'] - > - ) { - return await apmApiClient.readUser({ - endpoint: 'GET /internal/apm/service-map', - params: { - query: { - start: new Date(start).toISOString(), - end: new Date(end).toISOString(), - environment: 'ENVIRONMENT_ALL', - kuery: '', - ...overrides?.query, - }, - }, - }); - } - - registry.when('Service Map', { config: 'trial', archives: [] }, () => { - describe('optional kuery param', () => { - before(async () => { - const events = timerange(start, end) - .interval('15m') - .rate(1) - .generator( - serviceMap({ - services: [ - { 'synthbeans-go': 'go' }, - { 'synthbeans-java': 'java' }, - { 'synthbeans-node': 'nodejs' }, - ], - definePaths([go, java, node]) { - return [ - [go, java], - [java, go, 'redis'], - [node, 'redis'], - { - path: [node, java, go, 'elasticsearch'], - transaction: (t) => t.defaults({ 'labels.name': 'node-java-go-es' }), - }, - [go, node, java], - ]; - }, - }) - ); - await apmSynthtraceEsClient.index(events); - }); - - after(() => apmSynthtraceEsClient.clean()); - - it('returns full service map when no kuery is defined', async () => { - const { status, body } = await callApi(); - - expect(status).to.be(200); - - const { nodes, edges } = partitionElements(body.elements); - - expect(getIds(nodes)).to.eql([ - '>elasticsearch', - '>redis', - 'synthbeans-go', - 'synthbeans-java', - 'synthbeans-node', - ]); - expect(getIds(edges)).to.eql([ - 'synthbeans-go~>elasticsearch', - 'synthbeans-go~>redis', - 'synthbeans-go~synthbeans-java', - 'synthbeans-go~synthbeans-node', - 'synthbeans-java~synthbeans-go', - 'synthbeans-node~>redis', - 'synthbeans-node~synthbeans-java', - ]); - }); - - it('returns only service nodes and connections filtered by given kuery', async () => { - const { status, body } = await callApi({ - query: { kuery: `labels.name: "node-java-go-es"` }, - }); - - expect(status).to.be(200); - - const { nodes, edges } = partitionElements(body.elements); - - expect(getIds(nodes)).to.eql([ - '>elasticsearch', - 'synthbeans-go', - 'synthbeans-java', - 'synthbeans-node', - ]); - expect(getIds(edges)).to.eql([ - 'synthbeans-go~>elasticsearch', - 'synthbeans-java~synthbeans-go', - 'synthbeans-node~synthbeans-java', - ]); - }); - }); - }); -} - -type ConnectionElements = APIReturnType<'GET /internal/apm/service-map'>['elements']; - -function partitionElements(elements: ConnectionElements) { - const edges = elements.filter(({ data }) => 'source' in data && 'target' in data); - const nodes = elements.filter((element) => !edges.includes(element)); - return { edges, nodes }; -} - -function getIds(elements: ConnectionElements) { - return elements.map(({ data }) => data.id).sort(); -} diff --git a/x-pack/test/security_solution_cypress/cypress/screens/timeline.ts b/x-pack/test/security_solution_cypress/cypress/screens/timeline.ts index df81ad54ecd48..c25bd1b9b115f 100644 --- a/x-pack/test/security_solution_cypress/cypress/screens/timeline.ts +++ b/x-pack/test/security_solution_cypress/cypress/screens/timeline.ts @@ -117,8 +117,6 @@ export const ALERTS_TABLE_COUNT = `[data-test-subj="toolbar-alerts-count"]`; export const STAR_ICON = '[data-test-subj="timeline-favorite-empty-star"]'; -export const TIMELINE_COLUMN_SPINNER = '[data-test-subj="timeline-loading-spinner"]'; - export const TIMELINE_COLLAPSED_ITEMS_BTN = '[data-test-subj="euiCollapsedItemActionsButton"]'; export const TIMELINE_CREATE_TEMPLATE_FROM_TIMELINE_BTN = diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/alerts.ts b/x-pack/test/security_solution_cypress/cypress/tasks/alerts.ts index e8541a529add0..b70adbefa1850 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/alerts.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/alerts.ts @@ -57,7 +57,6 @@ import { TOOLTIP, } from '../screens/alerts'; import { LOADING_INDICATOR, REFRESH_BUTTON } from '../screens/security_header'; -import { TIMELINE_COLUMN_SPINNER } from '../screens/timeline'; import { UPDATE_ENRICHMENT_RANGE_BUTTON, ENRICHMENT_QUERY_END_INPUT, @@ -216,7 +215,6 @@ export const goToClosedAlertsOnRuleDetailsPage = () => { cy.get(CLOSED_ALERTS_FILTER_BTN).click(); cy.get(REFRESH_BUTTON).should('not.have.attr', 'aria-label', 'Needs updating'); cy.get(REFRESH_BUTTON).should('have.attr', 'aria-label', 'Refresh query'); - cy.get(TIMELINE_COLUMN_SPINNER).should('not.exist'); }; export const goToClosedAlerts = () => { @@ -233,7 +231,6 @@ export const goToClosedAlerts = () => { selectPageFilterValue(0, 'closed'); cy.get(REFRESH_BUTTON).should('not.have.attr', 'aria-label', 'Needs updating'); cy.get(REFRESH_BUTTON).should('have.attr', 'aria-label', 'Refresh query'); - cy.get(TIMELINE_COLUMN_SPINNER).should('not.exist'); }; export const goToOpenedAlertsOnRuleDetailsPage = () => { @@ -297,7 +294,6 @@ export const goToAcknowledgedAlerts = () => { selectPageFilterValue(0, 'acknowledged'); cy.get(REFRESH_BUTTON).should('not.have.attr', 'aria-label', 'Needs updating'); cy.get(REFRESH_BUTTON).should('have.attr', 'aria-label', 'Refresh query'); - cy.get(TIMELINE_COLUMN_SPINNER).should('not.exist'); }; export const markAlertsAcknowledged = () => { diff --git a/x-pack/test_serverless/README.md b/x-pack/test_serverless/README.md index 44f871273aca2..17e5a9056f5d8 100644 --- a/x-pack/test_serverless/README.md +++ b/x-pack/test_serverless/README.md @@ -154,7 +154,7 @@ Kibana provides both public and internal APIs, each requiring authentication wit Recommendations: - use `roleScopedSupertest` service to create a supertest instance scoped to a specific role and predefined request headers - `roleScopedSupertest.getSupertestWithRoleScope()` authenticates requests with an API key by default -- pass `withCookieHeader: true` to use Cookie header for request authentication +- pass `useCookieHeader: true` to use Cookie header for request authentication - don't forget to invalidate API keys by using `destroy()` on the supertest scoped instance in the `after` hook ``` @@ -183,7 +183,7 @@ describe("my internal APIs test suite", async function() { before(async () => { supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope('admin', { - withCookieHeader: true, // to avoid generating API key and use Cookie header instead + useCookieHeader: true, // to avoid generating API key and use Cookie header instead withInternalHeaders: true, }); }); diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/apm_api_integration/service_maps/service_maps.ts b/x-pack/test_serverless/api_integration/test_suites/observability/apm_api_integration/service_maps/service_maps.ts deleted file mode 100644 index 1c849164d54c5..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/apm_api_integration/service_maps/service_maps.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; -import expect from 'expect'; -import { serviceMap, timerange } from '@kbn/apm-synthtrace-client'; -import { Readable } from 'stream'; -import type { InternalRequestHeader, RoleCredentials } from '../../../../../shared/services'; -import { APMFtrContextProvider } from '../common/services'; - -export default function ({ getService }: APMFtrContextProvider) { - const apmApiClient = getService('apmApiClient'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - const synthtrace = getService('synthtrace'); - - const start = new Date('2024-06-01T00:00:00.000Z').getTime(); - const end = new Date('2024-06-01T00:01:00.000Z').getTime(); - - describe('APM Service maps', () => { - let roleAuthc: RoleCredentials; - let internalReqHeader: InternalRequestHeader; - let synthtraceEsClient: ApmSynthtraceEsClient; - - before(async () => { - synthtraceEsClient = await synthtrace.createSynthtraceEsClient(); - - const events = timerange(start, end) - .interval('10s') - .rate(3) - .generator( - serviceMap({ - services: [ - { 'frontend-rum': 'rum-js' }, - { 'frontend-node': 'nodejs' }, - { advertService: 'java' }, - ], - definePaths([rum, node, adv]) { - return [ - [ - [rum, 'fetchAd'], - [node, 'GET /nodejs/adTag'], - [adv, 'APIRestController#getAd'], - ['elasticsearch', 'GET ad-*/_search'], - ], - ]; - }, - }) - ); - - internalReqHeader = svlCommonApi.getInternalRequestHeader(); - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - - return synthtraceEsClient.index(Readable.from(Array.from(events))); - }); - - after(async () => { - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - return synthtraceEsClient.clean(); - }); - - it('returns service map elements', async () => { - const response = await apmApiClient.slsUser({ - endpoint: 'GET /internal/apm/service-map', - params: { - query: { - start: new Date(start).toISOString(), - end: new Date(end).toISOString(), - environment: 'ENVIRONMENT_ALL', - }, - }, - roleAuthc, - internalReqHeader, - }); - - expect(response.status).toBe(200); - expect(response.body.elements.length).toBeGreaterThan(0); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/index.ts b/x-pack/test_serverless/api_integration/test_suites/observability/index.ts index 9bcf9b4faece8..d3d8d4805695a 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/index.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/index.ts @@ -12,7 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { this.tags(['esGate']); loadTestFile(require.resolve('./apm_api_integration/feature_flags.ts')); - loadTestFile(require.resolve('./apm_api_integration/service_maps/service_maps')); loadTestFile(require.resolve('./cases')); loadTestFile(require.resolve('./synthetics')); loadTestFile(require.resolve('./dataset_quality_api_integration'));