-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathplugin.tsx
More file actions
229 lines (205 loc) · 8 KB
/
plugin.tsx
File metadata and controls
229 lines (205 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* 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 { i18n as kbnI18n } from '@kbn/i18n';
import { BehaviorSubject } from 'rxjs';
import type { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import type { ServerlessPluginStart } from '@kbn/serverless/public';
import type {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
AppMountParameters,
AppUpdater,
AppDeepLink,
} from '@kbn/core/public';
import { DEFAULT_APP_CATEGORIES, AppStatus } from '@kbn/core/public';
import type {
ConfigSchema,
ManagementSetup,
ManagementStart,
NavigationCardsSubject,
AutoOpsStatusHook,
AutoOpsStatusResult,
} from './types';
import { MANAGEMENT_APP_ID } from '../common/contants';
import { ManagementAppLocatorDefinition } from '../common/locator';
import {
ManagementSectionsService,
getSectionsServiceStartPrivate,
} from './management_sections_service';
import type { ManagementSection } from './utils';
const defaultAutoOpsStatusResult: AutoOpsStatusResult = {
isCloudConnectAutoopsEnabled: false,
isLoading: true,
};
const defaultAutoOpsStatusHook: AutoOpsStatusHook = () => defaultAutoOpsStatusResult;
interface ManagementSetupDependencies {
home?: HomePublicPluginSetup;
share: SharePluginSetup;
cloud?: { isCloudEnabled: boolean; baseUrl?: string };
}
interface ManagementStartDependencies {
share: SharePluginStart;
serverless?: ServerlessPluginStart;
cloud?: { isCloudEnabled: boolean; baseUrl?: string };
}
export class ManagementPlugin
implements
Plugin<
ManagementSetup,
ManagementStart,
ManagementSetupDependencies,
ManagementStartDependencies
>
{
private readonly managementSections = new ManagementSectionsService();
private readonly appUpdater = new BehaviorSubject<AppUpdater>(() => {
const deepLinks: AppDeepLink[] = this.managementSections
.getAllSections()
.map((section: ManagementSection) => ({
id: section.id,
title: section.title,
deepLinks: section
.getAppsEnabled()
.filter((mgmtApp) => mgmtApp.visibleIn || !mgmtApp.hideFromGlobalSearch)
.map((mgmtApp) => ({
id: mgmtApp.id,
title: mgmtApp.title,
path: mgmtApp.basePath,
keywords: mgmtApp.keywords,
visibleIn: mgmtApp.visibleIn ?? ['globalSearch', 'solutionSideNav'],
})),
}));
return { deepLinks };
});
private hasAnyEnabledApps = true;
private isSidebarEnabled$ = new BehaviorSubject<boolean>(true);
private cardsNavigationConfig$ = new BehaviorSubject<NavigationCardsSubject>({
enabled: false,
hideLinksTo: [],
extendCardNavDefinitions: {},
});
private autoOpsStatusHook?: AutoOpsStatusHook;
constructor(private initializerContext: PluginInitializerContext<ConfigSchema>) {}
private registerAutoOpsStatusHook = (hook: AutoOpsStatusHook) => {
this.autoOpsStatusHook = hook;
};
private getAutoOpsStatusHook = () => {
return this.autoOpsStatusHook ?? defaultAutoOpsStatusHook;
};
public setup(
core: CoreSetup<ManagementStartDependencies>,
{ home, share, cloud }: ManagementSetupDependencies
) {
const kibanaVersion = this.initializerContext.env.packageInfo.version;
const locator = share.url.locators.create(new ManagementAppLocatorDefinition());
const managementPlugin = this;
if (home) {
home.featureCatalogue.register({
id: 'stack-management',
title: kbnI18n.translate('management.stackManagement.managementLabel', {
defaultMessage: 'Stack Management',
}),
description: kbnI18n.translate('management.stackManagement.managementDescription', {
defaultMessage: 'Your center console for managing the Elastic Stack.',
}),
icon: 'managementApp',
path: '/app/management',
showOnHomePage: false,
category: 'admin',
visible: () => this.hasAnyEnabledApps,
});
}
core.application.register({
id: MANAGEMENT_APP_ID,
title: kbnI18n.translate('management.stackManagement.title', {
defaultMessage: 'Stack Management',
}),
order: 9040,
euiIconType: 'logoElastic',
category: DEFAULT_APP_CATEGORIES.management,
updater$: this.appUpdater,
async mount(params: AppMountParameters) {
const { renderApp } = await import('./application');
const [coreStart, deps] = await core.getStartServices();
const chromeStyle$ = coreStart.chrome.getChromeStyle$();
// Resolve fleet at runtime via `core.plugins.onStart` instead of declaring it
// as a plugin dependency to avoid massive circular dependency issues in the plugin graph.
const fleetResult = await coreStart.plugins.onStart<{
fleet: { config: { isAirGapped?: boolean } };
}>('fleet');
const isAirGapped =
Boolean(fleetResult.fleet.found && fleetResult.fleet.contract.config.isAirGapped) &&
!Boolean(deps.cloud?.isCloudEnabled);
return renderApp(params, {
sections: getSectionsServiceStartPrivate(),
kibanaVersion,
coreStart,
cloud: deps.cloud,
isAirGapped,
setBreadcrumbs: (newBreadcrumbs) => {
if (deps.serverless) {
// drop the root management breadcrumb in serverless because it comes from the navigation tree
const [, ...trailingBreadcrumbs] = newBreadcrumbs;
deps.serverless.setBreadcrumbs(trailingBreadcrumbs);
} else {
const chromeStyle = coreStart.chrome.getChromeStyle();
if (chromeStyle === 'project') {
// Project chrome (solution spaces): the navigation tree provides "Stack Management > App".
// Management apps provide breadcrumbs as [Stack Management, App, ...details].
// We drop the first two and append the rest to the nav tree path.
const [, , ...trailingBreadcrumbs] = newBreadcrumbs;
coreStart.chrome.setBreadcrumbs([], {
project: { value: trailingBreadcrumbs },
});
} else {
// Classic chrome: use full breadcrumb trail as-is
coreStart.chrome.setBreadcrumbs(newBreadcrumbs);
}
}
},
isSidebarEnabled$: managementPlugin.isSidebarEnabled$,
cardsNavigationConfig$: managementPlugin.cardsNavigationConfig$,
chromeStyle$,
getAutoOpsStatusHook: managementPlugin.getAutoOpsStatusHook,
});
},
});
core.getStartServices().then(([coreStart]) => {
coreStart.chrome
.getChromeStyle$()
.subscribe((style) => this.isSidebarEnabled$.next(style === 'classic'));
});
return {
sections: this.managementSections.setup(),
locator,
registerAutoOpsStatusHook: this.registerAutoOpsStatusHook,
};
}
public start(core: CoreStart, plugins: ManagementStartDependencies): ManagementStart {
this.managementSections.start({ capabilities: core.application.capabilities });
this.hasAnyEnabledApps = getSectionsServiceStartPrivate()
.getSectionsEnabled()
.some((section) => section.getAppsEnabled().length > 0);
if (!this.hasAnyEnabledApps) {
this.appUpdater.next(() => {
return {
status: AppStatus.inaccessible,
visibleIn: [],
};
});
}
return {
setupCardsNavigation: ({ enabled, hideLinksTo, extendCardNavDefinitions }) =>
this.cardsNavigationConfig$.next({ enabled, hideLinksTo, extendCardNavDefinitions }),
};
}
}