Pick ML UI from #166813 (#167354)

## Summary

We're breaking https://github.com/elastic/kibana/pull/166813 up into
smaller PRs in the interest of getting PRs through sooner for type
fixes. These are the changes for ML UI.

---------

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
This commit is contained in:
Brad White 2023-09-27 05:04:18 -06:00 committed by GitHub
parent d7e88167fa
commit 7d92c16ec0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 19 deletions

View file

@ -9,30 +9,33 @@ import { sharePluginMock } from '@kbn/share-plugin/public/mocks';
import { type ElasticModels } from './application/services/elastic_models_service';
import type { MlPluginSetup, MlPluginStart } from './plugin';
const createElasticModelsMock = (): jest.Mocked<ElasticModels> => {
return {
getELSER: jest.fn().mockResolvedValue({
version: 2,
default: true,
config: {
input: {
field_names: ['text_field'],
},
},
description: 'Elastic Learned Sparse EncodeR v2 (Tech Preview)',
name: '.elser_model_2',
}),
} as unknown as jest.Mocked<ElasticModels>;
};
const createSetupContract = (): jest.Mocked<MlPluginSetup> => {
return {
locator: sharePluginMock.createLocator(),
elasticModels: createElasticModelsMock(),
};
};
const createStartContract = (): jest.Mocked<MlPluginStart> => {
return {
locator: sharePluginMock.createLocator(),
elasticModels: {
getELSER: jest.fn(() =>
Promise.resolve({
version: 2,
default: true,
config: {
input: {
field_names: ['text_field'],
},
},
description: 'Elastic Learned Sparse EncodeR v2 (Tech Preview)',
name: '.elser_model_2',
})
),
} as unknown as jest.Mocked<ElasticModels>,
elasticModels: createElasticModelsMock(),
};
};

View file

@ -18,7 +18,7 @@ import { take } from 'rxjs/operators';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { ManagementSetup } from '@kbn/management-plugin/public';
import type { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import type { LocatorPublic, SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import type { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public';
@ -54,7 +54,7 @@ import {
MlSharedServices,
} from './application/services/get_shared_ml_services';
import { registerManagementSection } from './application/management';
import { MlLocatorDefinition, type MlLocator } from './locator';
import { MlLocatorDefinition, MlLocatorParams, type MlLocator } from './locator';
import { setDependencyCache } from './application/util/dependency_cache';
import { registerHomeFeature } from './register_home_feature';
import { isFullLicense, isMlEnabled } from '../common/license';
@ -67,6 +67,7 @@ import {
type ConfigSchema,
} from '../common/constants/app';
import type { MlCapabilities } from './shared';
import { ElasticModels } from './application/services/elastic_models_service';
export interface MlStartDependencies {
dataViewEditor: DataViewEditorStart;
@ -131,7 +132,10 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
initEnabledFeatures(this.enabledFeatures, initializerContext.config.get());
}
setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) {
setup(
core: MlCoreSetup,
pluginsSetup: MlSetupDependencies
): { locator?: LocatorPublic<MlLocatorParams>; elasticModels?: ElasticModels } {
this.sharedMlServices = getMlSharedServices(core.http);
core.application.register({
@ -262,10 +266,14 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
return {
locator: this.locator,
elasticModels: this.sharedMlServices.elasticModels,
};
}
start(core: CoreStart, deps: MlStartDependencies) {
start(
core: CoreStart,
deps: MlStartDependencies
): { locator?: LocatorPublic<MlLocatorParams>; elasticModels?: ElasticModels } {
setDependencyCache({
docLinks: core.docLinks!,
basePath: core.http.basePath,