-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathplugin.ts
202 lines (179 loc) · 5.73 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
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import './index.scss';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { ConfigSchema } from '../config';
import { Storage, IStorageWrapper, createStartServicesGetter } from '../../kibana_utils/public';
import {
DataPublicPluginSetup,
DataPublicPluginStart,
DataSetupDependencies,
DataStartDependencies,
} from './types';
import { AutocompleteService } from './autocomplete';
import { SearchService } from './search/search_service';
import { QueryService } from './query';
import { createIndexPatternSelect } from './ui/index_pattern_select';
import {
setIndexPatterns,
setNotifications,
setOverlays,
setSearchService,
setUiSettings,
} from './services';
import { createSearchBar } from './ui/search_bar/create_search_bar';
import {
ACTION_GLOBAL_APPLY_FILTER,
createFilterAction,
createFiltersFromValueClickAction,
createFiltersFromRangeSelectAction,
createValueClickAction,
createSelectRangeAction,
} from './actions';
import { APPLY_FILTER_TRIGGER, applyFilterTrigger } from './triggers';
import { UsageCollectionSetup } from '../../usage_collection/public';
import { getTableViewDescription } from './utils/table_inspector_view';
import { NowProvider, NowProviderInternalContract } from './now_provider';
import { getAggsFormats } from '../common';
export class DataPublicPlugin
implements
Plugin<
DataPublicPluginSetup,
DataPublicPluginStart,
DataSetupDependencies,
DataStartDependencies
>
{
private readonly autocomplete: AutocompleteService;
private readonly searchService: SearchService;
private readonly queryService: QueryService;
private readonly storage: IStorageWrapper;
private usageCollection: UsageCollectionSetup | undefined;
private readonly nowProvider: NowProviderInternalContract;
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.searchService = new SearchService(initializerContext);
this.queryService = new QueryService();
this.autocomplete = new AutocompleteService(initializerContext);
this.storage = new Storage(window.localStorage);
this.nowProvider = new NowProvider();
}
public setup(
core: CoreSetup<DataStartDependencies, DataPublicPluginStart>,
{
bfetch,
expressions,
uiActions,
usageCollection,
inspector,
fieldFormats,
}: DataSetupDependencies
): DataPublicPluginSetup {
const startServices = createStartServicesGetter(core.getStartServices);
this.usageCollection = usageCollection;
const searchService = this.searchService.setup(core, {
bfetch,
usageCollection,
expressions,
nowProvider: this.nowProvider,
});
const queryService = this.queryService.setup({
uiSettings: core.uiSettings,
storage: this.storage,
nowProvider: this.nowProvider,
});
uiActions.registerTrigger(applyFilterTrigger);
uiActions.registerAction(
createFilterAction(queryService.filterManager, queryService.timefilter.timefilter)
);
inspector.registerView(
getTableViewDescription(() => ({
uiActions: startServices().plugins.uiActions,
uiSettings: startServices().core.uiSettings,
fieldFormats: startServices().self.fieldFormats,
isFilterable: startServices().self.search.aggs.datatableUtilities.isFilterable,
}))
);
fieldFormats.register(
getAggsFormats((serializedFieldFormat) =>
startServices().plugins.fieldFormats.deserialize(serializedFieldFormat)
)
);
return {
autocomplete: this.autocomplete.setup(core, {
timefilter: queryService.timefilter,
usageCollection,
}),
search: searchService,
query: queryService,
};
}
public start(
core: CoreStart,
{ uiActions, fieldFormats, dataViews }: DataStartDependencies
): DataPublicPluginStart {
const { uiSettings, notifications, overlays } = core;
setNotifications(notifications);
setOverlays(overlays);
setUiSettings(uiSettings);
setIndexPatterns(dataViews);
const query = this.queryService.start({
storage: this.storage,
http: core.http,
uiSettings,
});
const search = this.searchService.start(core, { fieldFormats, indexPatterns: dataViews });
setSearchService(search);
uiActions.addTriggerAction(
'SELECT_RANGE_TRIGGER',
createSelectRangeAction(() => ({
uiActions,
}))
);
uiActions.addTriggerAction(
'VALUE_CLICK_TRIGGER',
createValueClickAction(() => ({
uiActions,
}))
);
uiActions.addTriggerAction(
APPLY_FILTER_TRIGGER,
uiActions.getAction(ACTION_GLOBAL_APPLY_FILTER)
);
const dataServices = {
actions: {
createFiltersFromValueClickAction,
createFiltersFromRangeSelectAction,
},
autocomplete: this.autocomplete.start(),
fieldFormats,
indexPatterns: dataViews,
dataViews,
query,
search,
nowProvider: this.nowProvider,
};
const SearchBar = createSearchBar({
core,
data: dataServices,
storage: this.storage,
usageCollection: this.usageCollection,
});
return {
...dataServices,
ui: {
IndexPatternSelect: createIndexPatternSelect(dataViews),
SearchBar,
},
};
}
public stop() {
this.autocomplete.clearProviders();
this.queryService.stop();
this.searchService.stop();
}
}