-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Add embeddable via saved object example #61692
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
Add embeddable via saved object example #61692
Conversation
|
Pinging @elastic/kibana-app-arch (Team:AppArch) |
88bc0ed to
5c6c42c
Compare
5c6c42c to
0bd8979
Compare
4ef738e to
e5efc6b
Compare
b7ea965 to
683939a
Compare
683939a to
fa8395b
Compare
…bed-example-saved-object
…bed-example-saved-object
streamich
left a comment
There was a problem hiding this 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.
examples/embeddable_examples/public/todo/todo_ref_embeddable_factory.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
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 }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is [k: string]?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…bed-example-saved-object
|
@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. |
…bed-example-saved-object
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* 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>
* 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>
* 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>
This PR:
PanelStatefromto
addSavedObjectEmbeddablefrom the container interface. Now the functionaddNewEmbeddablecan be used for both use cases.A follow up will be to remove the
factory.createFromSavedObjectfunction as that should not be needed anymore.