Skip to content

Conversation

@stacey-gammon
Copy link

@stacey-gammon stacey-gammon commented Mar 27, 2020

This PR:

  • Adds sample data when the Embeddable Explorer is run so users can see a saved object listed in the add panel flyout. There is a test for this functionality.
  • Changes container PanelState from
 { 
  type: string
  savedObjectId?: string
  explicitInput: {...}
 }

to

 { 
  type: string
  explicitInput: {
   savedObjectId?: string
  }
 }
  • Removes addSavedObjectEmbeddable from the container interface. Now the function addNewEmbeddable can be used for both use cases.

A follow up will be to remove the factory.createFromSavedObject function as that should not be needed anymore.

@botelastic botelastic bot added Feature:Embedding Embedding content via iFrame Team:AppArch labels Mar 27, 2020
@elasticmachine
Copy link
Contributor

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

@stacey-gammon stacey-gammon force-pushed the 2020-03-27-embed-example-saved-object branch 13 times, most recently from 88bc0ed to 5c6c42c Compare March 28, 2020 13:05
@stacey-gammon stacey-gammon marked this pull request as ready for review March 28, 2020 15:47
@stacey-gammon stacey-gammon requested a review from a team March 28, 2020 15:47
@stacey-gammon stacey-gammon requested a review from a team as a code owner March 28, 2020 15:47
@stacey-gammon stacey-gammon changed the title [WIP] Add embeddable via saved object example Add embeddable via saved object example Mar 28, 2020
@stacey-gammon stacey-gammon added v7.8.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Mar 28, 2020
@stacey-gammon stacey-gammon force-pushed the 2020-03-27-embed-example-saved-object branch from 5c6c42c to 0bd8979 Compare March 30, 2020 15:36
@stacey-gammon stacey-gammon reopened this Apr 3, 2020
@stacey-gammon stacey-gammon force-pushed the 2020-03-27-embed-example-saved-object branch 2 times, most recently from 4ef738e to e5efc6b Compare April 3, 2020 17:48
@stacey-gammon stacey-gammon force-pushed the 2020-03-27-embed-example-saved-object branch 4 times, most recently from b7ea965 to 683939a Compare April 3, 2020 19:39
@stacey-gammon stacey-gammon force-pushed the 2020-03-27-embed-example-saved-object branch from 683939a to fa8395b Compare April 3, 2020 21:08
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.

Nice to see createFromSavedObject go away. PR LGTM, checked on Mac/Chrome.

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

This is such a great change 🙌
I've tested this in Chrome 80 on Mac OS. I was focusing on the existing Dashboard flow - adding a new visualization, replacing a panel - works as expected.
Tested todo example - works well.

Left a few questions for my own understanding, but they shouldn't block merging this.

const type = $routeParams[DashboardConstants.ADD_EMBEDDABLE_TYPE];
const id = $routeParams[DashboardConstants.ADD_EMBEDDABLE_ID];
container.addSavedObjectEmbeddable(type, id);
container.addNewEmbeddable<SavedObjectEmbeddableInput>(type, { savedObjectId: id });
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

isFullScreenMode: boolean;
panels: {
[panelId: string]: DashboardPanelState;
[panelId: string]: DashboardPanelState<EmbeddableInput & { [k: string]: unknown }>;
Copy link
Contributor

Choose a reason for hiding this comment

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

what is [k: string]?

Copy link
Author

Choose a reason for hiding this comment

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

it's the key in the object: { [key: string]: unknown} is how it's often written.

It means that panel state can hold EmbeddableInput or additional data. I don't know a way to type is so that it's based of panel.type and that panel.explicitInput is Partial<EmbeddableInputForType>. so that if you did something like:

const input: DashboardContainerInput = {
  panels: {
    '1': {
       type: 'fooEmbeddable',
       explicitInput: {
         'foo': 'bar' // Typescript should make sure `FooEmbeddableInput` has a `foo` attribute!
       }
     }
  }
}

I've kind of given up on improving types to that regard. Without this edit here, typescript would warn on the above, even if foo was on FooEmbeddableInput.

// Since this is an expensive task, we save a local copy of the previous
// savedObjectId locally and only retrieve the new saved object if the id
// actually changed.
if (this.savedObjectId !== this.input.savedObjectId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in which scenario would this happen?

Copy link
Author

Choose a reason for hiding this comment

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

If any user of this embeddable called embeddable.updateInput({ savedObjectId: 'newId' }).

Embeddables should be prepared to react appropriately to any of its input data changing during its lifetime.

This could possibly happen also if dashboard had an embeddable like this and someone hand edited the url to change the id.

@stacey-gammon
Copy link
Author

@ppisljar will you be able to review this week? If not, would you mind if I merged with the existing reviews, and you can take a look after the fact? I have more PRs blocked on this one.

@kibanamachine
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 d040448 into elastic:master Apr 15, 2020
stacey-gammon pushed a commit to stacey-gammon/kibana that referenced this pull request Apr 15, 2020
* Add embeddable via saved object example

* give todoRefEmbed a different name from the by value one

* fix types

* fix order of unmounting

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
stacey-gammon pushed a commit that referenced this pull request Apr 15, 2020
* Add embeddable via saved object example

* give todoRefEmbed a different name from the by value one

* fix types

* fix order of unmounting

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
wayneseymour pushed a commit that referenced this pull request Apr 15, 2020
* Add embeddable via saved object example

* give todoRefEmbed a different name from the by value one

* fix types

* fix order of unmounting

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
ThomThomson added a commit to ThomThomson/kibana that referenced this pull request Apr 16, 2020
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.8.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants