Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embeddable examples on the platform and included with --run-examples flag #52111

Merged

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Dec 3, 2019

Embeddable examples built and tested on the platform

Builds off #52027 and adds some new embeddable examples that are in the new platform. Also adds more text to make it more helpful, so it's not just for testing purposes but built to help developers as well.

Screen Shot 2019-12-03 at 8 59 32 PM

Run with yarn start --run-examples and navigate to the Embeddable explorer to play around.

In addition to the examples, some code changes were made as well:

  • Embeddable exposes getEmbeddableFactory on application mount context
  • New EmbeddableRoot react helper component that takes care of rendering the embeddable on a react root node.
  • New EmbeddableFactoryRenderer react helper component that takes care of getting the right factory, and instantiating a new embeddable with the given input, and then mounting and rendering it to the DOM.
  • New withEmbeddableSubscription react helper HOC which takes care of the inner react component binding itself to state changes from the embeddable object.

Some extra clean up:

  • test/examples test suite wasn't running on ci, now fixed.

More things to follow:

  • EmbeddableFactoryRenderer is not type safe in regard to the input shape and the type of embeddable. Adding more type safety, similar to how the data search services does it would be great. Filed: [Embeddables] Extra type safety #52887
  • Dashboard container example
  • More examples to help explain/test more of the concepts.

fyi @streamich @oatkiller

@stacey-gammon stacey-gammon force-pushed the 2019-12-03-embeddable-example branch 2 times, most recently from 5331cc3 to 1363ae0 Compare December 3, 2019 21:58
@stacey-gammon stacey-gammon changed the title [skip ci] 2019 12 03 embeddable example [skip ci] Embeddable examples on the platform and part of examples dir Dec 3, 2019
@stacey-gammon stacey-gammon added the release_note:skip Skip the PR/issue when compiling release notes label Dec 3, 2019
@stacey-gammon stacey-gammon changed the title [skip ci] Embeddable examples on the platform and part of examples dir Embeddable examples on the platform and included with --run-examples flag Dec 4, 2019
@stacey-gammon stacey-gammon force-pushed the 2019-12-03-embeddable-example branch 3 times, most recently from 0285490 to 77f5eb2 Compare December 4, 2019 17:24
@stacey-gammon stacey-gammon force-pushed the 2019-12-03-embeddable-example branch 2 times, most recently from 041e4d3 to ad20043 Compare December 4, 2019 20:37
@elastic elastic deleted a comment from elasticmachine Dec 4, 2019
@elastic elastic deleted a comment from elasticmachine Dec 4, 2019
@stacey-gammon stacey-gammon force-pushed the 2019-12-03-embeddable-example branch 4 times, most recently from d84bd5c to 86b893f Compare December 11, 2019 20:01
import * as Rx from 'rxjs';
import { IEmbeddable, EmbeddableInput, EmbeddableOutput } from './i_embeddable';

export const withEmbeddableSubscription = <
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @streamich -- am adding this helper react class. All my examples ended up with the same subscription code, etc. Lmk if you have any suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This withEmbeddableSubscription higher order component seems to be OK. I'm planning to improve Embeddable DX in general for React, so you would not need to write such helpers.

@stacey-gammon stacey-gammon force-pushed the 2019-12-03-embeddable-example branch 8 times, most recently from 5c92648 to a3fe7c1 Compare December 12, 2019 15:06
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elasticmachine
Copy link
Contributor

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

@stacey-gammon
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Added a couple of UX oriented comments.
Overall LGTM

HelloWorldEmbeddable,
HelloWorldContainer,
} from '../../../../src/plugins/embeddable/public/lib/test_samples';
import { HelloWorldContainer } from '../../../../src/plugins/embeddable/public/lib/test_samples';
Copy link
Contributor

@lizozom lizozom Dec 13, 2019

Choose a reason for hiding this comment

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

Will this import work once #52447 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, there is a /* eslint-disable */ surrounding it (as there was originally). The example plugins actually make this easier because they can export the examples at the top level, while we don't want that in here. I've thought about replacing all these samples with ones from the examples repo but some really are only built for testing not so much examples. Some of this could still probably be cleaned up and more example embeddables used for testing.

}

