-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0ce7b5
commit 279c622
Showing
28 changed files
with
711 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const PLUGIN_ID = 'deprecations'; | ||
export const PLUGIN_NAME = 'deprecations'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
Oops, something went wrong.