-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Canvas] Generic embeddable function #104499
[Canvas] Generic embeddable function #104499
Conversation
f588bc7
to
2150ef8
Compare
Pinging @elastic/kibana-presentation (Team:Presentation) |
f84c1f3
to
910d8eb
Compare
d3d9d1e
to
14f66b5
Compare
1093d6d
to
199a5f4
Compare
@elasticmachine merge upstream |
const partialElement = { | ||
expression: `markdown "Could not find embeddable for type ${type}" | render`, | ||
}; | ||
if (allowedEmbeddables[type]) { | ||
|
||
if (isByValueEnabled) { |
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 by value flag is used even for by reference embeddables? Maybe a little confusing but if I'm understanding this all correctly, all the new embeddable behavior will be controlled by this flag, right?
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.
Yeah, my intention is to favor the new generic embeddable fn, which handles both by-value and by-reference embeddables, as the default expression for an embeddable added from the library, so we can eventually phase out the type specific embeddable functions.
We're using the new embeddable
expression introduced in this PR if the by-value lab is enabled. So all embeddables added with this feature enabled should have an expression like
embeddable config="eyJ2aWV3TW9kZSI6ImVkaXQiLCJ0aW1lUmFuZ2UiOnsiZnJvbSI6Im5vdy0xNWQiLCJ0byI6Im5vdyJ9LCJkaXNhYmxlVHJpZ2dlcnMiOnRydWUsInJlbmRlck1vZGUiOiJub0ludGVyYWN0aXZpdHkiLCJpZCI6IjJjOWMxZjYwLTE5MDktMTFlOS05MTliLWZmZTU5NDlhMThkMiIsImZpbHRlcnMiOltdLCJzYXZlZE9iamVjdElkIjoiMmM5YzFmNjAtMTkwOS0xMWU5LTkxOWItZmZlNTk0OWExOGQyIiwibWFwQ2VudGVyIjp7ImxhdCI6NTcuNTgyNDYsImxvbiI6LTExMi43NjM2Nywiem9vbSI6Mi4xMX0sIm1hcEJ1ZmZlciI6eyJtaW5Mb24iOi0xODAsIm1pbkxhdCI6MCwibWF4TG9uIjotNDUsIm1heExhdCI6NzkuMTcxMzN9LCJpc0xheWVyVE9DT3BlbiI6ZmFsc2UsIm9wZW5UT0NEZXRhaWxzIjpbXSwiaGlkZGVuTGF5ZXJzIjpbIjdhbWVxIl19"
type="map"
| render
If the lab is disabled, we use the original logic which builds an expression based on embeddable type from our mapping of allowed embeddables.
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.
Gotcha. I wonder if it makes sense to rename the lab flag to something that isn't necessarily by-value specific. When I'm reading this code and I see a flag checking for by-value to be enabled, my brain makes the assumption that the code I'm going to be reading next has to do with by-value embeddables which isn't necessarily the case. If it's going to be a pain to re-name the flag, maybe a comment explaining that by-reference embeddables are still handled in the block -- it's just going to use the new function
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.
Approving to unblock! I still think we'll want to figure out some clarity around the lab's flag but otherwise this looks good to me.
I also verified that flipping the flag on/off won't break existing workpads (or in the case of flipping the flag off, a workpad using the new generic function doesn't break)
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.
Looks great 👍
Left a few little nits that should be cleaned up
}, | ||
]; | ||
|
||
return { |
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 this is a "by value" embeddable, then the state should be passed on to the EmbeddablePersistableStateService for extract.
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.
I'll tackle this in a separate PR to address extracting/injecting references for by-value embeddables.
|
||
inject(state, references) { | ||
const reference = references.find((ref) => ref.name === 'embeddable.id'); | ||
if (reference) { |
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.
And here should also be passed on to EmbeddablePersistableStateService for inject
export function toExpression(input: EmbeddableInput, embeddableType: string): string { | ||
const expressionParts = [] as string[]; | ||
|
||
expressionParts.push('embeddable'); |
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.
since there's nothing conditional here, can you just build this as one big string instead of doing the parts+join.
return `embeddable config="${encode(input)}" type="${embeddableType}"`
availableEmbeddables: string[]; | ||
} | ||
|
||
export const AddEmbeddableFlyout: FC<Props> = ({ onSelect, availableEmbeddables, onClose }) => { | ||
const embeddablesService = useEmbeddablesService(); | ||
const labsService = useLabsService(); |
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.
I think it makes more sense to pull the labsService up to the flyout.tsx and not in this component. It's only purpose being in this file is to pass to that callback, so why not have that callback know about it instead and then this component has less to deal with.
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.
I still need the lab service in flyout.component
to check if by value is enabled when filtering out embeddable factories.
line 63-64
const availableSavedObjects = Array.from(embeddableFactories)
.filter((factory) => isByValueEnabled || availableEmbeddables.includes(factory.type))
If by-value is enabled, then this conditional always evaluates to true and doesn't end up filtering out any factories, but if it is disabled, we want to restore the original functionality and filter out for only the allowed embeddable factories.
I can move labsService up to flyout.tsx
, but I'd end up using it in both files.
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.
I moved labsService
up to flyout.tsx
and pass isByValueEnabled
as a prop into flyout.component
in 5163ffd.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* [Canvas] Generic embeddable function (#104499) * Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment * [Canvas] Adds Save and Return Workflow (#111411) * [Canvas] Adds editor menu to Canvas (#113194) * Merge existing embeddable input with incoming embeddable input (#116026) * [Canvas] Extract and inject references for by-value embeddables (#115124) * Extract/inject references for by-value embeddables in embeddable function Fixed server interpreter setup Register external functions in canvas_plugin_src plugin def * Fixed ref name in embeddable.inject * Fixed ts errors * Fix missing type error Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
* Created generic embeddable function Fixed telemetry Updates expression on input change Fixed ts errors Store embeddable input to expression Added lib functions Added comments Fixed type errors Fixed ts errors Clean up Removed extraneous import Added context type to embeddable function def Fix import Update encode/decode fns Moved embeddable data url lib file Added embeddable test Updated comment * Fix reference extract/inject in embeddable fn * Simplify embeddable toExpression * Moved labsService to flyout.tsx * Added comment
Summary
Related to #81812.
Related to #101633.
This creates a single generic
embeddable
function to handle all by-reference embeddables in Canvas.It accepts only two arguments:
config
: a base64 encoded string of the embeddable input objecttype
: the embeddable typeExample expression:
Changes:
embeddable
function that serves as a generic version ofsavedMap
,savedVisualizations
, etcsavedSearch
embeddable type via generic embeddable functionKnown Issues:
palettes
which are supported by Lens. Do we want to support palettes with this generic function if not all embeddables support palettes?Checklist
Delete any items that are not applicable to this PR.
For maintainers