-
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
Showing
19 changed files
with
442 additions
and
0 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
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
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
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
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,3 @@ | ||
# dataUsage | ||
Serverless only plugin for users to view data usage | ||
|
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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const PLUGIN_ID = 'data_usage'; | ||
export const PLUGIN_NAME = i18n.translate('xpack.dataUsage.name', { | ||
defaultMessage: 'Data Usage', | ||
}); |
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,15 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/plugins/data_usage'], | ||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/data_usage', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: ['<rootDir>/x-pack/plugins/datas_usage/{common,public}/**/*.{ts,tsx}'], | ||
}; |
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,16 @@ | ||
{ | ||
"type": "plugin", | ||
"id": "@kbn/data-usage-plugin", | ||
"owner": ["@elastic/obs-ai-assistant", "@elastic/security-solution"], | ||
"plugin": { | ||
"id": "dataUsage", | ||
"server": true, | ||
"browser": true, | ||
"configPath": ["xpack", "dataUsage"], | ||
"requiredPlugins": ["home", "management", "features", "share"], | ||
"optionalPlugins": [], | ||
"requiredBundles": [ | ||
"kibanaReact", | ||
], | ||
} | ||
} |
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,83 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CoreStart } from '@kbn/core/public'; | ||
import { ManagementAppMountParams } from '@kbn/management-plugin/public'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render'; | ||
import { Route, Router, Routes } from '@kbn/shared-ux-router'; | ||
import { useExecutionContext } from '@kbn/kibana-react-plugin/public'; | ||
import { PerformanceContextProvider } from '@kbn/ebt-tools'; | ||
import { useKibanaContextForPluginProvider } from './utils/use_kibana'; | ||
import { AppPluginStartDependencies, DataUsagePluginStart } from './types'; | ||
import { PLUGIN_ID } from '../common'; | ||
|
||
export const renderApp = ( | ||
core: CoreStart, | ||
plugins: AppPluginStartDependencies, | ||
pluginStart: DataUsagePluginStart, | ||
params: ManagementAppMountParams | ||
) => { | ||
ReactDOM.render( | ||
<App params={params} core={core} plugins={plugins} pluginStart={pluginStart} />, | ||
params.element | ||
); | ||
|
||
return () => { | ||
ReactDOM.unmountComponentAtNode(params.element); | ||
}; | ||
}; | ||
|
||
const AppWithExecutionContext = ({ | ||
core, | ||
params, | ||
}: { | ||
core: CoreStart; | ||
params: ManagementAppMountParams; | ||
}) => { | ||
const { executionContext } = core; | ||
|
||
useExecutionContext(executionContext, { | ||
type: 'application', | ||
page: PLUGIN_ID, | ||
}); | ||
|
||
return ( | ||
<Router history={params.history}> | ||
<PerformanceContextProvider> | ||
<Routes> | ||
<Route path="/" exact={true} render={() => <div>Data Usage</div>} /> | ||
</Routes> | ||
</PerformanceContextProvider> | ||
</Router> | ||
); | ||
}; | ||
|
||
interface AppProps { | ||
core: CoreStart; | ||
plugins: AppPluginStartDependencies; | ||
pluginStart: DataUsagePluginStart; | ||
params: ManagementAppMountParams; | ||
} | ||
|
||
const App = ({ core, plugins, pluginStart, params }: AppProps) => { | ||
const KibanaContextProviderForPlugin = useKibanaContextForPluginProvider( | ||
core, | ||
plugins, | ||
pluginStart, | ||
params | ||
); | ||
|
||
return ( | ||
<KibanaRenderContextProvider {...core} {...params}> | ||
<KibanaContextProviderForPlugin> | ||
<AppWithExecutionContext core={core} params={params} /> | ||
</KibanaContextProviderForPlugin> | ||
</KibanaRenderContextProvider> | ||
); | ||
}; |
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,26 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { PluginInitializer, PluginInitializerContext } from '@kbn/core/public'; | ||
import type { | ||
DataUsagePublicSetup, | ||
DataUsagePublicStart, | ||
DataUsageSetupDependencies, | ||
DataUsageStartDependencies, | ||
ConfigSchema, | ||
} from './types'; | ||
import { DataUsagePlugin } from './plugin'; | ||
|
||
export type { DataUsagePublicSetup, DataUsagePublicStart } from './types'; | ||
|
||
export const plugin: PluginInitializer< | ||
DataUsagePublicSetup, | ||
DataUsagePublicStart, | ||
DataUsageSetupDependencies, | ||
DataUsageStartDependencies | ||
> = (pluginInitializerContext: PluginInitializerContext<ConfigSchema>) => | ||
new DataUsagePlugin(pluginInitializerContext); |
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,61 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; | ||
import { ManagementAppMountParams } from '@kbn/management-plugin/public'; | ||
import type { PluginInitializerContext } from '@kbn/core/public'; | ||
import { | ||
DataUsagePublicSetup, | ||
DataUsagePublicStart, | ||
DataUsageStartDependencies, | ||
DataUsageSetupDependencies, | ||
} from './types'; | ||
import { PLUGIN_ID, PLUGIN_NAME } from '../common'; | ||
|
||
export class DataUsagePlugin | ||
implements | ||
Plugin< | ||
DataUsagePublicSetup, | ||
DataUsagePublicStart, | ||
DataUsageSetupDependencies, | ||
DataUsageStartDependencies | ||
> | ||
{ | ||
private isServerless: boolean = false; | ||
constructor(initializerContext: PluginInitializerContext) { | ||
this.isServerless = initializerContext.env.packageInfo.buildFlavor === 'serverless'; | ||
} | ||
public setup( | ||
core: CoreSetup<DataUsageStartDependencies, DataUsagePublicStart>, | ||
plugins: DataUsageSetupDependencies | ||
): DataUsagePublicSetup { | ||
const { management } = plugins; | ||
if (!this.isServerless) return {}; | ||
management.sections.section.data.registerApp({ | ||
id: PLUGIN_ID, | ||
title: PLUGIN_NAME, | ||
order: 6, | ||
keywords: ['data usage', 'usage'], | ||
async mount(params: ManagementAppMountParams) { | ||
const [{ renderApp }, [coreStart, pluginsStartDeps, pluginStart]] = await Promise.all([ | ||
import('./application'), | ||
core.getStartServices(), | ||
]); | ||
|
||
return renderApp(coreStart, pluginsStartDeps, pluginStart, params); | ||
}, | ||
}); | ||
|
||
return {}; | ||
} | ||
|
||
public start(_core: CoreStart): DataUsagePublicStart { | ||
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,27 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public'; | ||
import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface DataUsagePublicSetup {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface DataUsagePublicStart {} | ||
|
||
export interface DataUsageSetupDependencies { | ||
management: ManagementSetup; | ||
share: SharePluginSetup; | ||
} | ||
|
||
export interface DataUsageStartDependencies { | ||
management: ManagementStart; | ||
share: SharePluginStart; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ConfigSchema {} |
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,53 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CoreStart } from '@kbn/core/public'; | ||
import { | ||
createKibanaReactContext, | ||
KibanaReactContextValue, | ||
useKibana, | ||
} from '@kbn/kibana-react-plugin/public'; | ||
import { ManagementAppMountParams } from '@kbn/management-plugin/public'; | ||
import { useMemo } from 'react'; | ||
import { AppPluginStartDependencies, DataUsagePluginStart } from '../types'; | ||
|
||
export type PluginKibanaContextValue = CoreStart & | ||
AppPluginStartDependencies & | ||
DataUsagePluginStart & { | ||
appParams: ManagementAppMountParams; | ||
}; | ||
|
||
export const createKibanaContextForPlugin = ( | ||
core: CoreStart, | ||
plugins: AppPluginStartDependencies, | ||
pluginStart: DataUsagePluginStart, | ||
appParams: ManagementAppMountParams | ||
) => { | ||
return createKibanaReactContext<PluginKibanaContextValue>({ | ||
...core, | ||
...plugins, | ||
...pluginStart, | ||
appParams, | ||
}); | ||
}; | ||
|
||
export const useKibanaContextForPlugin = | ||
useKibana as () => KibanaReactContextValue<PluginKibanaContextValue>; | ||
|
||
export const useKibanaContextForPluginProvider = ( | ||
core: CoreStart, | ||
plugins: AppPluginStartDependencies, | ||
pluginStart: DataUsagePluginStart, | ||
appParams: ManagementAppMountParams | ||
) => { | ||
const { Provider } = useMemo( | ||
() => createKibanaContextForPlugin(core, plugins, pluginStart, appParams), | ||
[appParams, core, pluginStart, plugins] | ||
); | ||
|
||
return Provider; | ||
}; |
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,14 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema, type TypeOf } from '@kbn/config-schema'; | ||
|
||
export const config = schema.object({ | ||
enabled: schema.boolean({ defaultValue: false }), | ||
}); | ||
|
||
export type DataUsageConfig = TypeOf<typeof config>; |
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,36 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import type { | ||
PluginInitializer, | ||
PluginInitializerContext, | ||
PluginConfigDescriptor, | ||
} from '@kbn/core/server'; | ||
import { DataUsageConfig } from './config'; | ||
|
||
import { DataUsagePlugin } from './plugin'; | ||
import type { | ||
DataUsageServerSetup, | ||
DataUsageServerStart, | ||
DataUsageSetupDependencies, | ||
DataUsageStartDependencies, | ||
} from './types'; | ||
|
||
import { config as configSchema } from './config'; | ||
|
||
export type { DataUsageServerSetup, DataUsageServerStart }; | ||
|
||
export const config: PluginConfigDescriptor<DataUsageConfig> = { | ||
schema: configSchema, | ||
}; | ||
|
||
export const plugin: PluginInitializer< | ||
DataUsageServerSetup, | ||
DataUsageServerStart, | ||
DataUsageSetupDependencies, | ||
DataUsageStartDependencies | ||
> = async (pluginInitializerContext: PluginInitializerContext<DataUsageConfig>) => | ||
await new DataUsagePlugin(pluginInitializerContext); |
Oops, something went wrong.