Skip to content

Commit

Permalink
Graph: Migrate feature registration (#61419)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Mar 30, 2020
1 parent 84d1bbd commit b6101f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
37 changes: 0 additions & 37 deletions x-pack/legacy/plugins/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';

// @ts-ignore
import migrations from './migrations';
import mappings from './mappings.json';
Expand All @@ -30,40 +28,5 @@ export const graph: LegacyPluginInitializer = kibana => {
.default('configAndData'),
}).default();
},

init(server) {
server.plugins.xpack_main.registerFeature({
id: 'graph',
name: i18n.translate('xpack.graph.featureRegistry.graphFeatureName', {
defaultMessage: 'Graph',
}),
order: 1200,
icon: 'graphApp',
navLinkId: 'graph',
app: ['graph', 'kibana'],
catalogue: ['graph'],
validLicenses: ['platinum', 'enterprise', 'trial'],
privileges: {
all: {
app: ['graph', 'kibana'],
catalogue: ['graph'],
savedObject: {
all: ['graph-workspace'],
read: ['index-pattern'],
},
ui: ['save', 'delete'],
},
read: {
app: ['graph', 'kibana'],
catalogue: ['graph'],
savedObject: {
all: [],
read: ['index-pattern', 'graph-workspace'],
},
ui: [],
},
},
});
},
});
};
2 changes: 1 addition & 1 deletion x-pack/plugins/graph/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"server": true,
"ui": true,
"requiredPlugins": ["licensing", "data", "navigation"],
"optionalPlugins": ["home"],
"optionalPlugins": ["home", "features"],
"configPath": ["xpack", "graph"]
}
47 changes: 46 additions & 1 deletion x-pack/plugins/graph/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { Plugin, CoreSetup } from 'src/core/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { LicenseState } from './lib/license_state';
import { registerSearchRoute } from './routes/search';
import { registerExploreRoute } from './routes/explore';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
import { registerSampleData } from './sample_data';
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';

export class GraphPlugin implements Plugin {
private licenseState: LicenseState | null = null;

public async setup(
core: CoreSetup,
{ licensing, home }: { licensing: LicensingPluginSetup; home?: HomeServerPluginSetup }
{
licensing,
home,
features,
}: {
licensing: LicensingPluginSetup;
home?: HomeServerPluginSetup;
features?: FeaturesPluginSetup;
}
) {
const licenseState = new LicenseState();
licenseState.start(licensing.license$);
Expand All @@ -27,6 +37,41 @@ export class GraphPlugin implements Plugin {
registerSampleData(home.sampleData, licenseState);
}

if (features) {
features.registerFeature({
id: 'graph',
name: i18n.translate('xpack.graph.featureRegistry.graphFeatureName', {
defaultMessage: 'Graph',
}),
order: 1200,
icon: 'graphApp',
navLinkId: 'graph',
app: ['graph', 'kibana'],
catalogue: ['graph'],
validLicenses: ['platinum', 'enterprise', 'trial'],
privileges: {
all: {
app: ['graph', 'kibana'],
catalogue: ['graph'],
savedObject: {
all: ['graph-workspace'],
read: ['index-pattern'],
},
ui: ['save', 'delete'],
},
read: {
app: ['graph', 'kibana'],
catalogue: ['graph'],
savedObject: {
all: [],
read: ['index-pattern', 'graph-workspace'],
},
ui: [],
},
},
});
}

const router = core.http.createRouter();
registerSearchRoute({ licenseState, router });
registerExploreRoute({ licenseState, router });
Expand Down

0 comments on commit b6101f0

Please sign in to comment.