Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 9, 2021
1 parent a0ce7b5 commit 279c622
Show file tree
Hide file tree
Showing 28 changed files with 711 additions and 17 deletions.
19 changes: 19 additions & 0 deletions src/plugins/deprecations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# deprecations

A Kibana plugin

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment.

## Scripts

<dl>
<dt><code>yarn kbn bootstrap</code></dt>
<dd>Execute this to install node_modules and setup the dependencies in your plugin and in Kibana</dd>

<dt><code>yarn plugin-helpers build</code></dt>
<dd>Execute this to create a distributable version of this plugin that can be installed in Kibana</dd>
</dl>
2 changes: 2 additions & 0 deletions src/plugins/deprecations/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const PLUGIN_ID = 'deprecations';
export const PLUGIN_NAME = 'deprecations';
13 changes: 13 additions & 0 deletions src/plugins/deprecations/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/deprecations'],
};
9 changes: 9 additions & 0 deletions src/plugins/deprecations/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "deprecations",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["navigation"],
"optionalPlugins": []
}
31 changes: 31 additions & 0 deletions src/plugins/deprecations/public/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 React from 'react';
import ReactDOM from 'react-dom';
import { AppMountParameters, CoreStart } from 'src/core/public';
import { AppPluginStartDependencies } from './types';
import { DeprecationsApp } from './components/app';

export const renderApp = (
{ notifications, http }: CoreStart,
{ navigation }: AppPluginStartDependencies,
{ appBasePath, element }: AppMountParameters
) => {
ReactDOM.render(
<DeprecationsApp
basename={appBasePath}
notifications={notifications}
http={http}
navigation={navigation}
/>,
element
);

return () => ReactDOM.unmountComponentAtNode(element);
};
124 changes: 124 additions & 0 deletions src/plugins/deprecations/public/components/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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 React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';
import { BrowserRouter as Router } from 'react-router-dom';

import {
EuiButton,
EuiHorizontalRule,
EuiPage,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageContentHeader,
EuiPageHeader,
EuiTitle,
EuiText,
} from '@elastic/eui';

import { CoreStart } from 'src/core/public';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';

import { PLUGIN_ID, PLUGIN_NAME } from '../../common';

interface DeprecationsAppDeps {
basename: string;
notifications: CoreStart['notifications'];
http: CoreStart['http'];
navigation: NavigationPublicPluginStart;
}

export const DeprecationsApp = ({
basename,
notifications,
http,
navigation,
}: DeprecationsAppDeps) => {
// Use React hooks to manage state.
const [timestamp, setTimestamp] = useState<string | undefined>();

const onClickHandler = () => {
// Use the core http service to make a response to the server API.
http.get('/api/deprecations/example').then((res) => {
setTimestamp(res.time);
// Use the core notifications service to display a success message.
notifications.toasts.addSuccess(
i18n.translate('deprecations.dataUpdated', {
defaultMessage: 'Data updated',
})
);
});
};

// Render the application DOM.
// Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract.
return (
<Router basename={basename}>
<I18nProvider>
<>
<navigation.ui.TopNavMenu
appName={PLUGIN_ID}
showSearchBar={true}
useDefaultBehaviors={true}
/>
<EuiPage restrictWidth="1000px">
<EuiPageBody>
<EuiPageHeader>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="deprecations.helloWorldText"
defaultMessage="{name}"
values={{ name: PLUGIN_NAME }}
/>
</h1>
</EuiTitle>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiTitle>
<h2>
<FormattedMessage
id="deprecations.congratulationsTitle"
defaultMessage="Congratulations, you have successfully created a new Kibana Plugin!"
/>
</h2>
</EuiTitle>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiText>
<p>
<FormattedMessage
id="deprecations.content"
defaultMessage="Look through the generated code and check out the plugin development documentation."
/>
</p>
<EuiHorizontalRule />
<p>
<FormattedMessage
id="deprecations.timestampText"
defaultMessage="Last timestamp: {time}"
values={{ time: timestamp ? timestamp : 'Unknown' }}
/>
</p>
<EuiButton type="primary" size="s" onClick={onClickHandler}>
<FormattedMessage id="deprecations.buttonText" defaultMessage="Get data" />
</EuiButton>
</EuiText>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
</>
</I18nProvider>
</Router>
);
};
Empty file.
10 changes: 10 additions & 0 deletions src/plugins/deprecations/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './index.scss';

import { DeprecationsPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, Kibana Platform `plugin()` initializer.
export function plugin() {
return new DeprecationsPlugin();
}
export { DeprecationsPluginSetup, DeprecationsPluginStart } from './types';
45 changes: 45 additions & 0 deletions src/plugins/deprecations/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { i18n } from '@kbn/i18n';
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../src/core/public';
import {
DeprecationsPluginSetup,
DeprecationsPluginStart,
AppPluginStartDependencies,
} from './types';
import { PLUGIN_NAME } from '../common';

export class DeprecationsPlugin
implements Plugin<DeprecationsPluginSetup, DeprecationsPluginStart> {
public setup(core: CoreSetup): DeprecationsPluginSetup {
// Register an application into the side navigation menu
core.application.register({
id: 'deprecations',
title: PLUGIN_NAME,
async mount(params: AppMountParameters) {
// Load application bundle
const { renderApp } = await import('./application');
// Get start services as specified in kibana.json
const [coreStart, depsStart] = await core.getStartServices();
// Render the application
return renderApp(coreStart, depsStart as AppPluginStartDependencies, params);
},
});

// Return methods that should be available to other plugins
return {
getGreeting() {
return i18n.translate('deprecations.greetingText', {
defaultMessage: 'Hello from {name}!',
values: {
name: PLUGIN_NAME,
},
});
},
};
}

public start(core: CoreStart): DeprecationsPluginStart {
return {};
}

public stop() {}
}
11 changes: 11 additions & 0 deletions src/plugins/deprecations/public/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public';

export interface DeprecationsPluginSetup {
getGreeting: () => string;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeprecationsPluginStart {}

export interface AppPluginStartDependencies {
navigation: NavigationPublicPluginStart;
}
39 changes: 39 additions & 0 deletions src/plugins/deprecations/server/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/

interface DeprecationInfo {
message: string;
documentationUrl: string;
level: 'critical' | 'warning';
correctiveAction?: () => void;
}

interface PluginDeprecation {
pluginId: string;
getDeprecations: () => Promise<DeprecationInfo>;
}

export class Deprecations {
private readonly deprecations: { [key: string]: PluginDeprecation } = {};

public registerDeprecations = (deprecation: PluginDeprecation) => {
if (this.deprecations[deprecation.pluginId]) {
throw new Error(`Plugin "${deprecation.pluginId}" is duplicated.`);
}

this.deprecations[deprecation.pluginId] = deprecation;
};

public getDeprecationsByPluginId = (pluginId: string) => {
return this.deprecations[pluginId];
};

public getDeprecations = () => {
return this.deprecations;
};
}
13 changes: 13 additions & 0 deletions src/plugins/deprecations/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { PluginInitializerContext } from 'src/core/server';
import { DeprecationsPlugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) =>
new DeprecationsPlugin(initializerContext);
7 changes: 7 additions & 0 deletions src/plugins/deprecations/server/mocks.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
* 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.
*/
43 changes: 43 additions & 0 deletions src/plugins/deprecations/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from 'src/core/server';

import { DeprecationsPluginSetup, DeprecationsPluginStart } from './types';
import { setupRoutes } from './routes';
import { Deprecations } from './deprecations';

export class DeprecationsPlugin
implements Plugin<DeprecationsPluginSetup, DeprecationsPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup) {
this.logger.debug('deprecations: Setup');

const deprecations = new Deprecations();
const router = core.http.createRouter();

// Register server side APIs
setupRoutes({ router, deprecations });

return deprecations;
}

public start(core: CoreStart) {
this.logger.debug('deprecations: Started');
return {};
}

public stop() {
this.logger.debug('Stopping plugin');
}
}
Loading

0 comments on commit 279c622

Please sign in to comment.