Skip to content

Commit

Permalink
[Canvas] Move sample data and feature registration to canvas np plugin (
Browse files Browse the repository at this point in the history
elastic#56564)

* Move sample data and feature registration to canvas np plugin

* Prepare to move i18n to new platform and adjust paths

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
poffdeluxe and elasticmachine authored Feb 11, 2020
1 parent f304f88 commit 0dd8129
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 37 deletions.
31 changes: 0 additions & 31 deletions x-pack/legacy/plugins/canvas/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,9 @@

import { CoreSetup, PluginsSetup } from './shim';
import { functions } from '../canvas_plugin_src/functions/server';
import { loadSampleData } from './sample_data';

export class Plugin {
public setup(core: CoreSetup, plugins: PluginsSetup) {
plugins.interpreter.register({ serverFunctions: functions });

plugins.features.registerFeature({
id: 'canvas',
name: 'Canvas',
icon: 'canvasApp',
navLinkId: 'canvas',
app: ['canvas', 'kibana'],
catalogue: ['canvas'],
privileges: {
all: {
savedObject: {
all: ['canvas-workpad', 'canvas-element'],
read: ['index-pattern'],
},
ui: ['save', 'show'],
},
read: {
savedObject: {
all: [],
read: ['index-pattern', 'canvas-workpad', 'canvas-element'],
},
ui: ['show'],
},
},
});

loadSampleData(
plugins.home.sampleData.addSavedObjectsToSampleDataset,
plugins.home.sampleData.addAppLinksToSampleDataset
);
}
}
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/canvas/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export interface PluginsSetup {
kibana: {
injectedUiAppVars: ReturnType<Legacy.Server['getInjectedUiAppVars']>;
};
sampleData: {
addSavedObjectsToSampleDataset: any;
addAppLinksToSampleDataset: any;
};
usageCollection: UsageCollectionSetup;
}

Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/canvas/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from '../../../legacy/plugins/canvas/i18n';
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"configPath": ["xpack", "canvas"],
"server": true,
"ui": false,
"requiredPlugins": [],
"requiredPlugins": ["features", "home"],
"optionalPlugins": ["usageCollection"]
}
35 changes: 35 additions & 0 deletions x-pack/plugins/canvas/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import { first } from 'rxjs/operators';
import { CoreSetup, PluginInitializerContext, Plugin, Logger } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { HomeServerPluginSetup } from 'src/plugins/home/server';
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
import { initRoutes } from './routes';
import { registerCanvasUsageCollector } from './collectors';
import { loadSampleData } from './sample_data';

interface PluginsSetup {
usageCollection?: UsageCollectionSetup;
features: FeaturesPluginSetup;
home: HomeServerPluginSetup;
}

export class CanvasPlugin implements Plugin {
Expand All @@ -21,10 +26,40 @@ export class CanvasPlugin implements Plugin {
}

public async setup(coreSetup: CoreSetup, plugins: PluginsSetup) {
plugins.features.registerFeature({
id: 'canvas',
name: 'Canvas',
icon: 'canvasApp',
navLinkId: 'canvas',
app: ['canvas', 'kibana'],
catalogue: ['canvas'],
privileges: {
all: {
savedObject: {
all: ['canvas-workpad', 'canvas-element'],
read: ['index-pattern'],
},
ui: ['save', 'show'],
},
read: {
savedObject: {
all: [],
read: ['index-pattern', 'canvas-workpad', 'canvas-element'],
},
ui: ['show'],
},
},
});

const canvasRouter = coreSetup.http.createRouter();

initRoutes({ router: canvasRouter, logger: this.logger });

loadSampleData(
plugins.home.sampleData.addSavedObjectsToSampleDataset,
plugins.home.sampleData.addAppLinksToSampleDataset
);

// we need the kibana index provided by global config for the Canvas usage collector
const globalConfig = await this.initializerContext.config.legacy.globalConfig$
.pipe(first())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SampleDataRegistrySetup } from 'src/plugins/home/server';
import { CANVAS as label } from '../../i18n';
// @ts-ignore Untyped local
import { ecommerceSavedObjects, flightsSavedObjects, webLogsSavedObjects } from './index';
import { SampleDataRegistrySetup } from '../../../../../../src/plugins/home/server';

export function loadSampleData(
addSavedObjectsToSampleDataset: SampleDataRegistrySetup['addSavedObjectsToSampleDataset'],
Expand Down

0 comments on commit 0dd8129

Please sign in to comment.