-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathui_app.js
128 lines (113 loc) · 3.3 KB
/
ui_app.js
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
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { UiNavLink } from '../ui_nav_links';
export class UiApp {
constructor(kbnServer, spec) {
const {
pluginId,
id = pluginId,
main,
title,
order = 0,
icon,
euiIconType,
hidden,
linkToLastSubUrl,
disableSubUrlTracking,
listed,
category,
url = `/app/${id}`,
} = spec;
if (!id) {
throw new Error('Every app must specify an id');
}
this._id = id;
this._main = main;
this._title = title;
this._order = order;
this._icon = icon;
this._euiIconType = euiIconType;
this._linkToLastSubUrl = linkToLastSubUrl;
this._disableSubUrlTracking = disableSubUrlTracking;
this._category = category;
this._hidden = hidden;
this._listed = listed;
this._url = url;
this._pluginId = pluginId;
this._kbnServer = kbnServer;
if (this._pluginId && !this._getPlugin()) {
throw new Error(`Unknown plugin id "${this._pluginId}"`);
}
if (!this.isHidden()) {
// unless an app is hidden it gets a navlink, but we only respond to `getNavLink()`
// if the app is also listed. This means that all apps in the kibanaPayload will
// have a navLink property since that list includes all normally accessible apps
this._navLink = new UiNavLink({
id: this._id,
title: this._title,
order: this._order,
icon: this._icon,
euiIconType: this._euiIconType,
url: this._url,
linkToLastSubUrl: this._linkToLastSubUrl,
disableSubUrlTracking: this._disableSubUrlTracking,
category: this._category,
});
}
}
getId() {
return this._id;
}
getPluginId() {
const plugin = this._getPlugin();
return plugin ? plugin.id : undefined;
}
isHidden() {
return !!this._hidden;
}
isListed() {
return !this.isHidden() && (this._listed == null || !!this._listed);
}
getNavLink() {
if (this.isListed()) {
return this._navLink;
}
}
getMainModuleId() {
return this._main;
}
_getPlugin() {
const pluginId = this._pluginId;
const { plugins } = this._kbnServer;
return pluginId ? plugins.find(plugin => plugin.id === pluginId) : undefined;
}
toJSON() {
return {
id: this._id,
title: this._title,
icon: this._icon,
euiIconType: this._euiIconType,
main: this._main,
navLink: this._navLink,
linkToLastSubUrl: this._linkToLastSubUrl,
disableSubUrlTracking: this._disableSubUrlTracking,
category: this._category,
};
}
}