public start(core: CoreStart, deps: EmbeddableExamplesStartDependencies) {
deps.embeddable.registerEmbeddableFactory(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you register some in the setup phase and dome in the start?

I assume they internally consume services available only in the start phase, but how can we make this clearer to devs (including ourselves)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, because deps.embeddable.getEmbeddableFactory is only available in start, not setup. :( I could move them all to start... or make getEmbeddableFactory available in both. I'm not sure what the best thing is, I think this whole when to expose a registry getter we still don't have a super clear recommendation of. Unless we do and I am just not caught up yet. For now I'll add a comment.

paddingSize="none"
role="figure"
>
<EmbeddableFactoryRenderer
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the fact that filter applies only to inner items to be confusing
If you could hide empty items or gray them out, it would be much clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I agree, but I wanted an example of a container passing data down to the child. I agree the scenario you mention would make more sense but we'd need them to implement something so the child could communicate "i have a match vs no match" to it's parent and we don't have that kind of communication yet.

Think of it like on the dashboard - we pass down the filters and the child does something with that, but the container never changes how the child is rendered.

It is something to think about though. I wonder if there is a better example I could do here. Maybe pass down "highlight" and highlight the search terms instead of filter by them? What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually that's a great idea - search highlight would make it much clearer

error?: string;
}

export class EmbeddableRoot extends React.Component<Props> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't EmbeddableFactoryRenderer and EmbeddableRoot be the same component?
It feels like they couldn't really exist one without the other, or could they?

Copy link
Contributor Author

@stacey-gammon stacey-gammon Dec 13, 2019

Choose a reason for hiding this comment

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

EmbeddableFactoryRenderer encapsulates more logic, but EmbeddableRoot is helpful if you need a reference to the embeddable object, like in todo_embeddable_example. Adding some text there:


                You may also notice this example uses `EmbeddableRoot` instead of the
                `EmbeddableFactoryRenderer` helper component. This is because it needs a reference
                to the embeddable to update it, and `EmbeddableFactoryRenderer` creates and holds
                the embeddable instance internally.

output: EmbeddableOutput;
}

export function TodoEmbeddableComponentInner({ input: { icon, title, task } }: Props) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a TODO app, I would expect to be able to add new items.
I could't figure out how to add a new item, just edit the existing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet, but it's a good idea to add and I might be able to showcase the add panel flyout. Just felt like this PR was getting big so wanted to stop. There are def more examples of use cases I'd like to add.

examples/embeddable_explorer/public/application.tsx Outdated Show resolved Hide resolved
@stacey-gammon
Copy link
Contributor Author

stacey-gammon commented Dec 16, 2019

@lizozom - I updated the examples so that the parent does actually filter out the children (I realized the current infrastructure will actually support this). I also added highlighting. This change of code actually helped me realize some bugs:

  • The react components should not be calling embeddable.destroy() - just because it might not be rendered on the screen doesn't mean it's not still useful. For example, the parent container may choose not to render some children because they don't match the filter, but when the filter changes, they then should be re-rendered. So they are still children in the parent, just temporarily not on the screen.

  • With the above fix I realized that none of my embeddables were correctly implementing their destroy method. Need to call super.destroy and unmount the react node.

Screen Shot 2019-12-16 at 11 30 16 AM

Copy link
Contributor

@streamich streamich left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

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

@stacey-gammon stacey-gammon merged commit 7e67d1f into elastic:master Dec 16, 2019
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Dec 16, 2019
…` flag (elastic#52111)

* Add a new platform embeddable example plugin

* Remove extra hello world test impl.

* cleanup

* code review updates

* Change example to highlight and have parent filter out children

* Fix deep comparison of embeddable prop

* adjust help text
stacey-gammon added a commit that referenced this pull request Dec 16, 2019
…` flag (#52111) (#53190)

* Add a new platform embeddable example plugin

* Remove extra hello world test impl.

* cleanup

* code review updates

* Change example to highlight and have parent filter out children

* Fix deep comparison of embeddable prop

* adjust help text
spalger added a commit to spalger/kibana that referenced this pull request Dec 17, 2019
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:skip Skip the PR/issue when compiling release notes review v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants