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

[Canvas] Generic embeddable function #104499

Conversation

cqliu1
Copy link
Contributor

@cqliu1 cqliu1 commented Jul 6, 2021

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 object
  • type: the embeddable type

Example expression:

embeddable config="eyJ2aWV3TW9kZSI6ImVkaXQiLCJ0aW1lUmFuZ2UiOnsiZnJvbSI6Im5vdy0xNWQiLCJ0byI6Im5vdyJ9LCJkaXNhYmxlVHJpZ2dlcnMiOnRydWUsInJlbmRlck1vZGUiOiJub0ludGVyYWN0aXZpdHkiLCJpZCI6IjJjOWMxZjYwLTE5MDktMTFlOS05MTliLWZmZTU5NDlhMThkMiIsImZpbHRlcnMiOltdLCJzYXZlZE9iamVjdElkIjoiMmM5YzFmNjAtMTkwOS0xMWU5LTkxOWItZmZlNTk0OWExOGQyIiwibWFwQ2VudGVyIjp7ImxhdCI6NTcuNTgyNDYsImxvbiI6LTExMi43NjM2Nywiem9vbSI6Mi4xMX0sIm1hcEJ1ZmZlciI6eyJtaW5Mb24iOi0xODAsIm1pbkxhdCI6MCwibWF4TG9uIjotNDUsIm1heExhdCI6NzkuMTcxMzN9LCJpc0xheWVyVE9DT3BlbiI6ZmFsc2UsIm9wZW5UT0NEZXRhaWxzIjpbXSwiaGlkZGVuTGF5ZXJzIjpbIjdhbWVxIl19" 
  type="map"
| render

Changes:

  • adds lab config for by-value embeddables and updates telemetry schema
  • adds embeddable function that serves as a generic version of savedMap, savedVisualizations, etc
  • adds support for savedSearch embeddable type via generic embeddable function
  • updates expression with changes to base embeddable input like time range, title, etc

Known Issues:

  • This function doesn't support palettes which are supported by Lens. Do we want to support palettes with this generic function if not all embeddables support palettes?
  • Input controls embeddables don't work in Canvas because filters can't be applied by embeddables currently

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cqliu1 cqliu1 changed the title [Canvas] Generic embeddable function [Canvas] [POC] Generic embeddable function Jul 6, 2021
@cqliu1 cqliu1 force-pushed the canvas/generic-embeddable-fn branch 2 times, most recently from f588bc7 to 2150ef8 Compare July 30, 2021 18:00
@cqliu1 cqliu1 changed the title [Canvas] [POC] Generic embeddable function [Canvas] Generic embeddable function Jul 30, 2021
@cqliu1 cqliu1 added Feature:Canvas Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v7.15.0 v8.0.0 impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort enhancement New value added to drive a business result release_note:skip Skip the PR/issue when compiling release notes labels Jul 30, 2021
@cqliu1 cqliu1 marked this pull request as ready for review July 30, 2021 19:58
@cqliu1 cqliu1 requested a review from a team as a code owner July 30, 2021 19:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@cqliu1 cqliu1 added the review label Jul 30, 2021
@cqliu1 cqliu1 requested a review from a team as a code owner August 3, 2021 14:33
@cqliu1 cqliu1 force-pushed the canvas/generic-embeddable-fn branch from f84c1f3 to 910d8eb Compare August 3, 2021 14:35
@cqliu1 cqliu1 requested a review from a team as a code owner August 3, 2021 15:43
@cqliu1 cqliu1 changed the base branch from master to canvas/by-value-embeddables August 3, 2021 17:02
@cqliu1 cqliu1 closed this Aug 3, 2021
@cqliu1 cqliu1 force-pushed the canvas/generic-embeddable-fn branch from d3d9d1e to 14f66b5 Compare August 3, 2021 17:10
@cqliu1 cqliu1 reopened this Aug 3, 2021
@cqliu1 cqliu1 force-pushed the canvas/generic-embeddable-fn branch 3 times, most recently from 1093d6d to 199a5f4 Compare August 3, 2021 19:08
@cqliu1
Copy link
Contributor Author

cqliu1 commented Aug 5, 2021

@elasticmachine merge upstream

const partialElement = {
expression: `markdown "Could not find embeddable for type ${type}" | render`,
};
if (allowedEmbeddables[type]) {

if (isByValueEnabled) {
Copy link
Contributor

@poffdeluxe poffdeluxe Sep 28, 2021

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?

Copy link
Contributor Author

@cqliu1 cqliu1 Sep 28, 2021

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.

Copy link
Contributor

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

Copy link
Contributor

@poffdeluxe poffdeluxe left a 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)

Copy link
Contributor

@crob611 crob611 left a 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@cqliu1 cqliu1 Sep 29, 2021

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) {
Copy link
Contributor

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');
Copy link
Contributor

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

https:/elastic/kibana/pull/104499/files#diff-9aab885adf620bf919f3fad7f54143c060854b29a0a780272e45701aab457821R64

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.

Copy link
Contributor Author

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.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@cqliu1 cqliu1 merged commit 3650aea into elastic:canvas/by-value-embeddables Oct 1, 2021
@cqliu1 cqliu1 deleted the canvas/generic-embeddable-fn branch October 1, 2021 17:55
cqliu1 added a commit that referenced this pull request Oct 3, 2021
* 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
@cqliu1 cqliu1 mentioned this pull request Oct 4, 2021
11 tasks
cqliu1 added a commit that referenced this pull request Oct 5, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 5, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 12, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 15, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 15, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 18, 2021
* 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
cqliu1 added a commit to cqliu1/kibana that referenced this pull request Oct 19, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 19, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 20, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 20, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 25, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 25, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 26, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 26, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 27, 2021
* [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 <[email protected]>
cqliu1 added a commit that referenced this pull request Oct 28, 2021
* 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
cqliu1 added a commit that referenced this pull request Oct 28, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Canvas impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort release_note:skip Skip the PR/issue when compiling release notes review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants