[Embeddable Rebuild] Make React embeddables work in Canvas#179667
[Embeddable Rebuild] Make React embeddables work in Canvas#179667Heenawter merged 24 commits intoelastic:mainfrom
Conversation
c44c189 to
7e13d30
Compare
|
/ci |
|
/ci |
68d8859 to
da56fe0
Compare
da56fe0 to
0228319
Compare
|
/ci |
|
/ci |
|
/ci |
|
/ci |
|
/ci |
|
/ci |
|
/ci |
x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable_input_to_expression.ts
Show resolved
Hide resolved
| public readonly hasTrigger = (triggerId: string): boolean => { | ||
| return Boolean(this.triggers.get(triggerId)); | ||
| }; |
There was a problem hiding this comment.
Rather than swallowing the error that is thrown when trying to attach an action to a trigger that doesn't exist, I wanted a cleaner way to ensure that the trigger exists before attaching the action - this is useful for preventing blocking errors from being thrown in situations where a trigger is known to be conditionally registered.
For example, the new Canvas add panel trigger is not registered in Serverless because the Canvas plugin does not exist in this version - so, before attaching an action to this trigger, we should verify that it exists like so: https://github.com/elastic/kibana/pull/179667/files#diff-65c205deed13f182061f156d76c8108c8b68a0d51d27100e36e22263ca087b3e
There was a problem hiding this comment.
Nice clean implementation of this.
|
/ci |
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
ThomThomson
left a comment
There was a problem hiding this comment.
Changes LGTM! Ran this locally and went through the motions with legacy embeddable types (lens & maps) and with the EUI React Embeddable.
Everything runs well and works as expected (better than it used to even). NIce work!
packages/presentation/presentation_containers/interfaces/presentation_container.ts
Show resolved
Hide resolved
packages/presentation/presentation_publishing/interfaces/can_add_new_panel.ts
Outdated
Show resolved
Hide resolved
packages/presentation/presentation_publishing/interfaces/can_add_new_panel.ts
Outdated
Show resolved
Hide resolved
src/plugins/embeddable/public/react_embeddable_system/react_embeddable_renderer.tsx
Outdated
Show resolved
Hide resolved
| public readonly hasTrigger = (triggerId: string): boolean => { | ||
| return Boolean(this.triggers.get(triggerId)); | ||
| }; |
There was a problem hiding this comment.
Nice clean implementation of this.
x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable_input_to_expression.ts
Show resolved
Hide resolved
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: cc @Heenawter |
Closes #179548
Summary
This PR makes it so that React embeddables will now work in Canvas. It does so by doing two main things:
It ensures that the
ReactEmbeddableRendereris used in Canvas when an embeddable exists in the React embeddable registry - if it does not exist, it continues to use the legacy embeddable factory'srendermethod.Since Canvas auto-applies all changes and doesn't have save functionality like Dashboard does, we must keep track of changes as they happen and update the expression to match the new Embeddable input - therefore, I had to add a
onAnyStateChangecallback to theReactEmbeddableRendereras a backdoor for Canvas. As a bonus to this, embeddables that previously didn't respect inline editing (such as the Image embeddable) will start to work once they are converted!It adds a new trigger (
ADD_CANVAS_ELEMENT_TRIGGER) specifically for registering an embeddable to the Canvas add panel menu. This trigger can be attached to the same action that the DashboardADD_PANEL_TRIGGERis attached to - this makes it super simple to add React embeddables to Canvas:As a small cleanup, I also replaced some inline embeddable expressions with
embeddableInputToExpression- this is because I was originally missing| renderat the end of my expression, and I didn't catch it because the expressions I was comparing it to were all declared inline. This should help keep things more consistent.How to Test
I attached the
ADD_EUI_MARKDOWN_ACTION_IDaction to the newADD_CANVAS_ELEMENT_TRIGGER, so the new EUI Markdown React embeddable should show up in the Canvas add panel menu. Ensure that this React embeddable can be added to a workpad, and make sure it responds to edits as expected:Screen.Recording.2024-04-01.at.3.56.04.PM.mov
Checklist
For maintainers