Skip to content

UiComponent#56555

Merged
streamich merged 12 commits intoelastic:masterfrom
streamich:ui-component
Feb 5, 2020
Merged

UiComponent#56555
streamich merged 12 commits intoelastic:masterfrom
streamich:ui-component

Conversation

@streamich
Copy link
Contributor

@streamich streamich commented Jan 31, 2020

Summary

  • Introduces UiComponent interface.
  • Adds uiToReactComponent function.
  • Adds reactToUiComponent function.
  • Adds ability for IAction to render arbitrary HTML in context menu.
  • Added needed functionality to EUI in a separate PR.

Run embeddable test samples:

yarn start --plugin-path test/plugin_functional/plugins/kbn_tp_embeddable_explorer/

Open context menu, see secret badge next to Hello world! action:

image

This will also allow us to render Edit button in drilldowns:

image


Dev Docs

UiComponent interface was added to kibana_utils plugin. UiComponent represents a user interface building block, like a React component, but UiComponent does not have to be implemented in React—it can be implemented in plain JS or React, or Angular, etc.

In many places in Kibana we want to be agnostic to frontend view library, i.e. instead of exposing React-specific APIs we want to expose APIs that are orthogonal to any rendering library. UiComponent interface represents such UI components. UI component receives a DOM element and props through render() method, the render() method can be called many times.

export type UiComponent<Props extends object = object> = () => {
  render(el: HTMLElement, props: Props): void;
  unmount?(): void;
};

Although Kibana aims to be library agnostic, Kibana itself is written in React, therefore UiComponent is designed such that it maps directly to a functional React component: UiCompnent interface corresponds to React.ComponentType type and UiCompnent props map to React component props.

To help use UiComponent interface in the codebase uiToReactComponent and reactToUiComponent helper functions were added to kibana_react plugin, they transform a UiComponent into a React component and vice versa, respectively.

const uiToReactComponent: (comp: UiComponent) => React.ComponentType;
const reactToUiComponent: (comp: React.ComponentType) => UiComponent;

@streamich streamich requested a review from a team as a code owner January 31, 2020 21:03
@streamich streamich added Feature:Embedding Embedding content via iFrame release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. review Team:AppArch v7.7.0 v8.0.0 labels Jan 31, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@streamich streamich changed the title Ui component UiComponent Jan 31, 2020
@streamich
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!


export * from './defer';
export * from './of';
export * from './ui';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would prefer explicit exports

@mattkime
Copy link
Contributor

mattkime commented Feb 3, 2020

I've read through the code buy should probably talk to @streamich to make sure my understanding of the code is correct. I'm a little fuzzy on why the interfaces are configured as they are although I see what they do.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@streamich streamich merged commit 2814bf6 into elastic:master Feb 5, 2020
streamich added a commit that referenced this pull request Feb 6, 2020
* UiComponent (#56555)

* feat: 🎸 add UiComponent and adapters

* feat: 🎸 improve UiComponent

* feat: 🎸 add MenuItem to IAction

* test: 💍 add uiToReactComponent() tests

* test: 💍 add reactToUiComponent() tests

* feat: 🎸 allow specifying wrapper tag in uiToReactComponent()

* style: 💄 format according to ESLint

* docs: ✏️ improve JSDocs

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Matthew Kime <matt@mattki.me>

* chore: 🤖 remove missing exports

* style: add comma

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Matthew Kime <matt@mattki.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Embedding Embedding content via iFrame release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. review v7.7.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants