-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backporting shared observability plugin to 7.x so it can be used goin…
…g forward
- Loading branch information
1 parent
6961a16
commit 8f93d65
Showing
4 changed files
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Observability Shared Resources | ||
|
||
This "faux" plugin serves as a place to statically share resources, helpers, and components across observability plugins. There is some discussion still happening about the best way to do this, but this is one suggested method that will work for now and has the benefit of adopting our pre-defined build and compile tooling out of the box. | ||
|
||
Files found here can be imported from any other x-pack plugin, with the caveat that these shared components should all be exposed from either `public/index` or `server/index` so that the platform can attempt to monitor breaking changes in this shared API. | ||
|
||
# for a file found at `x-pack/legacy/plugins/infra/public/components/Example.tsx` | ||
|
||
```ts | ||
import { ExampleSharedComponent } from '../../../observability/public'; | ||
``` | ||
|
||
### Plugin registration and config | ||
|
||
There is no plugin registration code or config in this folder because it's a "faux" plugin only being used to share code between other plugins. Plugins using this code do not need to register a dependency on this plugin unless this plugin ever exports functionality that relies on Kibana core itself (rather than being static DI components and utilities only, as it is now). | ||
|
||
### Directory structure | ||
|
||
Code meant to be shared by the UI should live in `public/` and be explicity exported from `public/index` while server helpers etc should live in `server/` and be explicitly exported from `server/index`. Code that needs to be shared across client and server should be exported from both places (not put in `common`, etc). |
15 changes: 15 additions & 0 deletions
15
x-pack/legacy/plugins/observability/public/components/example_shared_component.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,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
interface Props { | ||
message?: string; | ||
} | ||
|
||
export function ExampleSharedComponent({ message = 'See how it loads.' }: Props) { | ||
return <p>This is an example of an observability shared component. {message}</p>; | ||
} |
25 changes: 25 additions & 0 deletions
25
x-pack/legacy/plugins/observability/public/context/kibana_core.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,25 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React, { createContext, useContext } from 'react'; | ||
import { InternalCoreStart } from '../../../../../../src/core/public'; | ||
|
||
interface AppMountContext { | ||
core: InternalCoreStart; | ||
} | ||
|
||
// TODO: Replace CoreStart/CoreSetup with AppMountContext | ||
// see: https://github.com/elastic/kibana/pull/41007 | ||
|
||
export const KibanaCoreContext = createContext({} as AppMountContext['core']); | ||
|
||
export const KibanaCoreContextProvider: React.FC<{ core: AppMountContext['core'] }> = props => ( | ||
<KibanaCoreContext.Provider {...props} value={props.core} children={props.children} /> | ||
); | ||
|
||
export function useKibanaCore() { | ||
return useContext(KibanaCoreContext); | ||
} |
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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
import { KibanaCoreContext, KibanaCoreContextProvider, useKibanaCore } from './context/kibana_core'; | ||
import { ExampleSharedComponent } from './components/example_shared_component'; | ||
|
||
export { ExampleSharedComponent, KibanaCoreContext, KibanaCoreContextProvider, useKibanaCore }; |