Skip to content

Commit

Permalink
[Discover] Rename everything 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Sep 25, 2024
1 parent 4342088 commit 8c305b9
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) {
spaces,
observabilityAIAssistant,
dataVisualizer: dataVisualizerService,
ebtContextManager,
ebtManager,
fieldsMetadata,
} = useDiscoverServices();
const pageBackgroundColor = useEuiBackgroundColor('plain');
Expand Down Expand Up @@ -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
Expand All @@ -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: '+' | '-') => {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +131,7 @@ export interface DiscoverServices {
noDataPage?: NoDataPagePluginStart;
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
profilesManager: ProfilesManager;
ebtContextManager: DiscoverEBTContextManager;
ebtManager: DiscoverEBTManager;
fieldsMetadata?: FieldsMetadataPublicStart;
}

Expand All @@ -147,7 +147,7 @@ export const buildServices = memoize(
scopedHistory,
urlTracker,
profilesManager,
ebtContextManager,
ebtManager,
setHeaderActionMenu = noop,
}: {
core: CoreStart;
Expand All @@ -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;
Expand Down Expand Up @@ -221,7 +221,7 @@ export const buildServices = memoize(
noDataPage: plugins.noDataPage,
observabilityAIAssistant: plugins.observabilityAIAssistant,
profilesManager,
ebtContextManager,
ebtManager,
fieldsMetadata: plugins.fieldsMetadata,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down Expand Up @@ -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();
Expand All @@ -172,7 +172,7 @@ export const createContextAwarenessMocks = ({
contextRecordMock2,
profilesManagerMock,
profileProviderServices,
ebtContextManagerMock,
ebtManagerMock,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('ProfilesManager', () => {
mocks.documentProfileProviderMock.profile,
]);

expect(mocks.ebtContextManagerMock.updateProfilesContextWith).toHaveBeenCalledWith([
expect(mocks.ebtManagerMock.updateProfilesContextWith).toHaveBeenCalledWith([
'root-profile',
'data-source-profile',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -53,7 +53,7 @@ export interface GetProfilesOptions {
export class ProfilesManager {
private readonly rootContext$: BehaviorSubject<ContextWithProfileId<RootContext>>;
private readonly dataSourceContext$: BehaviorSubject<ContextWithProfileId<DataSourceContext>>;
private readonly ebtContextManager: DiscoverEBTContextManager;
private readonly ebtManager: DiscoverEBTManager;

private prevRootProfileParams?: SerializedRootProfileParams;
private prevDataSourceProfileParams?: SerializedDataSourceProfileParams;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
44 changes: 20 additions & 24 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -181,7 +181,7 @@ export class DiscoverPlugin
window.dispatchEvent(new HashChangeEvent('hashchange'));
});

ebtContextManager.enableContext();
ebtManager.enableContext();

const services = buildServices({
core: coreStart,
Expand All @@ -195,9 +195,9 @@ export class DiscoverPlugin
urlTracker: this.urlTracker!,
profilesManager: await this.createProfilesManager({
plugins: discoverStartPlugins,
ebtContextManager,
ebtManager,
}),
ebtContextManager,
ebtManager,
setHeaderActionMenu: params.setHeaderActionMenu,
});

Expand Down Expand Up @@ -230,7 +230,7 @@ export class DiscoverPlugin
});

return () => {
ebtContextManager.disableAndResetContext();
ebtManager.disableAndResetContext();
unlistenParentHistory();
unmount();
appUnMounted();
Expand Down Expand Up @@ -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
);
};

Expand Down Expand Up @@ -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 });
Expand All @@ -355,28 +355,24 @@ 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
);
}

private getDiscoverServices = (
core: CoreStart,
plugins: DiscoverStartPlugins,
profilesManager: ProfilesManager,
ebtContextManager: DiscoverEBTContextManager
ebtManager: DiscoverEBTManager
) => {
return buildServices({
core,
Expand All @@ -388,12 +384,12 @@ export class DiscoverPlugin
history: this.historyService.getHistory(),
urlTracker: this.urlTracker!,
profilesManager,
ebtContextManager,
ebtManager,
});
};

private registerEmbeddable(core: CoreSetup<DiscoverStartPlugins>, 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();
Expand All @@ -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<SavedSearchAttributes>({
Expand Down
Loading

0 comments on commit 8c305b9

Please sign in to comment.