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

[Expressions Plugin] Allow render definitions with extended IInterpreterRenderHandlers #74133

Closed
crob611 opened this issue Aug 3, 2020 · 8 comments
Labels
enhancement New value added to drive a business result Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort triage_needed

Comments

@crob611
Copy link
Contributor

crob611 commented Aug 3, 2020

Canvas was trying to type all of our render definitions, but we have some extra handlers that we define to extend IInterpreterRenderHandlers.

Defining our renderers with a render function with the handlers typed to our HandlerType causes a type error when trying to add to the registry due to those handlers being mismatched with the IInterpreterRenderHandlers.

Is there a way to relax the type on ExpressionRenderDefinition to allow additional handlers? Or is there a different way we should be going about adding additional handlers?

@elasticmachine
Copy link
Contributor

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

@lukeelmers
Copy link
Member

We could consider adding an optional type parameter to ExpressionRenderDefinition to take in custom render handlers:

interface MyHandlers extends IInterpreterRenderHandlers {
  hello: () => void;
}

const myRenderer: ExpressionRenderDefinition<Config, MyHandlers> = {};

The generic ExpressionRenderDefinition would enforce that the provided handlers extend IInterpreterRenderHandlers.

Would that work for you @crob611? AFAICT this shouldn't be a problem, but would need to test it.

@crob611
Copy link
Contributor Author

crob611 commented Aug 3, 2020

I experimented with that. The problem I hit then was at the ExpressionRenderRegistry level. register function is expecting a definition of type AnyExpressionRenderDefinition, so hits the same problem. If you don't give it a generic and it defaults to IInterpreterRenderHandlers then the Canvas Handlers don't match the expected signature.

I didn't dig much after that and just bailed things on our end and explicitly casted our stuff to AnyExpressionDefinition.

I'm starting to think maybe handlers isn't the correct place for us to add additional handler functionality?

@lukeelmers
Copy link
Member

Ah, I had missed that. So in that case we'd also need to make AnyExpressionRenderDefinition be ExpressionRenderDefinition<any, any>. This would be consistent with how we have handled the typings for registering functions & types.

@lukeelmers
Copy link
Member

I'm starting to think maybe handlers isn't the correct place for us to add additional handler functionality?

Yeah, @ppisljar and I talked about this a bit and I believe he's planning to follow up with some thoughts on how to address what you are looking to do.

@crob611
Copy link
Contributor Author

crob611 commented Aug 7, 2020

Just for reference: We create the handlers that we pass into the render functions in create_handlers.ts We just have empty stubs for most of the methods defined by IInterpreterRegisterHandlers

We pass them through to the render function in render_with_fn

@ppisljar
Copy link
Member

The reason we didn't allow extending the handlers definition is that we need a fixed (agreed upon) set of handlers that every renderer consumes as else the renderers are not usable outside of specific context. If we don't know what handlers the specific renderer requires its impossible to consume it.

I opened an issue for addressing the current extra handlers that canvas is passing into expressions here: #74644

i think we should try to address that as soon as possible. I think reusability is one of the main advantages of expressions and we should really try hard to make all functions and renderers reusable.

@streamich streamich added enhancement New value added to drive a business result Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. triage_needed labels May 4, 2021
@petrklapka petrklapka added 1 and removed 1 labels May 10, 2021
@exalate-issue-sync exalate-issue-sync bot added impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort and removed impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. labels May 13, 2021
@ppisljar
Copy link
Member

closing this in favor of #74644

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:ExpressionLanguage Interpreter expression language (aka canvas pipeline) impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort triage_needed
Projects
None yet
Development

No branches or pull requests

6 participants