@@ -30,16 +30,20 @@ import type { EmbeddableSetup } from 'src/plugins/embeddable/public';
3030import { AppStatus , AppUpdater , DEFAULT_APP_CATEGORIES } from '../../../../src/core/public' ;
3131import type { UiActionsSetup , UiActionsStart } from '../../../../src/plugins/ui_actions/public' ;
3232import type { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public' ;
33+ import { MlCardState } from '../../../../src/plugins/index_pattern_management/public' ;
3334
3435import type { LicenseManagementUIPluginSetup } from '../../license_management/public' ;
3536import type { LicensingPluginSetup } from '../../licensing/public' ;
3637import type { SecurityPluginSetup } from '../../security/public' ;
3738
3839import { PLUGIN_ICON_SOLUTION , PLUGIN_ID } from '../common/constants/app' ;
40+ import { ML_APP_URL_GENERATOR } from '../common/constants/ml_url_generator' ;
41+ import { isFullLicense , isMlEnabled } from '../common/license' ;
3942
4043import { setDependencyCache } from './application/util/dependency_cache' ;
41- import { ML_APP_URL_GENERATOR } from '../common/constants/ml_url_generator' ;
42- import { registerUrlGenerator } from './ml_url_generator' ;
44+ import { registerFeature } from './register_feature' ;
45+ // Not importing from `ml_url_generator/index` here to avoid importing unnecessary code
46+ import { registerUrlGenerator } from './ml_url_generator/ml_url_generator' ;
4347
4448export interface MlStartDependencies {
4549 data : DataPublicPluginStart ;
@@ -112,46 +116,39 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
112116 const licensing = pluginsSetup . licensing . license$ . pipe ( take ( 1 ) ) ;
113117 licensing . subscribe ( async ( license ) => {
114118 const [ coreStart ] = await core . getStartServices ( ) ;
115-
116- const {
117- isFullLicense,
118- isMlEnabled,
119- registerEmbeddables,
120- registerFeature,
121- registerManagementSection,
122- registerMlUiActions,
123- MlCardState,
124- } = await import ( './register_helper' ) ;
119+ const { capabilities } = coreStart . application ;
125120
126121 if ( isMlEnabled ( license ) ) {
127122 // add ML to home page
128123 if ( pluginsSetup . home ) {
129124 registerFeature ( pluginsSetup . home ) ;
130125 }
131- const { capabilities } = coreStart . application ;
132126
133127 // register ML for the index pattern management no data screen.
134128 pluginsSetup . indexPatternManagement . environment . update ( {
135129 ml : ( ) =>
136130 capabilities . ml . canFindFileStructure ? MlCardState . ENABLED : MlCardState . HIDDEN ,
137131 } ) ;
138-
139- const canManageMLJobs = capabilities . management ?. insightsAndAlerting ?. jobsListLink ?? false ;
140-
141- // register various ML plugin features which require a full license
142- if ( isFullLicense ( license ) ) {
143- if ( canManageMLJobs && pluginsSetup . management !== undefined ) {
144- registerManagementSection ( pluginsSetup . management , core ) . enable ( ) ;
145- }
146- registerEmbeddables ( pluginsSetup . embeddable , core ) ;
147- registerMlUiActions ( pluginsSetup . uiActions , core ) ;
148- }
149132 } else {
150133 // if ml is disabled in elasticsearch, disable ML in kibana
151134 this . appUpdater . next ( ( ) => ( {
152135 status : AppStatus . inaccessible ,
153136 } ) ) ;
154137 }
138+
139+ // register various ML plugin features which require a full license
140+ const { registerEmbeddables, registerManagementSection, registerMlUiActions } = await import (
141+ './register_helper'
142+ ) ;
143+
144+ if ( isMlEnabled ( license ) && isFullLicense ( license ) ) {
145+ const canManageMLJobs = capabilities . management ?. insightsAndAlerting ?. jobsListLink ?? false ;
146+ if ( canManageMLJobs && pluginsSetup . management !== undefined ) {
147+ registerManagementSection ( pluginsSetup . management , core ) . enable ( ) ;
148+ }
149+ registerEmbeddables ( pluginsSetup . embeddable , core ) ;
150+ registerMlUiActions ( pluginsSetup . uiActions , core ) ;
151+ }
155152 } ) ;
156153
157154 return {
0 commit comments