Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce UI PluginsService #32672

Merged
merged 20 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/public/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { loadPluginBundle } from './plugin_loader';
* The `plugin` export at the root of a plugin's `public` directory should conform
* to this interface.
*/
export type PluginInitializer<TSetup, TDependencies extends Record<string, unknown>> = (
export type PluginInitializer<TSetup, TDependencies extends Record<string, unknown> = {}> = (
core: PluginInitializerContext
) => {
setup: (core: PluginSetupContext, dependencies: TDependencies) => TSetup | Promise<TSetup>;
Expand Down
1 change: 1 addition & 0 deletions test/plugin_functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function ({ readConfigFile }) {
require.resolve('./test_suites/custom_visualizations'),
require.resolve('./test_suites/embedding_visualizations'),
require.resolve('./test_suites/panel_actions'),
require.resolve('./test_suites/core_plugins'),
],
services: functionalConfig.get('services'),
pageObjects: functionalConfig.get('pageObjects'),
Expand Down
7 changes: 7 additions & 0 deletions test/plugin_functional/plugins/core_plugin_a/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "core_plugin_a",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["core_plugin_a"],
"ui": true
}
17 changes: 17 additions & 0 deletions test/plugin_functional/plugins/core_plugin_a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "core_plugin_a",
"version": "1.0.0",
"main": "target/test/plugin_functional/plugins/core_plugin_a",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
},
"license": "Apache-2.0",
"scripts": {
"kbn": "node ../../../../scripts/kbn.js",
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "^3.3.3333"
}
}
23 changes: 23 additions & 0 deletions test/plugin_functional/plugins/core_plugin_a/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { PluginInitializer } from 'kibana/public';
import { CorePluginAPlugin, CorePluginAPluginSetup } from './plugin';

export const plugin: PluginInitializer<CorePluginAPluginSetup> = () => new CorePluginAPlugin();
32 changes: 32 additions & 0 deletions test/plugin_functional/plugins/core_plugin_a/public/plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { PluginInitializer, PluginSetupContext } from 'kibana/public';

export class CorePluginAPlugin implements ReturnType<PluginInitializer<CorePluginAPluginSetup>> {
joshdover marked this conversation as resolved.
Show resolved Hide resolved
public setup(core: PluginSetupContext, deps: {}) {
return {
getGreeting() {
return 'Hello from Plugin A!';
},
};
}
}

export type CorePluginAPluginSetup = ReturnType<CorePluginAPlugin['setup']>;
14 changes: 14 additions & 0 deletions test/plugin_functional/plugins/core_plugin_a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"../../../../typings/**/*",
],
"exclude": []
}
9 changes: 9 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "core_plugin_b",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["core_plugin_b"],
"ui": true,
"requiredPlugins": ["core_plugin_a"],
"optionalPlugins": ["core_plugin_c"]
}
17 changes: 17 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "core_plugin_b",
"version": "1.0.0",
"main": "target/test/plugin_functional/plugins/core_plugin_b",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
},
"license": "Apache-2.0",
"scripts": {
"kbn": "node ../../../../scripts/kbn.js",
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "^3.3.3333"
}
}
24 changes: 24 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { PluginInitializer } from 'kibana/public';
import { CorePluginBDeps, CorePluginBPlugin, CorePluginBPluginSetup } from './plugin';

export const plugin: PluginInitializer<CorePluginBPluginSetup, CorePluginBDeps> = () =>
new CorePluginBPlugin();
40 changes: 40 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { PluginInitializer, PluginSetupContext } from 'kibana/public';
import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin';

declare global {
interface Window {
corePluginB?: string;
}
}

export interface CorePluginBDeps {
core_plugin_a: CorePluginAPluginSetup;
}

export class CorePluginBPlugin
implements ReturnType<PluginInitializer<CorePluginBPluginSetup, CorePluginBDeps>> {
public setup(core: PluginSetupContext, deps: CorePluginBDeps) {
window.corePluginB = `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
}
}

export type CorePluginBPluginSetup = ReturnType<CorePluginBPlugin['setup']>;
14 changes: 14 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"../../../../typings/**/*",
],
"exclude": []
}
24 changes: 24 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

export default function ({ loadTestFile }) {
describe('core plugins', () => {
loadTestFile(require.resolve('./ui_plugins'));
});
}
36 changes: 36 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/ui_plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 expect from '@kbn/expect';

export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'header', 'home']);
joshdover marked this conversation as resolved.
Show resolved Hide resolved
const browser = getService('browser');

describe('ui plugin loading', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('settings');
});

it('should attach string to window.corePluginB', async () => {
const corePluginB = await browser.execute('return window.corePluginB');
expect(corePluginB).to.equal(`Plugin A said: Hello from Plugin A!`);
});
});
}