From 8c305b94377e9795d5c22fd05f97d0a468e92e72 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Wed, 25 Sep 2024 17:44:33 +0200 Subject: [PATCH] [Discover] Rename everything 2 --- .../components/layout/discover_documents.tsx | 11 +++-- .../components/layout/discover_layout.tsx | 26 ++++------- src/plugins/discover/public/build_services.ts | 10 ++--- .../context_awareness/__mocks__/index.tsx | 8 ++-- .../profiles_manager.test.ts | 4 +- .../context_awareness/profiles_manager.ts | 10 ++--- src/plugins/discover/public/plugin.tsx | 44 +++++++++---------- ...r.test.ts => discover_ebt_manager.test.ts} | 8 ++-- ...ext_manager.ts => discover_ebt_manager.ts} | 2 +- 9 files changed, 55 insertions(+), 68 deletions(-) rename src/plugins/discover/public/services/{discover_ebt_context_manager.test.ts => discover_ebt_manager.test.ts} (97%) rename src/plugins/discover/public/services/{discover_ebt_context_manager.ts => discover_ebt_manager.ts} (99%) diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 2c625ad3cce8d..eb04c4899fa72 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -114,8 +114,7 @@ function DiscoverDocumentsComponent({ const services = useDiscoverServices(); const documents$ = stateContainer.dataState.data$.documents$; const savedSearch = useSavedSearchInitial(); - const { dataViews, capabilities, uiSettings, uiActions, ebtContextManager, fieldsMetadata } = - services; + const { dataViews, capabilities, uiSettings, uiActions, ebtManager, fieldsMetadata } = services; const [ dataSource, query, @@ -201,17 +200,17 @@ function DiscoverDocumentsComponent({ const onAddColumnWithTracking = useCallback( (columnName: string) => { onAddColumn(columnName); - void ebtContextManager.trackDataTableSelection({ fieldName: columnName, fieldsMetadata }); + void ebtManager.trackDataTableSelection({ fieldName: columnName, fieldsMetadata }); }, - [onAddColumn, ebtContextManager, fieldsMetadata] + [onAddColumn, ebtManager, fieldsMetadata] ); const onRemoveColumnWithTracking = useCallback( (columnName: string) => { onRemoveColumn(columnName); - void ebtContextManager.trackDataTableRemoval({ fieldName: columnName, fieldsMetadata }); + void ebtManager.trackDataTableRemoval({ fieldName: columnName, fieldsMetadata }); }, - [onRemoveColumn, ebtContextManager, fieldsMetadata] + [onRemoveColumn, ebtManager, fieldsMetadata] ); const setExpandedDoc = useCallback( diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx index 784dece24ff71..bc9cad72a5eb6 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx @@ -78,7 +78,7 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { spaces, observabilityAIAssistant, dataVisualizer: dataVisualizerService, - ebtContextManager, + ebtManager, fieldsMetadata, } = useDiscoverServices(); const pageBackgroundColor = useEuiBackgroundColor('plain'); @@ -159,17 +159,17 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { const onAddColumnWithTracking = useCallback( (columnName: string) => { onAddColumn(columnName); - void ebtContextManager.trackDataTableSelection({ fieldName: columnName, fieldsMetadata }); + void ebtManager.trackDataTableSelection({ fieldName: columnName, fieldsMetadata }); }, - [onAddColumn, ebtContextManager, fieldsMetadata] + [onAddColumn, ebtManager, fieldsMetadata] ); const onRemoveColumnWithTracking = useCallback( (columnName: string) => { onRemoveColumn(columnName); - void ebtContextManager.trackDataTableRemoval({ fieldName: columnName, fieldsMetadata }); + void ebtManager.trackDataTableRemoval({ fieldName: columnName, fieldsMetadata }); }, - [onRemoveColumn, ebtContextManager, fieldsMetadata] + [onRemoveColumn, ebtManager, fieldsMetadata] ); // The assistant is getting the state from the url correctly @@ -193,22 +193,14 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { if (trackUiMetric) { trackUiMetric(METRIC_TYPE.CLICK, 'filter_added'); } - void ebtContextManager.trackFilterAddition({ + void ebtManager.trackFilterAddition({ fieldName: fieldName === '_exists_' ? String(values) : fieldName, filterOperation: fieldName === '_exists_' ? '_exists_' : operation, fieldsMetadata, }); return filterManager.addFilters(newFilters); }, - [ - filterManager, - dataView, - dataViews, - trackUiMetric, - capabilities, - ebtContextManager, - fieldsMetadata, - ] + [filterManager, dataView, dataViews, trackUiMetric, capabilities, ebtManager, fieldsMetadata] ); const getOperator = (fieldName: string, values: unknown, operation: '+' | '-') => { @@ -253,13 +245,13 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { if (trackUiMetric) { trackUiMetric(METRIC_TYPE.CLICK, 'esql_filter_added'); } - void ebtContextManager.trackFilterAddition({ + void ebtManager.trackFilterAddition({ fieldName: fieldName === '_exists_' ? String(values) : fieldName, filterOperation: fieldName === '_exists_' ? '_exists_' : operation, fieldsMetadata, }); }, - [data.query.queryString, query, trackUiMetric, ebtContextManager, fieldsMetadata] + [data.query.queryString, query, trackUiMetric, ebtManager, fieldsMetadata] ); const onFilter = isEsqlMode ? onPopulateWhereClause : onAddFilter; diff --git a/src/plugins/discover/public/build_services.ts b/src/plugins/discover/public/build_services.ts index f4ee14fcf04f7..130082c82707f 100644 --- a/src/plugins/discover/public/build_services.ts +++ b/src/plugins/discover/public/build_services.ts @@ -63,7 +63,7 @@ import type { DiscoverContextAppLocator } from './application/context/services/l import type { DiscoverSingleDocLocator } from './application/doc/locator'; import type { DiscoverAppLocator } from '../common'; import type { ProfilesManager } from './context_awareness'; -import type { DiscoverEBTContextManager } from './services/discover_ebt_context_manager'; +import type { DiscoverEBTManager } from './services/discover_ebt_manager'; /** * Location state of internal Discover history instance @@ -131,7 +131,7 @@ export interface DiscoverServices { noDataPage?: NoDataPagePluginStart; observabilityAIAssistant?: ObservabilityAIAssistantPublicStart; profilesManager: ProfilesManager; - ebtContextManager: DiscoverEBTContextManager; + ebtManager: DiscoverEBTManager; fieldsMetadata?: FieldsMetadataPublicStart; } @@ -147,7 +147,7 @@ export const buildServices = memoize( scopedHistory, urlTracker, profilesManager, - ebtContextManager, + ebtManager, setHeaderActionMenu = noop, }: { core: CoreStart; @@ -160,7 +160,7 @@ export const buildServices = memoize( scopedHistory?: ScopedHistory; urlTracker: UrlTracker; profilesManager: ProfilesManager; - ebtContextManager: DiscoverEBTContextManager; + ebtManager: DiscoverEBTManager; setHeaderActionMenu?: AppMountParameters['setHeaderActionMenu']; }): DiscoverServices => { const { usageCollection } = plugins; @@ -221,7 +221,7 @@ export const buildServices = memoize( noDataPage: plugins.noDataPage, observabilityAIAssistant: plugins.observabilityAIAssistant, profilesManager, - ebtContextManager, + ebtManager, fieldsMetadata: plugins.fieldsMetadata, }; } diff --git a/src/plugins/discover/public/context_awareness/__mocks__/index.tsx b/src/plugins/discover/public/context_awareness/__mocks__/index.tsx index c0e3d981668cf..35f50beb88f30 100644 --- a/src/plugins/discover/public/context_awareness/__mocks__/index.tsx +++ b/src/plugins/discover/public/context_awareness/__mocks__/index.tsx @@ -22,7 +22,7 @@ import { SolutionType, } from '../profiles'; import { ProfilesManager } from '../profiles_manager'; -import { DiscoverEBTContextManager } from '../../services/discover_ebt_context_manager'; +import { DiscoverEBTManager } from '../../services/discover_ebt_manager'; import { createLogsContextServiceMock } from '@kbn/discover-utils/src/__mocks__'; export const createContextAwarenessMocks = ({ @@ -151,12 +151,12 @@ export const createContextAwarenessMocks = ({ documentProfileServiceMock.registerProvider(documentProfileProviderMock); } - const ebtContextManagerMock = new DiscoverEBTContextManager(); + const ebtManagerMock = new DiscoverEBTManager(); const profilesManagerMock = new ProfilesManager( rootProfileServiceMock, dataSourceProfileServiceMock, documentProfileServiceMock, - ebtContextManagerMock + ebtManagerMock ); const profileProviderServices = createProfileProviderServicesMock(); @@ -172,7 +172,7 @@ export const createContextAwarenessMocks = ({ contextRecordMock2, profilesManagerMock, profileProviderServices, - ebtContextManagerMock, + ebtManagerMock, }; }; diff --git a/src/plugins/discover/public/context_awareness/profiles_manager.test.ts b/src/plugins/discover/public/context_awareness/profiles_manager.test.ts index 87965edbe7488..da5ad8b56dcf3 100644 --- a/src/plugins/discover/public/context_awareness/profiles_manager.test.ts +++ b/src/plugins/discover/public/context_awareness/profiles_manager.test.ts @@ -21,7 +21,7 @@ describe('ProfilesManager', () => { beforeEach(() => { jest.clearAllMocks(); mocks = createContextAwarenessMocks(); - jest.spyOn(mocks.ebtContextManagerMock, 'updateProfilesContextWith'); + jest.spyOn(mocks.ebtManagerMock, 'updateProfilesContextWith'); }); it('should return default profiles', () => { @@ -62,7 +62,7 @@ describe('ProfilesManager', () => { mocks.documentProfileProviderMock.profile, ]); - expect(mocks.ebtContextManagerMock.updateProfilesContextWith).toHaveBeenCalledWith([ + expect(mocks.ebtManagerMock.updateProfilesContextWith).toHaveBeenCalledWith([ 'root-profile', 'data-source-profile', ]); diff --git a/src/plugins/discover/public/context_awareness/profiles_manager.ts b/src/plugins/discover/public/context_awareness/profiles_manager.ts index 2c8b1c7d16cb0..6b7bef5e02294 100644 --- a/src/plugins/discover/public/context_awareness/profiles_manager.ts +++ b/src/plugins/discover/public/context_awareness/profiles_manager.ts @@ -25,7 +25,7 @@ import type { DocumentContext, } from './profiles'; import type { ContextWithProfileId } from './profile_service'; -import { DiscoverEBTContextManager } from '../services/discover_ebt_context_manager'; +import { DiscoverEBTManager } from '../services/discover_ebt_manager'; interface SerializedRootProfileParams { solutionNavId: RootProfileProviderParams['solutionNavId']; @@ -53,7 +53,7 @@ export interface GetProfilesOptions { export class ProfilesManager { private readonly rootContext$: BehaviorSubject>; private readonly dataSourceContext$: BehaviorSubject>; - private readonly ebtContextManager: DiscoverEBTContextManager; + private readonly ebtManager: DiscoverEBTManager; private prevRootProfileParams?: SerializedRootProfileParams; private prevDataSourceProfileParams?: SerializedDataSourceProfileParams; @@ -64,11 +64,11 @@ export class ProfilesManager { private readonly rootProfileService: RootProfileService, private readonly dataSourceProfileService: DataSourceProfileService, private readonly documentProfileService: DocumentProfileService, - ebtContextManager: DiscoverEBTContextManager + ebtManager: DiscoverEBTManager ) { this.rootContext$ = new BehaviorSubject(rootProfileService.defaultContext); this.dataSourceContext$ = new BehaviorSubject(dataSourceProfileService.defaultContext); - this.ebtContextManager = ebtContextManager; + this.ebtManager = ebtManager; } /** @@ -206,7 +206,7 @@ export class ProfilesManager { private trackActiveProfiles(rootContextProfileId: string, dataSourceContextProfileId: string) { const dscProfiles = [rootContextProfileId, dataSourceContextProfileId]; - this.ebtContextManager.updateProfilesContextWith(dscProfiles); + this.ebtManager.updateProfilesContextWith(dscProfiles); } } diff --git a/src/plugins/discover/public/plugin.tsx b/src/plugins/discover/public/plugin.tsx index fb049112e6d2e..1627e7771cec7 100644 --- a/src/plugins/discover/public/plugin.tsx +++ b/src/plugins/discover/public/plugin.tsx @@ -60,7 +60,7 @@ import { RootProfileService } from './context_awareness/profiles/root_profile'; import { DataSourceProfileService } from './context_awareness/profiles/data_source_profile'; import { DocumentProfileService } from './context_awareness/profiles/document_profile'; import { ProfilesManager } from './context_awareness/profiles_manager'; -import { DiscoverEBTContextManager } from './services/discover_ebt_context_manager'; +import { DiscoverEBTManager } from './services/discover_ebt_manager'; /** * Contains Discover, one of the oldest parts of Kibana @@ -150,8 +150,8 @@ export class DiscoverPlugin this.urlTracker = { setTrackedUrl, restorePreviousUrl, setTrackingEnabled }; this.stopUrlTracking = stopUrlTracker; - const ebtContextManager = new DiscoverEBTContextManager(); - ebtContextManager.initialize({ + const ebtManager = new DiscoverEBTManager(); + ebtManager.initialize({ core, shouldInitializeCustomContext: true, shouldInitializeCustomEvents: true, @@ -181,7 +181,7 @@ export class DiscoverPlugin window.dispatchEvent(new HashChangeEvent('hashchange')); }); - ebtContextManager.enableContext(); + ebtManager.enableContext(); const services = buildServices({ core: coreStart, @@ -195,9 +195,9 @@ export class DiscoverPlugin urlTracker: this.urlTracker!, profilesManager: await this.createProfilesManager({ plugins: discoverStartPlugins, - ebtContextManager, + ebtManager, }), - ebtContextManager, + ebtManager, setHeaderActionMenu: params.setHeaderActionMenu, }); @@ -230,7 +230,7 @@ export class DiscoverPlugin }); return () => { - ebtContextManager.disableAndResetContext(); + ebtManager.disableAndResetContext(); unlistenParentHistory(); unmount(); appUnMounted(); @@ -300,12 +300,12 @@ export class DiscoverPlugin } const getDiscoverServicesInternal = () => { - const ebtContextManager = new DiscoverEBTContextManager(); // It is not initialized outside of Discover + const ebtManager = new DiscoverEBTManager(); // It is not initialized outside of Discover return this.getDiscoverServices( core, plugins, - this.createEmptyProfilesManager({ ebtContextManager }), - ebtContextManager + this.createEmptyProfilesManager({ ebtManager }), + ebtManager ); }; @@ -343,10 +343,10 @@ export class DiscoverPlugin private async createProfilesManager({ plugins, - ebtContextManager, + ebtManager, }: { plugins: DiscoverStartPlugins; - ebtContextManager: DiscoverEBTContextManager; + ebtManager: DiscoverEBTManager; }) { const { rootProfileService, dataSourceProfileService, documentProfileService } = await this.createProfileServices({ plugins }); @@ -355,20 +355,16 @@ export class DiscoverPlugin rootProfileService, dataSourceProfileService, documentProfileService, - ebtContextManager + ebtManager ); } - private createEmptyProfilesManager({ - ebtContextManager, - }: { - ebtContextManager: DiscoverEBTContextManager; - }) { + private createEmptyProfilesManager({ ebtManager }: { ebtManager: DiscoverEBTManager }) { return new ProfilesManager( new RootProfileService(), new DataSourceProfileService(), new DocumentProfileService(), - ebtContextManager + ebtManager ); } @@ -376,7 +372,7 @@ export class DiscoverPlugin core: CoreStart, plugins: DiscoverStartPlugins, profilesManager: ProfilesManager, - ebtContextManager: DiscoverEBTContextManager + ebtManager: DiscoverEBTManager ) => { return buildServices({ core, @@ -388,12 +384,12 @@ export class DiscoverPlugin history: this.historyService.getHistory(), urlTracker: this.urlTracker!, profilesManager, - ebtContextManager, + ebtManager, }); }; private registerEmbeddable(core: CoreSetup, plugins: DiscoverSetupPlugins) { - const ebtContextManager = new DiscoverEBTContextManager(); // It is not initialized outside of Discover + const ebtManager = new DiscoverEBTManager(); // It is not initialized outside of Discover const getStartServices = async () => { const [coreStart, deps] = await core.getStartServices(); @@ -408,9 +404,9 @@ export class DiscoverPlugin const profilesManager = await this.createProfilesManager({ plugins: deps, - ebtContextManager, + ebtManager, }); - return this.getDiscoverServices(coreStart, deps, profilesManager, ebtContextManager); + return this.getDiscoverServices(coreStart, deps, profilesManager, ebtManager); }; plugins.embeddable.registerReactEmbeddableSavedObject({ diff --git a/src/plugins/discover/public/services/discover_ebt_context_manager.test.ts b/src/plugins/discover/public/services/discover_ebt_manager.test.ts similarity index 97% rename from src/plugins/discover/public/services/discover_ebt_context_manager.test.ts rename to src/plugins/discover/public/services/discover_ebt_manager.test.ts index 366028bc2b832..0ed20dacdb0ce 100644 --- a/src/plugins/discover/public/services/discover_ebt_context_manager.test.ts +++ b/src/plugins/discover/public/services/discover_ebt_manager.test.ts @@ -9,11 +9,11 @@ import { BehaviorSubject } from 'rxjs'; import { coreMock } from '@kbn/core/public/mocks'; -import { DiscoverEBTContextManager } from './discover_ebt_context_manager'; +import { DiscoverEBTManager } from './discover_ebt_manager'; import { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public'; -describe('DiscoverEBTContextManager', () => { - let discoverEBTContextManager: DiscoverEBTContextManager; +describe('DiscoverEBTManager', () => { + let discoverEBTContextManager: DiscoverEBTManager; const coreSetupMock = coreMock.createSetup(); @@ -30,7 +30,7 @@ describe('DiscoverEBTContextManager', () => { } as unknown as FieldsMetadataPublicStart; beforeEach(() => { - discoverEBTContextManager = new DiscoverEBTContextManager(); + discoverEBTContextManager = new DiscoverEBTManager(); }); describe('register', () => { diff --git a/src/plugins/discover/public/services/discover_ebt_context_manager.ts b/src/plugins/discover/public/services/discover_ebt_manager.ts similarity index 99% rename from src/plugins/discover/public/services/discover_ebt_context_manager.ts rename to src/plugins/discover/public/services/discover_ebt_manager.ts index c226071f23f5e..420eb6c244444 100644 --- a/src/plugins/discover/public/services/discover_ebt_context_manager.ts +++ b/src/plugins/discover/public/services/discover_ebt_manager.ts @@ -35,7 +35,7 @@ export interface DiscoverEBTContextProps { } export type DiscoverEBTContext = BehaviorSubject; -export class DiscoverEBTContextManager { +export class DiscoverEBTManager { private isCustomContextEnabled: boolean = false; private customContext$: DiscoverEBTContext | undefined; private reportEvent: CoreSetup['analytics']['reportEvent'] | undefined;