Skip to content

Commit

Permalink
Backporting shared observability plugin to 7.x so it can be used goin…
Browse files Browse the repository at this point in the history
…g forward
  • Loading branch information
jasonrhodes committed Aug 29, 2019
1 parent 6961a16 commit 8f93d65
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions x-pack/legacy/plugins/observability/README.md
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).
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 x-pack/legacy/plugins/observability/public/context/kibana_core.tsx
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);
}
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/observability/public/index.tsx
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 };

0 comments on commit 8f93d65

Please sign in to comment.