diff --git a/src/platform/packages/shared/kbn-scout/src/playwright/page_objects/discover_app.ts b/src/platform/packages/shared/kbn-scout/src/playwright/page_objects/discover_app.ts index 3329a6c254704..000e5104f172b 100644 --- a/src/platform/packages/shared/kbn-scout/src/playwright/page_objects/discover_app.ts +++ b/src/platform/packages/shared/kbn-scout/src/playwright/page_objects/discover_app.ts @@ -337,7 +337,8 @@ export class DiscoverApp { async selectTextBaseLang() { if (await this.page.testSubj.isEnabled('select-text-based-language-btn')) { await this.page.testSubj.click('select-text-based-language-btn'); - await this.waitForDocTableRendered(); + await this.waitUntilSearchingHasFinished(); + await this.codeEditor.waitCodeEditorReady('ESQLEditor'); } } diff --git a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.test.ts b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.test.ts new file mode 100644 index 0000000000000..bb5b865fe9b17 --- /dev/null +++ b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.test.ts @@ -0,0 +1,54 @@ +/* + * 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 { dataViewMock } from '@kbn/discover-utils/src/__mocks__'; +import { DataSourceCategory } from '../../../../profiles'; +import type { DefaultAppStateExtension, DefaultAppStateExtensionParams } from '../../../../types'; +import { getDefaultAppState } from './get_default_app_state'; + +const createGetDefaultAppState = (prevAppState: DefaultAppStateExtension) => + getDefaultAppState(() => prevAppState, { + context: { + category: DataSourceCategory.Metrics, + }, + }); + +describe('getDefaultAppState', () => { + it('preserves the previous app state while applying the metrics defaults', () => { + const params: DefaultAppStateExtensionParams = { dataView: dataViewMock }; + const prevAppState: DefaultAppStateExtension = { + breakdownField: 'host.name', + columns: [{ name: 'host.name' }], + rowHeight: 3, + }; + + const appState = createGetDefaultAppState(prevAppState)(params); + + expect(appState).toEqual({ + ...prevAppState, + hideChart: false, + hideTable: true, + }); + }); + + it('overrides previous chart visibility state with metrics defaults', () => { + const params: DefaultAppStateExtensionParams = { dataView: dataViewMock }; + const prevAppState: DefaultAppStateExtension = { + hideChart: true, + hideTable: false, + }; + + const appState = createGetDefaultAppState(prevAppState)(params); + + expect(appState).toEqual({ + hideChart: false, + hideTable: true, + }); + }); +}); diff --git a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.ts b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.ts new file mode 100644 index 0000000000000..38cde82c598e5 --- /dev/null +++ b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/accessor/get_default_app_state.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import type { MetricsExperienceDataSourceProfileProvider } from '../profile'; + +export const getDefaultAppState: NonNullable< + MetricsExperienceDataSourceProfileProvider['profile']['getDefaultAppState'] +> = (prev) => (params) => ({ + ...prev(params), + hideChart: false, + hideTable: true, +}); diff --git a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/profile.ts b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/profile.ts index 6a37e710849ed..5d6e77834e79a 100644 --- a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/profile.ts +++ b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/profile.ts @@ -14,6 +14,7 @@ import { METRICS_EXPERIENCE_PRODUCT_FEATURE_ID } from '../../../../../common/con import type { DataSourceProfileProvider } from '../../../profiles'; import { DataSourceCategory, SolutionType } from '../../../profiles'; import { createChartSection } from './accessor/chart_section'; +import { getDefaultAppState } from './accessor/get_default_app_state'; export type MetricsExperienceDataSourceProfileProvider = DataSourceProfileProvider<{}>; @@ -26,6 +27,7 @@ export const createMetricsDataSourceProfileProvider = restrictedToProductFeature: METRICS_EXPERIENCE_PRODUCT_FEATURE_ID, profile: { getChartSectionConfiguration: createChartSection(), + getDefaultAppState, }, resolve: async ({ query, rootContext }) => { if (!isQuerySupported(query) || !isSolutionValid(rootContext.solutionType)) {