-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
plugin.ts
154 lines (142 loc) · 4.92 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
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import SemVer from 'semver/classes/semver';
import {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
ScopedHistory,
} from '@kbn/core/public';
import { setExtensionsService } from './application/store/selectors/extension_service';
import { ExtensionsService, PublicApiService } from './services';
import {
IndexManagementPluginSetup,
SetupDependencies,
StartDependencies,
ClientConfigType,
IndexManagementPluginStart,
} from './types';
// avoid import from index files in plugin.ts, use specific import paths
import { PLUGIN } from '../common/constants/plugin';
import { IndexMapping } from './application/sections/home/index_list/details_page/index_mappings_embeddable';
export class IndexMgmtUIPlugin
implements
Plugin<
IndexManagementPluginSetup,
IndexManagementPluginStart,
SetupDependencies,
StartDependencies
>
{
private extensionsService = new ExtensionsService();
private kibanaVersion: SemVer;
private config: {
enableIndexActions: boolean;
enableLegacyTemplates: boolean;
enableIndexStats: boolean;
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
isIndexManagementUiEnabled: boolean;
};
constructor(ctx: PluginInitializerContext) {
// Temporary hack to provide the service instances in module files in order to avoid a big refactor
// For the selectors we should expose them through app dependencies and read them from there on each container component.
setExtensionsService(this.extensionsService);
this.kibanaVersion = new SemVer(ctx.env.packageInfo.version);
const {
ui: { enabled: isIndexManagementUiEnabled },
enableIndexActions,
enableLegacyTemplates,
enableIndexStats,
editableIndexSettings,
enableDataStreamsStorageColumn,
} = ctx.config.get<ClientConfigType>();
this.config = {
isIndexManagementUiEnabled,
enableIndexActions: enableIndexActions ?? true,
enableLegacyTemplates: enableLegacyTemplates ?? true,
enableIndexStats: enableIndexStats ?? true,
editableIndexSettings: editableIndexSettings ?? 'all',
enableDataStreamsStorageColumn: enableDataStreamsStorageColumn ?? true,
};
}
public setup(
coreSetup: CoreSetup<StartDependencies>,
plugins: SetupDependencies
): IndexManagementPluginSetup {
if (this.config.isIndexManagementUiEnabled) {
const { fleet, usageCollection, management, cloud } = plugins;
management.sections.section.data.registerApp({
id: PLUGIN.id,
title: i18n.translate('xpack.idxMgmt.appTitle', { defaultMessage: 'Index Management' }),
order: 0,
mount: async (params) => {
const { mountManagementSection } = await import('./application/mount_management_section');
return mountManagementSection({
coreSetup,
usageCollection,
params,
extensionsService: this.extensionsService,
isFleetEnabled: Boolean(fleet),
kibanaVersion: this.kibanaVersion,
config: this.config,
cloud,
});
},
});
}
return {
apiService: new PublicApiService(coreSetup.http),
extensionsService: this.extensionsService.setup(),
};
}
public start(coreStart: CoreStart, plugins: StartDependencies): IndexManagementPluginStart {
const { fleet, usageCollection, cloud, share, console } = plugins;
return {
extensionsService: this.extensionsService.setup(),
getIndexMappingComponent: (deps: { history: ScopedHistory<unknown> }) => {
const { docLinks, fatalErrors, application, uiSettings, executionContext, settings, http } =
coreStart;
const { url } = share;
const appDependencies = {
core: {
fatalErrors,
getUrlForApp: application.getUrlForApp,
executionContext,
application,
http,
},
plugins: {
usageCollection,
isFleetEnabled: Boolean(fleet),
share,
cloud,
console,
},
services: {
extensionsService: this.extensionsService,
},
config: this.config,
history: deps.history,
setBreadcrumbs: undefined as any, // breadcrumbService.setBreadcrumbs,
uiSettings,
settings,
url,
docLinks,
kibanaVersion: this.kibanaVersion,
theme$: coreStart.theme.theme$,
};
return (props: any) => {
return IndexMapping({ dependencies: appDependencies, core: coreStart, ...props });
};
},
};
}
public stop() {}
}