-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
plugin.ts
213 lines (192 loc) · 7.08 KB
/
plugin.ts
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
/*
* 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 {
AppMountParameters,
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
} from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { UrlForwardingSetup, UrlForwardingStart } from '@kbn/url-forwarding-plugin/public';
import type { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import type { CloudSetup, CloudStart } from '@kbn/cloud-plugin/public';
import { PLUGIN_ID, HOME_APP_BASE_PATH } from '../common/constants';
import { setServices } from './application/kibana_services';
import type { ConfigSchema } from '../server/config';
import {
EnvironmentService,
EnvironmentServiceSetup,
FeatureCatalogueRegistry,
FeatureCatalogueRegistrySetup,
TutorialService,
TutorialServiceSetup,
AddDataService,
AddDataServiceSetup,
WelcomeService,
WelcomeServiceSetup,
} from './services';
export interface HomePluginStartDependencies {
dataViews: DataViewsPublicPluginStart;
urlForwarding: UrlForwardingStart;
guidedOnboarding?: GuidedOnboardingPluginStart;
cloud: CloudStart;
share: SharePluginStart;
}
export interface HomePluginSetupDependencies {
cloud: CloudSetup;
share: SharePluginSetup;
usageCollection?: UsageCollectionSetup;
urlForwarding: UrlForwardingSetup;
}
export class HomePublicPlugin
implements
Plugin<
HomePublicPluginSetup,
HomePublicPluginStart,
HomePluginSetupDependencies,
HomePluginStartDependencies
>
{
private readonly featuresCatalogueRegistry = new FeatureCatalogueRegistry();
private readonly environmentService = new EnvironmentService();
private readonly tutorialService = new TutorialService();
private readonly addDataService = new AddDataService();
private readonly welcomeService = new WelcomeService();
constructor(private readonly initializerContext: PluginInitializerContext<ConfigSchema>) {}
public setup(
core: CoreSetup<HomePluginStartDependencies>,
{ cloud, share, urlForwarding, usageCollection }: HomePluginSetupDependencies
): HomePublicPluginSetup {
core.application.register({
id: PLUGIN_ID,
title: 'Home',
visibleIn: [],
mount: async (params: AppMountParameters) => {
const trackUiMetric = usageCollection
? usageCollection.reportUiCounter.bind(usageCollection, 'Kibana_home')
: () => {};
const [
coreStart,
{
dataViews,
urlForwarding: urlForwardingStart,
guidedOnboarding,
share: shareStart,
cloud: cloudStart,
},
] = await core.getStartServices();
setServices({
share,
trackUiMetric,
kibanaVersion: this.initializerContext.env.packageInfo.version,
http: coreStart.http,
toastNotifications: coreStart.notifications.toasts,
banners: coreStart.overlays.banners,
docLinks: coreStart.docLinks,
savedObjectsClient: coreStart.savedObjects.client,
chrome: coreStart.chrome,
application: coreStart.application,
uiSettings: core.uiSettings,
addBasePath: core.http.basePath.prepend,
getBasePath: core.http.basePath.get,
dataViewsService: dataViews,
environmentService: this.environmentService,
urlForwarding: urlForwardingStart,
homeConfig: this.initializerContext.config.get(),
tutorialService: this.tutorialService,
addDataService: this.addDataService,
featureCatalogue: this.featuresCatalogueRegistry,
welcomeService: this.welcomeService,
guidedOnboardingService: guidedOnboarding?.guidedOnboardingApi,
cloud,
cloudStart,
overlays: coreStart.overlays,
theme: core.theme,
i18nStart: coreStart.i18n,
shareStart,
});
coreStart.chrome.docTitle.change(
i18n.translate('home.pageTitle', { defaultMessage: 'Home' })
);
const { renderApp } = await import('./application');
return await renderApp(params.element, coreStart, params.history);
},
});
urlForwarding.forwardApp('home', 'home');
const featureCatalogue = { ...this.featuresCatalogueRegistry.setup() };
featureCatalogue.register({
id: 'home_tutorial_directory',
title: i18n.translate('home.tutorialDirectory.featureCatalogueTitle', {
defaultMessage: 'Add data',
}),
description: i18n.translate('home.tutorialDirectory.featureCatalogueDescription', {
defaultMessage: 'Ingest data from popular apps and services.',
}),
icon: 'indexOpen',
showOnHomePage: true,
path: `${HOME_APP_BASE_PATH}#/tutorial_directory`,
category: 'data',
order: 500,
});
const environment = { ...this.environmentService.setup() };
const tutorials = { ...this.tutorialService.setup() };
if (cloud) {
environment.update({ cloud: cloud.isCloudEnabled });
if (cloud.isCloudEnabled) {
tutorials.setVariable('cloud', {
id: cloud.cloudId,
baseUrl: cloud.baseUrl,
// Cloud's API already provides the full URLs
profileUrl: cloud.profileUrl?.replace(cloud.baseUrl ?? '', ''),
deploymentUrl: cloud.deploymentUrl?.replace(cloud.baseUrl ?? '', ''),
});
}
}
return {
featureCatalogue,
environment,
tutorials,
addData: { ...this.addDataService.setup() },
welcomeScreen: { ...this.welcomeService.setup() },
};
}
public start({ application: { capabilities } }: CoreStart) {
this.featuresCatalogueRegistry.start({ capabilities });
return { featureCatalogue: this.featuresCatalogueRegistry };
}
}
/** @public */
export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup;
/** @public */
export type EnvironmentSetup = EnvironmentServiceSetup;
/** @public */
export type TutorialSetup = TutorialServiceSetup;
/** @public */
export type AddDataSetup = AddDataServiceSetup;
/** @public */
export interface HomePublicPluginSetup {
tutorials: TutorialServiceSetup;
addData: AddDataServiceSetup;
featureCatalogue: FeatureCatalogueSetup;
welcomeScreen: WelcomeServiceSetup;
/**
* The environment service is only available for a transition period and will
* be replaced by display specific extension points.
* @deprecated
* @removeBy 8.8.0
*/
environment: EnvironmentSetup;
}
export interface HomePublicPluginStart {
featureCatalogue: FeatureCatalogueRegistry;
}